blob: d2edf74c81216d1d5e473080d785900be772858e [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);
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001134 if (numfields == -1) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001135 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001136 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001137 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001138
Neal Norwitz207c9f32008-03-31 04:42:11 +00001139 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001140 if (numfields < PyTuple_GET_SIZE(args)) {
1141 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1142 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001143 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001144 numfields, numfields == 1 ? "" : "s");
1145 res = -1;
1146 goto cleanup;
1147 }
1148 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1149 /* cannot be reached when fields is NULL */
1150 PyObject *name = PySequence_GetItem(fields, i);
1151 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001152 res = -1;
1153 goto cleanup;
1154 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001155 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1156 Py_DECREF(name);
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001157 if (res < 0) {
INADA Naoki4c78c522017-02-24 02:48:17 +09001158 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001159 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001160 }
1161 if (kw) {
1162 i = 0; /* needed by PyDict_Next */
1163 while (PyDict_Next(kw, &i, &key, &value)) {
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001164 int contains = PySequence_Contains(fields, key);
1165 if (contains == -1) {
1166 res = -1;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001167 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001168 } else if (contains == 1) {
1169 Py_ssize_t p = PySequence_Index(fields, key);
1170 if (p == -1) {
1171 res = -1;
1172 goto cleanup;
1173 }
1174 if (p < PyTuple_GET_SIZE(args)) {
1175 PyErr_Format(PyExc_TypeError,
1176 "%.400s got multiple values for argument '%U'",
1177 Py_TYPE(self)->tp_name, key);
1178 res = -1;
1179 goto cleanup;
1180 }
1181 }
1182 res = PyObject_SetAttr(self, key, value);
1183 if (res < 0) {
1184 goto cleanup;
1185 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001186 }
1187 }
1188 cleanup:
1189 Py_XDECREF(fields);
1190 return res;
1191}
1192
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001193/* Pickling support */
1194static PyObject *
1195ast_type_reduce(PyObject *self, PyObject *unused)
1196{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001197 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001198 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001199 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001200 }
1201 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001202 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001203 }
1204 return Py_BuildValue("O()", Py_TYPE(self));
1205}
1206
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001207static PyMemberDef ast_type_members[] = {
1208 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1209 {NULL} /* Sentinel */
1210};
1211
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001212static PyMethodDef ast_type_methods[] = {
1213 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1214 {NULL}
1215};
1216
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001217static PyGetSetDef ast_type_getsets[] = {
1218 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1219 {NULL}
1220};
1221
Dino Viehlandac46eb42019-09-11 10:16:34 -07001222static PyType_Slot AST_type_slots[] = {
1223 {Py_tp_dealloc, ast_dealloc},
1224 {Py_tp_getattro, PyObject_GenericGetAttr},
1225 {Py_tp_setattro, PyObject_GenericSetAttr},
1226 {Py_tp_traverse, ast_traverse},
1227 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001228 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001229 {Py_tp_methods, ast_type_methods},
1230 {Py_tp_getset, ast_type_getsets},
1231 {Py_tp_init, ast_type_init},
1232 {Py_tp_alloc, PyType_GenericAlloc},
1233 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001234 {Py_tp_free, PyObject_GC_Del},
1235 {0, 0},
1236};
1237
1238static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001239 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001240 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001241 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001242 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1243 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001244};
1245
Dino Viehlandac46eb42019-09-11 10:16:34 -07001246static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001247make_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 +00001248{
1249 PyObject *fnames, *result;
1250 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001251 fnames = PyTuple_New(num_fields);
1252 if (!fnames) return NULL;
1253 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001254 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001255 if (!field) {
1256 Py_DECREF(fnames);
1257 return NULL;
1258 }
1259 PyTuple_SET_ITEM(fnames, i, field);
1260 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001261 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001262 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001263 astmodulestate_global->_fields, fnames,
1264 astmodulestate_global->__module__,
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001265 astmodulestate_global->ast,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001266 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001267 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001268 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001269}
1270
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001271static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001272add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001273{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001274 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001275 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001276 if (!l)
1277 return 0;
1278 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001279 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001280 if (!s) {
1281 Py_DECREF(l);
1282 return 0;
1283 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001284 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001285 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001286 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001287 Py_DECREF(l);
1288 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001289}
1290
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001291/* Conversion AST -> Python */
1292
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001293static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1294{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001295 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001296 PyObject *result = PyList_New(n);
1297 PyObject *value;
1298 if (!result)
1299 return NULL;
1300 for (i = 0; i < n; i++) {
1301 value = func(asdl_seq_GET(seq, i));
1302 if (!value) {
1303 Py_DECREF(result);
1304 return NULL;
1305 }
1306 PyList_SET_ITEM(result, i, value);
1307 }
1308 return result;
1309}
1310
1311static PyObject* ast2obj_object(void *o)
1312{
1313 if (!o)
1314 o = Py_None;
1315 Py_INCREF((PyObject*)o);
1316 return (PyObject*)o;
1317}
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001318#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001319#define ast2obj_identifier ast2obj_object
1320#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001321
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001322static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001323{
Christian Heimes217cfd12007-12-02 14:31:20 +00001324 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001325}
1326
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001327/* Conversion Python -> AST */
1328
1329static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1330{
1331 if (obj == Py_None)
1332 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001333 if (obj) {
1334 if (PyArena_AddPyObject(arena, obj) < 0) {
1335 *out = NULL;
1336 return -1;
1337 }
1338 Py_INCREF(obj);
1339 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001340 *out = obj;
1341 return 0;
1342}
1343
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001344static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1345{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001346 if (PyArena_AddPyObject(arena, obj) < 0) {
1347 *out = NULL;
1348 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001349 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001350 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001351 *out = obj;
1352 return 0;
1353}
1354
Benjamin Peterson180e6352011-07-22 11:09:07 -05001355static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001356{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001357 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1358 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001359 return 1;
1360 }
1361 return obj2ast_object(obj, out, arena);
1362}
1363
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001364static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1365{
1366 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1367 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1368 return 1;
1369 }
1370 return obj2ast_object(obj, out, arena);
1371}
1372
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001373static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1374{
1375 int i;
1376 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001377 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001378 return 1;
1379 }
1380
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001381 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001382 if (i == -1 && PyErr_Occurred())
1383 return 1;
1384 *out = i;
1385 return 0;
1386}
1387
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001388static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001389{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001390 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001391 empty_tuple = PyTuple_New(0);
1392 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001393 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1394 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001395 Py_XDECREF(empty_tuple);
1396 return -1;
1397 }
1398 Py_DECREF(empty_tuple);
1399 return 0;
1400}
1401
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001402
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001403static int init_types(void)
1404{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001405 PyObject *m;
1406 if (PyState_FindModule(&_astmodule) == NULL) {
1407 m = PyModule_Create(&_astmodule);
1408 if (!m) return 0;
1409 PyState_AddModule(m, &_astmodule);
1410 }
1411 astmodulestate *state = astmodulestate_global;
1412 if (state->initialized) return 1;
1413 if (init_identifiers() < 0) return 0;
1414 state->AST_type = PyType_FromSpec(&AST_type_spec);
1415 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001416 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001417 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1418 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1419 " | Interactive(stmt* body)\n"
1420 " | Expression(expr body)\n"
1421 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001422 if (!state->mod_type) return 0;
1423 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001424 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1425 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001426 if (!state->Module_type) return 0;
1427 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001428 Interactive_fields, 1,
1429 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001430 if (!state->Interactive_type) return 0;
1431 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001432 Expression_fields, 1,
1433 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001434 if (!state->Expression_type) return 0;
1435 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001436 FunctionType_fields, 2,
1437 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001438 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001439 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1440 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1441 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1442 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1443 " | Return(expr? value)\n"
1444 " | Delete(expr* targets)\n"
1445 " | Assign(expr* targets, expr value, string? type_comment)\n"
1446 " | AugAssign(expr target, operator op, expr value)\n"
1447 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1448 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1449 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1450 " | While(expr test, stmt* body, stmt* orelse)\n"
1451 " | If(expr test, stmt* body, stmt* orelse)\n"
1452 " | With(withitem* items, stmt* body, string? type_comment)\n"
1453 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1454 " | Raise(expr? exc, expr? cause)\n"
1455 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1456 " | Assert(expr test, expr? msg)\n"
1457 " | Import(alias* names)\n"
1458 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1459 " | Global(identifier* names)\n"
1460 " | Nonlocal(identifier* names)\n"
1461 " | Expr(expr value)\n"
1462 " | Pass\n"
1463 " | Break\n"
1464 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001465 if (!state->stmt_type) return 0;
1466 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001467 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1468 return 0;
1469 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1470 -1)
1471 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001472 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001473 FunctionDef_fields, 6,
1474 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001475 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001476 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1477 -1)
1478 return 0;
1479 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1480 == -1)
1481 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001482 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1483 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001484 AsyncFunctionDef_fields, 6,
1485 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001486 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001487 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1488 == -1)
1489 return 0;
1490 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1491 Py_None) == -1)
1492 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001493 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001494 ClassDef_fields, 5,
1495 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001496 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001497 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1498 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001499 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001500 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1501 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001502 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1503 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001504 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001505 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1506 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001507 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001508 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1509 -1)
1510 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001511 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001512 AugAssign_fields, 3,
1513 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001514 if (!state->AugAssign_type) return 0;
1515 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001516 AnnAssign_fields, 4,
1517 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001518 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001519 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1520 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001521 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1522 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001523 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001524 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1525 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001526 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001527 AsyncFor_fields, 5,
1528 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001529 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001530 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1531 -1)
1532 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001533 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1534 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001535 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001536 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1537 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001538 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001539 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1540 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001541 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001542 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1543 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001544 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001545 AsyncWith_fields, 3,
1546 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001547 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001548 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1549 == -1)
1550 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001551 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1552 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001553 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001554 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1555 return 0;
1556 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1557 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001558 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1559 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001560 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001561 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1562 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001563 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001564 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1565 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001566 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1567 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001568 if (!state->Import_type) return 0;
1569 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001570 ImportFrom_fields, 3,
1571 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001572 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001573 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1574 return 0;
1575 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1576 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001577 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1578 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001579 if (!state->Global_type) return 0;
1580 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001581 Nonlocal_fields, 1,
1582 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001583 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001584 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1585 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001586 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001587 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1588 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001589 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001590 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1591 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001592 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001593 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1594 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001595 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001596 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1597 "expr = BoolOp(boolop op, expr* values)\n"
1598 " | NamedExpr(expr target, expr value)\n"
1599 " | BinOp(expr left, operator op, expr right)\n"
1600 " | UnaryOp(unaryop op, expr operand)\n"
1601 " | Lambda(arguments args, expr body)\n"
1602 " | IfExp(expr test, expr body, expr orelse)\n"
1603 " | Dict(expr* keys, expr* values)\n"
1604 " | Set(expr* elts)\n"
1605 " | ListComp(expr elt, comprehension* generators)\n"
1606 " | SetComp(expr elt, comprehension* generators)\n"
1607 " | DictComp(expr key, expr value, comprehension* generators)\n"
1608 " | GeneratorExp(expr elt, comprehension* generators)\n"
1609 " | Await(expr value)\n"
1610 " | Yield(expr? value)\n"
1611 " | YieldFrom(expr value)\n"
1612 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1613 " | Call(expr func, expr* args, keyword* keywords)\n"
1614 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1615 " | JoinedStr(expr* values)\n"
1616 " | Constant(constant value, string? kind)\n"
1617 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1618 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1619 " | Starred(expr value, expr_context ctx)\n"
1620 " | Name(identifier id, expr_context ctx)\n"
1621 " | List(expr* elts, expr_context ctx)\n"
1622 " | Tuple(expr* elts, expr_context ctx)\n"
1623 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001624 if (!state->expr_type) return 0;
1625 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001626 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1627 return 0;
1628 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1629 -1)
1630 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001631 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1632 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001633 if (!state->BoolOp_type) return 0;
1634 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001635 NamedExpr_fields, 2,
1636 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001637 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001638 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1639 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001640 if (!state->BinOp_type) return 0;
1641 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001642 UnaryOp_fields, 2,
1643 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001644 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001645 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1646 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001647 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001648 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1649 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001650 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001651 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1652 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001653 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001654 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1655 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001656 if (!state->Set_type) return 0;
1657 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001658 ListComp_fields, 2,
1659 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001660 if (!state->ListComp_type) return 0;
1661 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001662 SetComp_fields, 2,
1663 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001664 if (!state->SetComp_type) return 0;
1665 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001666 DictComp_fields, 3,
1667 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001668 if (!state->DictComp_type) return 0;
1669 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001670 GeneratorExp_fields, 2,
1671 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001672 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001673 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1674 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001675 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001676 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1677 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001678 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001679 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1680 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001681 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001682 YieldFrom_fields, 1,
1683 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001684 if (!state->YieldFrom_type) return 0;
1685 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001686 Compare_fields, 3,
1687 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001688 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001689 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1690 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001691 if (!state->Call_type) return 0;
1692 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001693 FormattedValue_fields, 3,
1694 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001695 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001696 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1697 Py_None) == -1)
1698 return 0;
1699 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1700 Py_None) == -1)
1701 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001702 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001703 JoinedStr_fields, 1,
1704 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001705 if (!state->JoinedStr_type) return 0;
1706 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001707 Constant_fields, 2,
1708 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001709 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001710 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1711 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001712 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001713 Attribute_fields, 3,
1714 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001715 if (!state->Attribute_type) return 0;
1716 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001717 Subscript_fields, 3,
1718 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001719 if (!state->Subscript_type) return 0;
1720 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001721 Starred_fields, 2,
1722 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001723 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001724 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1725 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001726 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001727 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1728 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001729 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001730 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1731 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001732 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001733 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1734 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001735 if (!state->Slice_type) return 0;
1736 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1737 return 0;
1738 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1739 return 0;
1740 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1741 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001742 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001743 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001744 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001745 if (!state->expr_context_type) return 0;
1746 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001747 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1748 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001749 if (!state->Load_type) return 0;
1750 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1751 NULL, NULL);
1752 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001753 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1754 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001755 if (!state->Store_type) return 0;
1756 state->Store_singleton = PyType_GenericNew((PyTypeObject
1757 *)state->Store_type, NULL, NULL);
1758 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001759 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1760 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001761 if (!state->Del_type) return 0;
1762 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1763 NULL, NULL);
1764 if (!state->Del_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001765 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1766 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001767 if (!state->boolop_type) return 0;
1768 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001769 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1770 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001771 if (!state->And_type) return 0;
1772 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1773 NULL, NULL);
1774 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001775 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1776 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001777 if (!state->Or_type) return 0;
1778 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1779 NULL, NULL);
1780 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001781 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1782 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001783 if (!state->operator_type) return 0;
1784 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001785 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1786 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001787 if (!state->Add_type) return 0;
1788 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1789 NULL, NULL);
1790 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001791 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1792 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001793 if (!state->Sub_type) return 0;
1794 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1795 NULL, NULL);
1796 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001797 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1798 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001799 if (!state->Mult_type) return 0;
1800 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1801 NULL, NULL);
1802 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001803 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1804 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001805 if (!state->MatMult_type) return 0;
1806 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1807 *)state->MatMult_type, NULL,
1808 NULL);
1809 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001810 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1811 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001812 if (!state->Div_type) return 0;
1813 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1814 NULL, NULL);
1815 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001816 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1817 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001818 if (!state->Mod_type) return 0;
1819 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1820 NULL, NULL);
1821 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001822 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1823 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001824 if (!state->Pow_type) return 0;
1825 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1826 NULL, NULL);
1827 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001828 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1829 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001830 if (!state->LShift_type) return 0;
1831 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1832 *)state->LShift_type, NULL,
1833 NULL);
1834 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001835 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1836 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001837 if (!state->RShift_type) return 0;
1838 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1839 *)state->RShift_type, NULL,
1840 NULL);
1841 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001842 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1843 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001844 if (!state->BitOr_type) return 0;
1845 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1846 *)state->BitOr_type, NULL, NULL);
1847 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001848 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1849 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001850 if (!state->BitXor_type) return 0;
1851 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1852 *)state->BitXor_type, NULL,
1853 NULL);
1854 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001855 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1856 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001857 if (!state->BitAnd_type) return 0;
1858 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1859 *)state->BitAnd_type, NULL,
1860 NULL);
1861 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001862 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1863 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001864 if (!state->FloorDiv_type) return 0;
1865 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1866 *)state->FloorDiv_type, NULL,
1867 NULL);
1868 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001869 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1870 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001871 if (!state->unaryop_type) return 0;
1872 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001873 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1874 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001875 if (!state->Invert_type) return 0;
1876 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1877 *)state->Invert_type, NULL,
1878 NULL);
1879 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001880 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1881 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001882 if (!state->Not_type) return 0;
1883 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1884 NULL, NULL);
1885 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001886 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1887 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001888 if (!state->UAdd_type) return 0;
1889 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1890 NULL, NULL);
1891 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001892 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1893 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001894 if (!state->USub_type) return 0;
1895 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1896 NULL, NULL);
1897 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001898 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1899 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001900 if (!state->cmpop_type) return 0;
1901 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001902 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1903 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001904 if (!state->Eq_type) return 0;
1905 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1906 NULL, NULL);
1907 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001908 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1909 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001910 if (!state->NotEq_type) return 0;
1911 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1912 *)state->NotEq_type, NULL, NULL);
1913 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001914 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1915 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001916 if (!state->Lt_type) return 0;
1917 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1918 NULL, NULL);
1919 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001920 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1921 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001922 if (!state->LtE_type) return 0;
1923 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1924 NULL, NULL);
1925 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001926 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1927 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001928 if (!state->Gt_type) return 0;
1929 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1930 NULL, NULL);
1931 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001932 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1933 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001934 if (!state->GtE_type) return 0;
1935 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1936 NULL, NULL);
1937 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001938 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1939 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001940 if (!state->Is_type) return 0;
1941 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1942 NULL, NULL);
1943 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001944 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1945 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001946 if (!state->IsNot_type) return 0;
1947 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1948 *)state->IsNot_type, NULL, NULL);
1949 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001950 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1951 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001952 if (!state->In_type) return 0;
1953 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1954 NULL, NULL);
1955 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001956 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1957 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001958 if (!state->NotIn_type) return 0;
1959 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1960 *)state->NotIn_type, NULL, NULL);
1961 if (!state->NotIn_singleton) return 0;
1962 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001963 comprehension_fields, 4,
1964 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001965 if (!state->comprehension_type) return 0;
1966 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1967 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001968 NULL, 0,
1969 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001970 if (!state->excepthandler_type) return 0;
1971 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1972 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001973 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1974 == -1)
1975 return 0;
1976 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1977 Py_None) == -1)
1978 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001979 state->ExceptHandler_type = make_type("ExceptHandler",
1980 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001981 ExceptHandler_fields, 3,
1982 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001983 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001984 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1985 return 0;
1986 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1987 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001988 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001989 arguments_fields, 7,
1990 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001991 if (!state->arguments_type) return 0;
1992 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001993 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1994 return 0;
1995 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1996 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001997 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
1998 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001999 if (!state->arg_type) return 0;
2000 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002001 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
2002 return 0;
2003 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
2004 return 0;
2005 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
2006 return 0;
2007 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
2008 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002009 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002010 2,
2011 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002012 if (!state->keyword_type) return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01002013 if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002014 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
2015 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01002016 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
2017 return 0;
2018 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
2019 == -1)
2020 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002021 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
2022 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002023 if (!state->alias_type) return 0;
2024 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002025 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
2026 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002027 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002028 withitem_fields, 2,
2029 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002030 if (!state->withitem_type) return 0;
2031 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002032 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2033 == -1)
2034 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002035 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2036 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002037 if (!state->type_ignore_type) return 0;
2038 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2039 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002040 TypeIgnore_fields, 2,
2041 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002042 if (!state->TypeIgnore_type) return 0;
2043 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002044 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002045}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002046
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002047static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2048static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2049static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2050static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2051 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002052static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2053static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2054static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2055static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2056static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2057 arena);
2058static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2059 arena);
2060static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2061static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2062static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2063static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002064static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002065static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2066 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002067
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002068mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002069Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002070{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002071 mod_ty p;
2072 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2073 if (!p)
2074 return NULL;
2075 p->kind = Module_kind;
2076 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002077 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002078 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002079}
2080
2081mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002082Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002083{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002084 mod_ty p;
2085 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2086 if (!p)
2087 return NULL;
2088 p->kind = Interactive_kind;
2089 p->v.Interactive.body = body;
2090 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002091}
2092
2093mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002094Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002095{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002096 mod_ty p;
2097 if (!body) {
2098 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002099 "field 'body' is required for Expression");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002100 return NULL;
2101 }
2102 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2103 if (!p)
2104 return NULL;
2105 p->kind = Expression_kind;
2106 p->v.Expression.body = body;
2107 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002108}
2109
2110mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002111FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2112{
2113 mod_ty p;
2114 if (!returns) {
2115 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002116 "field 'returns' is required for FunctionType");
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002117 return NULL;
2118 }
2119 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2120 if (!p)
2121 return NULL;
2122 p->kind = FunctionType_kind;
2123 p->v.FunctionType.argtypes = argtypes;
2124 p->v.FunctionType.returns = returns;
2125 return p;
2126}
2127
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002128stmt_ty
2129FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002130 decorator_list, expr_ty returns, string type_comment, int lineno,
2131 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002132{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002133 stmt_ty p;
2134 if (!name) {
2135 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002136 "field 'name' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002137 return NULL;
2138 }
2139 if (!args) {
2140 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002141 "field 'args' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002142 return NULL;
2143 }
2144 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2145 if (!p)
2146 return NULL;
2147 p->kind = FunctionDef_kind;
2148 p->v.FunctionDef.name = name;
2149 p->v.FunctionDef.args = args;
2150 p->v.FunctionDef.body = body;
2151 p->v.FunctionDef.decorator_list = decorator_list;
2152 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002153 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002154 p->lineno = lineno;
2155 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002156 p->end_lineno = end_lineno;
2157 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002158 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002159}
2160
2161stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002162AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002163 * decorator_list, expr_ty returns, string type_comment, int
2164 lineno, int col_offset, int end_lineno, int end_col_offset,
2165 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002166{
2167 stmt_ty p;
2168 if (!name) {
2169 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002170 "field 'name' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002171 return NULL;
2172 }
2173 if (!args) {
2174 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002175 "field 'args' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002176 return NULL;
2177 }
2178 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2179 if (!p)
2180 return NULL;
2181 p->kind = AsyncFunctionDef_kind;
2182 p->v.AsyncFunctionDef.name = name;
2183 p->v.AsyncFunctionDef.args = args;
2184 p->v.AsyncFunctionDef.body = body;
2185 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2186 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002187 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002188 p->lineno = lineno;
2189 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002190 p->end_lineno = end_lineno;
2191 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002192 return p;
2193}
2194
2195stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002196ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002197 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2198 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002200 stmt_ty p;
2201 if (!name) {
2202 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002203 "field 'name' is required for ClassDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002204 return NULL;
2205 }
2206 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2207 if (!p)
2208 return NULL;
2209 p->kind = ClassDef_kind;
2210 p->v.ClassDef.name = name;
2211 p->v.ClassDef.bases = bases;
2212 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002213 p->v.ClassDef.body = body;
2214 p->v.ClassDef.decorator_list = decorator_list;
2215 p->lineno = lineno;
2216 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002217 p->end_lineno = end_lineno;
2218 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002219 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220}
2221
2222stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002223Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2224 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002225{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002226 stmt_ty p;
2227 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2228 if (!p)
2229 return NULL;
2230 p->kind = Return_kind;
2231 p->v.Return.value = value;
2232 p->lineno = lineno;
2233 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002234 p->end_lineno = end_lineno;
2235 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002236 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002237}
2238
2239stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002240Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2241 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002242{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002243 stmt_ty p;
2244 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2245 if (!p)
2246 return NULL;
2247 p->kind = Delete_kind;
2248 p->v.Delete.targets = targets;
2249 p->lineno = lineno;
2250 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002251 p->end_lineno = end_lineno;
2252 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002253 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002254}
2255
2256stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002257Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2258 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002260 stmt_ty p;
2261 if (!value) {
2262 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002263 "field 'value' is required for Assign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002264 return NULL;
2265 }
2266 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2267 if (!p)
2268 return NULL;
2269 p->kind = Assign_kind;
2270 p->v.Assign.targets = targets;
2271 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002272 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002273 p->lineno = lineno;
2274 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002275 p->end_lineno = end_lineno;
2276 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002277 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002278}
2279
2280stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002281AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002282 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002283{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002284 stmt_ty p;
2285 if (!target) {
2286 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002287 "field 'target' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002288 return NULL;
2289 }
2290 if (!op) {
2291 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002292 "field 'op' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002293 return NULL;
2294 }
2295 if (!value) {
2296 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002297 "field 'value' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002298 return NULL;
2299 }
2300 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2301 if (!p)
2302 return NULL;
2303 p->kind = AugAssign_kind;
2304 p->v.AugAssign.target = target;
2305 p->v.AugAssign.op = op;
2306 p->v.AugAssign.value = value;
2307 p->lineno = lineno;
2308 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002309 p->end_lineno = end_lineno;
2310 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002311 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002312}
2313
2314stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002315AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002316 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2317 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002318{
2319 stmt_ty p;
2320 if (!target) {
2321 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002322 "field 'target' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002323 return NULL;
2324 }
2325 if (!annotation) {
2326 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002327 "field 'annotation' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002328 return NULL;
2329 }
2330 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2331 if (!p)
2332 return NULL;
2333 p->kind = AnnAssign_kind;
2334 p->v.AnnAssign.target = target;
2335 p->v.AnnAssign.annotation = annotation;
2336 p->v.AnnAssign.value = value;
2337 p->v.AnnAssign.simple = simple;
2338 p->lineno = lineno;
2339 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002340 p->end_lineno = end_lineno;
2341 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002342 return p;
2343}
2344
2345stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002346For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2347 type_comment, int lineno, int col_offset, int end_lineno, int
2348 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002349{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002350 stmt_ty p;
2351 if (!target) {
2352 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002353 "field 'target' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002354 return NULL;
2355 }
2356 if (!iter) {
2357 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002358 "field 'iter' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002359 return NULL;
2360 }
2361 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2362 if (!p)
2363 return NULL;
2364 p->kind = For_kind;
2365 p->v.For.target = target;
2366 p->v.For.iter = iter;
2367 p->v.For.body = body;
2368 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002369 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002370 p->lineno = lineno;
2371 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002372 p->end_lineno = end_lineno;
2373 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002374 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375}
2376
2377stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002378AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2379 string type_comment, int lineno, int col_offset, int end_lineno, int
2380 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002381{
2382 stmt_ty p;
2383 if (!target) {
2384 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002385 "field 'target' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002386 return NULL;
2387 }
2388 if (!iter) {
2389 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002390 "field 'iter' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002391 return NULL;
2392 }
2393 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2394 if (!p)
2395 return NULL;
2396 p->kind = AsyncFor_kind;
2397 p->v.AsyncFor.target = target;
2398 p->v.AsyncFor.iter = iter;
2399 p->v.AsyncFor.body = body;
2400 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002401 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002402 p->lineno = lineno;
2403 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002404 p->end_lineno = end_lineno;
2405 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002406 return p;
2407}
2408
2409stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002410While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002411 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002412{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002413 stmt_ty p;
2414 if (!test) {
2415 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002416 "field 'test' is required for While");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002417 return NULL;
2418 }
2419 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2420 if (!p)
2421 return NULL;
2422 p->kind = While_kind;
2423 p->v.While.test = test;
2424 p->v.While.body = body;
2425 p->v.While.orelse = orelse;
2426 p->lineno = lineno;
2427 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002428 p->end_lineno = end_lineno;
2429 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002430 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002431}
2432
2433stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002434If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002435 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002437 stmt_ty p;
2438 if (!test) {
2439 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002440 "field 'test' is required for If");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002441 return NULL;
2442 }
2443 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2444 if (!p)
2445 return NULL;
2446 p->kind = If_kind;
2447 p->v.If.test = test;
2448 p->v.If.body = body;
2449 p->v.If.orelse = orelse;
2450 p->lineno = lineno;
2451 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002452 p->end_lineno = end_lineno;
2453 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002454 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455}
2456
2457stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002458With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2459 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002460{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002461 stmt_ty p;
2462 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2463 if (!p)
2464 return NULL;
2465 p->kind = With_kind;
2466 p->v.With.items = items;
2467 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002468 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002469 p->lineno = lineno;
2470 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002471 p->end_lineno = end_lineno;
2472 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002473 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002474}
2475
2476stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002477AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2478 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002479{
2480 stmt_ty p;
2481 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2482 if (!p)
2483 return NULL;
2484 p->kind = AsyncWith_kind;
2485 p->v.AsyncWith.items = items;
2486 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002487 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002488 p->lineno = lineno;
2489 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002490 p->end_lineno = end_lineno;
2491 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002492 return p;
2493}
2494
2495stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002496Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2497 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002498{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002499 stmt_ty p;
2500 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2501 if (!p)
2502 return NULL;
2503 p->kind = Raise_kind;
2504 p->v.Raise.exc = exc;
2505 p->v.Raise.cause = cause;
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
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002514Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002515 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2516 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002518 stmt_ty p;
2519 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2520 if (!p)
2521 return NULL;
2522 p->kind = Try_kind;
2523 p->v.Try.body = body;
2524 p->v.Try.handlers = handlers;
2525 p->v.Try.orelse = orelse;
2526 p->v.Try.finalbody = finalbody;
2527 p->lineno = lineno;
2528 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002529 p->end_lineno = end_lineno;
2530 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002531 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002532}
2533
2534stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002535Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2536 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002537{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002538 stmt_ty p;
2539 if (!test) {
2540 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002541 "field 'test' is required for Assert");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002542 return NULL;
2543 }
2544 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2545 if (!p)
2546 return NULL;
2547 p->kind = Assert_kind;
2548 p->v.Assert.test = test;
2549 p->v.Assert.msg = msg;
2550 p->lineno = lineno;
2551 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002552 p->end_lineno = end_lineno;
2553 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002554 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002555}
2556
2557stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002558Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2559 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002560{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002561 stmt_ty p;
2562 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2563 if (!p)
2564 return NULL;
2565 p->kind = Import_kind;
2566 p->v.Import.names = names;
2567 p->lineno = lineno;
2568 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002569 p->end_lineno = end_lineno;
2570 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002571 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002572}
2573
2574stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002575ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002576 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002577{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002578 stmt_ty p;
2579 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2580 if (!p)
2581 return NULL;
2582 p->kind = ImportFrom_kind;
2583 p->v.ImportFrom.module = module;
2584 p->v.ImportFrom.names = names;
2585 p->v.ImportFrom.level = level;
2586 p->lineno = lineno;
2587 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002588 p->end_lineno = end_lineno;
2589 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002590 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002591}
2592
2593stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002594Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2595 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002596{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002597 stmt_ty p;
2598 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2599 if (!p)
2600 return NULL;
2601 p->kind = Global_kind;
2602 p->v.Global.names = names;
2603 p->lineno = lineno;
2604 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002605 p->end_lineno = end_lineno;
2606 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002607 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002608}
2609
2610stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002611Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2612 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002613{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002614 stmt_ty p;
2615 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2616 if (!p)
2617 return NULL;
2618 p->kind = Nonlocal_kind;
2619 p->v.Nonlocal.names = names;
2620 p->lineno = lineno;
2621 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002622 p->end_lineno = end_lineno;
2623 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002624 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002625}
2626
2627stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002628Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2629 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002630{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002631 stmt_ty p;
2632 if (!value) {
2633 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002634 "field 'value' is required for Expr");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002635 return NULL;
2636 }
2637 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2638 if (!p)
2639 return NULL;
2640 p->kind = Expr_kind;
2641 p->v.Expr.value = value;
2642 p->lineno = lineno;
2643 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002644 p->end_lineno = end_lineno;
2645 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002646 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647}
2648
2649stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002650Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2651 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002652{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002653 stmt_ty p;
2654 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2655 if (!p)
2656 return NULL;
2657 p->kind = Pass_kind;
2658 p->lineno = lineno;
2659 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002660 p->end_lineno = end_lineno;
2661 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002662 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002663}
2664
2665stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002666Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2667 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002668{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002669 stmt_ty p;
2670 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2671 if (!p)
2672 return NULL;
2673 p->kind = Break_kind;
2674 p->lineno = lineno;
2675 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002676 p->end_lineno = end_lineno;
2677 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002678 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002679}
2680
2681stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002682Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2683 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002684{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002685 stmt_ty p;
2686 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2687 if (!p)
2688 return NULL;
2689 p->kind = Continue_kind;
2690 p->lineno = lineno;
2691 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002692 p->end_lineno = end_lineno;
2693 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002694 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002695}
2696
2697expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002698BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2699 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002700{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002701 expr_ty p;
2702 if (!op) {
2703 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002704 "field 'op' is required for BoolOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002705 return NULL;
2706 }
2707 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2708 if (!p)
2709 return NULL;
2710 p->kind = BoolOp_kind;
2711 p->v.BoolOp.op = op;
2712 p->v.BoolOp.values = values;
2713 p->lineno = lineno;
2714 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002715 p->end_lineno = end_lineno;
2716 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002717 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002718}
2719
2720expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002721NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2722 end_lineno, int end_col_offset, PyArena *arena)
2723{
2724 expr_ty p;
2725 if (!target) {
2726 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002727 "field 'target' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002728 return NULL;
2729 }
2730 if (!value) {
2731 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002732 "field 'value' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002733 return NULL;
2734 }
2735 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2736 if (!p)
2737 return NULL;
2738 p->kind = NamedExpr_kind;
2739 p->v.NamedExpr.target = target;
2740 p->v.NamedExpr.value = value;
2741 p->lineno = lineno;
2742 p->col_offset = col_offset;
2743 p->end_lineno = end_lineno;
2744 p->end_col_offset = end_col_offset;
2745 return p;
2746}
2747
2748expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002749BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002750 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002751{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002752 expr_ty p;
2753 if (!left) {
2754 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002755 "field 'left' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002756 return NULL;
2757 }
2758 if (!op) {
2759 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002760 "field 'op' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002761 return NULL;
2762 }
2763 if (!right) {
2764 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002765 "field 'right' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002766 return NULL;
2767 }
2768 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2769 if (!p)
2770 return NULL;
2771 p->kind = BinOp_kind;
2772 p->v.BinOp.left = left;
2773 p->v.BinOp.op = op;
2774 p->v.BinOp.right = right;
2775 p->lineno = lineno;
2776 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002777 p->end_lineno = end_lineno;
2778 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002779 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002780}
2781
2782expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002783UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2784 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002785{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002786 expr_ty p;
2787 if (!op) {
2788 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002789 "field 'op' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002790 return NULL;
2791 }
2792 if (!operand) {
2793 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002794 "field 'operand' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002795 return NULL;
2796 }
2797 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2798 if (!p)
2799 return NULL;
2800 p->kind = UnaryOp_kind;
2801 p->v.UnaryOp.op = op;
2802 p->v.UnaryOp.operand = operand;
2803 p->lineno = lineno;
2804 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002805 p->end_lineno = end_lineno;
2806 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002807 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002808}
2809
2810expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002811Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2812 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002813{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002814 expr_ty p;
2815 if (!args) {
2816 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002817 "field 'args' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002818 return NULL;
2819 }
2820 if (!body) {
2821 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002822 "field 'body' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002823 return NULL;
2824 }
2825 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2826 if (!p)
2827 return NULL;
2828 p->kind = Lambda_kind;
2829 p->v.Lambda.args = args;
2830 p->v.Lambda.body = body;
2831 p->lineno = lineno;
2832 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002833 p->end_lineno = end_lineno;
2834 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002835 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002836}
2837
2838expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002839IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002840 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002841{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002842 expr_ty p;
2843 if (!test) {
2844 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002845 "field 'test' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002846 return NULL;
2847 }
2848 if (!body) {
2849 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002850 "field 'body' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002851 return NULL;
2852 }
2853 if (!orelse) {
2854 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002855 "field 'orelse' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002856 return NULL;
2857 }
2858 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2859 if (!p)
2860 return NULL;
2861 p->kind = IfExp_kind;
2862 p->v.IfExp.test = test;
2863 p->v.IfExp.body = body;
2864 p->v.IfExp.orelse = orelse;
2865 p->lineno = lineno;
2866 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002867 p->end_lineno = end_lineno;
2868 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002869 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002870}
2871
2872expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002873Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2874 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002875{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002876 expr_ty p;
2877 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2878 if (!p)
2879 return NULL;
2880 p->kind = Dict_kind;
2881 p->v.Dict.keys = keys;
2882 p->v.Dict.values = values;
2883 p->lineno = lineno;
2884 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002885 p->end_lineno = end_lineno;
2886 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002887 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002888}
2889
2890expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002891Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2892 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002893{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002894 expr_ty p;
2895 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2896 if (!p)
2897 return NULL;
2898 p->kind = Set_kind;
2899 p->v.Set.elts = elts;
2900 p->lineno = lineno;
2901 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002902 p->end_lineno = end_lineno;
2903 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002904 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002905}
2906
2907expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002908ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2909 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002910{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002911 expr_ty p;
2912 if (!elt) {
2913 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002914 "field 'elt' is required for ListComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002915 return NULL;
2916 }
2917 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2918 if (!p)
2919 return NULL;
2920 p->kind = ListComp_kind;
2921 p->v.ListComp.elt = elt;
2922 p->v.ListComp.generators = generators;
2923 p->lineno = lineno;
2924 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002925 p->end_lineno = end_lineno;
2926 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002927 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002928}
2929
2930expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002931SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2932 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002933{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002934 expr_ty p;
2935 if (!elt) {
2936 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002937 "field 'elt' is required for SetComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002938 return NULL;
2939 }
2940 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2941 if (!p)
2942 return NULL;
2943 p->kind = SetComp_kind;
2944 p->v.SetComp.elt = elt;
2945 p->v.SetComp.generators = generators;
2946 p->lineno = lineno;
2947 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002948 p->end_lineno = end_lineno;
2949 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002950 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002951}
2952
2953expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002954DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002955 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002956{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002957 expr_ty p;
2958 if (!key) {
2959 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002960 "field 'key' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002961 return NULL;
2962 }
2963 if (!value) {
2964 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002965 "field 'value' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002966 return NULL;
2967 }
2968 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2969 if (!p)
2970 return NULL;
2971 p->kind = DictComp_kind;
2972 p->v.DictComp.key = key;
2973 p->v.DictComp.value = value;
2974 p->v.DictComp.generators = generators;
2975 p->lineno = lineno;
2976 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002977 p->end_lineno = end_lineno;
2978 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002979 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002980}
2981
2982expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002983GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002984 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002985{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002986 expr_ty p;
2987 if (!elt) {
2988 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002989 "field 'elt' is required for GeneratorExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002990 return NULL;
2991 }
2992 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2993 if (!p)
2994 return NULL;
2995 p->kind = GeneratorExp_kind;
2996 p->v.GeneratorExp.elt = elt;
2997 p->v.GeneratorExp.generators = generators;
2998 p->lineno = lineno;
2999 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003000 p->end_lineno = end_lineno;
3001 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003002 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003003}
3004
3005expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003006Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
3007 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04003008{
3009 expr_ty p;
3010 if (!value) {
3011 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003012 "field 'value' is required for Await");
Yury Selivanov75445082015-05-11 22:57:16 -04003013 return NULL;
3014 }
3015 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3016 if (!p)
3017 return NULL;
3018 p->kind = Await_kind;
3019 p->v.Await.value = value;
3020 p->lineno = lineno;
3021 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003022 p->end_lineno = end_lineno;
3023 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04003024 return p;
3025}
3026
3027expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003028Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3029 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003030{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003031 expr_ty p;
3032 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3033 if (!p)
3034 return NULL;
3035 p->kind = Yield_kind;
3036 p->v.Yield.value = value;
3037 p->lineno = lineno;
3038 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003039 p->end_lineno = end_lineno;
3040 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003041 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003042}
3043
3044expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003045YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3046 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003047{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003048 expr_ty p;
3049 if (!value) {
3050 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003051 "field 'value' is required for YieldFrom");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003052 return NULL;
3053 }
3054 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3055 if (!p)
3056 return NULL;
3057 p->kind = YieldFrom_kind;
3058 p->v.YieldFrom.value = value;
3059 p->lineno = lineno;
3060 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003061 p->end_lineno = end_lineno;
3062 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003063 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003064}
3065
3066expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003067Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003068 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003069{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003070 expr_ty p;
3071 if (!left) {
3072 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003073 "field 'left' is required for Compare");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003074 return NULL;
3075 }
3076 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3077 if (!p)
3078 return NULL;
3079 p->kind = Compare_kind;
3080 p->v.Compare.left = left;
3081 p->v.Compare.ops = ops;
3082 p->v.Compare.comparators = comparators;
3083 p->lineno = lineno;
3084 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003085 p->end_lineno = end_lineno;
3086 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003087 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003088}
3089
3090expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003091Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003092 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003093{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003094 expr_ty p;
3095 if (!func) {
3096 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003097 "field 'func' is required for Call");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003098 return NULL;
3099 }
3100 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3101 if (!p)
3102 return NULL;
3103 p->kind = Call_kind;
3104 p->v.Call.func = func;
3105 p->v.Call.args = args;
3106 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003107 p->lineno = lineno;
3108 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003109 p->end_lineno = end_lineno;
3110 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003111 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003112}
3113
3114expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003115FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3116 int col_offset, int end_lineno, int end_col_offset, PyArena
3117 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003118{
3119 expr_ty p;
3120 if (!value) {
3121 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003122 "field 'value' is required for FormattedValue");
Eric V. Smith235a6f02015-09-19 14:51:32 -04003123 return NULL;
3124 }
3125 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3126 if (!p)
3127 return NULL;
3128 p->kind = FormattedValue_kind;
3129 p->v.FormattedValue.value = value;
3130 p->v.FormattedValue.conversion = conversion;
3131 p->v.FormattedValue.format_spec = format_spec;
3132 p->lineno = lineno;
3133 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003134 p->end_lineno = end_lineno;
3135 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003136 return p;
3137}
3138
3139expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003140JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3141 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003142{
3143 expr_ty p;
3144 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3145 if (!p)
3146 return NULL;
3147 p->kind = JoinedStr_kind;
3148 p->v.JoinedStr.values = values;
3149 p->lineno = lineno;
3150 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003151 p->end_lineno = end_lineno;
3152 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003153 return p;
3154}
3155
3156expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003157Constant(constant value, string kind, int lineno, int col_offset, int
3158 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003159{
3160 expr_ty p;
3161 if (!value) {
3162 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003163 "field 'value' is required for Constant");
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003164 return NULL;
3165 }
3166 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3167 if (!p)
3168 return NULL;
3169 p->kind = Constant_kind;
3170 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003171 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003172 p->lineno = lineno;
3173 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003174 p->end_lineno = end_lineno;
3175 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003176 return p;
3177}
3178
3179expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003180Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003181 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003182{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003183 expr_ty p;
3184 if (!value) {
3185 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003186 "field 'value' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003187 return NULL;
3188 }
3189 if (!attr) {
3190 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003191 "field 'attr' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003192 return NULL;
3193 }
3194 if (!ctx) {
3195 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003196 "field 'ctx' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003197 return NULL;
3198 }
3199 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3200 if (!p)
3201 return NULL;
3202 p->kind = Attribute_kind;
3203 p->v.Attribute.value = value;
3204 p->v.Attribute.attr = attr;
3205 p->v.Attribute.ctx = ctx;
3206 p->lineno = lineno;
3207 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003208 p->end_lineno = end_lineno;
3209 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003210 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003211}
3212
3213expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003214Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003215 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003216{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003217 expr_ty p;
3218 if (!value) {
3219 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003220 "field 'value' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003221 return NULL;
3222 }
3223 if (!slice) {
3224 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003225 "field 'slice' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003226 return NULL;
3227 }
3228 if (!ctx) {
3229 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003230 "field 'ctx' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003231 return NULL;
3232 }
3233 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3234 if (!p)
3235 return NULL;
3236 p->kind = Subscript_kind;
3237 p->v.Subscript.value = value;
3238 p->v.Subscript.slice = slice;
3239 p->v.Subscript.ctx = ctx;
3240 p->lineno = lineno;
3241 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003242 p->end_lineno = end_lineno;
3243 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003244 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003245}
3246
3247expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003248Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3249 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003250{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003251 expr_ty p;
3252 if (!value) {
3253 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003254 "field 'value' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003255 return NULL;
3256 }
3257 if (!ctx) {
3258 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003259 "field 'ctx' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003260 return NULL;
3261 }
3262 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3263 if (!p)
3264 return NULL;
3265 p->kind = Starred_kind;
3266 p->v.Starred.value = value;
3267 p->v.Starred.ctx = ctx;
3268 p->lineno = lineno;
3269 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003270 p->end_lineno = end_lineno;
3271 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003272 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003273}
3274
3275expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003276Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3277 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003278{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003279 expr_ty p;
3280 if (!id) {
3281 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003282 "field 'id' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003283 return NULL;
3284 }
3285 if (!ctx) {
3286 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003287 "field 'ctx' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003288 return NULL;
3289 }
3290 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3291 if (!p)
3292 return NULL;
3293 p->kind = Name_kind;
3294 p->v.Name.id = id;
3295 p->v.Name.ctx = ctx;
3296 p->lineno = lineno;
3297 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003298 p->end_lineno = end_lineno;
3299 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003300 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003301}
3302
3303expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003304List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3305 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003306{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003307 expr_ty p;
3308 if (!ctx) {
3309 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003310 "field 'ctx' is required for List");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003311 return NULL;
3312 }
3313 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3314 if (!p)
3315 return NULL;
3316 p->kind = List_kind;
3317 p->v.List.elts = elts;
3318 p->v.List.ctx = ctx;
3319 p->lineno = lineno;
3320 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003321 p->end_lineno = end_lineno;
3322 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003323 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003324}
3325
3326expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003327Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3328 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003329{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003330 expr_ty p;
3331 if (!ctx) {
3332 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003333 "field 'ctx' is required for Tuple");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003334 return NULL;
3335 }
3336 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3337 if (!p)
3338 return NULL;
3339 p->kind = Tuple_kind;
3340 p->v.Tuple.elts = elts;
3341 p->v.Tuple.ctx = ctx;
3342 p->lineno = lineno;
3343 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003344 p->end_lineno = end_lineno;
3345 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003346 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003347}
3348
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003349expr_ty
3350Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3351 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003352{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003353 expr_ty p;
3354 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003355 if (!p)
3356 return NULL;
3357 p->kind = Slice_kind;
3358 p->v.Slice.lower = lower;
3359 p->v.Slice.upper = upper;
3360 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003361 p->lineno = lineno;
3362 p->col_offset = col_offset;
3363 p->end_lineno = end_lineno;
3364 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003365 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003366}
3367
3368comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003369comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3370 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003371{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003372 comprehension_ty p;
3373 if (!target) {
3374 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003375 "field 'target' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003376 return NULL;
3377 }
3378 if (!iter) {
3379 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003380 "field 'iter' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003381 return NULL;
3382 }
3383 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3384 if (!p)
3385 return NULL;
3386 p->target = target;
3387 p->iter = iter;
3388 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003389 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003390 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003391}
3392
3393excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003394ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003395 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003396{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003397 excepthandler_ty p;
3398 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3399 if (!p)
3400 return NULL;
3401 p->kind = ExceptHandler_kind;
3402 p->v.ExceptHandler.type = type;
3403 p->v.ExceptHandler.name = name;
3404 p->v.ExceptHandler.body = body;
3405 p->lineno = lineno;
3406 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003407 p->end_lineno = end_lineno;
3408 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003409 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003410}
3411
3412arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003413arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003414 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3415 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003416{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003417 arguments_ty p;
3418 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3419 if (!p)
3420 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003421 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003422 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003423 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003424 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003425 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003426 p->kwarg = kwarg;
3427 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003428 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003429}
3430
Neal Norwitzc1505362006-12-28 06:47:50 +00003431arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003432arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3433 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003434{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003435 arg_ty p;
3436 if (!arg) {
3437 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003438 "field 'arg' is required for arg");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003439 return NULL;
3440 }
3441 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3442 if (!p)
3443 return NULL;
3444 p->arg = arg;
3445 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003446 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003447 p->lineno = lineno;
3448 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003449 p->end_lineno = end_lineno;
3450 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003451 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003452}
3453
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003454keyword_ty
Pablo Galindo168660b2020-04-02 00:47:39 +01003455keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3456 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003457{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003458 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003459 if (!value) {
3460 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003461 "field 'value' is required for keyword");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003462 return NULL;
3463 }
3464 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3465 if (!p)
3466 return NULL;
3467 p->arg = arg;
3468 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003469 p->lineno = lineno;
3470 p->col_offset = col_offset;
3471 p->end_lineno = end_lineno;
3472 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003473 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003474}
3475
3476alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003477alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003478{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003479 alias_ty p;
3480 if (!name) {
3481 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003482 "field 'name' is required for alias");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003483 return NULL;
3484 }
3485 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3486 if (!p)
3487 return NULL;
3488 p->name = name;
3489 p->asname = asname;
3490 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003491}
3492
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003493withitem_ty
3494withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3495{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003496 withitem_ty p;
3497 if (!context_expr) {
3498 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003499 "field 'context_expr' is required for withitem");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003500 return NULL;
3501 }
3502 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3503 if (!p)
3504 return NULL;
3505 p->context_expr = context_expr;
3506 p->optional_vars = optional_vars;
3507 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003508}
3509
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003510type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003511TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003512{
3513 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003514 if (!tag) {
3515 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003516 "field 'tag' is required for TypeIgnore");
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003517 return NULL;
3518 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003519 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3520 if (!p)
3521 return NULL;
3522 p->kind = TypeIgnore_kind;
3523 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003524 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003525 return p;
3526}
3527
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003528
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003529PyObject*
3530ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003531{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003532 mod_ty o = (mod_ty)_o;
3533 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003534 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003535 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003536 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003537 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003538
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003539 switch (o->kind) {
3540 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003541 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3542 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003543 if (!result) goto failed;
3544 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3545 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003546 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003547 goto failed;
3548 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003549 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3550 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003551 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3552 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003553 goto failed;
3554 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003555 break;
3556 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003557 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3558 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003559 if (!result) goto failed;
3560 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3561 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003562 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003563 goto failed;
3564 Py_DECREF(value);
3565 break;
3566 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003567 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3568 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003569 if (!result) goto failed;
3570 value = ast2obj_expr(o->v.Expression.body);
3571 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003572 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003573 goto failed;
3574 Py_DECREF(value);
3575 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003576 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003577 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3578 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003579 if (!result) goto failed;
3580 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3581 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003582 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3583 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003584 goto failed;
3585 Py_DECREF(value);
3586 value = ast2obj_expr(o->v.FunctionType.returns);
3587 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003588 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3589 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003590 goto failed;
3591 Py_DECREF(value);
3592 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003593 }
3594 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003595failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003596 Py_XDECREF(value);
3597 Py_XDECREF(result);
3598 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003599}
3600
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003601PyObject*
3602ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003603{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003604 stmt_ty o = (stmt_ty)_o;
3605 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003606 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003607 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003608 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003609 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003610
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003611 switch (o->kind) {
3612 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003613 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3614 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003615 if (!result) goto failed;
3616 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003617 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003618 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003619 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003620 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003621 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003622 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003623 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003624 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003625 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003626 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3627 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003628 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003629 goto failed;
3630 Py_DECREF(value);
3631 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3632 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003633 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3634 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003635 goto failed;
3636 Py_DECREF(value);
3637 value = ast2obj_expr(o->v.FunctionDef.returns);
3638 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003639 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3640 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003641 goto failed;
3642 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003643 value = ast2obj_string(o->v.FunctionDef.type_comment);
3644 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003645 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3646 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003647 goto failed;
3648 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003649 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003650 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003651 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3652 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003653 if (!result) goto failed;
3654 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3655 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003656 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003657 goto failed;
3658 Py_DECREF(value);
3659 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3660 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003661 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003662 goto failed;
3663 Py_DECREF(value);
3664 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3665 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003666 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003667 goto failed;
3668 Py_DECREF(value);
3669 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3670 ast2obj_expr);
3671 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003672 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3673 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003674 goto failed;
3675 Py_DECREF(value);
3676 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3677 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003678 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3679 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003680 goto failed;
3681 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003682 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3683 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003684 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3685 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003686 goto failed;
3687 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003688 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003689 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003690 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3691 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003692 if (!result) goto failed;
3693 value = ast2obj_identifier(o->v.ClassDef.name);
3694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003695 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003696 goto failed;
3697 Py_DECREF(value);
3698 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3699 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003700 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003701 goto failed;
3702 Py_DECREF(value);
3703 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3704 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003705 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3706 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003707 goto failed;
3708 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003709 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3710 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003711 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003712 goto failed;
3713 Py_DECREF(value);
3714 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3715 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003716 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3717 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003718 goto failed;
3719 Py_DECREF(value);
3720 break;
3721 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003722 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3723 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003724 if (!result) goto failed;
3725 value = ast2obj_expr(o->v.Return.value);
3726 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003728 goto failed;
3729 Py_DECREF(value);
3730 break;
3731 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003732 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3733 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003734 if (!result) goto failed;
3735 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3736 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003737 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3738 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003739 goto failed;
3740 Py_DECREF(value);
3741 break;
3742 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003743 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3744 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003745 if (!result) goto failed;
3746 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3747 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003748 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3749 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003750 goto failed;
3751 Py_DECREF(value);
3752 value = ast2obj_expr(o->v.Assign.value);
3753 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003754 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003755 goto failed;
3756 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003757 value = ast2obj_string(o->v.Assign.type_comment);
3758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003759 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3760 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003761 goto failed;
3762 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003763 break;
3764 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003765 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3766 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003767 if (!result) goto failed;
3768 value = ast2obj_expr(o->v.AugAssign.target);
3769 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003770 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3771 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003772 goto failed;
3773 Py_DECREF(value);
3774 value = ast2obj_operator(o->v.AugAssign.op);
3775 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003776 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003777 goto failed;
3778 Py_DECREF(value);
3779 value = ast2obj_expr(o->v.AugAssign.value);
3780 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003781 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003782 goto failed;
3783 Py_DECREF(value);
3784 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003785 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003786 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3787 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003788 if (!result) goto failed;
3789 value = ast2obj_expr(o->v.AnnAssign.target);
3790 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003791 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3792 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003793 goto failed;
3794 Py_DECREF(value);
3795 value = ast2obj_expr(o->v.AnnAssign.annotation);
3796 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003797 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3798 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003799 goto failed;
3800 Py_DECREF(value);
3801 value = ast2obj_expr(o->v.AnnAssign.value);
3802 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003803 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003804 goto failed;
3805 Py_DECREF(value);
3806 value = ast2obj_int(o->v.AnnAssign.simple);
3807 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003808 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3809 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003810 goto failed;
3811 Py_DECREF(value);
3812 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003814 tp = (PyTypeObject *)astmodulestate_global->For_type;
3815 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003816 if (!result) goto failed;
3817 value = ast2obj_expr(o->v.For.target);
3818 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003819 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3820 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003821 goto failed;
3822 Py_DECREF(value);
3823 value = ast2obj_expr(o->v.For.iter);
3824 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003825 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003826 goto failed;
3827 Py_DECREF(value);
3828 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3829 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003830 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003831 goto failed;
3832 Py_DECREF(value);
3833 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3834 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003835 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3836 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003837 goto failed;
3838 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003839 value = ast2obj_string(o->v.For.type_comment);
3840 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003841 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3842 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003843 goto failed;
3844 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003845 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003846 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003847 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3848 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003849 if (!result) goto failed;
3850 value = ast2obj_expr(o->v.AsyncFor.target);
3851 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003852 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3853 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003854 goto failed;
3855 Py_DECREF(value);
3856 value = ast2obj_expr(o->v.AsyncFor.iter);
3857 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003858 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003859 goto failed;
3860 Py_DECREF(value);
3861 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3862 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003863 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003864 goto failed;
3865 Py_DECREF(value);
3866 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3867 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003868 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3869 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003870 goto failed;
3871 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003872 value = ast2obj_string(o->v.AsyncFor.type_comment);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3875 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003876 goto failed;
3877 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003878 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003879 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003880 tp = (PyTypeObject *)astmodulestate_global->While_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.While.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.While.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.While.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 If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003901 tp = (PyTypeObject *)astmodulestate_global->If_type;
3902 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003903 if (!result) goto failed;
3904 value = ast2obj_expr(o->v.If.test);
3905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003906 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003907 goto failed;
3908 Py_DECREF(value);
3909 value = ast2obj_list(o->v.If.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);
3914 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3915 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003916 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3917 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 goto failed;
3919 Py_DECREF(value);
3920 break;
3921 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003922 tp = (PyTypeObject *)astmodulestate_global->With_type;
3923 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003924 if (!result) goto failed;
3925 value = ast2obj_list(o->v.With.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)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003928 goto failed;
3929 Py_DECREF(value);
3930 value = ast2obj_list(o->v.With.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)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003933 goto failed;
3934 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003935 value = ast2obj_string(o->v.With.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);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003941 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003942 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003943 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3944 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003945 if (!result) goto failed;
3946 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3947 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003948 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003949 goto failed;
3950 Py_DECREF(value);
3951 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3952 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003953 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003954 goto failed;
3955 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003956 value = ast2obj_string(o->v.AsyncWith.type_comment);
3957 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003958 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3959 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003960 goto failed;
3961 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003962 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003963 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003964 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3965 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003966 if (!result) goto failed;
3967 value = ast2obj_expr(o->v.Raise.exc);
3968 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003969 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003970 goto failed;
3971 Py_DECREF(value);
3972 value = ast2obj_expr(o->v.Raise.cause);
3973 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003974 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003975 goto failed;
3976 Py_DECREF(value);
3977 break;
3978 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003979 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3980 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003981 if (!result) goto failed;
3982 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3983 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003984 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003985 goto failed;
3986 Py_DECREF(value);
3987 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3988 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003989 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3990 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003991 goto failed;
3992 Py_DECREF(value);
3993 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3994 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003995 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3996 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003997 goto failed;
3998 Py_DECREF(value);
3999 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
4000 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004001 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
4002 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004003 goto failed;
4004 Py_DECREF(value);
4005 break;
4006 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004007 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
4008 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 if (!result) goto failed;
4010 value = ast2obj_expr(o->v.Assert.test);
4011 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004013 goto failed;
4014 Py_DECREF(value);
4015 value = ast2obj_expr(o->v.Assert.msg);
4016 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004017 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004018 goto failed;
4019 Py_DECREF(value);
4020 break;
4021 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 tp = (PyTypeObject *)astmodulestate_global->Import_type;
4023 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004024 if (!result) goto failed;
4025 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
4026 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 goto failed;
4029 Py_DECREF(value);
4030 break;
4031 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
4033 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004034 if (!result) goto failed;
4035 value = ast2obj_identifier(o->v.ImportFrom.module);
4036 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004037 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4038 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004039 goto failed;
4040 Py_DECREF(value);
4041 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004043 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 goto failed;
4045 Py_DECREF(value);
4046 value = ast2obj_int(o->v.ImportFrom.level);
4047 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004049 goto failed;
4050 Py_DECREF(value);
4051 break;
4052 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4054 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 if (!result) goto failed;
4056 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4057 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 goto failed;
4060 Py_DECREF(value);
4061 break;
4062 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004063 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4064 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004065 if (!result) goto failed;
4066 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4067 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004068 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004069 goto failed;
4070 Py_DECREF(value);
4071 break;
4072 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004073 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4074 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004075 if (!result) goto failed;
4076 value = ast2obj_expr(o->v.Expr.value);
4077 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004078 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004079 goto failed;
4080 Py_DECREF(value);
4081 break;
4082 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004083 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4084 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004085 if (!result) goto failed;
4086 break;
4087 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004088 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4089 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004090 if (!result) goto failed;
4091 break;
4092 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004093 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4094 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004095 if (!result) goto failed;
4096 break;
4097 }
4098 value = ast2obj_int(o->lineno);
4099 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004100 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004101 goto failed;
4102 Py_DECREF(value);
4103 value = ast2obj_int(o->col_offset);
4104 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004105 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004106 goto failed;
4107 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004108 value = ast2obj_int(o->end_lineno);
4109 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004110 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004111 goto failed;
4112 Py_DECREF(value);
4113 value = ast2obj_int(o->end_col_offset);
4114 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004115 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4116 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004117 goto failed;
4118 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004119 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004120failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004121 Py_XDECREF(value);
4122 Py_XDECREF(result);
4123 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004124}
4125
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004126PyObject*
4127ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004128{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004129 expr_ty o = (expr_ty)_o;
4130 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004131 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004132 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004133 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004134 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004135
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004136 switch (o->kind) {
4137 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004138 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4139 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004140 if (!result) goto failed;
4141 value = ast2obj_boolop(o->v.BoolOp.op);
4142 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004143 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004144 goto failed;
4145 Py_DECREF(value);
4146 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4147 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004148 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4149 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004150 goto failed;
4151 Py_DECREF(value);
4152 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004153 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004154 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4155 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004156 if (!result) goto failed;
4157 value = ast2obj_expr(o->v.NamedExpr.target);
4158 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004159 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4160 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004161 goto failed;
4162 Py_DECREF(value);
4163 value = ast2obj_expr(o->v.NamedExpr.value);
4164 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004165 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004166 goto failed;
4167 Py_DECREF(value);
4168 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004169 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004170 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4171 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004172 if (!result) goto failed;
4173 value = ast2obj_expr(o->v.BinOp.left);
4174 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004175 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004176 goto failed;
4177 Py_DECREF(value);
4178 value = ast2obj_operator(o->v.BinOp.op);
4179 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004180 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004181 goto failed;
4182 Py_DECREF(value);
4183 value = ast2obj_expr(o->v.BinOp.right);
4184 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004185 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004186 goto failed;
4187 Py_DECREF(value);
4188 break;
4189 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4191 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004192 if (!result) goto failed;
4193 value = ast2obj_unaryop(o->v.UnaryOp.op);
4194 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004196 goto failed;
4197 Py_DECREF(value);
4198 value = ast2obj_expr(o->v.UnaryOp.operand);
4199 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4201 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004202 goto failed;
4203 Py_DECREF(value);
4204 break;
4205 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004206 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4207 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004208 if (!result) goto failed;
4209 value = ast2obj_arguments(o->v.Lambda.args);
4210 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004211 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004212 goto failed;
4213 Py_DECREF(value);
4214 value = ast2obj_expr(o->v.Lambda.body);
4215 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004216 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 goto failed;
4218 Py_DECREF(value);
4219 break;
4220 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004221 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4222 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004223 if (!result) goto failed;
4224 value = ast2obj_expr(o->v.IfExp.test);
4225 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004226 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 goto failed;
4228 Py_DECREF(value);
4229 value = ast2obj_expr(o->v.IfExp.body);
4230 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004231 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004232 goto failed;
4233 Py_DECREF(value);
4234 value = ast2obj_expr(o->v.IfExp.orelse);
4235 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004236 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4237 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004238 goto failed;
4239 Py_DECREF(value);
4240 break;
4241 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004242 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4243 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004244 if (!result) goto failed;
4245 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4246 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004247 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004248 goto failed;
4249 Py_DECREF(value);
4250 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4251 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004252 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4253 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004254 goto failed;
4255 Py_DECREF(value);
4256 break;
4257 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004258 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4259 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004260 if (!result) goto failed;
4261 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4262 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004263 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004264 goto failed;
4265 Py_DECREF(value);
4266 break;
4267 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004268 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4269 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004270 if (!result) goto failed;
4271 value = ast2obj_expr(o->v.ListComp.elt);
4272 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004273 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004274 goto failed;
4275 Py_DECREF(value);
4276 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4277 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004278 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4279 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004280 goto failed;
4281 Py_DECREF(value);
4282 break;
4283 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004284 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4285 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004286 if (!result) goto failed;
4287 value = ast2obj_expr(o->v.SetComp.elt);
4288 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004289 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004290 goto failed;
4291 Py_DECREF(value);
4292 value = ast2obj_list(o->v.SetComp.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 DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004300 tp = (PyTypeObject *)astmodulestate_global->DictComp_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.DictComp.key);
4304 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004305 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004306 goto failed;
4307 Py_DECREF(value);
4308 value = ast2obj_expr(o->v.DictComp.value);
4309 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004310 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004311 goto failed;
4312 Py_DECREF(value);
4313 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4314 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004315 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4316 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004317 goto failed;
4318 Py_DECREF(value);
4319 break;
4320 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004321 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4322 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004323 if (!result) goto failed;
4324 value = ast2obj_expr(o->v.GeneratorExp.elt);
4325 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004326 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 goto failed;
4328 Py_DECREF(value);
4329 value = ast2obj_list(o->v.GeneratorExp.generators,
4330 ast2obj_comprehension);
4331 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004332 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4333 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004334 goto failed;
4335 Py_DECREF(value);
4336 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004337 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004338 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4339 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004340 if (!result) goto failed;
4341 value = ast2obj_expr(o->v.Await.value);
4342 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004343 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004344 goto failed;
4345 Py_DECREF(value);
4346 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004348 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4349 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004350 if (!result) goto failed;
4351 value = ast2obj_expr(o->v.Yield.value);
4352 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004353 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004354 goto failed;
4355 Py_DECREF(value);
4356 break;
4357 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004358 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4359 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004360 if (!result) goto failed;
4361 value = ast2obj_expr(o->v.YieldFrom.value);
4362 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004363 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004364 goto failed;
4365 Py_DECREF(value);
4366 break;
4367 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004368 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4369 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004370 if (!result) goto failed;
4371 value = ast2obj_expr(o->v.Compare.left);
4372 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004373 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004374 goto failed;
4375 Py_DECREF(value);
4376 {
4377 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4378 value = PyList_New(n);
4379 if (!value) goto failed;
4380 for(i = 0; i < n; i++)
4381 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004382 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004383 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004384 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004385 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004386 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004387 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004388 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004389 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4390 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004391 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004392 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004393 break;
4394 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004395 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4396 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004397 if (!result) goto failed;
4398 value = ast2obj_expr(o->v.Call.func);
4399 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004400 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004401 goto failed;
4402 Py_DECREF(value);
4403 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4404 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004405 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004406 goto failed;
4407 Py_DECREF(value);
4408 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4409 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004410 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4411 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004412 goto failed;
4413 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004414 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004415 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004416 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4417 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004418 if (!result) goto failed;
4419 value = ast2obj_expr(o->v.FormattedValue.value);
4420 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004421 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004422 goto failed;
4423 Py_DECREF(value);
4424 value = ast2obj_int(o->v.FormattedValue.conversion);
4425 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004426 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4427 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004428 goto failed;
4429 Py_DECREF(value);
4430 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4431 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004432 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4433 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004434 goto failed;
4435 Py_DECREF(value);
4436 break;
4437 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004438 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4439 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004440 if (!result) goto failed;
4441 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4442 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004443 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4444 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004445 goto failed;
4446 Py_DECREF(value);
4447 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004448 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004449 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4450 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004451 if (!result) goto failed;
4452 value = ast2obj_constant(o->v.Constant.value);
4453 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004454 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004455 goto failed;
4456 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004457 value = ast2obj_string(o->v.Constant.kind);
4458 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004459 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004460 goto failed;
4461 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004462 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004463 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004464 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4465 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004466 if (!result) goto failed;
4467 value = ast2obj_expr(o->v.Attribute.value);
4468 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004469 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004470 goto failed;
4471 Py_DECREF(value);
4472 value = ast2obj_identifier(o->v.Attribute.attr);
4473 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004474 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004475 goto failed;
4476 Py_DECREF(value);
4477 value = ast2obj_expr_context(o->v.Attribute.ctx);
4478 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004479 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004480 goto failed;
4481 Py_DECREF(value);
4482 break;
4483 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004484 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4485 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004486 if (!result) goto failed;
4487 value = ast2obj_expr(o->v.Subscript.value);
4488 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004489 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004490 goto failed;
4491 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004492 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004493 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004494 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 goto failed;
4496 Py_DECREF(value);
4497 value = ast2obj_expr_context(o->v.Subscript.ctx);
4498 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004499 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004500 goto failed;
4501 Py_DECREF(value);
4502 break;
4503 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004504 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4505 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004506 if (!result) goto failed;
4507 value = ast2obj_expr(o->v.Starred.value);
4508 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004509 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 goto failed;
4511 Py_DECREF(value);
4512 value = ast2obj_expr_context(o->v.Starred.ctx);
4513 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004514 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004515 goto failed;
4516 Py_DECREF(value);
4517 break;
4518 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004519 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4520 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004521 if (!result) goto failed;
4522 value = ast2obj_identifier(o->v.Name.id);
4523 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004524 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004525 goto failed;
4526 Py_DECREF(value);
4527 value = ast2obj_expr_context(o->v.Name.ctx);
4528 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004529 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004530 goto failed;
4531 Py_DECREF(value);
4532 break;
4533 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004534 tp = (PyTypeObject *)astmodulestate_global->List_type;
4535 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004536 if (!result) goto failed;
4537 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4538 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004539 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004540 goto failed;
4541 Py_DECREF(value);
4542 value = ast2obj_expr_context(o->v.List.ctx);
4543 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004544 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004545 goto failed;
4546 Py_DECREF(value);
4547 break;
4548 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004549 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4550 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004551 if (!result) goto failed;
4552 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4553 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004554 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004555 goto failed;
4556 Py_DECREF(value);
4557 value = ast2obj_expr_context(o->v.Tuple.ctx);
4558 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004559 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004560 goto failed;
4561 Py_DECREF(value);
4562 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004563 case Slice_kind:
4564 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4565 result = PyType_GenericNew(tp, NULL, NULL);
4566 if (!result) goto failed;
4567 value = ast2obj_expr(o->v.Slice.lower);
4568 if (!value) goto failed;
4569 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4570 goto failed;
4571 Py_DECREF(value);
4572 value = ast2obj_expr(o->v.Slice.upper);
4573 if (!value) goto failed;
4574 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4575 goto failed;
4576 Py_DECREF(value);
4577 value = ast2obj_expr(o->v.Slice.step);
4578 if (!value) goto failed;
4579 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4580 goto failed;
4581 Py_DECREF(value);
4582 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004583 }
4584 value = ast2obj_int(o->lineno);
4585 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004586 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004587 goto failed;
4588 Py_DECREF(value);
4589 value = ast2obj_int(o->col_offset);
4590 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004591 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004592 goto failed;
4593 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004594 value = ast2obj_int(o->end_lineno);
4595 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004596 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004597 goto failed;
4598 Py_DECREF(value);
4599 value = ast2obj_int(o->end_col_offset);
4600 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004601 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4602 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004603 goto failed;
4604 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004605 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004606failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004607 Py_XDECREF(value);
4608 Py_XDECREF(result);
4609 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004610}
4611
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004612PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004613{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004614 switch(o) {
4615 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004616 Py_INCREF(astmodulestate_global->Load_singleton);
4617 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004618 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004619 Py_INCREF(astmodulestate_global->Store_singleton);
4620 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004621 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004622 Py_INCREF(astmodulestate_global->Del_singleton);
4623 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004624 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004625 Py_UNREACHABLE();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004626}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004627PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004628{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004629 switch(o) {
4630 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004631 Py_INCREF(astmodulestate_global->And_singleton);
4632 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004633 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004634 Py_INCREF(astmodulestate_global->Or_singleton);
4635 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004636 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004637 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004638}
4639PyObject* ast2obj_operator(operator_ty o)
4640{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 switch(o) {
4642 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004643 Py_INCREF(astmodulestate_global->Add_singleton);
4644 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004645 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004646 Py_INCREF(astmodulestate_global->Sub_singleton);
4647 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004648 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004649 Py_INCREF(astmodulestate_global->Mult_singleton);
4650 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004651 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004652 Py_INCREF(astmodulestate_global->MatMult_singleton);
4653 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004654 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004655 Py_INCREF(astmodulestate_global->Div_singleton);
4656 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004658 Py_INCREF(astmodulestate_global->Mod_singleton);
4659 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004660 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004661 Py_INCREF(astmodulestate_global->Pow_singleton);
4662 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004663 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004664 Py_INCREF(astmodulestate_global->LShift_singleton);
4665 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004666 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004667 Py_INCREF(astmodulestate_global->RShift_singleton);
4668 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004669 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004670 Py_INCREF(astmodulestate_global->BitOr_singleton);
4671 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004673 Py_INCREF(astmodulestate_global->BitXor_singleton);
4674 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004675 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004676 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4677 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004678 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004679 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4680 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004681 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004682 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004683}
4684PyObject* ast2obj_unaryop(unaryop_ty o)
4685{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004686 switch(o) {
4687 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004688 Py_INCREF(astmodulestate_global->Invert_singleton);
4689 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004690 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004691 Py_INCREF(astmodulestate_global->Not_singleton);
4692 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004693 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004694 Py_INCREF(astmodulestate_global->UAdd_singleton);
4695 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004697 Py_INCREF(astmodulestate_global->USub_singleton);
4698 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004699 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004700 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004701}
4702PyObject* ast2obj_cmpop(cmpop_ty o)
4703{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 switch(o) {
4705 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004706 Py_INCREF(astmodulestate_global->Eq_singleton);
4707 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004708 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004709 Py_INCREF(astmodulestate_global->NotEq_singleton);
4710 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004711 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004712 Py_INCREF(astmodulestate_global->Lt_singleton);
4713 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004714 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004715 Py_INCREF(astmodulestate_global->LtE_singleton);
4716 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004718 Py_INCREF(astmodulestate_global->Gt_singleton);
4719 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004720 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004721 Py_INCREF(astmodulestate_global->GtE_singleton);
4722 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004723 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004724 Py_INCREF(astmodulestate_global->Is_singleton);
4725 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004726 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004727 Py_INCREF(astmodulestate_global->IsNot_singleton);
4728 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004729 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004730 Py_INCREF(astmodulestate_global->In_singleton);
4731 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004733 Py_INCREF(astmodulestate_global->NotIn_singleton);
4734 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004735 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004736 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004737}
4738PyObject*
4739ast2obj_comprehension(void* _o)
4740{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004741 comprehension_ty o = (comprehension_ty)_o;
4742 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004743 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004744 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004745 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004746 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004747
Dino Viehlandac46eb42019-09-11 10:16:34 -07004748 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4749 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 if (!result) return NULL;
4751 value = ast2obj_expr(o->target);
4752 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004753 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004754 goto failed;
4755 Py_DECREF(value);
4756 value = ast2obj_expr(o->iter);
4757 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004758 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004759 goto failed;
4760 Py_DECREF(value);
4761 value = ast2obj_list(o->ifs, ast2obj_expr);
4762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004763 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004764 goto failed;
4765 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004766 value = ast2obj_int(o->is_async);
4767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004768 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004769 goto failed;
4770 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004772failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 Py_XDECREF(value);
4774 Py_XDECREF(result);
4775 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004776}
4777
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004778PyObject*
4779ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004780{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004781 excepthandler_ty o = (excepthandler_ty)_o;
4782 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004783 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004784 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004785 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004786 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004787
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004788 switch (o->kind) {
4789 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004790 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4791 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004792 if (!result) goto failed;
4793 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004795 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004796 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004797 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004798 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004799 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004800 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004801 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004802 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004803 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4804 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004805 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004806 goto failed;
4807 Py_DECREF(value);
4808 break;
4809 }
4810 value = ast2obj_int(o->lineno);
4811 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004812 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004813 goto failed;
4814 Py_DECREF(value);
4815 value = ast2obj_int(o->col_offset);
4816 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004817 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004818 goto failed;
4819 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004820 value = ast2obj_int(o->end_lineno);
4821 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004822 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004823 goto failed;
4824 Py_DECREF(value);
4825 value = ast2obj_int(o->end_col_offset);
4826 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004827 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4828 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004829 goto failed;
4830 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004831 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004832failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004833 Py_XDECREF(value);
4834 Py_XDECREF(result);
4835 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004836}
4837
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004838PyObject*
4839ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004840{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004841 arguments_ty o = (arguments_ty)_o;
4842 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004843 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004844 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004845 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004847
Dino Viehlandac46eb42019-09-11 10:16:34 -07004848 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4849 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004850 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004851 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4852 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004853 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4854 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004855 goto failed;
4856 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004857 value = ast2obj_list(o->args, ast2obj_arg);
4858 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004859 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004860 goto failed;
4861 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004862 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004864 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 goto failed;
4866 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004869 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4870 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004871 goto failed;
4872 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004873 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004874 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004875 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4876 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004877 goto failed;
4878 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004879 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004880 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004881 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004882 goto failed;
4883 Py_DECREF(value);
4884 value = ast2obj_list(o->defaults, ast2obj_expr);
4885 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004886 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 goto failed;
4888 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004889 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004890failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 Py_XDECREF(value);
4892 Py_XDECREF(result);
4893 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004894}
4895
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004896PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004897ast2obj_arg(void* _o)
4898{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004899 arg_ty o = (arg_ty)_o;
4900 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004901 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004902 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004903 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004904 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004905
Dino Viehlandac46eb42019-09-11 10:16:34 -07004906 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4907 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 if (!result) return NULL;
4909 value = ast2obj_identifier(o->arg);
4910 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004911 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004912 goto failed;
4913 Py_DECREF(value);
4914 value = ast2obj_expr(o->annotation);
4915 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004916 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4917 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004918 goto failed;
4919 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004920 value = ast2obj_string(o->type_comment);
4921 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004922 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4923 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004924 goto failed;
4925 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004926 value = ast2obj_int(o->lineno);
4927 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004928 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004929 goto failed;
4930 Py_DECREF(value);
4931 value = ast2obj_int(o->col_offset);
4932 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004933 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004934 goto failed;
4935 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004936 value = ast2obj_int(o->end_lineno);
4937 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004938 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004939 goto failed;
4940 Py_DECREF(value);
4941 value = ast2obj_int(o->end_col_offset);
4942 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004943 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4944 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004945 goto failed;
4946 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004947 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004948failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004949 Py_XDECREF(value);
4950 Py_XDECREF(result);
4951 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004952}
4953
4954PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004955ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004956{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004957 keyword_ty o = (keyword_ty)_o;
4958 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004959 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004960 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004961 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004962 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004963
Dino Viehlandac46eb42019-09-11 10:16:34 -07004964 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4965 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004966 if (!result) return NULL;
4967 value = ast2obj_identifier(o->arg);
4968 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004969 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004970 goto failed;
4971 Py_DECREF(value);
4972 value = ast2obj_expr(o->value);
4973 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004974 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004975 goto failed;
4976 Py_DECREF(value);
Pablo Galindo168660b2020-04-02 00:47:39 +01004977 value = ast2obj_int(o->lineno);
4978 if (!value) goto failed;
4979 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
4980 goto failed;
4981 Py_DECREF(value);
4982 value = ast2obj_int(o->col_offset);
4983 if (!value) goto failed;
4984 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
4985 goto failed;
4986 Py_DECREF(value);
4987 value = ast2obj_int(o->end_lineno);
4988 if (!value) goto failed;
4989 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
4990 goto failed;
4991 Py_DECREF(value);
4992 value = ast2obj_int(o->end_col_offset);
4993 if (!value) goto failed;
4994 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4995 < 0)
4996 goto failed;
4997 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004998 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004999failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005000 Py_XDECREF(value);
5001 Py_XDECREF(result);
5002 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005003}
5004
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005005PyObject*
5006ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005007{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005008 alias_ty o = (alias_ty)_o;
5009 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005010 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005011 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005012 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005013 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005014
Dino Viehlandac46eb42019-09-11 10:16:34 -07005015 tp = (PyTypeObject *)astmodulestate_global->alias_type;
5016 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005017 if (!result) return NULL;
5018 value = ast2obj_identifier(o->name);
5019 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005020 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005021 goto failed;
5022 Py_DECREF(value);
5023 value = ast2obj_identifier(o->asname);
5024 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005025 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005026 goto failed;
5027 Py_DECREF(value);
5028 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005029failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005030 Py_XDECREF(value);
5031 Py_XDECREF(result);
5032 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005033}
5034
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005035PyObject*
5036ast2obj_withitem(void* _o)
5037{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005038 withitem_ty o = (withitem_ty)_o;
5039 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005040 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005041 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005042 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005043 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005044
Dino Viehlandac46eb42019-09-11 10:16:34 -07005045 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5046 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005047 if (!result) return NULL;
5048 value = ast2obj_expr(o->context_expr);
5049 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005050 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5051 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005052 goto failed;
5053 Py_DECREF(value);
5054 value = ast2obj_expr(o->optional_vars);
5055 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005056 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5057 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005058 goto failed;
5059 Py_DECREF(value);
5060 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005061failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005062 Py_XDECREF(value);
5063 Py_XDECREF(result);
5064 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005065}
5066
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005067PyObject*
5068ast2obj_type_ignore(void* _o)
5069{
5070 type_ignore_ty o = (type_ignore_ty)_o;
5071 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005072 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005073 if (!o) {
5074 Py_RETURN_NONE;
5075 }
5076
5077 switch (o->kind) {
5078 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005079 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5080 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005081 if (!result) goto failed;
5082 value = ast2obj_int(o->v.TypeIgnore.lineno);
5083 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005084 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5085 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005086 goto failed;
5087 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005088 value = ast2obj_string(o->v.TypeIgnore.tag);
5089 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005090 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005091 goto failed;
5092 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005093 break;
5094 }
5095 return result;
5096failed:
5097 Py_XDECREF(value);
5098 Py_XDECREF(result);
5099 return NULL;
5100}
5101
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005102
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005103int
5104obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5105{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005106 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005107
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005108 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005109 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005110
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005111 if (obj == Py_None) {
5112 *out = NULL;
5113 return 0;
5114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005115 tp = astmodulestate_global->Module_type;
5116 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005117 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005118 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005119 }
5120 if (isinstance) {
5121 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005122 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005123
Dino Viehlandac46eb42019-09-11 10:16:34 -07005124 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005125 return 1;
5126 }
5127 if (tmp == NULL) {
5128 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5129 return 1;
5130 }
5131 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005132 int res;
5133 Py_ssize_t len;
5134 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005135 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005136 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 +02005137 goto failed;
5138 }
5139 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005140 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005141 if (body == NULL) goto failed;
5142 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005143 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005144 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5145 Py_INCREF(tmp2);
5146 res = obj2ast_stmt(tmp2, &val, arena);
5147 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005148 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005149 if (len != PyList_GET_SIZE(tmp)) {
5150 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5151 goto failed;
5152 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005153 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005154 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005155 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005157 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5158 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005159 return 1;
5160 }
5161 if (tmp == NULL) {
5162 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5163 return 1;
5164 }
5165 else {
5166 int res;
5167 Py_ssize_t len;
5168 Py_ssize_t i;
5169 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005170 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 -08005171 goto failed;
5172 }
5173 len = PyList_GET_SIZE(tmp);
5174 type_ignores = _Py_asdl_seq_new(len, arena);
5175 if (type_ignores == NULL) goto failed;
5176 for (i = 0; i < len; i++) {
5177 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005178 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5179 Py_INCREF(tmp2);
5180 res = obj2ast_type_ignore(tmp2, &val, arena);
5181 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005182 if (res != 0) goto failed;
5183 if (len != PyList_GET_SIZE(tmp)) {
5184 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5185 goto failed;
5186 }
5187 asdl_seq_SET(type_ignores, i, val);
5188 }
5189 Py_CLEAR(tmp);
5190 }
5191 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005192 if (*out == NULL) goto failed;
5193 return 0;
5194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005195 tp = astmodulestate_global->Interactive_type;
5196 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005197 if (isinstance == -1) {
5198 return 1;
5199 }
5200 if (isinstance) {
5201 asdl_seq* body;
5202
Dino Viehlandac46eb42019-09-11 10:16:34 -07005203 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005204 return 1;
5205 }
5206 if (tmp == NULL) {
5207 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5208 return 1;
5209 }
5210 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005211 int res;
5212 Py_ssize_t len;
5213 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005214 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005215 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 +02005216 goto failed;
5217 }
5218 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005219 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005220 if (body == NULL) goto failed;
5221 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005222 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005223 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5224 Py_INCREF(tmp2);
5225 res = obj2ast_stmt(tmp2, &val, arena);
5226 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005227 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005228 if (len != PyList_GET_SIZE(tmp)) {
5229 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5230 goto failed;
5231 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005232 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005233 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005234 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005235 }
5236 *out = Interactive(body, arena);
5237 if (*out == NULL) goto failed;
5238 return 0;
5239 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005240 tp = astmodulestate_global->Expression_type;
5241 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005242 if (isinstance == -1) {
5243 return 1;
5244 }
5245 if (isinstance) {
5246 expr_ty body;
5247
Dino Viehlandac46eb42019-09-11 10:16:34 -07005248 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005249 return 1;
5250 }
5251 if (tmp == NULL) {
5252 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5253 return 1;
5254 }
5255 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005256 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005257 res = obj2ast_expr(tmp, &body, arena);
5258 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005259 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005260 }
5261 *out = Expression(body, arena);
5262 if (*out == NULL) goto failed;
5263 return 0;
5264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005265 tp = astmodulestate_global->FunctionType_type;
5266 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005267 if (isinstance == -1) {
5268 return 1;
5269 }
5270 if (isinstance) {
5271 asdl_seq* argtypes;
5272 expr_ty returns;
5273
Dino Viehlandac46eb42019-09-11 10:16:34 -07005274 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5275 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005276 return 1;
5277 }
5278 if (tmp == NULL) {
5279 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5280 return 1;
5281 }
5282 else {
5283 int res;
5284 Py_ssize_t len;
5285 Py_ssize_t i;
5286 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005287 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 -08005288 goto failed;
5289 }
5290 len = PyList_GET_SIZE(tmp);
5291 argtypes = _Py_asdl_seq_new(len, arena);
5292 if (argtypes == NULL) goto failed;
5293 for (i = 0; i < len; i++) {
5294 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005295 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5296 Py_INCREF(tmp2);
5297 res = obj2ast_expr(tmp2, &val, arena);
5298 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005299 if (res != 0) goto failed;
5300 if (len != PyList_GET_SIZE(tmp)) {
5301 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5302 goto failed;
5303 }
5304 asdl_seq_SET(argtypes, i, val);
5305 }
5306 Py_CLEAR(tmp);
5307 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005308 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5309 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005310 return 1;
5311 }
5312 if (tmp == NULL) {
5313 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5314 return 1;
5315 }
5316 else {
5317 int res;
5318 res = obj2ast_expr(tmp, &returns, arena);
5319 if (res != 0) goto failed;
5320 Py_CLEAR(tmp);
5321 }
5322 *out = FunctionType(argtypes, returns, arena);
5323 if (*out == NULL) goto failed;
5324 return 0;
5325 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005326
5327 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5328 failed:
5329 Py_XDECREF(tmp);
5330 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005331}
5332
5333int
5334obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5335{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005336 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005337
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005338 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005339 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005340 int lineno;
5341 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005342 int end_lineno;
5343 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005344
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005345 if (obj == Py_None) {
5346 *out = NULL;
5347 return 0;
5348 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005349 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005350 return 1;
5351 }
5352 if (tmp == NULL) {
5353 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5354 return 1;
5355 }
5356 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005357 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005358 res = obj2ast_int(tmp, &lineno, arena);
5359 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005360 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005361 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005362 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5363 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005364 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005365 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005366 if (tmp == NULL) {
5367 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5368 return 1;
5369 }
5370 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005371 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005372 res = obj2ast_int(tmp, &col_offset, arena);
5373 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005374 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005375 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005376 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5377 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005378 return 1;
5379 }
5380 if (tmp == NULL || tmp == Py_None) {
5381 Py_CLEAR(tmp);
5382 end_lineno = 0;
5383 }
5384 else {
5385 int res;
5386 res = obj2ast_int(tmp, &end_lineno, arena);
5387 if (res != 0) goto failed;
5388 Py_CLEAR(tmp);
5389 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005390 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5391 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005392 return 1;
5393 }
5394 if (tmp == NULL || tmp == Py_None) {
5395 Py_CLEAR(tmp);
5396 end_col_offset = 0;
5397 }
5398 else {
5399 int res;
5400 res = obj2ast_int(tmp, &end_col_offset, arena);
5401 if (res != 0) goto failed;
5402 Py_CLEAR(tmp);
5403 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005404 tp = astmodulestate_global->FunctionDef_type;
5405 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005406 if (isinstance == -1) {
5407 return 1;
5408 }
5409 if (isinstance) {
5410 identifier name;
5411 arguments_ty args;
5412 asdl_seq* body;
5413 asdl_seq* decorator_list;
5414 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005415 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005416
Dino Viehlandac46eb42019-09-11 10:16:34 -07005417 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005418 return 1;
5419 }
5420 if (tmp == NULL) {
5421 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5422 return 1;
5423 }
5424 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005425 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005426 res = obj2ast_identifier(tmp, &name, arena);
5427 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005428 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005429 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005430 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005431 return 1;
5432 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005433 if (tmp == NULL) {
5434 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5435 return 1;
5436 }
5437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005438 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005439 res = obj2ast_arguments(tmp, &args, arena);
5440 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005441 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005442 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005443 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005444 return 1;
5445 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005446 if (tmp == NULL) {
5447 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5448 return 1;
5449 }
5450 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005451 int res;
5452 Py_ssize_t len;
5453 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005454 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005455 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 +02005456 goto failed;
5457 }
5458 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005459 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005460 if (body == NULL) goto failed;
5461 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005462 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005463 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5464 Py_INCREF(tmp2);
5465 res = obj2ast_stmt(tmp2, &val, arena);
5466 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005467 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005468 if (len != PyList_GET_SIZE(tmp)) {
5469 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5470 goto failed;
5471 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005472 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005473 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005474 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005475 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005476 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5477 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005478 return 1;
5479 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005480 if (tmp == NULL) {
5481 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5482 return 1;
5483 }
5484 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005485 int res;
5486 Py_ssize_t len;
5487 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005488 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005489 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 +02005490 goto failed;
5491 }
5492 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005493 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005494 if (decorator_list == NULL) goto failed;
5495 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005496 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005497 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5498 Py_INCREF(tmp2);
5499 res = obj2ast_expr(tmp2, &val, arena);
5500 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005501 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005502 if (len != PyList_GET_SIZE(tmp)) {
5503 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5504 goto failed;
5505 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005506 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005507 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005508 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005509 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005510 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5511 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005512 return 1;
5513 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005514 if (tmp == NULL || tmp == Py_None) {
5515 Py_CLEAR(tmp);
5516 returns = NULL;
5517 }
5518 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005519 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005520 res = obj2ast_expr(tmp, &returns, arena);
5521 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005522 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005523 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005524 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5525 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005526 return 1;
5527 }
5528 if (tmp == NULL || tmp == Py_None) {
5529 Py_CLEAR(tmp);
5530 type_comment = NULL;
5531 }
5532 else {
5533 int res;
5534 res = obj2ast_string(tmp, &type_comment, arena);
5535 if (res != 0) goto failed;
5536 Py_CLEAR(tmp);
5537 }
5538 *out = FunctionDef(name, args, body, decorator_list, returns,
5539 type_comment, lineno, col_offset, end_lineno,
5540 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005541 if (*out == NULL) goto failed;
5542 return 0;
5543 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005544 tp = astmodulestate_global->AsyncFunctionDef_type;
5545 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005546 if (isinstance == -1) {
5547 return 1;
5548 }
5549 if (isinstance) {
5550 identifier name;
5551 arguments_ty args;
5552 asdl_seq* body;
5553 asdl_seq* decorator_list;
5554 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005555 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005556
Dino Viehlandac46eb42019-09-11 10:16:34 -07005557 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005558 return 1;
5559 }
5560 if (tmp == NULL) {
5561 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5562 return 1;
5563 }
5564 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005565 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005566 res = obj2ast_identifier(tmp, &name, arena);
5567 if (res != 0) goto failed;
5568 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005569 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005570 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005571 return 1;
5572 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005573 if (tmp == NULL) {
5574 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5575 return 1;
5576 }
5577 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005578 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005579 res = obj2ast_arguments(tmp, &args, arena);
5580 if (res != 0) goto failed;
5581 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005582 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005583 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005584 return 1;
5585 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005586 if (tmp == NULL) {
5587 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5588 return 1;
5589 }
5590 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005591 int res;
5592 Py_ssize_t len;
5593 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005594 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005595 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 -04005596 goto failed;
5597 }
5598 len = PyList_GET_SIZE(tmp);
5599 body = _Py_asdl_seq_new(len, arena);
5600 if (body == NULL) goto failed;
5601 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005602 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005603 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5604 Py_INCREF(tmp2);
5605 res = obj2ast_stmt(tmp2, &val, arena);
5606 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005607 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005608 if (len != PyList_GET_SIZE(tmp)) {
5609 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5610 goto failed;
5611 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005612 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005613 }
5614 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005615 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005616 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5617 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005618 return 1;
5619 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005620 if (tmp == NULL) {
5621 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5622 return 1;
5623 }
5624 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005625 int res;
5626 Py_ssize_t len;
5627 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005628 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005629 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 -04005630 goto failed;
5631 }
5632 len = PyList_GET_SIZE(tmp);
5633 decorator_list = _Py_asdl_seq_new(len, arena);
5634 if (decorator_list == NULL) goto failed;
5635 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005636 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005637 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5638 Py_INCREF(tmp2);
5639 res = obj2ast_expr(tmp2, &val, arena);
5640 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005641 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005642 if (len != PyList_GET_SIZE(tmp)) {
5643 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5644 goto failed;
5645 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005646 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005647 }
5648 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005649 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005650 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5651 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005652 return 1;
5653 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005654 if (tmp == NULL || tmp == Py_None) {
5655 Py_CLEAR(tmp);
5656 returns = NULL;
5657 }
5658 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005659 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005660 res = obj2ast_expr(tmp, &returns, arena);
5661 if (res != 0) goto failed;
5662 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005663 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005664 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5665 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005666 return 1;
5667 }
5668 if (tmp == NULL || tmp == Py_None) {
5669 Py_CLEAR(tmp);
5670 type_comment = NULL;
5671 }
5672 else {
5673 int res;
5674 res = obj2ast_string(tmp, &type_comment, arena);
5675 if (res != 0) goto failed;
5676 Py_CLEAR(tmp);
5677 }
Yury Selivanov75445082015-05-11 22:57:16 -04005678 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005679 type_comment, lineno, col_offset, end_lineno,
5680 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005681 if (*out == NULL) goto failed;
5682 return 0;
5683 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005684 tp = astmodulestate_global->ClassDef_type;
5685 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005686 if (isinstance == -1) {
5687 return 1;
5688 }
5689 if (isinstance) {
5690 identifier name;
5691 asdl_seq* bases;
5692 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005693 asdl_seq* body;
5694 asdl_seq* decorator_list;
5695
Dino Viehlandac46eb42019-09-11 10:16:34 -07005696 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005697 return 1;
5698 }
5699 if (tmp == NULL) {
5700 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5701 return 1;
5702 }
5703 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005704 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005705 res = obj2ast_identifier(tmp, &name, arena);
5706 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005707 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005708 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005709 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005710 return 1;
5711 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005712 if (tmp == NULL) {
5713 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5714 return 1;
5715 }
5716 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005717 int res;
5718 Py_ssize_t len;
5719 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005720 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005721 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 +02005722 goto failed;
5723 }
5724 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005725 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005726 if (bases == NULL) goto failed;
5727 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005728 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005729 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5730 Py_INCREF(tmp2);
5731 res = obj2ast_expr(tmp2, &val, arena);
5732 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005733 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005734 if (len != PyList_GET_SIZE(tmp)) {
5735 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5736 goto failed;
5737 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005738 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005739 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005740 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005741 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005742 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5743 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005744 return 1;
5745 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005746 if (tmp == NULL) {
5747 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5748 return 1;
5749 }
5750 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005751 int res;
5752 Py_ssize_t len;
5753 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005754 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005755 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 +02005756 goto failed;
5757 }
5758 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005759 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005760 if (keywords == NULL) goto failed;
5761 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005762 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005763 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5764 Py_INCREF(tmp2);
5765 res = obj2ast_keyword(tmp2, &val, arena);
5766 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005767 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005768 if (len != PyList_GET_SIZE(tmp)) {
5769 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5770 goto failed;
5771 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005772 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005773 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005774 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005775 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005776 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005777 return 1;
5778 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005779 if (tmp == NULL) {
5780 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5781 return 1;
5782 }
5783 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005784 int res;
5785 Py_ssize_t len;
5786 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005787 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005788 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 +02005789 goto failed;
5790 }
5791 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005792 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005793 if (body == NULL) goto failed;
5794 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005795 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005796 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5797 Py_INCREF(tmp2);
5798 res = obj2ast_stmt(tmp2, &val, arena);
5799 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005800 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005801 if (len != PyList_GET_SIZE(tmp)) {
5802 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5803 goto failed;
5804 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005805 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005807 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005808 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005809 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5810 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005811 return 1;
5812 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005813 if (tmp == NULL) {
5814 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5815 return 1;
5816 }
5817 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005818 int res;
5819 Py_ssize_t len;
5820 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005821 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005822 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 +02005823 goto failed;
5824 }
5825 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005826 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005827 if (decorator_list == NULL) goto failed;
5828 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005829 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005830 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5831 Py_INCREF(tmp2);
5832 res = obj2ast_expr(tmp2, &val, arena);
5833 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005834 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005835 if (len != PyList_GET_SIZE(tmp)) {
5836 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5837 goto failed;
5838 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005839 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005840 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005841 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005842 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005843 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005844 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005845 if (*out == NULL) goto failed;
5846 return 0;
5847 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005848 tp = astmodulestate_global->Return_type;
5849 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005850 if (isinstance == -1) {
5851 return 1;
5852 }
5853 if (isinstance) {
5854 expr_ty value;
5855
Dino Viehlandac46eb42019-09-11 10:16:34 -07005856 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005857 return 1;
5858 }
5859 if (tmp == NULL || tmp == Py_None) {
5860 Py_CLEAR(tmp);
5861 value = NULL;
5862 }
5863 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005865 res = obj2ast_expr(tmp, &value, arena);
5866 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005867 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005868 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005869 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5870 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005871 if (*out == NULL) goto failed;
5872 return 0;
5873 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005874 tp = astmodulestate_global->Delete_type;
5875 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005876 if (isinstance == -1) {
5877 return 1;
5878 }
5879 if (isinstance) {
5880 asdl_seq* targets;
5881
Dino Viehlandac46eb42019-09-11 10:16:34 -07005882 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5883 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005884 return 1;
5885 }
5886 if (tmp == NULL) {
5887 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5888 return 1;
5889 }
5890 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005891 int res;
5892 Py_ssize_t len;
5893 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005894 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005895 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 +02005896 goto failed;
5897 }
5898 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005899 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005900 if (targets == NULL) goto failed;
5901 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005902 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005903 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5904 Py_INCREF(tmp2);
5905 res = obj2ast_expr(tmp2, &val, arena);
5906 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005907 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005908 if (len != PyList_GET_SIZE(tmp)) {
5909 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5910 goto failed;
5911 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005912 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005913 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005914 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005915 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005916 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5917 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005918 if (*out == NULL) goto failed;
5919 return 0;
5920 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005921 tp = astmodulestate_global->Assign_type;
5922 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005923 if (isinstance == -1) {
5924 return 1;
5925 }
5926 if (isinstance) {
5927 asdl_seq* targets;
5928 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005929 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005930
Dino Viehlandac46eb42019-09-11 10:16:34 -07005931 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5932 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005933 return 1;
5934 }
5935 if (tmp == NULL) {
5936 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5937 return 1;
5938 }
5939 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005940 int res;
5941 Py_ssize_t len;
5942 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005943 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005944 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 +02005945 goto failed;
5946 }
5947 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005948 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005949 if (targets == NULL) goto failed;
5950 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005951 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005952 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5953 Py_INCREF(tmp2);
5954 res = obj2ast_expr(tmp2, &val, arena);
5955 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005956 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005957 if (len != PyList_GET_SIZE(tmp)) {
5958 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5959 goto failed;
5960 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005961 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005962 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005963 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005965 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005966 return 1;
5967 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005968 if (tmp == NULL) {
5969 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5970 return 1;
5971 }
5972 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005974 res = obj2ast_expr(tmp, &value, arena);
5975 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005976 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005978 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5979 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005980 return 1;
5981 }
5982 if (tmp == NULL || tmp == Py_None) {
5983 Py_CLEAR(tmp);
5984 type_comment = NULL;
5985 }
5986 else {
5987 int res;
5988 res = obj2ast_string(tmp, &type_comment, arena);
5989 if (res != 0) goto failed;
5990 Py_CLEAR(tmp);
5991 }
5992 *out = Assign(targets, value, type_comment, lineno, col_offset,
5993 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005994 if (*out == NULL) goto failed;
5995 return 0;
5996 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005997 tp = astmodulestate_global->AugAssign_type;
5998 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005999 if (isinstance == -1) {
6000 return 1;
6001 }
6002 if (isinstance) {
6003 expr_ty target;
6004 operator_ty op;
6005 expr_ty value;
6006
Dino Viehlandac46eb42019-09-11 10:16:34 -07006007 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6008 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006009 return 1;
6010 }
6011 if (tmp == NULL) {
6012 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6013 return 1;
6014 }
6015 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006016 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006017 res = obj2ast_expr(tmp, &target, arena);
6018 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006019 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006021 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006022 return 1;
6023 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006024 if (tmp == NULL) {
6025 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6026 return 1;
6027 }
6028 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006029 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006030 res = obj2ast_operator(tmp, &op, arena);
6031 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006032 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006034 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006035 return 1;
6036 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006037 if (tmp == NULL) {
6038 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6039 return 1;
6040 }
6041 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006042 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006043 res = obj2ast_expr(tmp, &value, arena);
6044 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006045 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006046 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006047 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6048 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006049 if (*out == NULL) goto failed;
6050 return 0;
6051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006052 tp = astmodulestate_global->AnnAssign_type;
6053 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006054 if (isinstance == -1) {
6055 return 1;
6056 }
6057 if (isinstance) {
6058 expr_ty target;
6059 expr_ty annotation;
6060 expr_ty value;
6061 int simple;
6062
Dino Viehlandac46eb42019-09-11 10:16:34 -07006063 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6064 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006065 return 1;
6066 }
6067 if (tmp == NULL) {
6068 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6069 return 1;
6070 }
6071 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006072 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006073 res = obj2ast_expr(tmp, &target, arena);
6074 if (res != 0) goto failed;
6075 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006076 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006077 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6078 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006079 return 1;
6080 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006081 if (tmp == NULL) {
6082 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6083 return 1;
6084 }
6085 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006086 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006087 res = obj2ast_expr(tmp, &annotation, arena);
6088 if (res != 0) goto failed;
6089 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006090 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006091 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006092 return 1;
6093 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006094 if (tmp == NULL || tmp == Py_None) {
6095 Py_CLEAR(tmp);
6096 value = NULL;
6097 }
6098 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006099 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006100 res = obj2ast_expr(tmp, &value, arena);
6101 if (res != 0) goto failed;
6102 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006103 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006104 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6105 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006106 return 1;
6107 }
6108 if (tmp == NULL) {
6109 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6110 return 1;
6111 }
6112 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006113 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006114 res = obj2ast_int(tmp, &simple, arena);
6115 if (res != 0) goto failed;
6116 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006117 }
6118 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006119 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006120 if (*out == NULL) goto failed;
6121 return 0;
6122 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006123 tp = astmodulestate_global->For_type;
6124 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006125 if (isinstance == -1) {
6126 return 1;
6127 }
6128 if (isinstance) {
6129 expr_ty target;
6130 expr_ty iter;
6131 asdl_seq* body;
6132 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006133 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006134
Dino Viehlandac46eb42019-09-11 10:16:34 -07006135 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6136 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006137 return 1;
6138 }
6139 if (tmp == NULL) {
6140 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6141 return 1;
6142 }
6143 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006144 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006145 res = obj2ast_expr(tmp, &target, arena);
6146 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006147 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006149 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006150 return 1;
6151 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006152 if (tmp == NULL) {
6153 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6154 return 1;
6155 }
6156 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006157 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006158 res = obj2ast_expr(tmp, &iter, arena);
6159 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006160 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006162 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006163 return 1;
6164 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006165 if (tmp == NULL) {
6166 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6167 return 1;
6168 }
6169 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006170 int res;
6171 Py_ssize_t len;
6172 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006173 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006174 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 +02006175 goto failed;
6176 }
6177 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006178 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006179 if (body == NULL) goto failed;
6180 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006181 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006182 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6183 Py_INCREF(tmp2);
6184 res = obj2ast_stmt(tmp2, &val, arena);
6185 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006186 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006187 if (len != PyList_GET_SIZE(tmp)) {
6188 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6189 goto failed;
6190 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006191 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006192 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006193 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006195 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6196 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006197 return 1;
6198 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006199 if (tmp == NULL) {
6200 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6201 return 1;
6202 }
6203 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006204 int res;
6205 Py_ssize_t len;
6206 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006207 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006208 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 +02006209 goto failed;
6210 }
6211 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006212 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006213 if (orelse == NULL) goto failed;
6214 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006215 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006216 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6217 Py_INCREF(tmp2);
6218 res = obj2ast_stmt(tmp2, &val, arena);
6219 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006220 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006221 if (len != PyList_GET_SIZE(tmp)) {
6222 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6223 goto failed;
6224 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006225 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006226 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006227 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006229 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6230 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006231 return 1;
6232 }
6233 if (tmp == NULL || tmp == Py_None) {
6234 Py_CLEAR(tmp);
6235 type_comment = NULL;
6236 }
6237 else {
6238 int res;
6239 res = obj2ast_string(tmp, &type_comment, arena);
6240 if (res != 0) goto failed;
6241 Py_CLEAR(tmp);
6242 }
6243 *out = For(target, iter, body, orelse, type_comment, lineno,
6244 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006245 if (*out == NULL) goto failed;
6246 return 0;
6247 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006248 tp = astmodulestate_global->AsyncFor_type;
6249 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006250 if (isinstance == -1) {
6251 return 1;
6252 }
6253 if (isinstance) {
6254 expr_ty target;
6255 expr_ty iter;
6256 asdl_seq* body;
6257 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006258 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006259
Dino Viehlandac46eb42019-09-11 10:16:34 -07006260 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6261 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006262 return 1;
6263 }
6264 if (tmp == NULL) {
6265 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6266 return 1;
6267 }
6268 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006269 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006270 res = obj2ast_expr(tmp, &target, arena);
6271 if (res != 0) goto failed;
6272 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006274 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006275 return 1;
6276 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006277 if (tmp == NULL) {
6278 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6279 return 1;
6280 }
6281 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006282 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006283 res = obj2ast_expr(tmp, &iter, arena);
6284 if (res != 0) goto failed;
6285 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006287 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006288 return 1;
6289 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006290 if (tmp == NULL) {
6291 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6292 return 1;
6293 }
6294 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006295 int res;
6296 Py_ssize_t len;
6297 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006298 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006299 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 -04006300 goto failed;
6301 }
6302 len = PyList_GET_SIZE(tmp);
6303 body = _Py_asdl_seq_new(len, arena);
6304 if (body == NULL) goto failed;
6305 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006306 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006307 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6308 Py_INCREF(tmp2);
6309 res = obj2ast_stmt(tmp2, &val, arena);
6310 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006311 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006312 if (len != PyList_GET_SIZE(tmp)) {
6313 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6314 goto failed;
6315 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006316 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006317 }
6318 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006319 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006320 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6321 {
Yury Selivanov75445082015-05-11 22:57:16 -04006322 return 1;
6323 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006324 if (tmp == NULL) {
6325 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6326 return 1;
6327 }
6328 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006329 int res;
6330 Py_ssize_t len;
6331 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006332 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006333 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 -04006334 goto failed;
6335 }
6336 len = PyList_GET_SIZE(tmp);
6337 orelse = _Py_asdl_seq_new(len, arena);
6338 if (orelse == NULL) goto failed;
6339 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006340 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006341 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6342 Py_INCREF(tmp2);
6343 res = obj2ast_stmt(tmp2, &val, arena);
6344 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006345 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006346 if (len != PyList_GET_SIZE(tmp)) {
6347 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6348 goto failed;
6349 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006350 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006351 }
6352 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006353 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006354 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6355 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006356 return 1;
6357 }
6358 if (tmp == NULL || tmp == Py_None) {
6359 Py_CLEAR(tmp);
6360 type_comment = NULL;
6361 }
6362 else {
6363 int res;
6364 res = obj2ast_string(tmp, &type_comment, arena);
6365 if (res != 0) goto failed;
6366 Py_CLEAR(tmp);
6367 }
6368 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6369 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006370 if (*out == NULL) goto failed;
6371 return 0;
6372 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006373 tp = astmodulestate_global->While_type;
6374 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006375 if (isinstance == -1) {
6376 return 1;
6377 }
6378 if (isinstance) {
6379 expr_ty test;
6380 asdl_seq* body;
6381 asdl_seq* orelse;
6382
Dino Viehlandac46eb42019-09-11 10:16:34 -07006383 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006384 return 1;
6385 }
6386 if (tmp == NULL) {
6387 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6388 return 1;
6389 }
6390 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006391 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006392 res = obj2ast_expr(tmp, &test, arena);
6393 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006394 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006395 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006396 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006397 return 1;
6398 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006399 if (tmp == NULL) {
6400 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6401 return 1;
6402 }
6403 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006404 int res;
6405 Py_ssize_t len;
6406 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006407 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006408 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 +02006409 goto failed;
6410 }
6411 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006412 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006413 if (body == NULL) goto failed;
6414 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006415 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006416 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6417 Py_INCREF(tmp2);
6418 res = obj2ast_stmt(tmp2, &val, arena);
6419 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006420 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006421 if (len != PyList_GET_SIZE(tmp)) {
6422 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6423 goto failed;
6424 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006425 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006426 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006427 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006428 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006429 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6430 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006431 return 1;
6432 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006433 if (tmp == NULL) {
6434 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6435 return 1;
6436 }
6437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006438 int res;
6439 Py_ssize_t len;
6440 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006441 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006442 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 +02006443 goto failed;
6444 }
6445 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006446 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006447 if (orelse == NULL) goto failed;
6448 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006449 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006450 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6451 Py_INCREF(tmp2);
6452 res = obj2ast_stmt(tmp2, &val, arena);
6453 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006454 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006455 if (len != PyList_GET_SIZE(tmp)) {
6456 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6457 goto failed;
6458 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006459 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006460 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006461 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006462 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006463 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6464 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006465 if (*out == NULL) goto failed;
6466 return 0;
6467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006468 tp = astmodulestate_global->If_type;
6469 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006470 if (isinstance == -1) {
6471 return 1;
6472 }
6473 if (isinstance) {
6474 expr_ty test;
6475 asdl_seq* body;
6476 asdl_seq* orelse;
6477
Dino Viehlandac46eb42019-09-11 10:16:34 -07006478 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006479 return 1;
6480 }
6481 if (tmp == NULL) {
6482 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6483 return 1;
6484 }
6485 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006486 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006487 res = obj2ast_expr(tmp, &test, arena);
6488 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006489 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006490 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006491 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006492 return 1;
6493 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006494 if (tmp == NULL) {
6495 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6496 return 1;
6497 }
6498 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006499 int res;
6500 Py_ssize_t len;
6501 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006502 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006503 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 +02006504 goto failed;
6505 }
6506 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006507 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006508 if (body == NULL) goto failed;
6509 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006510 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006511 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6512 Py_INCREF(tmp2);
6513 res = obj2ast_stmt(tmp2, &val, arena);
6514 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006515 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006516 if (len != PyList_GET_SIZE(tmp)) {
6517 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6518 goto failed;
6519 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006520 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006521 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006522 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006523 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006524 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6525 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006526 return 1;
6527 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006528 if (tmp == NULL) {
6529 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6530 return 1;
6531 }
6532 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006533 int res;
6534 Py_ssize_t len;
6535 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006536 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006537 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 +02006538 goto failed;
6539 }
6540 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006541 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006542 if (orelse == NULL) goto failed;
6543 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006544 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006545 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6546 Py_INCREF(tmp2);
6547 res = obj2ast_stmt(tmp2, &val, arena);
6548 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006549 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006550 if (len != PyList_GET_SIZE(tmp)) {
6551 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6552 goto failed;
6553 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006554 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006555 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006556 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006557 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006558 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6559 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006560 if (*out == NULL) goto failed;
6561 return 0;
6562 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006563 tp = astmodulestate_global->With_type;
6564 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006565 if (isinstance == -1) {
6566 return 1;
6567 }
6568 if (isinstance) {
6569 asdl_seq* items;
6570 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006571 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006572
Dino Viehlandac46eb42019-09-11 10:16:34 -07006573 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006574 return 1;
6575 }
6576 if (tmp == NULL) {
6577 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6578 return 1;
6579 }
6580 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006581 int res;
6582 Py_ssize_t len;
6583 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006584 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006585 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 +02006586 goto failed;
6587 }
6588 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006589 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006590 if (items == NULL) goto failed;
6591 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006592 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006593 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6594 Py_INCREF(tmp2);
6595 res = obj2ast_withitem(tmp2, &val, arena);
6596 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006597 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006598 if (len != PyList_GET_SIZE(tmp)) {
6599 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6600 goto failed;
6601 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006602 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006603 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006604 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006605 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006606 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006607 return 1;
6608 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006609 if (tmp == NULL) {
6610 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6611 return 1;
6612 }
6613 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006614 int res;
6615 Py_ssize_t len;
6616 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006617 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006618 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 +02006619 goto failed;
6620 }
6621 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006622 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006623 if (body == NULL) goto failed;
6624 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006625 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006626 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6627 Py_INCREF(tmp2);
6628 res = obj2ast_stmt(tmp2, &val, arena);
6629 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006630 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006631 if (len != PyList_GET_SIZE(tmp)) {
6632 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6633 goto failed;
6634 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006635 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006636 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006637 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006638 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006639 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6640 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006641 return 1;
6642 }
6643 if (tmp == NULL || tmp == Py_None) {
6644 Py_CLEAR(tmp);
6645 type_comment = NULL;
6646 }
6647 else {
6648 int res;
6649 res = obj2ast_string(tmp, &type_comment, arena);
6650 if (res != 0) goto failed;
6651 Py_CLEAR(tmp);
6652 }
6653 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006654 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006655 if (*out == NULL) goto failed;
6656 return 0;
6657 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006658 tp = astmodulestate_global->AsyncWith_type;
6659 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006660 if (isinstance == -1) {
6661 return 1;
6662 }
6663 if (isinstance) {
6664 asdl_seq* items;
6665 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006666 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006667
Dino Viehlandac46eb42019-09-11 10:16:34 -07006668 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006669 return 1;
6670 }
6671 if (tmp == NULL) {
6672 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6673 return 1;
6674 }
6675 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006676 int res;
6677 Py_ssize_t len;
6678 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006679 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006680 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 -04006681 goto failed;
6682 }
6683 len = PyList_GET_SIZE(tmp);
6684 items = _Py_asdl_seq_new(len, arena);
6685 if (items == NULL) goto failed;
6686 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006687 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006688 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6689 Py_INCREF(tmp2);
6690 res = obj2ast_withitem(tmp2, &val, arena);
6691 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006692 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006693 if (len != PyList_GET_SIZE(tmp)) {
6694 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6695 goto failed;
6696 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006697 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006698 }
6699 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006700 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006701 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006702 return 1;
6703 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006704 if (tmp == NULL) {
6705 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6706 return 1;
6707 }
6708 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006709 int res;
6710 Py_ssize_t len;
6711 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006712 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006713 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 -04006714 goto failed;
6715 }
6716 len = PyList_GET_SIZE(tmp);
6717 body = _Py_asdl_seq_new(len, arena);
6718 if (body == NULL) goto failed;
6719 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006720 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006721 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6722 Py_INCREF(tmp2);
6723 res = obj2ast_stmt(tmp2, &val, arena);
6724 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006725 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006726 if (len != PyList_GET_SIZE(tmp)) {
6727 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6728 goto failed;
6729 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006730 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006731 }
6732 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006733 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006734 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6735 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006736 return 1;
6737 }
6738 if (tmp == NULL || tmp == Py_None) {
6739 Py_CLEAR(tmp);
6740 type_comment = NULL;
6741 }
6742 else {
6743 int res;
6744 res = obj2ast_string(tmp, &type_comment, arena);
6745 if (res != 0) goto failed;
6746 Py_CLEAR(tmp);
6747 }
6748 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6749 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006750 if (*out == NULL) goto failed;
6751 return 0;
6752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006753 tp = astmodulestate_global->Raise_type;
6754 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006755 if (isinstance == -1) {
6756 return 1;
6757 }
6758 if (isinstance) {
6759 expr_ty exc;
6760 expr_ty cause;
6761
Dino Viehlandac46eb42019-09-11 10:16:34 -07006762 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006763 return 1;
6764 }
6765 if (tmp == NULL || tmp == Py_None) {
6766 Py_CLEAR(tmp);
6767 exc = NULL;
6768 }
6769 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006770 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006771 res = obj2ast_expr(tmp, &exc, arena);
6772 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006773 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006774 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006775 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006776 return 1;
6777 }
6778 if (tmp == NULL || tmp == Py_None) {
6779 Py_CLEAR(tmp);
6780 cause = NULL;
6781 }
6782 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006783 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006784 res = obj2ast_expr(tmp, &cause, arena);
6785 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006786 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006787 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006788 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6789 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006790 if (*out == NULL) goto failed;
6791 return 0;
6792 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006793 tp = astmodulestate_global->Try_type;
6794 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006795 if (isinstance == -1) {
6796 return 1;
6797 }
6798 if (isinstance) {
6799 asdl_seq* body;
6800 asdl_seq* handlers;
6801 asdl_seq* orelse;
6802 asdl_seq* finalbody;
6803
Dino Viehlandac46eb42019-09-11 10:16:34 -07006804 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006805 return 1;
6806 }
6807 if (tmp == NULL) {
6808 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6809 return 1;
6810 }
6811 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006812 int res;
6813 Py_ssize_t len;
6814 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006815 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006816 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 +02006817 goto failed;
6818 }
6819 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006820 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006821 if (body == NULL) goto failed;
6822 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006823 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006824 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6825 Py_INCREF(tmp2);
6826 res = obj2ast_stmt(tmp2, &val, arena);
6827 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006828 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006829 if (len != PyList_GET_SIZE(tmp)) {
6830 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6831 goto failed;
6832 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006833 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006834 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006835 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006836 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006837 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6838 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006839 return 1;
6840 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006841 if (tmp == NULL) {
6842 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6843 return 1;
6844 }
6845 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006846 int res;
6847 Py_ssize_t len;
6848 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006849 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006850 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 +02006851 goto failed;
6852 }
6853 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006854 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006855 if (handlers == NULL) goto failed;
6856 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006857 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006858 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6859 Py_INCREF(tmp2);
6860 res = obj2ast_excepthandler(tmp2, &val, arena);
6861 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006862 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006863 if (len != PyList_GET_SIZE(tmp)) {
6864 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6865 goto failed;
6866 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006867 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006868 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006869 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006870 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006871 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6872 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006873 return 1;
6874 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006875 if (tmp == NULL) {
6876 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6877 return 1;
6878 }
6879 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006880 int res;
6881 Py_ssize_t len;
6882 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006883 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006884 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 +02006885 goto failed;
6886 }
6887 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006888 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006889 if (orelse == NULL) goto failed;
6890 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006891 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006892 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6893 Py_INCREF(tmp2);
6894 res = obj2ast_stmt(tmp2, &val, arena);
6895 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006896 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006897 if (len != PyList_GET_SIZE(tmp)) {
6898 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6899 goto failed;
6900 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006901 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006902 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006903 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006904 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006905 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6906 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006907 return 1;
6908 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006909 if (tmp == NULL) {
6910 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6911 return 1;
6912 }
6913 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006914 int res;
6915 Py_ssize_t len;
6916 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006917 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006918 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 +02006919 goto failed;
6920 }
6921 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006922 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006923 if (finalbody == NULL) goto failed;
6924 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006925 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006926 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6927 Py_INCREF(tmp2);
6928 res = obj2ast_stmt(tmp2, &val, arena);
6929 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006930 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006931 if (len != PyList_GET_SIZE(tmp)) {
6932 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6933 goto failed;
6934 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006935 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006936 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006937 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006938 }
6939 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006940 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006941 if (*out == NULL) goto failed;
6942 return 0;
6943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006944 tp = astmodulestate_global->Assert_type;
6945 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006946 if (isinstance == -1) {
6947 return 1;
6948 }
6949 if (isinstance) {
6950 expr_ty test;
6951 expr_ty msg;
6952
Dino Viehlandac46eb42019-09-11 10:16:34 -07006953 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006954 return 1;
6955 }
6956 if (tmp == NULL) {
6957 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6958 return 1;
6959 }
6960 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006961 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006962 res = obj2ast_expr(tmp, &test, arena);
6963 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006964 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006966 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006967 return 1;
6968 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006969 if (tmp == NULL || tmp == Py_None) {
6970 Py_CLEAR(tmp);
6971 msg = NULL;
6972 }
6973 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006975 res = obj2ast_expr(tmp, &msg, arena);
6976 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006977 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006978 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006979 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6980 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006981 if (*out == NULL) goto failed;
6982 return 0;
6983 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006984 tp = astmodulestate_global->Import_type;
6985 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006986 if (isinstance == -1) {
6987 return 1;
6988 }
6989 if (isinstance) {
6990 asdl_seq* names;
6991
Dino Viehlandac46eb42019-09-11 10:16:34 -07006992 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006993 return 1;
6994 }
6995 if (tmp == NULL) {
6996 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6997 return 1;
6998 }
6999 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007000 int res;
7001 Py_ssize_t len;
7002 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007004 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 +02007005 goto failed;
7006 }
7007 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007008 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007009 if (names == NULL) goto failed;
7010 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007011 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007012 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7013 Py_INCREF(tmp2);
7014 res = obj2ast_alias(tmp2, &val, arena);
7015 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007016 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007017 if (len != PyList_GET_SIZE(tmp)) {
7018 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7019 goto failed;
7020 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007021 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007022 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007023 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007024 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007025 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
7026 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007027 if (*out == NULL) goto failed;
7028 return 0;
7029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007030 tp = astmodulestate_global->ImportFrom_type;
7031 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007032 if (isinstance == -1) {
7033 return 1;
7034 }
7035 if (isinstance) {
7036 identifier module;
7037 asdl_seq* names;
7038 int level;
7039
Dino Viehlandac46eb42019-09-11 10:16:34 -07007040 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7041 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007042 return 1;
7043 }
7044 if (tmp == NULL || tmp == Py_None) {
7045 Py_CLEAR(tmp);
7046 module = NULL;
7047 }
7048 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007050 res = obj2ast_identifier(tmp, &module, arena);
7051 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007052 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007054 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007055 return 1;
7056 }
7057 if (tmp == NULL) {
7058 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7059 return 1;
7060 }
7061 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007062 int res;
7063 Py_ssize_t len;
7064 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007065 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007066 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 +02007067 goto failed;
7068 }
7069 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007070 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007071 if (names == NULL) goto failed;
7072 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007073 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007074 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7075 Py_INCREF(tmp2);
7076 res = obj2ast_alias(tmp2, &val, arena);
7077 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007078 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007079 if (len != PyList_GET_SIZE(tmp)) {
7080 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7081 goto failed;
7082 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007083 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007084 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007085 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007087 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007088 return 1;
7089 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007090 if (tmp == NULL || tmp == Py_None) {
7091 Py_CLEAR(tmp);
7092 level = 0;
7093 }
7094 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007095 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007096 res = obj2ast_int(tmp, &level, arena);
7097 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007098 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007099 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007100 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7101 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007102 if (*out == NULL) goto failed;
7103 return 0;
7104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007105 tp = astmodulestate_global->Global_type;
7106 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007107 if (isinstance == -1) {
7108 return 1;
7109 }
7110 if (isinstance) {
7111 asdl_seq* names;
7112
Dino Viehlandac46eb42019-09-11 10:16:34 -07007113 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007114 return 1;
7115 }
7116 if (tmp == NULL) {
7117 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7118 return 1;
7119 }
7120 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007121 int res;
7122 Py_ssize_t len;
7123 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007124 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007125 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 +02007126 goto failed;
7127 }
7128 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007129 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007130 if (names == NULL) goto failed;
7131 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007132 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007133 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7134 Py_INCREF(tmp2);
7135 res = obj2ast_identifier(tmp2, &val, arena);
7136 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007137 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007138 if (len != PyList_GET_SIZE(tmp)) {
7139 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7140 goto failed;
7141 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007142 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007143 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007144 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007145 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007146 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7147 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007148 if (*out == NULL) goto failed;
7149 return 0;
7150 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007151 tp = astmodulestate_global->Nonlocal_type;
7152 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007153 if (isinstance == -1) {
7154 return 1;
7155 }
7156 if (isinstance) {
7157 asdl_seq* names;
7158
Dino Viehlandac46eb42019-09-11 10:16:34 -07007159 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007160 return 1;
7161 }
7162 if (tmp == NULL) {
7163 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7164 return 1;
7165 }
7166 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007167 int res;
7168 Py_ssize_t len;
7169 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007170 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007171 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 +02007172 goto failed;
7173 }
7174 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007175 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007176 if (names == NULL) goto failed;
7177 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007178 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007179 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7180 Py_INCREF(tmp2);
7181 res = obj2ast_identifier(tmp2, &val, arena);
7182 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007183 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007184 if (len != PyList_GET_SIZE(tmp)) {
7185 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7186 goto failed;
7187 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007188 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007189 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007190 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007191 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007192 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7193 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007194 if (*out == NULL) goto failed;
7195 return 0;
7196 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007197 tp = astmodulestate_global->Expr_type;
7198 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007199 if (isinstance == -1) {
7200 return 1;
7201 }
7202 if (isinstance) {
7203 expr_ty value;
7204
Dino Viehlandac46eb42019-09-11 10:16:34 -07007205 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007206 return 1;
7207 }
7208 if (tmp == NULL) {
7209 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7210 return 1;
7211 }
7212 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007213 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007214 res = obj2ast_expr(tmp, &value, arena);
7215 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007216 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007217 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007218 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7219 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007220 if (*out == NULL) goto failed;
7221 return 0;
7222 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007223 tp = astmodulestate_global->Pass_type;
7224 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007225 if (isinstance == -1) {
7226 return 1;
7227 }
7228 if (isinstance) {
7229
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007230 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007231 if (*out == NULL) goto failed;
7232 return 0;
7233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007234 tp = astmodulestate_global->Break_type;
7235 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007236 if (isinstance == -1) {
7237 return 1;
7238 }
7239 if (isinstance) {
7240
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007241 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007242 if (*out == NULL) goto failed;
7243 return 0;
7244 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007245 tp = astmodulestate_global->Continue_type;
7246 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007247 if (isinstance == -1) {
7248 return 1;
7249 }
7250 if (isinstance) {
7251
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007252 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007253 if (*out == NULL) goto failed;
7254 return 0;
7255 }
7256
7257 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7258 failed:
7259 Py_XDECREF(tmp);
7260 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007261}
7262
7263int
7264obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7265{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007266 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007267
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007268 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007269 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007270 int lineno;
7271 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007272 int end_lineno;
7273 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007274
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007275 if (obj == Py_None) {
7276 *out = NULL;
7277 return 0;
7278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007279 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007280 return 1;
7281 }
7282 if (tmp == NULL) {
7283 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7284 return 1;
7285 }
7286 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007287 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 res = obj2ast_int(tmp, &lineno, arena);
7289 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007290 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007292 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7293 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007294 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007295 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007296 if (tmp == NULL) {
7297 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7298 return 1;
7299 }
7300 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007301 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007302 res = obj2ast_int(tmp, &col_offset, arena);
7303 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007304 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007305 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007306 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7307 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007308 return 1;
7309 }
7310 if (tmp == NULL || tmp == Py_None) {
7311 Py_CLEAR(tmp);
7312 end_lineno = 0;
7313 }
7314 else {
7315 int res;
7316 res = obj2ast_int(tmp, &end_lineno, arena);
7317 if (res != 0) goto failed;
7318 Py_CLEAR(tmp);
7319 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007320 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7321 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007322 return 1;
7323 }
7324 if (tmp == NULL || tmp == Py_None) {
7325 Py_CLEAR(tmp);
7326 end_col_offset = 0;
7327 }
7328 else {
7329 int res;
7330 res = obj2ast_int(tmp, &end_col_offset, arena);
7331 if (res != 0) goto failed;
7332 Py_CLEAR(tmp);
7333 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007334 tp = astmodulestate_global->BoolOp_type;
7335 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007336 if (isinstance == -1) {
7337 return 1;
7338 }
7339 if (isinstance) {
7340 boolop_ty op;
7341 asdl_seq* values;
7342
Dino Viehlandac46eb42019-09-11 10:16:34 -07007343 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007344 return 1;
7345 }
7346 if (tmp == NULL) {
7347 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7348 return 1;
7349 }
7350 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007351 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007352 res = obj2ast_boolop(tmp, &op, arena);
7353 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007354 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007355 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007356 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7357 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007358 return 1;
7359 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007360 if (tmp == NULL) {
7361 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7362 return 1;
7363 }
7364 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007365 int res;
7366 Py_ssize_t len;
7367 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007368 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007369 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 +02007370 goto failed;
7371 }
7372 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007373 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007374 if (values == NULL) goto failed;
7375 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007376 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007377 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7378 Py_INCREF(tmp2);
7379 res = obj2ast_expr(tmp2, &val, arena);
7380 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007381 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007382 if (len != PyList_GET_SIZE(tmp)) {
7383 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7384 goto failed;
7385 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007386 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007387 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007388 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007389 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007390 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7391 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007392 if (*out == NULL) goto failed;
7393 return 0;
7394 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007395 tp = astmodulestate_global->NamedExpr_type;
7396 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007397 if (isinstance == -1) {
7398 return 1;
7399 }
7400 if (isinstance) {
7401 expr_ty target;
7402 expr_ty value;
7403
Dino Viehlandac46eb42019-09-11 10:16:34 -07007404 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7405 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007406 return 1;
7407 }
7408 if (tmp == NULL) {
7409 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7410 return 1;
7411 }
7412 else {
7413 int res;
7414 res = obj2ast_expr(tmp, &target, arena);
7415 if (res != 0) goto failed;
7416 Py_CLEAR(tmp);
7417 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007418 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007419 return 1;
7420 }
7421 if (tmp == NULL) {
7422 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7423 return 1;
7424 }
7425 else {
7426 int res;
7427 res = obj2ast_expr(tmp, &value, arena);
7428 if (res != 0) goto failed;
7429 Py_CLEAR(tmp);
7430 }
7431 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7432 end_col_offset, arena);
7433 if (*out == NULL) goto failed;
7434 return 0;
7435 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007436 tp = astmodulestate_global->BinOp_type;
7437 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007438 if (isinstance == -1) {
7439 return 1;
7440 }
7441 if (isinstance) {
7442 expr_ty left;
7443 operator_ty op;
7444 expr_ty right;
7445
Dino Viehlandac46eb42019-09-11 10:16:34 -07007446 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007447 return 1;
7448 }
7449 if (tmp == NULL) {
7450 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7451 return 1;
7452 }
7453 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007454 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007455 res = obj2ast_expr(tmp, &left, arena);
7456 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007457 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007458 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007459 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007460 return 1;
7461 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007462 if (tmp == NULL) {
7463 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7464 return 1;
7465 }
7466 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007467 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007468 res = obj2ast_operator(tmp, &op, arena);
7469 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007470 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007471 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007472 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 return 1;
7474 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007475 if (tmp == NULL) {
7476 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7477 return 1;
7478 }
7479 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007481 res = obj2ast_expr(tmp, &right, arena);
7482 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007483 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007484 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007485 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7486 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007487 if (*out == NULL) goto failed;
7488 return 0;
7489 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007490 tp = astmodulestate_global->UnaryOp_type;
7491 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007492 if (isinstance == -1) {
7493 return 1;
7494 }
7495 if (isinstance) {
7496 unaryop_ty op;
7497 expr_ty operand;
7498
Dino Viehlandac46eb42019-09-11 10:16:34 -07007499 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007500 return 1;
7501 }
7502 if (tmp == NULL) {
7503 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7504 return 1;
7505 }
7506 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007508 res = obj2ast_unaryop(tmp, &op, arena);
7509 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007510 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007511 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007512 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7513 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 return 1;
7515 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007516 if (tmp == NULL) {
7517 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7518 return 1;
7519 }
7520 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007521 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007522 res = obj2ast_expr(tmp, &operand, arena);
7523 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007524 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007525 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007526 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7527 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007528 if (*out == NULL) goto failed;
7529 return 0;
7530 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007531 tp = astmodulestate_global->Lambda_type;
7532 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007533 if (isinstance == -1) {
7534 return 1;
7535 }
7536 if (isinstance) {
7537 arguments_ty args;
7538 expr_ty body;
7539
Dino Viehlandac46eb42019-09-11 10:16:34 -07007540 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007541 return 1;
7542 }
7543 if (tmp == NULL) {
7544 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7545 return 1;
7546 }
7547 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007548 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 res = obj2ast_arguments(tmp, &args, arena);
7550 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007551 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007552 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007553 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007554 return 1;
7555 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007556 if (tmp == NULL) {
7557 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7558 return 1;
7559 }
7560 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007562 res = obj2ast_expr(tmp, &body, arena);
7563 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007564 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007565 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007566 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7567 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007568 if (*out == NULL) goto failed;
7569 return 0;
7570 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007571 tp = astmodulestate_global->IfExp_type;
7572 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007573 if (isinstance == -1) {
7574 return 1;
7575 }
7576 if (isinstance) {
7577 expr_ty test;
7578 expr_ty body;
7579 expr_ty orelse;
7580
Dino Viehlandac46eb42019-09-11 10:16:34 -07007581 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007582 return 1;
7583 }
7584 if (tmp == NULL) {
7585 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7586 return 1;
7587 }
7588 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007589 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007590 res = obj2ast_expr(tmp, &test, arena);
7591 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007592 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007593 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007594 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 return 1;
7596 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007597 if (tmp == NULL) {
7598 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7599 return 1;
7600 }
7601 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007603 res = obj2ast_expr(tmp, &body, arena);
7604 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007605 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007606 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007607 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7608 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007609 return 1;
7610 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007611 if (tmp == NULL) {
7612 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7613 return 1;
7614 }
7615 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007617 res = obj2ast_expr(tmp, &orelse, arena);
7618 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007619 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007620 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007621 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7622 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007623 if (*out == NULL) goto failed;
7624 return 0;
7625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007626 tp = astmodulestate_global->Dict_type;
7627 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007628 if (isinstance == -1) {
7629 return 1;
7630 }
7631 if (isinstance) {
7632 asdl_seq* keys;
7633 asdl_seq* values;
7634
Dino Viehlandac46eb42019-09-11 10:16:34 -07007635 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007636 return 1;
7637 }
7638 if (tmp == NULL) {
7639 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7640 return 1;
7641 }
7642 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007643 int res;
7644 Py_ssize_t len;
7645 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007646 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007647 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 +02007648 goto failed;
7649 }
7650 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007651 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007652 if (keys == NULL) goto failed;
7653 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007654 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007655 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7656 Py_INCREF(tmp2);
7657 res = obj2ast_expr(tmp2, &val, arena);
7658 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007659 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007660 if (len != PyList_GET_SIZE(tmp)) {
7661 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7662 goto failed;
7663 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007664 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007665 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007666 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007667 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007668 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7669 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007670 return 1;
7671 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007672 if (tmp == NULL) {
7673 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7674 return 1;
7675 }
7676 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007677 int res;
7678 Py_ssize_t len;
7679 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007680 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007681 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 +02007682 goto failed;
7683 }
7684 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007685 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007686 if (values == NULL) goto failed;
7687 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007688 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007689 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7690 Py_INCREF(tmp2);
7691 res = obj2ast_expr(tmp2, &val, arena);
7692 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007693 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007694 if (len != PyList_GET_SIZE(tmp)) {
7695 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7696 goto failed;
7697 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007698 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007699 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007700 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007701 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007702 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7703 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007704 if (*out == NULL) goto failed;
7705 return 0;
7706 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007707 tp = astmodulestate_global->Set_type;
7708 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007709 if (isinstance == -1) {
7710 return 1;
7711 }
7712 if (isinstance) {
7713 asdl_seq* elts;
7714
Dino Viehlandac46eb42019-09-11 10:16:34 -07007715 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007716 return 1;
7717 }
7718 if (tmp == NULL) {
7719 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7720 return 1;
7721 }
7722 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007723 int res;
7724 Py_ssize_t len;
7725 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007726 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007727 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 +02007728 goto failed;
7729 }
7730 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007731 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007732 if (elts == NULL) goto failed;
7733 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007734 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007735 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7736 Py_INCREF(tmp2);
7737 res = obj2ast_expr(tmp2, &val, arena);
7738 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007739 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007740 if (len != PyList_GET_SIZE(tmp)) {
7741 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7742 goto failed;
7743 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007744 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007745 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007746 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007747 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007748 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007749 if (*out == NULL) goto failed;
7750 return 0;
7751 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007752 tp = astmodulestate_global->ListComp_type;
7753 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007754 if (isinstance == -1) {
7755 return 1;
7756 }
7757 if (isinstance) {
7758 expr_ty elt;
7759 asdl_seq* generators;
7760
Dino Viehlandac46eb42019-09-11 10:16:34 -07007761 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007762 return 1;
7763 }
7764 if (tmp == NULL) {
7765 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7766 return 1;
7767 }
7768 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007769 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007770 res = obj2ast_expr(tmp, &elt, arena);
7771 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007772 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007773 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007774 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7775 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007776 return 1;
7777 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007778 if (tmp == NULL) {
7779 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7780 return 1;
7781 }
7782 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007783 int res;
7784 Py_ssize_t len;
7785 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007786 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007787 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 +02007788 goto failed;
7789 }
7790 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007791 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007792 if (generators == NULL) goto failed;
7793 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007794 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007795 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7796 Py_INCREF(tmp2);
7797 res = obj2ast_comprehension(tmp2, &val, arena);
7798 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007799 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007800 if (len != PyList_GET_SIZE(tmp)) {
7801 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7802 goto failed;
7803 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007804 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007805 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007806 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007807 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007808 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7809 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007810 if (*out == NULL) goto failed;
7811 return 0;
7812 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007813 tp = astmodulestate_global->SetComp_type;
7814 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007815 if (isinstance == -1) {
7816 return 1;
7817 }
7818 if (isinstance) {
7819 expr_ty elt;
7820 asdl_seq* generators;
7821
Dino Viehlandac46eb42019-09-11 10:16:34 -07007822 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007823 return 1;
7824 }
7825 if (tmp == NULL) {
7826 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7827 return 1;
7828 }
7829 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007830 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007831 res = obj2ast_expr(tmp, &elt, arena);
7832 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007833 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007834 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007835 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7836 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007837 return 1;
7838 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007839 if (tmp == NULL) {
7840 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7841 return 1;
7842 }
7843 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007844 int res;
7845 Py_ssize_t len;
7846 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007847 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007848 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 +02007849 goto failed;
7850 }
7851 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007852 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007853 if (generators == NULL) goto failed;
7854 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007855 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007856 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7857 Py_INCREF(tmp2);
7858 res = obj2ast_comprehension(tmp2, &val, arena);
7859 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007860 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007861 if (len != PyList_GET_SIZE(tmp)) {
7862 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7863 goto failed;
7864 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007865 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007866 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007867 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007868 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007869 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7870 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007871 if (*out == NULL) goto failed;
7872 return 0;
7873 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007874 tp = astmodulestate_global->DictComp_type;
7875 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007876 if (isinstance == -1) {
7877 return 1;
7878 }
7879 if (isinstance) {
7880 expr_ty key;
7881 expr_ty value;
7882 asdl_seq* generators;
7883
Dino Viehlandac46eb42019-09-11 10:16:34 -07007884 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007885 return 1;
7886 }
7887 if (tmp == NULL) {
7888 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7889 return 1;
7890 }
7891 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007892 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007893 res = obj2ast_expr(tmp, &key, arena);
7894 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007895 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007896 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007897 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007898 return 1;
7899 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007900 if (tmp == NULL) {
7901 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7902 return 1;
7903 }
7904 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007905 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007906 res = obj2ast_expr(tmp, &value, arena);
7907 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007908 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007909 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007910 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7911 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007912 return 1;
7913 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007914 if (tmp == NULL) {
7915 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7916 return 1;
7917 }
7918 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007919 int res;
7920 Py_ssize_t len;
7921 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007922 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007923 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 +02007924 goto failed;
7925 }
7926 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007927 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007928 if (generators == NULL) goto failed;
7929 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007930 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007931 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7932 Py_INCREF(tmp2);
7933 res = obj2ast_comprehension(tmp2, &val, arena);
7934 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007935 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007936 if (len != PyList_GET_SIZE(tmp)) {
7937 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7938 goto failed;
7939 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007940 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007941 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007942 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007943 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007944 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7945 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007946 if (*out == NULL) goto failed;
7947 return 0;
7948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007949 tp = astmodulestate_global->GeneratorExp_type;
7950 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007951 if (isinstance == -1) {
7952 return 1;
7953 }
7954 if (isinstance) {
7955 expr_ty elt;
7956 asdl_seq* generators;
7957
Dino Viehlandac46eb42019-09-11 10:16:34 -07007958 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007959 return 1;
7960 }
7961 if (tmp == NULL) {
7962 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7963 return 1;
7964 }
7965 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007966 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007967 res = obj2ast_expr(tmp, &elt, arena);
7968 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007969 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007971 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7972 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007973 return 1;
7974 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007975 if (tmp == NULL) {
7976 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7977 return 1;
7978 }
7979 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007980 int res;
7981 Py_ssize_t len;
7982 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007983 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007984 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 +02007985 goto failed;
7986 }
7987 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007988 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007989 if (generators == NULL) goto failed;
7990 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007991 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007992 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7993 Py_INCREF(tmp2);
7994 res = obj2ast_comprehension(tmp2, &val, arena);
7995 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007996 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007997 if (len != PyList_GET_SIZE(tmp)) {
7998 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7999 goto failed;
8000 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008001 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008002 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008003 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008004 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008005 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
8006 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008007 if (*out == NULL) goto failed;
8008 return 0;
8009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008010 tp = astmodulestate_global->Await_type;
8011 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008012 if (isinstance == -1) {
8013 return 1;
8014 }
8015 if (isinstance) {
8016 expr_ty value;
8017
Dino Viehlandac46eb42019-09-11 10:16:34 -07008018 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008019 return 1;
8020 }
8021 if (tmp == NULL) {
8022 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8023 return 1;
8024 }
8025 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008026 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04008027 res = obj2ast_expr(tmp, &value, arena);
8028 if (res != 0) goto failed;
8029 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008030 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008031 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
8032 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008033 if (*out == NULL) goto failed;
8034 return 0;
8035 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008036 tp = astmodulestate_global->Yield_type;
8037 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008038 if (isinstance == -1) {
8039 return 1;
8040 }
8041 if (isinstance) {
8042 expr_ty value;
8043
Dino Viehlandac46eb42019-09-11 10:16:34 -07008044 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008045 return 1;
8046 }
8047 if (tmp == NULL || tmp == Py_None) {
8048 Py_CLEAR(tmp);
8049 value = NULL;
8050 }
8051 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008052 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008053 res = obj2ast_expr(tmp, &value, arena);
8054 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008055 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008056 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008057 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8058 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008059 if (*out == NULL) goto failed;
8060 return 0;
8061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008062 tp = astmodulestate_global->YieldFrom_type;
8063 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008064 if (isinstance == -1) {
8065 return 1;
8066 }
8067 if (isinstance) {
8068 expr_ty value;
8069
Dino Viehlandac46eb42019-09-11 10:16:34 -07008070 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008071 return 1;
8072 }
8073 if (tmp == NULL) {
8074 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8075 return 1;
8076 }
8077 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008078 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008079 res = obj2ast_expr(tmp, &value, arena);
8080 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008081 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008082 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008083 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8084 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008085 if (*out == NULL) goto failed;
8086 return 0;
8087 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008088 tp = astmodulestate_global->Compare_type;
8089 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008090 if (isinstance == -1) {
8091 return 1;
8092 }
8093 if (isinstance) {
8094 expr_ty left;
8095 asdl_int_seq* ops;
8096 asdl_seq* comparators;
8097
Dino Viehlandac46eb42019-09-11 10:16:34 -07008098 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008099 return 1;
8100 }
8101 if (tmp == NULL) {
8102 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8103 return 1;
8104 }
8105 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008106 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008107 res = obj2ast_expr(tmp, &left, arena);
8108 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008109 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008110 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008111 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008112 return 1;
8113 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008114 if (tmp == NULL) {
8115 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8116 return 1;
8117 }
8118 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008119 int res;
8120 Py_ssize_t len;
8121 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008122 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008123 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 +02008124 goto failed;
8125 }
8126 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008127 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008128 if (ops == NULL) goto failed;
8129 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008130 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008131 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8132 Py_INCREF(tmp2);
8133 res = obj2ast_cmpop(tmp2, &val, arena);
8134 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008135 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008136 if (len != PyList_GET_SIZE(tmp)) {
8137 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8138 goto failed;
8139 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008140 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008141 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008142 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008144 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8145 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008146 return 1;
8147 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008148 if (tmp == NULL) {
8149 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8150 return 1;
8151 }
8152 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008153 int res;
8154 Py_ssize_t len;
8155 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008156 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008157 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 +02008158 goto failed;
8159 }
8160 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008161 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008162 if (comparators == NULL) goto failed;
8163 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008164 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008165 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8166 Py_INCREF(tmp2);
8167 res = obj2ast_expr(tmp2, &val, arena);
8168 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008169 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008170 if (len != PyList_GET_SIZE(tmp)) {
8171 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8172 goto failed;
8173 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008174 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008175 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008176 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008177 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008178 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8179 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008180 if (*out == NULL) goto failed;
8181 return 0;
8182 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008183 tp = astmodulestate_global->Call_type;
8184 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008185 if (isinstance == -1) {
8186 return 1;
8187 }
8188 if (isinstance) {
8189 expr_ty func;
8190 asdl_seq* args;
8191 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008192
Dino Viehlandac46eb42019-09-11 10:16:34 -07008193 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008194 return 1;
8195 }
8196 if (tmp == NULL) {
8197 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8198 return 1;
8199 }
8200 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008201 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008202 res = obj2ast_expr(tmp, &func, arena);
8203 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008204 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008206 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008207 return 1;
8208 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008209 if (tmp == NULL) {
8210 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8211 return 1;
8212 }
8213 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008214 int res;
8215 Py_ssize_t len;
8216 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008217 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008218 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 +02008219 goto failed;
8220 }
8221 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008222 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008223 if (args == NULL) goto failed;
8224 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008225 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008226 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8227 Py_INCREF(tmp2);
8228 res = obj2ast_expr(tmp2, &val, arena);
8229 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008230 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008231 if (len != PyList_GET_SIZE(tmp)) {
8232 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8233 goto failed;
8234 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008235 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008236 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008237 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008238 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008239 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8240 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008241 return 1;
8242 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008243 if (tmp == NULL) {
8244 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8245 return 1;
8246 }
8247 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008248 int res;
8249 Py_ssize_t len;
8250 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008251 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008252 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 +02008253 goto failed;
8254 }
8255 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008256 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008257 if (keywords == NULL) goto failed;
8258 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008259 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008260 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8261 Py_INCREF(tmp2);
8262 res = obj2ast_keyword(tmp2, &val, arena);
8263 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008264 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008265 if (len != PyList_GET_SIZE(tmp)) {
8266 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8267 goto failed;
8268 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008269 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008270 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008271 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008272 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008273 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8274 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008275 if (*out == NULL) goto failed;
8276 return 0;
8277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008278 tp = astmodulestate_global->FormattedValue_type;
8279 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008280 if (isinstance == -1) {
8281 return 1;
8282 }
8283 if (isinstance) {
8284 expr_ty value;
8285 int conversion;
8286 expr_ty format_spec;
8287
Dino Viehlandac46eb42019-09-11 10:16:34 -07008288 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008289 return 1;
8290 }
8291 if (tmp == NULL) {
8292 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8293 return 1;
8294 }
8295 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008296 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008297 res = obj2ast_expr(tmp, &value, arena);
8298 if (res != 0) goto failed;
8299 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008300 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008301 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8302 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008303 return 1;
8304 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008305 if (tmp == NULL || tmp == Py_None) {
8306 Py_CLEAR(tmp);
8307 conversion = 0;
8308 }
8309 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008310 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008311 res = obj2ast_int(tmp, &conversion, arena);
8312 if (res != 0) goto failed;
8313 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008314 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008315 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8316 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008317 return 1;
8318 }
8319 if (tmp == NULL || tmp == Py_None) {
8320 Py_CLEAR(tmp);
8321 format_spec = NULL;
8322 }
8323 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008324 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008325 res = obj2ast_expr(tmp, &format_spec, arena);
8326 if (res != 0) goto failed;
8327 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008328 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008329 *out = FormattedValue(value, conversion, format_spec, lineno,
8330 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008331 if (*out == NULL) goto failed;
8332 return 0;
8333 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008334 tp = astmodulestate_global->JoinedStr_type;
8335 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008336 if (isinstance == -1) {
8337 return 1;
8338 }
8339 if (isinstance) {
8340 asdl_seq* values;
8341
Dino Viehlandac46eb42019-09-11 10:16:34 -07008342 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8343 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008344 return 1;
8345 }
8346 if (tmp == NULL) {
8347 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8348 return 1;
8349 }
8350 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008351 int res;
8352 Py_ssize_t len;
8353 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008354 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008355 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 -04008356 goto failed;
8357 }
8358 len = PyList_GET_SIZE(tmp);
8359 values = _Py_asdl_seq_new(len, arena);
8360 if (values == NULL) goto failed;
8361 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008362 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008363 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8364 Py_INCREF(tmp2);
8365 res = obj2ast_expr(tmp2, &val, arena);
8366 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008367 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008368 if (len != PyList_GET_SIZE(tmp)) {
8369 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8370 goto failed;
8371 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008372 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008373 }
8374 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008375 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008376 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8377 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008378 if (*out == NULL) goto failed;
8379 return 0;
8380 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008381 tp = astmodulestate_global->Constant_type;
8382 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008383 if (isinstance == -1) {
8384 return 1;
8385 }
8386 if (isinstance) {
8387 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008388 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008389
Dino Viehlandac46eb42019-09-11 10:16:34 -07008390 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008391 return 1;
8392 }
8393 if (tmp == NULL) {
8394 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8395 return 1;
8396 }
8397 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008398 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008399 res = obj2ast_constant(tmp, &value, arena);
8400 if (res != 0) goto failed;
8401 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008402 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008403 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008404 return 1;
8405 }
8406 if (tmp == NULL || tmp == Py_None) {
8407 Py_CLEAR(tmp);
8408 kind = NULL;
8409 }
8410 else {
8411 int res;
8412 res = obj2ast_string(tmp, &kind, arena);
8413 if (res != 0) goto failed;
8414 Py_CLEAR(tmp);
8415 }
8416 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8417 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008418 if (*out == NULL) goto failed;
8419 return 0;
8420 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008421 tp = astmodulestate_global->Attribute_type;
8422 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008423 if (isinstance == -1) {
8424 return 1;
8425 }
8426 if (isinstance) {
8427 expr_ty value;
8428 identifier attr;
8429 expr_context_ty ctx;
8430
Dino Viehlandac46eb42019-09-11 10:16:34 -07008431 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008432 return 1;
8433 }
8434 if (tmp == NULL) {
8435 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8436 return 1;
8437 }
8438 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008439 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008440 res = obj2ast_expr(tmp, &value, arena);
8441 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008442 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008443 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008444 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008445 return 1;
8446 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008447 if (tmp == NULL) {
8448 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8449 return 1;
8450 }
8451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008452 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008453 res = obj2ast_identifier(tmp, &attr, arena);
8454 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008455 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008456 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008457 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008458 return 1;
8459 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008460 if (tmp == NULL) {
8461 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8462 return 1;
8463 }
8464 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008466 res = obj2ast_expr_context(tmp, &ctx, arena);
8467 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008468 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008469 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008470 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8471 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008472 if (*out == NULL) goto failed;
8473 return 0;
8474 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008475 tp = astmodulestate_global->Subscript_type;
8476 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008477 if (isinstance == -1) {
8478 return 1;
8479 }
8480 if (isinstance) {
8481 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008482 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008483 expr_context_ty ctx;
8484
Dino Viehlandac46eb42019-09-11 10:16:34 -07008485 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008486 return 1;
8487 }
8488 if (tmp == NULL) {
8489 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8490 return 1;
8491 }
8492 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008493 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008494 res = obj2ast_expr(tmp, &value, arena);
8495 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008496 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008497 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008498 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008499 return 1;
8500 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008501 if (tmp == NULL) {
8502 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8503 return 1;
8504 }
8505 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008506 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008507 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008508 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008509 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008510 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008511 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008512 return 1;
8513 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008514 if (tmp == NULL) {
8515 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8516 return 1;
8517 }
8518 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008520 res = obj2ast_expr_context(tmp, &ctx, arena);
8521 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008522 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008523 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008524 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8525 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008526 if (*out == NULL) goto failed;
8527 return 0;
8528 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008529 tp = astmodulestate_global->Starred_type;
8530 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008531 if (isinstance == -1) {
8532 return 1;
8533 }
8534 if (isinstance) {
8535 expr_ty value;
8536 expr_context_ty ctx;
8537
Dino Viehlandac46eb42019-09-11 10:16:34 -07008538 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008539 return 1;
8540 }
8541 if (tmp == NULL) {
8542 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8543 return 1;
8544 }
8545 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008546 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008547 res = obj2ast_expr(tmp, &value, arena);
8548 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008549 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008550 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008551 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008552 return 1;
8553 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008554 if (tmp == NULL) {
8555 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8556 return 1;
8557 }
8558 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008559 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008560 res = obj2ast_expr_context(tmp, &ctx, arena);
8561 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008562 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008563 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008564 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8565 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008566 if (*out == NULL) goto failed;
8567 return 0;
8568 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008569 tp = astmodulestate_global->Name_type;
8570 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 if (isinstance == -1) {
8572 return 1;
8573 }
8574 if (isinstance) {
8575 identifier id;
8576 expr_context_ty ctx;
8577
Dino Viehlandac46eb42019-09-11 10:16:34 -07008578 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008579 return 1;
8580 }
8581 if (tmp == NULL) {
8582 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8583 return 1;
8584 }
8585 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008586 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008587 res = obj2ast_identifier(tmp, &id, arena);
8588 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008589 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008590 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008591 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008592 return 1;
8593 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008594 if (tmp == NULL) {
8595 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8596 return 1;
8597 }
8598 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008599 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008600 res = obj2ast_expr_context(tmp, &ctx, arena);
8601 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008602 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008603 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008604 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8605 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008606 if (*out == NULL) goto failed;
8607 return 0;
8608 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008609 tp = astmodulestate_global->List_type;
8610 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008611 if (isinstance == -1) {
8612 return 1;
8613 }
8614 if (isinstance) {
8615 asdl_seq* elts;
8616 expr_context_ty ctx;
8617
Dino Viehlandac46eb42019-09-11 10:16:34 -07008618 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008619 return 1;
8620 }
8621 if (tmp == NULL) {
8622 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8623 return 1;
8624 }
8625 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008626 int res;
8627 Py_ssize_t len;
8628 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008629 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008630 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 +02008631 goto failed;
8632 }
8633 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008634 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008635 if (elts == NULL) goto failed;
8636 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008637 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008638 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8639 Py_INCREF(tmp2);
8640 res = obj2ast_expr(tmp2, &val, arena);
8641 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008642 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008643 if (len != PyList_GET_SIZE(tmp)) {
8644 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8645 goto failed;
8646 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008647 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008648 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008649 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008650 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008651 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008652 return 1;
8653 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008654 if (tmp == NULL) {
8655 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8656 return 1;
8657 }
8658 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008659 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008660 res = obj2ast_expr_context(tmp, &ctx, arena);
8661 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008662 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008663 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008664 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8665 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008666 if (*out == NULL) goto failed;
8667 return 0;
8668 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008669 tp = astmodulestate_global->Tuple_type;
8670 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008671 if (isinstance == -1) {
8672 return 1;
8673 }
8674 if (isinstance) {
8675 asdl_seq* elts;
8676 expr_context_ty ctx;
8677
Dino Viehlandac46eb42019-09-11 10:16:34 -07008678 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008679 return 1;
8680 }
8681 if (tmp == NULL) {
8682 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8683 return 1;
8684 }
8685 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008686 int res;
8687 Py_ssize_t len;
8688 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008689 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008690 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 +02008691 goto failed;
8692 }
8693 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008694 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008695 if (elts == NULL) goto failed;
8696 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008697 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008698 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8699 Py_INCREF(tmp2);
8700 res = obj2ast_expr(tmp2, &val, arena);
8701 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008702 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008703 if (len != PyList_GET_SIZE(tmp)) {
8704 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8705 goto failed;
8706 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008707 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008708 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008709 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008710 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008711 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008712 return 1;
8713 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008714 if (tmp == NULL) {
8715 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8716 return 1;
8717 }
8718 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008719 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008720 res = obj2ast_expr_context(tmp, &ctx, arena);
8721 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008722 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008723 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008724 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8725 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008726 if (*out == NULL) goto failed;
8727 return 0;
8728 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008729 tp = astmodulestate_global->Slice_type;
8730 isinstance = PyObject_IsInstance(obj, tp);
8731 if (isinstance == -1) {
8732 return 1;
8733 }
8734 if (isinstance) {
8735 expr_ty lower;
8736 expr_ty upper;
8737 expr_ty step;
8738
8739 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8740 return 1;
8741 }
8742 if (tmp == NULL || tmp == Py_None) {
8743 Py_CLEAR(tmp);
8744 lower = NULL;
8745 }
8746 else {
8747 int res;
8748 res = obj2ast_expr(tmp, &lower, arena);
8749 if (res != 0) goto failed;
8750 Py_CLEAR(tmp);
8751 }
8752 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8753 return 1;
8754 }
8755 if (tmp == NULL || tmp == Py_None) {
8756 Py_CLEAR(tmp);
8757 upper = NULL;
8758 }
8759 else {
8760 int res;
8761 res = obj2ast_expr(tmp, &upper, arena);
8762 if (res != 0) goto failed;
8763 Py_CLEAR(tmp);
8764 }
8765 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8766 return 1;
8767 }
8768 if (tmp == NULL || tmp == Py_None) {
8769 Py_CLEAR(tmp);
8770 step = NULL;
8771 }
8772 else {
8773 int res;
8774 res = obj2ast_expr(tmp, &step, arena);
8775 if (res != 0) goto failed;
8776 Py_CLEAR(tmp);
8777 }
8778 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8779 end_col_offset, arena);
8780 if (*out == NULL) goto failed;
8781 return 0;
8782 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008783
8784 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8785 failed:
8786 Py_XDECREF(tmp);
8787 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008788}
8789
8790int
8791obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8792{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008793 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008794
Dino Viehlandac46eb42019-09-11 10:16:34 -07008795 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008796 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008797 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008798 }
8799 if (isinstance) {
8800 *out = Load;
8801 return 0;
8802 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008803 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008804 if (isinstance == -1) {
8805 return 1;
8806 }
8807 if (isinstance) {
8808 *out = Store;
8809 return 0;
8810 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008811 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008812 if (isinstance == -1) {
8813 return 1;
8814 }
8815 if (isinstance) {
8816 *out = Del;
8817 return 0;
8818 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008819
8820 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8821 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008822}
8823
8824int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008825obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8826{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008827 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008828
Dino Viehlandac46eb42019-09-11 10:16:34 -07008829 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008830 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008831 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008832 }
8833 if (isinstance) {
8834 *out = And;
8835 return 0;
8836 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008837 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008838 if (isinstance == -1) {
8839 return 1;
8840 }
8841 if (isinstance) {
8842 *out = Or;
8843 return 0;
8844 }
8845
8846 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8847 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008848}
8849
8850int
8851obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8852{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008853 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008854
Dino Viehlandac46eb42019-09-11 10:16:34 -07008855 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008856 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008857 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008858 }
8859 if (isinstance) {
8860 *out = Add;
8861 return 0;
8862 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008863 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008864 if (isinstance == -1) {
8865 return 1;
8866 }
8867 if (isinstance) {
8868 *out = Sub;
8869 return 0;
8870 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008871 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008872 if (isinstance == -1) {
8873 return 1;
8874 }
8875 if (isinstance) {
8876 *out = Mult;
8877 return 0;
8878 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008879 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008880 if (isinstance == -1) {
8881 return 1;
8882 }
8883 if (isinstance) {
8884 *out = MatMult;
8885 return 0;
8886 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008887 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008888 if (isinstance == -1) {
8889 return 1;
8890 }
8891 if (isinstance) {
8892 *out = Div;
8893 return 0;
8894 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008895 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008896 if (isinstance == -1) {
8897 return 1;
8898 }
8899 if (isinstance) {
8900 *out = Mod;
8901 return 0;
8902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008903 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008904 if (isinstance == -1) {
8905 return 1;
8906 }
8907 if (isinstance) {
8908 *out = Pow;
8909 return 0;
8910 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008911 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008912 if (isinstance == -1) {
8913 return 1;
8914 }
8915 if (isinstance) {
8916 *out = LShift;
8917 return 0;
8918 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008919 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008920 if (isinstance == -1) {
8921 return 1;
8922 }
8923 if (isinstance) {
8924 *out = RShift;
8925 return 0;
8926 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008927 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008928 if (isinstance == -1) {
8929 return 1;
8930 }
8931 if (isinstance) {
8932 *out = BitOr;
8933 return 0;
8934 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008935 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008936 if (isinstance == -1) {
8937 return 1;
8938 }
8939 if (isinstance) {
8940 *out = BitXor;
8941 return 0;
8942 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008943 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008944 if (isinstance == -1) {
8945 return 1;
8946 }
8947 if (isinstance) {
8948 *out = BitAnd;
8949 return 0;
8950 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008951 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008952 if (isinstance == -1) {
8953 return 1;
8954 }
8955 if (isinstance) {
8956 *out = FloorDiv;
8957 return 0;
8958 }
8959
8960 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8961 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008962}
8963
8964int
8965obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8966{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008967 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008968
Dino Viehlandac46eb42019-09-11 10:16:34 -07008969 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008970 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008971 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008972 }
8973 if (isinstance) {
8974 *out = Invert;
8975 return 0;
8976 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008977 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008978 if (isinstance == -1) {
8979 return 1;
8980 }
8981 if (isinstance) {
8982 *out = Not;
8983 return 0;
8984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008985 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008986 if (isinstance == -1) {
8987 return 1;
8988 }
8989 if (isinstance) {
8990 *out = UAdd;
8991 return 0;
8992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008993 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008994 if (isinstance == -1) {
8995 return 1;
8996 }
8997 if (isinstance) {
8998 *out = USub;
8999 return 0;
9000 }
9001
9002 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9003 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009004}
9005
9006int
9007obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9008{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009009 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009010
Dino Viehlandac46eb42019-09-11 10:16:34 -07009011 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009012 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009013 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009014 }
9015 if (isinstance) {
9016 *out = Eq;
9017 return 0;
9018 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009019 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009020 if (isinstance == -1) {
9021 return 1;
9022 }
9023 if (isinstance) {
9024 *out = NotEq;
9025 return 0;
9026 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009027 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009028 if (isinstance == -1) {
9029 return 1;
9030 }
9031 if (isinstance) {
9032 *out = Lt;
9033 return 0;
9034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009035 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009036 if (isinstance == -1) {
9037 return 1;
9038 }
9039 if (isinstance) {
9040 *out = LtE;
9041 return 0;
9042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009043 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009044 if (isinstance == -1) {
9045 return 1;
9046 }
9047 if (isinstance) {
9048 *out = Gt;
9049 return 0;
9050 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009051 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009052 if (isinstance == -1) {
9053 return 1;
9054 }
9055 if (isinstance) {
9056 *out = GtE;
9057 return 0;
9058 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009059 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009060 if (isinstance == -1) {
9061 return 1;
9062 }
9063 if (isinstance) {
9064 *out = Is;
9065 return 0;
9066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009067 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009068 if (isinstance == -1) {
9069 return 1;
9070 }
9071 if (isinstance) {
9072 *out = IsNot;
9073 return 0;
9074 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009075 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009076 if (isinstance == -1) {
9077 return 1;
9078 }
9079 if (isinstance) {
9080 *out = In;
9081 return 0;
9082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009083 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009084 if (isinstance == -1) {
9085 return 1;
9086 }
9087 if (isinstance) {
9088 *out = NotIn;
9089 return 0;
9090 }
9091
9092 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9093 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009094}
9095
9096int
9097obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9098{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009099 PyObject* tmp = NULL;
9100 expr_ty target;
9101 expr_ty iter;
9102 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009103 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009104
Dino Viehlandac46eb42019-09-11 10:16:34 -07009105 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009106 return 1;
9107 }
9108 if (tmp == NULL) {
9109 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9110 return 1;
9111 }
9112 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009113 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009114 res = obj2ast_expr(tmp, &target, arena);
9115 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009116 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009118 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009119 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009120 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009121 if (tmp == NULL) {
9122 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9123 return 1;
9124 }
9125 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009126 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009127 res = obj2ast_expr(tmp, &iter, arena);
9128 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009129 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009130 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009131 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009132 return 1;
9133 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009134 if (tmp == NULL) {
9135 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9136 return 1;
9137 }
9138 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009139 int res;
9140 Py_ssize_t len;
9141 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009142 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009143 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 +02009144 goto failed;
9145 }
9146 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009147 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009148 if (ifs == NULL) goto failed;
9149 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009150 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009151 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9152 Py_INCREF(tmp2);
9153 res = obj2ast_expr(tmp2, &val, arena);
9154 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009155 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009156 if (len != PyList_GET_SIZE(tmp)) {
9157 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9158 goto failed;
9159 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009160 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009161 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009162 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009163 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009164 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009165 return 1;
9166 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009167 if (tmp == NULL) {
9168 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9169 return 1;
9170 }
9171 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009172 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009173 res = obj2ast_int(tmp, &is_async, arena);
9174 if (res != 0) goto failed;
9175 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009176 }
9177 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009178 return 0;
9179failed:
9180 Py_XDECREF(tmp);
9181 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009182}
9183
9184int
9185obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9186{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009187 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009188
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009189 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009190 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009191 int lineno;
9192 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009193 int end_lineno;
9194 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009195
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 if (obj == Py_None) {
9197 *out = NULL;
9198 return 0;
9199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009200 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009201 return 1;
9202 }
9203 if (tmp == NULL) {
9204 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9205 return 1;
9206 }
9207 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009208 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009209 res = obj2ast_int(tmp, &lineno, arena);
9210 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009211 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009213 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9214 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009215 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009216 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009217 if (tmp == NULL) {
9218 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9219 return 1;
9220 }
9221 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009222 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009223 res = obj2ast_int(tmp, &col_offset, arena);
9224 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009225 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009227 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9228 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009229 return 1;
9230 }
9231 if (tmp == NULL || tmp == Py_None) {
9232 Py_CLEAR(tmp);
9233 end_lineno = 0;
9234 }
9235 else {
9236 int res;
9237 res = obj2ast_int(tmp, &end_lineno, arena);
9238 if (res != 0) goto failed;
9239 Py_CLEAR(tmp);
9240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009241 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9242 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009243 return 1;
9244 }
9245 if (tmp == NULL || tmp == Py_None) {
9246 Py_CLEAR(tmp);
9247 end_col_offset = 0;
9248 }
9249 else {
9250 int res;
9251 res = obj2ast_int(tmp, &end_col_offset, arena);
9252 if (res != 0) goto failed;
9253 Py_CLEAR(tmp);
9254 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009255 tp = astmodulestate_global->ExceptHandler_type;
9256 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009257 if (isinstance == -1) {
9258 return 1;
9259 }
9260 if (isinstance) {
9261 expr_ty type;
9262 identifier name;
9263 asdl_seq* body;
9264
Dino Viehlandac46eb42019-09-11 10:16:34 -07009265 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009266 return 1;
9267 }
9268 if (tmp == NULL || tmp == Py_None) {
9269 Py_CLEAR(tmp);
9270 type = NULL;
9271 }
9272 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009273 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009274 res = obj2ast_expr(tmp, &type, arena);
9275 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009276 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009278 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009279 return 1;
9280 }
9281 if (tmp == NULL || tmp == Py_None) {
9282 Py_CLEAR(tmp);
9283 name = NULL;
9284 }
9285 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009286 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009287 res = obj2ast_identifier(tmp, &name, arena);
9288 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009289 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009290 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009291 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009292 return 1;
9293 }
9294 if (tmp == NULL) {
9295 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9296 return 1;
9297 }
9298 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009299 int res;
9300 Py_ssize_t len;
9301 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009302 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009303 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 +02009304 goto failed;
9305 }
9306 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009307 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009308 if (body == NULL) goto failed;
9309 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009310 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009311 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9312 Py_INCREF(tmp2);
9313 res = obj2ast_stmt(tmp2, &val, arena);
9314 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009315 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009316 if (len != PyList_GET_SIZE(tmp)) {
9317 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9318 goto failed;
9319 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009320 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009321 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009322 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009323 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009324 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9325 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009326 if (*out == NULL) goto failed;
9327 return 0;
9328 }
9329
9330 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9331 failed:
9332 Py_XDECREF(tmp);
9333 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009334}
9335
9336int
9337obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9338{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009339 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009340 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009341 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009342 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009343 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009344 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009345 arg_ty kwarg;
9346 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009347
Dino Viehlandac46eb42019-09-11 10:16:34 -07009348 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9349 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009350 return 1;
9351 }
9352 if (tmp == NULL) {
9353 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9354 return 1;
9355 }
9356 else {
9357 int res;
9358 Py_ssize_t len;
9359 Py_ssize_t i;
9360 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009361 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 +01009362 goto failed;
9363 }
9364 len = PyList_GET_SIZE(tmp);
9365 posonlyargs = _Py_asdl_seq_new(len, arena);
9366 if (posonlyargs == NULL) goto failed;
9367 for (i = 0; i < len; i++) {
9368 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009369 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9370 Py_INCREF(tmp2);
9371 res = obj2ast_arg(tmp2, &val, arena);
9372 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009373 if (res != 0) goto failed;
9374 if (len != PyList_GET_SIZE(tmp)) {
9375 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9376 goto failed;
9377 }
9378 asdl_seq_SET(posonlyargs, i, val);
9379 }
9380 Py_CLEAR(tmp);
9381 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009382 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009383 return 1;
9384 }
9385 if (tmp == NULL) {
9386 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9387 return 1;
9388 }
9389 else {
9390 int res;
9391 Py_ssize_t len;
9392 Py_ssize_t i;
9393 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009394 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 +02009395 goto failed;
9396 }
9397 len = PyList_GET_SIZE(tmp);
9398 args = _Py_asdl_seq_new(len, arena);
9399 if (args == NULL) goto failed;
9400 for (i = 0; i < len; i++) {
9401 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009402 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9403 Py_INCREF(tmp2);
9404 res = obj2ast_arg(tmp2, &val, arena);
9405 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009406 if (res != 0) goto failed;
9407 if (len != PyList_GET_SIZE(tmp)) {
9408 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9409 goto failed;
9410 }
9411 asdl_seq_SET(args, i, val);
9412 }
9413 Py_CLEAR(tmp);
9414 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009415 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009416 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009417 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009418 if (tmp == NULL || tmp == Py_None) {
9419 Py_CLEAR(tmp);
9420 vararg = NULL;
9421 }
9422 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009423 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009424 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009425 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009426 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009427 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009428 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9429 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009430 return 1;
9431 }
9432 if (tmp == NULL) {
9433 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9434 return 1;
9435 }
9436 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009437 int res;
9438 Py_ssize_t len;
9439 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009440 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009441 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 +02009442 goto failed;
9443 }
9444 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009445 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009446 if (kwonlyargs == NULL) goto failed;
9447 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009448 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009449 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9450 Py_INCREF(tmp2);
9451 res = obj2ast_arg(tmp2, &val, arena);
9452 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009453 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009454 if (len != PyList_GET_SIZE(tmp)) {
9455 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9456 goto failed;
9457 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009458 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009459 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009460 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009461 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009462 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9463 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009464 return 1;
9465 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009466 if (tmp == NULL) {
9467 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9468 return 1;
9469 }
9470 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009471 int res;
9472 Py_ssize_t len;
9473 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009474 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009475 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 +02009476 goto failed;
9477 }
9478 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009479 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009480 if (kw_defaults == NULL) goto failed;
9481 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009482 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009483 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9484 Py_INCREF(tmp2);
9485 res = obj2ast_expr(tmp2, &val, arena);
9486 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009487 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009488 if (len != PyList_GET_SIZE(tmp)) {
9489 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9490 goto failed;
9491 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009492 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009493 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009494 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009495 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009496 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009497 return 1;
9498 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009499 if (tmp == NULL || tmp == Py_None) {
9500 Py_CLEAR(tmp);
9501 kwarg = NULL;
9502 }
9503 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009504 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009505 res = obj2ast_arg(tmp, &kwarg, arena);
9506 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009507 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009508 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009509 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009510 return 1;
9511 }
9512 if (tmp == NULL) {
9513 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9514 return 1;
9515 }
9516 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009517 int res;
9518 Py_ssize_t len;
9519 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009520 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009521 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 +02009522 goto failed;
9523 }
9524 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009525 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009526 if (defaults == NULL) goto failed;
9527 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009528 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009529 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9530 Py_INCREF(tmp2);
9531 res = obj2ast_expr(tmp2, &val, arena);
9532 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009533 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009534 if (len != PyList_GET_SIZE(tmp)) {
9535 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9536 goto failed;
9537 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009538 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009539 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009540 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009541 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009542 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009543 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009544 return 0;
9545failed:
9546 Py_XDECREF(tmp);
9547 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009548}
9549
9550int
9551obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9552{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009553 PyObject* tmp = NULL;
9554 identifier arg;
9555 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009556 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009557 int lineno;
9558 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009559 int end_lineno;
9560 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009561
Dino Viehlandac46eb42019-09-11 10:16:34 -07009562 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009563 return 1;
9564 }
9565 if (tmp == NULL) {
9566 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9567 return 1;
9568 }
9569 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009570 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009571 res = obj2ast_identifier(tmp, &arg, arena);
9572 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009573 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009574 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009575 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9576 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009577 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009578 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009579 if (tmp == NULL || tmp == Py_None) {
9580 Py_CLEAR(tmp);
9581 annotation = NULL;
9582 }
9583 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009584 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009585 res = obj2ast_expr(tmp, &annotation, arena);
9586 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009587 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009588 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009589 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9590 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009591 return 1;
9592 }
9593 if (tmp == NULL || tmp == Py_None) {
9594 Py_CLEAR(tmp);
9595 type_comment = NULL;
9596 }
9597 else {
9598 int res;
9599 res = obj2ast_string(tmp, &type_comment, arena);
9600 if (res != 0) goto failed;
9601 Py_CLEAR(tmp);
9602 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009603 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009604 return 1;
9605 }
9606 if (tmp == NULL) {
9607 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9608 return 1;
9609 }
9610 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009611 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009612 res = obj2ast_int(tmp, &lineno, arena);
9613 if (res != 0) goto failed;
9614 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009615 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009616 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9617 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009618 return 1;
9619 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009620 if (tmp == NULL) {
9621 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9622 return 1;
9623 }
9624 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009625 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009626 res = obj2ast_int(tmp, &col_offset, arena);
9627 if (res != 0) goto failed;
9628 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009629 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009630 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9631 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009632 return 1;
9633 }
9634 if (tmp == NULL || tmp == Py_None) {
9635 Py_CLEAR(tmp);
9636 end_lineno = 0;
9637 }
9638 else {
9639 int res;
9640 res = obj2ast_int(tmp, &end_lineno, arena);
9641 if (res != 0) goto failed;
9642 Py_CLEAR(tmp);
9643 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009644 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9645 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009646 return 1;
9647 }
9648 if (tmp == NULL || tmp == Py_None) {
9649 Py_CLEAR(tmp);
9650 end_col_offset = 0;
9651 }
9652 else {
9653 int res;
9654 res = obj2ast_int(tmp, &end_col_offset, arena);
9655 if (res != 0) goto failed;
9656 Py_CLEAR(tmp);
9657 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009658 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9659 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009660 return 0;
9661failed:
9662 Py_XDECREF(tmp);
9663 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009664}
9665
9666int
9667obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9668{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009669 PyObject* tmp = NULL;
9670 identifier arg;
9671 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +01009672 int lineno;
9673 int col_offset;
9674 int end_lineno;
9675 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009676
Dino Viehlandac46eb42019-09-11 10:16:34 -07009677 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009678 return 1;
9679 }
9680 if (tmp == NULL || tmp == Py_None) {
9681 Py_CLEAR(tmp);
9682 arg = NULL;
9683 }
9684 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009685 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009686 res = obj2ast_identifier(tmp, &arg, arena);
9687 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009688 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009689 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009690 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009691 return 1;
9692 }
9693 if (tmp == NULL) {
9694 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9695 return 1;
9696 }
9697 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009698 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009699 res = obj2ast_expr(tmp, &value, arena);
9700 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009701 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009702 }
Pablo Galindo168660b2020-04-02 00:47:39 +01009703 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
9704 return 1;
9705 }
9706 if (tmp == NULL) {
9707 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
9708 return 1;
9709 }
9710 else {
9711 int res;
9712 res = obj2ast_int(tmp, &lineno, arena);
9713 if (res != 0) goto failed;
9714 Py_CLEAR(tmp);
9715 }
9716 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9717 {
9718 return 1;
9719 }
9720 if (tmp == NULL) {
9721 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
9722 return 1;
9723 }
9724 else {
9725 int res;
9726 res = obj2ast_int(tmp, &col_offset, arena);
9727 if (res != 0) goto failed;
9728 Py_CLEAR(tmp);
9729 }
9730 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9731 {
9732 return 1;
9733 }
9734 if (tmp == NULL || tmp == Py_None) {
9735 Py_CLEAR(tmp);
9736 end_lineno = 0;
9737 }
9738 else {
9739 int res;
9740 res = obj2ast_int(tmp, &end_lineno, arena);
9741 if (res != 0) goto failed;
9742 Py_CLEAR(tmp);
9743 }
9744 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9745 < 0) {
9746 return 1;
9747 }
9748 if (tmp == NULL || tmp == Py_None) {
9749 Py_CLEAR(tmp);
9750 end_col_offset = 0;
9751 }
9752 else {
9753 int res;
9754 res = obj2ast_int(tmp, &end_col_offset, arena);
9755 if (res != 0) goto failed;
9756 Py_CLEAR(tmp);
9757 }
9758 *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset,
9759 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009760 return 0;
9761failed:
9762 Py_XDECREF(tmp);
9763 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009764}
9765
9766int
9767obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9768{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009769 PyObject* tmp = NULL;
9770 identifier name;
9771 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009772
Dino Viehlandac46eb42019-09-11 10:16:34 -07009773 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009774 return 1;
9775 }
9776 if (tmp == NULL) {
9777 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9778 return 1;
9779 }
9780 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009781 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009782 res = obj2ast_identifier(tmp, &name, arena);
9783 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009784 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009785 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009786 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009787 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009788 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009789 if (tmp == NULL || tmp == Py_None) {
9790 Py_CLEAR(tmp);
9791 asname = NULL;
9792 }
9793 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009794 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009795 res = obj2ast_identifier(tmp, &asname, arena);
9796 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009797 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009798 }
9799 *out = alias(name, asname, arena);
9800 return 0;
9801failed:
9802 Py_XDECREF(tmp);
9803 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009804}
9805
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009806int
9807obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9808{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009809 PyObject* tmp = NULL;
9810 expr_ty context_expr;
9811 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009812
Dino Viehlandac46eb42019-09-11 10:16:34 -07009813 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9814 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009815 return 1;
9816 }
9817 if (tmp == NULL) {
9818 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9819 return 1;
9820 }
9821 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009822 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009823 res = obj2ast_expr(tmp, &context_expr, arena);
9824 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009825 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009826 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009827 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9828 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009829 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009830 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009831 if (tmp == NULL || tmp == Py_None) {
9832 Py_CLEAR(tmp);
9833 optional_vars = NULL;
9834 }
9835 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009836 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009837 res = obj2ast_expr(tmp, &optional_vars, arena);
9838 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009839 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009840 }
9841 *out = withitem(context_expr, optional_vars, arena);
9842 return 0;
9843failed:
9844 Py_XDECREF(tmp);
9845 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009846}
9847
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009848int
9849obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9850{
9851 int isinstance;
9852
9853 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009854 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009855
9856 if (obj == Py_None) {
9857 *out = NULL;
9858 return 0;
9859 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009860 tp = astmodulestate_global->TypeIgnore_type;
9861 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009862 if (isinstance == -1) {
9863 return 1;
9864 }
9865 if (isinstance) {
9866 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009867 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009868
Dino Viehlandac46eb42019-09-11 10:16:34 -07009869 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9870 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009871 return 1;
9872 }
9873 if (tmp == NULL) {
9874 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9875 return 1;
9876 }
9877 else {
9878 int res;
9879 res = obj2ast_int(tmp, &lineno, arena);
9880 if (res != 0) goto failed;
9881 Py_CLEAR(tmp);
9882 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009883 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009884 return 1;
9885 }
9886 if (tmp == NULL) {
9887 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9888 return 1;
9889 }
9890 else {
9891 int res;
9892 res = obj2ast_string(tmp, &tag, arena);
9893 if (res != 0) goto failed;
9894 Py_CLEAR(tmp);
9895 }
9896 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009897 if (*out == NULL) goto failed;
9898 return 0;
9899 }
9900
9901 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9902 failed:
9903 Py_XDECREF(tmp);
9904 return 1;
9905}
9906
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009907
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009908PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009909PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009910{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009911 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009912 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009913 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009914 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009915 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9916 goto error;
9917 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009918 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009919 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9920 goto error;
9921 }
9922 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9923 goto error;
9924 }
9925 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9926 goto error;
9927 }
9928 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9929 goto error;
9930 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009931 Py_INCREF(astmodulestate(m)->mod_type);
9932 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009933 0) {
9934 goto error;
9935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009936 Py_INCREF(astmodulestate(m)->Module_type);
9937 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009938 astmodulestate_global->Interactive_type) < 0) {
9939 goto error;
9940 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009941 Py_INCREF(astmodulestate(m)->Interactive_type);
9942 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009943 astmodulestate_global->Expression_type) < 0) {
9944 goto error;
9945 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009946 Py_INCREF(astmodulestate(m)->Expression_type);
9947 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009948 astmodulestate_global->FunctionType_type) < 0) {
9949 goto error;
9950 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009951 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009952 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9953 goto error;
9954 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009955 Py_INCREF(astmodulestate(m)->stmt_type);
9956 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009957 astmodulestate_global->FunctionDef_type) < 0) {
9958 goto error;
9959 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009960 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9961 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009962 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9963 goto error;
9964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009965 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9966 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009967 < 0) {
9968 goto error;
9969 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009970 Py_INCREF(astmodulestate(m)->ClassDef_type);
9971 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009972 0) {
9973 goto error;
9974 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009975 Py_INCREF(astmodulestate(m)->Return_type);
9976 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009977 0) {
9978 goto error;
9979 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009980 Py_INCREF(astmodulestate(m)->Delete_type);
9981 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009982 0) {
9983 goto error;
9984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009985 Py_INCREF(astmodulestate(m)->Assign_type);
9986 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009987 astmodulestate_global->AugAssign_type) < 0) {
9988 goto error;
9989 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009990 Py_INCREF(astmodulestate(m)->AugAssign_type);
9991 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009992 astmodulestate_global->AnnAssign_type) < 0) {
9993 goto error;
9994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009995 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009996 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9997 goto error;
9998 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009999 Py_INCREF(astmodulestate(m)->For_type);
10000 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010001 < 0) {
10002 goto error;
10003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010004 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010005 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
10006 goto error;
10007 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010008 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010009 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
10010 goto error;
10011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010012 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010013 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
10014 goto error;
10015 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010016 Py_INCREF(astmodulestate(m)->With_type);
10017 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010018 astmodulestate_global->AsyncWith_type) < 0) {
10019 goto error;
10020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010021 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010022 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10023 goto error;
10024 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010025 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010026 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10027 goto error;
10028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010029 Py_INCREF(astmodulestate(m)->Try_type);
10030 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010031 0) {
10032 goto error;
10033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010034 Py_INCREF(astmodulestate(m)->Assert_type);
10035 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010036 0) {
10037 goto error;
10038 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010039 Py_INCREF(astmodulestate(m)->Import_type);
10040 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010041 astmodulestate_global->ImportFrom_type) < 0) {
10042 goto error;
10043 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010044 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10045 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010046 0) {
10047 goto error;
10048 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010049 Py_INCREF(astmodulestate(m)->Global_type);
10050 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010051 < 0) {
10052 goto error;
10053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010054 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010055 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10056 goto error;
10057 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010058 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010059 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10060 goto error;
10061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010062 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010063 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10064 goto error;
10065 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010066 Py_INCREF(astmodulestate(m)->Break_type);
10067 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010068 < 0) {
10069 goto error;
10070 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010071 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010072 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10073 goto error;
10074 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010075 Py_INCREF(astmodulestate(m)->expr_type);
10076 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010077 0) {
10078 goto error;
10079 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010080 Py_INCREF(astmodulestate(m)->BoolOp_type);
10081 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010082 astmodulestate_global->NamedExpr_type) < 0) {
10083 goto error;
10084 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010085 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010086 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10087 goto error;
10088 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010089 Py_INCREF(astmodulestate(m)->BinOp_type);
10090 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010091 0) {
10092 goto error;
10093 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010094 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10095 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010096 0) {
10097 goto error;
10098 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010099 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010100 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10101 goto error;
10102 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010103 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010104 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10105 goto error;
10106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010107 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010108 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10109 goto error;
10110 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010111 Py_INCREF(astmodulestate(m)->Set_type);
10112 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010113 < 0) {
10114 goto error;
10115 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010116 Py_INCREF(astmodulestate(m)->ListComp_type);
10117 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010118 0) {
10119 goto error;
10120 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010121 Py_INCREF(astmodulestate(m)->SetComp_type);
10122 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010123 < 0) {
10124 goto error;
10125 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010126 Py_INCREF(astmodulestate(m)->DictComp_type);
10127 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010128 astmodulestate_global->GeneratorExp_type) < 0) {
10129 goto error;
10130 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010131 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010132 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10133 goto error;
10134 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010135 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010136 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10137 goto error;
10138 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010139 Py_INCREF(astmodulestate(m)->Yield_type);
10140 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010141 astmodulestate_global->YieldFrom_type) < 0) {
10142 goto error;
10143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010144 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10145 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010146 0) {
10147 goto error;
10148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010149 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010150 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10151 goto error;
10152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010153 Py_INCREF(astmodulestate(m)->Call_type);
10154 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010155 astmodulestate_global->FormattedValue_type) < 0) {
10156 goto error;
10157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010158 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10159 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010160 astmodulestate_global->JoinedStr_type) < 0) {
10161 goto error;
10162 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010163 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10164 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010165 < 0) {
10166 goto error;
10167 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010168 Py_INCREF(astmodulestate(m)->Constant_type);
10169 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010170 astmodulestate_global->Attribute_type) < 0) {
10171 goto error;
10172 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010173 Py_INCREF(astmodulestate(m)->Attribute_type);
10174 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010175 astmodulestate_global->Subscript_type) < 0) {
10176 goto error;
10177 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010178 Py_INCREF(astmodulestate(m)->Subscript_type);
10179 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010180 0) {
10181 goto error;
10182 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010183 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010184 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10185 goto error;
10186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010187 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010192 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10193 goto error;
10194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010195 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010196 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10197 goto error;
10198 }
10199 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010200 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010201 astmodulestate_global->expr_context_type) < 0) {
10202 goto error;
10203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010204 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010205 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10206 goto error;
10207 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010208 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010209 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10210 goto error;
10211 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010212 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010213 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10214 goto error;
10215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010216 Py_INCREF(astmodulestate(m)->Del_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010218 0) {
10219 goto error;
10220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010221 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010222 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10223 goto error;
10224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010225 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010226 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10227 goto error;
10228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010229 Py_INCREF(astmodulestate(m)->Or_type);
10230 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010231 < 0) {
10232 goto error;
10233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010234 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010235 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10236 goto error;
10237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010238 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010239 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10240 goto error;
10241 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010242 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010243 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10244 goto error;
10245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010246 Py_INCREF(astmodulestate(m)->Mult_type);
10247 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010248 0) {
10249 goto error;
10250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010251 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010252 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10253 goto error;
10254 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010255 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010256 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10257 goto error;
10258 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010259 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010260 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10261 goto error;
10262 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010263 Py_INCREF(astmodulestate(m)->Pow_type);
10264 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010265 0) {
10266 goto error;
10267 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010268 Py_INCREF(astmodulestate(m)->LShift_type);
10269 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010270 0) {
10271 goto error;
10272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010273 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010274 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10275 goto error;
10276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010277 Py_INCREF(astmodulestate(m)->BitOr_type);
10278 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010279 0) {
10280 goto error;
10281 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010282 Py_INCREF(astmodulestate(m)->BitXor_type);
10283 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010284 0) {
10285 goto error;
10286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010287 Py_INCREF(astmodulestate(m)->BitAnd_type);
10288 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010289 < 0) {
10290 goto error;
10291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010292 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10293 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010294 0) {
10295 goto error;
10296 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010297 Py_INCREF(astmodulestate(m)->unaryop_type);
10298 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010299 0) {
10300 goto error;
10301 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010302 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010303 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10304 goto error;
10305 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010306 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010307 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10308 goto error;
10309 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010310 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010311 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10312 goto error;
10313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010314 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010315 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10316 goto error;
10317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010318 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010319 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10320 goto error;
10321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010322 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010323 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10324 goto error;
10325 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010326 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010327 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10328 goto error;
10329 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010330 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010331 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10332 goto error;
10333 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010334 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010335 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10336 goto error;
10337 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010338 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010339 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10340 goto error;
10341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010342 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010343 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10344 goto error;
10345 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010346 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010347 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10348 goto error;
10349 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010350 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010351 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10352 goto error;
10353 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010354 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010355 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10356 goto error;
10357 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010358 Py_INCREF(astmodulestate(m)->NotIn_type);
10359 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010360 astmodulestate_global->comprehension_type) < 0) {
10361 goto error;
10362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010363 Py_INCREF(astmodulestate(m)->comprehension_type);
10364 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010365 astmodulestate_global->excepthandler_type) < 0) {
10366 goto error;
10367 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010368 Py_INCREF(astmodulestate(m)->excepthandler_type);
10369 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010370 astmodulestate_global->ExceptHandler_type) < 0) {
10371 goto error;
10372 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010373 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10374 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010375 astmodulestate_global->arguments_type) < 0) {
10376 goto error;
10377 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010378 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010379 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10380 goto error;
10381 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010382 Py_INCREF(astmodulestate(m)->arg_type);
10383 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010384 0) {
10385 goto error;
10386 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010387 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010388 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10389 goto error;
10390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010391 Py_INCREF(astmodulestate(m)->alias_type);
10392 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010393 < 0) {
10394 goto error;
10395 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010396 Py_INCREF(astmodulestate(m)->withitem_type);
10397 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010398 astmodulestate_global->type_ignore_type) < 0) {
10399 goto error;
10400 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010401 Py_INCREF(astmodulestate(m)->type_ignore_type);
10402 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010403 astmodulestate_global->TypeIgnore_type) < 0) {
10404 goto error;
10405 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010406 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010407 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010408error:
10409 Py_DECREF(m);
10410 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010411}
10412
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010413
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010414PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010415{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010416 if (!init_types())
10417 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010418 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010419}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010420
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010421/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10422mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010423{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010424 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010425 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010426 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010427
Steve Dowerb82e17e2019-05-23 08:45:22 -070010428 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10429 return NULL;
10430 }
10431
Dino Viehlandac46eb42019-09-11 10:16:34 -070010432 req_type[0] = astmodulestate_global->Module_type;
10433 req_type[1] = astmodulestate_global->Expression_type;
10434 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010435
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010436 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010437
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010438 if (!init_types())
10439 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010440
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010441 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10442 if (isinstance == -1)
10443 return NULL;
10444 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010445 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010446 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010447 return NULL;
10448 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010449
10450 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010451 if (obj2ast_mod(ast, &res, arena) != 0)
10452 return NULL;
10453 else
10454 return res;
10455}
10456
10457int PyAST_Check(PyObject* obj)
10458{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010459 if (!init_types())
10460 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010461 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010462}
10463
Martin v. Löwis5b222132007-06-10 09:51:05 +000010464