blob: 80f91646fd62e4f5b170e0108a766d6948ff7e07 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07003#include <stddef.h>
4
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005#include "Python.h"
6#include "Python-ast.h"
Victor Stinner4a21e572020-04-15 02:35:41 +02007#include "structmember.h" // PyMemberDef
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008
Dino Viehlandac46eb42019-09-11 10:16:34 -07009typedef struct {
10 int initialized;
11 PyObject *AST_type;
12 PyObject *Add_singleton;
13 PyObject *Add_type;
14 PyObject *And_singleton;
15 PyObject *And_type;
16 PyObject *AnnAssign_type;
17 PyObject *Assert_type;
18 PyObject *Assign_type;
19 PyObject *AsyncFor_type;
20 PyObject *AsyncFunctionDef_type;
21 PyObject *AsyncWith_type;
22 PyObject *Attribute_type;
23 PyObject *AugAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070024 PyObject *Await_type;
25 PyObject *BinOp_type;
26 PyObject *BitAnd_singleton;
27 PyObject *BitAnd_type;
28 PyObject *BitOr_singleton;
29 PyObject *BitOr_type;
30 PyObject *BitXor_singleton;
31 PyObject *BitXor_type;
32 PyObject *BoolOp_type;
33 PyObject *Break_type;
34 PyObject *Call_type;
35 PyObject *ClassDef_type;
36 PyObject *Compare_type;
37 PyObject *Constant_type;
38 PyObject *Continue_type;
39 PyObject *Del_singleton;
40 PyObject *Del_type;
41 PyObject *Delete_type;
42 PyObject *DictComp_type;
43 PyObject *Dict_type;
44 PyObject *Div_singleton;
45 PyObject *Div_type;
46 PyObject *Eq_singleton;
47 PyObject *Eq_type;
48 PyObject *ExceptHandler_type;
49 PyObject *Expr_type;
50 PyObject *Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070051 PyObject *FloorDiv_singleton;
52 PyObject *FloorDiv_type;
53 PyObject *For_type;
54 PyObject *FormattedValue_type;
55 PyObject *FunctionDef_type;
56 PyObject *FunctionType_type;
57 PyObject *GeneratorExp_type;
58 PyObject *Global_type;
59 PyObject *GtE_singleton;
60 PyObject *GtE_type;
61 PyObject *Gt_singleton;
62 PyObject *Gt_type;
63 PyObject *IfExp_type;
64 PyObject *If_type;
65 PyObject *ImportFrom_type;
66 PyObject *Import_type;
67 PyObject *In_singleton;
68 PyObject *In_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070069 PyObject *Interactive_type;
70 PyObject *Invert_singleton;
71 PyObject *Invert_type;
72 PyObject *IsNot_singleton;
73 PyObject *IsNot_type;
74 PyObject *Is_singleton;
75 PyObject *Is_type;
76 PyObject *JoinedStr_type;
77 PyObject *LShift_singleton;
78 PyObject *LShift_type;
79 PyObject *Lambda_type;
80 PyObject *ListComp_type;
81 PyObject *List_type;
82 PyObject *Load_singleton;
83 PyObject *Load_type;
84 PyObject *LtE_singleton;
85 PyObject *LtE_type;
86 PyObject *Lt_singleton;
87 PyObject *Lt_type;
88 PyObject *MatMult_singleton;
89 PyObject *MatMult_type;
90 PyObject *Mod_singleton;
91 PyObject *Mod_type;
92 PyObject *Module_type;
93 PyObject *Mult_singleton;
94 PyObject *Mult_type;
95 PyObject *Name_type;
96 PyObject *NamedExpr_type;
97 PyObject *Nonlocal_type;
98 PyObject *NotEq_singleton;
99 PyObject *NotEq_type;
100 PyObject *NotIn_singleton;
101 PyObject *NotIn_type;
102 PyObject *Not_singleton;
103 PyObject *Not_type;
104 PyObject *Or_singleton;
105 PyObject *Or_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700106 PyObject *Pass_type;
107 PyObject *Pow_singleton;
108 PyObject *Pow_type;
109 PyObject *RShift_singleton;
110 PyObject *RShift_type;
111 PyObject *Raise_type;
112 PyObject *Return_type;
113 PyObject *SetComp_type;
114 PyObject *Set_type;
115 PyObject *Slice_type;
116 PyObject *Starred_type;
117 PyObject *Store_singleton;
118 PyObject *Store_type;
119 PyObject *Sub_singleton;
120 PyObject *Sub_type;
121 PyObject *Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700122 PyObject *Try_type;
123 PyObject *Tuple_type;
124 PyObject *TypeIgnore_type;
125 PyObject *UAdd_singleton;
126 PyObject *UAdd_type;
127 PyObject *USub_singleton;
128 PyObject *USub_type;
129 PyObject *UnaryOp_type;
130 PyObject *While_type;
131 PyObject *With_type;
132 PyObject *YieldFrom_type;
133 PyObject *Yield_type;
134 PyObject *__dict__;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300135 PyObject *__doc__;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700136 PyObject *__module__;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700137 PyObject *_attributes;
138 PyObject *_fields;
139 PyObject *alias_type;
140 PyObject *annotation;
141 PyObject *arg;
142 PyObject *arg_type;
143 PyObject *args;
144 PyObject *argtypes;
145 PyObject *arguments_type;
146 PyObject *asname;
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200147 PyObject *ast;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700148 PyObject *attr;
149 PyObject *bases;
150 PyObject *body;
151 PyObject *boolop_type;
152 PyObject *cause;
153 PyObject *cmpop_type;
154 PyObject *col_offset;
155 PyObject *comparators;
156 PyObject *comprehension_type;
157 PyObject *context_expr;
158 PyObject *conversion;
159 PyObject *ctx;
160 PyObject *decorator_list;
161 PyObject *defaults;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700162 PyObject *elt;
163 PyObject *elts;
164 PyObject *end_col_offset;
165 PyObject *end_lineno;
166 PyObject *exc;
167 PyObject *excepthandler_type;
168 PyObject *expr_context_type;
169 PyObject *expr_type;
170 PyObject *finalbody;
171 PyObject *format_spec;
172 PyObject *func;
173 PyObject *generators;
174 PyObject *handlers;
175 PyObject *id;
176 PyObject *ifs;
177 PyObject *is_async;
178 PyObject *items;
179 PyObject *iter;
180 PyObject *key;
181 PyObject *keys;
182 PyObject *keyword_type;
183 PyObject *keywords;
184 PyObject *kind;
185 PyObject *kw_defaults;
186 PyObject *kwarg;
187 PyObject *kwonlyargs;
188 PyObject *left;
189 PyObject *level;
190 PyObject *lineno;
191 PyObject *lower;
192 PyObject *mod_type;
193 PyObject *module;
194 PyObject *msg;
195 PyObject *name;
196 PyObject *names;
197 PyObject *op;
198 PyObject *operand;
199 PyObject *operator_type;
200 PyObject *ops;
201 PyObject *optional_vars;
202 PyObject *orelse;
203 PyObject *posonlyargs;
204 PyObject *returns;
205 PyObject *right;
206 PyObject *simple;
207 PyObject *slice;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700208 PyObject *step;
209 PyObject *stmt_type;
210 PyObject *tag;
211 PyObject *target;
212 PyObject *targets;
213 PyObject *test;
214 PyObject *type;
215 PyObject *type_comment;
216 PyObject *type_ignore_type;
217 PyObject *type_ignores;
218 PyObject *unaryop_type;
219 PyObject *upper;
220 PyObject *value;
221 PyObject *values;
222 PyObject *vararg;
223 PyObject *withitem_type;
224} astmodulestate;
225
226
227#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
228
229static int astmodule_clear(PyObject *module)
230{
231 Py_CLEAR(astmodulestate(module)->AST_type);
232 Py_CLEAR(astmodulestate(module)->Add_singleton);
233 Py_CLEAR(astmodulestate(module)->Add_type);
234 Py_CLEAR(astmodulestate(module)->And_singleton);
235 Py_CLEAR(astmodulestate(module)->And_type);
236 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
237 Py_CLEAR(astmodulestate(module)->Assert_type);
238 Py_CLEAR(astmodulestate(module)->Assign_type);
239 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
240 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
241 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
242 Py_CLEAR(astmodulestate(module)->Attribute_type);
243 Py_CLEAR(astmodulestate(module)->AugAssign_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700244 Py_CLEAR(astmodulestate(module)->Await_type);
245 Py_CLEAR(astmodulestate(module)->BinOp_type);
246 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
247 Py_CLEAR(astmodulestate(module)->BitAnd_type);
248 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
249 Py_CLEAR(astmodulestate(module)->BitOr_type);
250 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
251 Py_CLEAR(astmodulestate(module)->BitXor_type);
252 Py_CLEAR(astmodulestate(module)->BoolOp_type);
253 Py_CLEAR(astmodulestate(module)->Break_type);
254 Py_CLEAR(astmodulestate(module)->Call_type);
255 Py_CLEAR(astmodulestate(module)->ClassDef_type);
256 Py_CLEAR(astmodulestate(module)->Compare_type);
257 Py_CLEAR(astmodulestate(module)->Constant_type);
258 Py_CLEAR(astmodulestate(module)->Continue_type);
259 Py_CLEAR(astmodulestate(module)->Del_singleton);
260 Py_CLEAR(astmodulestate(module)->Del_type);
261 Py_CLEAR(astmodulestate(module)->Delete_type);
262 Py_CLEAR(astmodulestate(module)->DictComp_type);
263 Py_CLEAR(astmodulestate(module)->Dict_type);
264 Py_CLEAR(astmodulestate(module)->Div_singleton);
265 Py_CLEAR(astmodulestate(module)->Div_type);
266 Py_CLEAR(astmodulestate(module)->Eq_singleton);
267 Py_CLEAR(astmodulestate(module)->Eq_type);
268 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
269 Py_CLEAR(astmodulestate(module)->Expr_type);
270 Py_CLEAR(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700271 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
272 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
273 Py_CLEAR(astmodulestate(module)->For_type);
274 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
275 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
276 Py_CLEAR(astmodulestate(module)->FunctionType_type);
277 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
278 Py_CLEAR(astmodulestate(module)->Global_type);
279 Py_CLEAR(astmodulestate(module)->GtE_singleton);
280 Py_CLEAR(astmodulestate(module)->GtE_type);
281 Py_CLEAR(astmodulestate(module)->Gt_singleton);
282 Py_CLEAR(astmodulestate(module)->Gt_type);
283 Py_CLEAR(astmodulestate(module)->IfExp_type);
284 Py_CLEAR(astmodulestate(module)->If_type);
285 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
286 Py_CLEAR(astmodulestate(module)->Import_type);
287 Py_CLEAR(astmodulestate(module)->In_singleton);
288 Py_CLEAR(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700289 Py_CLEAR(astmodulestate(module)->Interactive_type);
290 Py_CLEAR(astmodulestate(module)->Invert_singleton);
291 Py_CLEAR(astmodulestate(module)->Invert_type);
292 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
293 Py_CLEAR(astmodulestate(module)->IsNot_type);
294 Py_CLEAR(astmodulestate(module)->Is_singleton);
295 Py_CLEAR(astmodulestate(module)->Is_type);
296 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
297 Py_CLEAR(astmodulestate(module)->LShift_singleton);
298 Py_CLEAR(astmodulestate(module)->LShift_type);
299 Py_CLEAR(astmodulestate(module)->Lambda_type);
300 Py_CLEAR(astmodulestate(module)->ListComp_type);
301 Py_CLEAR(astmodulestate(module)->List_type);
302 Py_CLEAR(astmodulestate(module)->Load_singleton);
303 Py_CLEAR(astmodulestate(module)->Load_type);
304 Py_CLEAR(astmodulestate(module)->LtE_singleton);
305 Py_CLEAR(astmodulestate(module)->LtE_type);
306 Py_CLEAR(astmodulestate(module)->Lt_singleton);
307 Py_CLEAR(astmodulestate(module)->Lt_type);
308 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
309 Py_CLEAR(astmodulestate(module)->MatMult_type);
310 Py_CLEAR(astmodulestate(module)->Mod_singleton);
311 Py_CLEAR(astmodulestate(module)->Mod_type);
312 Py_CLEAR(astmodulestate(module)->Module_type);
313 Py_CLEAR(astmodulestate(module)->Mult_singleton);
314 Py_CLEAR(astmodulestate(module)->Mult_type);
315 Py_CLEAR(astmodulestate(module)->Name_type);
316 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
317 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
318 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
319 Py_CLEAR(astmodulestate(module)->NotEq_type);
320 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
321 Py_CLEAR(astmodulestate(module)->NotIn_type);
322 Py_CLEAR(astmodulestate(module)->Not_singleton);
323 Py_CLEAR(astmodulestate(module)->Not_type);
324 Py_CLEAR(astmodulestate(module)->Or_singleton);
325 Py_CLEAR(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700326 Py_CLEAR(astmodulestate(module)->Pass_type);
327 Py_CLEAR(astmodulestate(module)->Pow_singleton);
328 Py_CLEAR(astmodulestate(module)->Pow_type);
329 Py_CLEAR(astmodulestate(module)->RShift_singleton);
330 Py_CLEAR(astmodulestate(module)->RShift_type);
331 Py_CLEAR(astmodulestate(module)->Raise_type);
332 Py_CLEAR(astmodulestate(module)->Return_type);
333 Py_CLEAR(astmodulestate(module)->SetComp_type);
334 Py_CLEAR(astmodulestate(module)->Set_type);
335 Py_CLEAR(astmodulestate(module)->Slice_type);
336 Py_CLEAR(astmodulestate(module)->Starred_type);
337 Py_CLEAR(astmodulestate(module)->Store_singleton);
338 Py_CLEAR(astmodulestate(module)->Store_type);
339 Py_CLEAR(astmodulestate(module)->Sub_singleton);
340 Py_CLEAR(astmodulestate(module)->Sub_type);
341 Py_CLEAR(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700342 Py_CLEAR(astmodulestate(module)->Try_type);
343 Py_CLEAR(astmodulestate(module)->Tuple_type);
344 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
345 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
346 Py_CLEAR(astmodulestate(module)->UAdd_type);
347 Py_CLEAR(astmodulestate(module)->USub_singleton);
348 Py_CLEAR(astmodulestate(module)->USub_type);
349 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
350 Py_CLEAR(astmodulestate(module)->While_type);
351 Py_CLEAR(astmodulestate(module)->With_type);
352 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
353 Py_CLEAR(astmodulestate(module)->Yield_type);
354 Py_CLEAR(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300355 Py_CLEAR(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700356 Py_CLEAR(astmodulestate(module)->__module__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700357 Py_CLEAR(astmodulestate(module)->_attributes);
358 Py_CLEAR(astmodulestate(module)->_fields);
359 Py_CLEAR(astmodulestate(module)->alias_type);
360 Py_CLEAR(astmodulestate(module)->annotation);
361 Py_CLEAR(astmodulestate(module)->arg);
362 Py_CLEAR(astmodulestate(module)->arg_type);
363 Py_CLEAR(astmodulestate(module)->args);
364 Py_CLEAR(astmodulestate(module)->argtypes);
365 Py_CLEAR(astmodulestate(module)->arguments_type);
366 Py_CLEAR(astmodulestate(module)->asname);
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200367 Py_CLEAR(astmodulestate(module)->ast);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700368 Py_CLEAR(astmodulestate(module)->attr);
369 Py_CLEAR(astmodulestate(module)->bases);
370 Py_CLEAR(astmodulestate(module)->body);
371 Py_CLEAR(astmodulestate(module)->boolop_type);
372 Py_CLEAR(astmodulestate(module)->cause);
373 Py_CLEAR(astmodulestate(module)->cmpop_type);
374 Py_CLEAR(astmodulestate(module)->col_offset);
375 Py_CLEAR(astmodulestate(module)->comparators);
376 Py_CLEAR(astmodulestate(module)->comprehension_type);
377 Py_CLEAR(astmodulestate(module)->context_expr);
378 Py_CLEAR(astmodulestate(module)->conversion);
379 Py_CLEAR(astmodulestate(module)->ctx);
380 Py_CLEAR(astmodulestate(module)->decorator_list);
381 Py_CLEAR(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700382 Py_CLEAR(astmodulestate(module)->elt);
383 Py_CLEAR(astmodulestate(module)->elts);
384 Py_CLEAR(astmodulestate(module)->end_col_offset);
385 Py_CLEAR(astmodulestate(module)->end_lineno);
386 Py_CLEAR(astmodulestate(module)->exc);
387 Py_CLEAR(astmodulestate(module)->excepthandler_type);
388 Py_CLEAR(astmodulestate(module)->expr_context_type);
389 Py_CLEAR(astmodulestate(module)->expr_type);
390 Py_CLEAR(astmodulestate(module)->finalbody);
391 Py_CLEAR(astmodulestate(module)->format_spec);
392 Py_CLEAR(astmodulestate(module)->func);
393 Py_CLEAR(astmodulestate(module)->generators);
394 Py_CLEAR(astmodulestate(module)->handlers);
395 Py_CLEAR(astmodulestate(module)->id);
396 Py_CLEAR(astmodulestate(module)->ifs);
397 Py_CLEAR(astmodulestate(module)->is_async);
398 Py_CLEAR(astmodulestate(module)->items);
399 Py_CLEAR(astmodulestate(module)->iter);
400 Py_CLEAR(astmodulestate(module)->key);
401 Py_CLEAR(astmodulestate(module)->keys);
402 Py_CLEAR(astmodulestate(module)->keyword_type);
403 Py_CLEAR(astmodulestate(module)->keywords);
404 Py_CLEAR(astmodulestate(module)->kind);
405 Py_CLEAR(astmodulestate(module)->kw_defaults);
406 Py_CLEAR(astmodulestate(module)->kwarg);
407 Py_CLEAR(astmodulestate(module)->kwonlyargs);
408 Py_CLEAR(astmodulestate(module)->left);
409 Py_CLEAR(astmodulestate(module)->level);
410 Py_CLEAR(astmodulestate(module)->lineno);
411 Py_CLEAR(astmodulestate(module)->lower);
412 Py_CLEAR(astmodulestate(module)->mod_type);
413 Py_CLEAR(astmodulestate(module)->module);
414 Py_CLEAR(astmodulestate(module)->msg);
415 Py_CLEAR(astmodulestate(module)->name);
416 Py_CLEAR(astmodulestate(module)->names);
417 Py_CLEAR(astmodulestate(module)->op);
418 Py_CLEAR(astmodulestate(module)->operand);
419 Py_CLEAR(astmodulestate(module)->operator_type);
420 Py_CLEAR(astmodulestate(module)->ops);
421 Py_CLEAR(astmodulestate(module)->optional_vars);
422 Py_CLEAR(astmodulestate(module)->orelse);
423 Py_CLEAR(astmodulestate(module)->posonlyargs);
424 Py_CLEAR(astmodulestate(module)->returns);
425 Py_CLEAR(astmodulestate(module)->right);
426 Py_CLEAR(astmodulestate(module)->simple);
427 Py_CLEAR(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700428 Py_CLEAR(astmodulestate(module)->step);
429 Py_CLEAR(astmodulestate(module)->stmt_type);
430 Py_CLEAR(astmodulestate(module)->tag);
431 Py_CLEAR(astmodulestate(module)->target);
432 Py_CLEAR(astmodulestate(module)->targets);
433 Py_CLEAR(astmodulestate(module)->test);
434 Py_CLEAR(astmodulestate(module)->type);
435 Py_CLEAR(astmodulestate(module)->type_comment);
436 Py_CLEAR(astmodulestate(module)->type_ignore_type);
437 Py_CLEAR(astmodulestate(module)->type_ignores);
438 Py_CLEAR(astmodulestate(module)->unaryop_type);
439 Py_CLEAR(astmodulestate(module)->upper);
440 Py_CLEAR(astmodulestate(module)->value);
441 Py_CLEAR(astmodulestate(module)->values);
442 Py_CLEAR(astmodulestate(module)->vararg);
443 Py_CLEAR(astmodulestate(module)->withitem_type);
444
445 return 0;
446}
447
448static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
449{
450 Py_VISIT(astmodulestate(module)->AST_type);
451 Py_VISIT(astmodulestate(module)->Add_singleton);
452 Py_VISIT(astmodulestate(module)->Add_type);
453 Py_VISIT(astmodulestate(module)->And_singleton);
454 Py_VISIT(astmodulestate(module)->And_type);
455 Py_VISIT(astmodulestate(module)->AnnAssign_type);
456 Py_VISIT(astmodulestate(module)->Assert_type);
457 Py_VISIT(astmodulestate(module)->Assign_type);
458 Py_VISIT(astmodulestate(module)->AsyncFor_type);
459 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
460 Py_VISIT(astmodulestate(module)->AsyncWith_type);
461 Py_VISIT(astmodulestate(module)->Attribute_type);
462 Py_VISIT(astmodulestate(module)->AugAssign_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700463 Py_VISIT(astmodulestate(module)->Await_type);
464 Py_VISIT(astmodulestate(module)->BinOp_type);
465 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
466 Py_VISIT(astmodulestate(module)->BitAnd_type);
467 Py_VISIT(astmodulestate(module)->BitOr_singleton);
468 Py_VISIT(astmodulestate(module)->BitOr_type);
469 Py_VISIT(astmodulestate(module)->BitXor_singleton);
470 Py_VISIT(astmodulestate(module)->BitXor_type);
471 Py_VISIT(astmodulestate(module)->BoolOp_type);
472 Py_VISIT(astmodulestate(module)->Break_type);
473 Py_VISIT(astmodulestate(module)->Call_type);
474 Py_VISIT(astmodulestate(module)->ClassDef_type);
475 Py_VISIT(astmodulestate(module)->Compare_type);
476 Py_VISIT(astmodulestate(module)->Constant_type);
477 Py_VISIT(astmodulestate(module)->Continue_type);
478 Py_VISIT(astmodulestate(module)->Del_singleton);
479 Py_VISIT(astmodulestate(module)->Del_type);
480 Py_VISIT(astmodulestate(module)->Delete_type);
481 Py_VISIT(astmodulestate(module)->DictComp_type);
482 Py_VISIT(astmodulestate(module)->Dict_type);
483 Py_VISIT(astmodulestate(module)->Div_singleton);
484 Py_VISIT(astmodulestate(module)->Div_type);
485 Py_VISIT(astmodulestate(module)->Eq_singleton);
486 Py_VISIT(astmodulestate(module)->Eq_type);
487 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
488 Py_VISIT(astmodulestate(module)->Expr_type);
489 Py_VISIT(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700490 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
491 Py_VISIT(astmodulestate(module)->FloorDiv_type);
492 Py_VISIT(astmodulestate(module)->For_type);
493 Py_VISIT(astmodulestate(module)->FormattedValue_type);
494 Py_VISIT(astmodulestate(module)->FunctionDef_type);
495 Py_VISIT(astmodulestate(module)->FunctionType_type);
496 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
497 Py_VISIT(astmodulestate(module)->Global_type);
498 Py_VISIT(astmodulestate(module)->GtE_singleton);
499 Py_VISIT(astmodulestate(module)->GtE_type);
500 Py_VISIT(astmodulestate(module)->Gt_singleton);
501 Py_VISIT(astmodulestate(module)->Gt_type);
502 Py_VISIT(astmodulestate(module)->IfExp_type);
503 Py_VISIT(astmodulestate(module)->If_type);
504 Py_VISIT(astmodulestate(module)->ImportFrom_type);
505 Py_VISIT(astmodulestate(module)->Import_type);
506 Py_VISIT(astmodulestate(module)->In_singleton);
507 Py_VISIT(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700508 Py_VISIT(astmodulestate(module)->Interactive_type);
509 Py_VISIT(astmodulestate(module)->Invert_singleton);
510 Py_VISIT(astmodulestate(module)->Invert_type);
511 Py_VISIT(astmodulestate(module)->IsNot_singleton);
512 Py_VISIT(astmodulestate(module)->IsNot_type);
513 Py_VISIT(astmodulestate(module)->Is_singleton);
514 Py_VISIT(astmodulestate(module)->Is_type);
515 Py_VISIT(astmodulestate(module)->JoinedStr_type);
516 Py_VISIT(astmodulestate(module)->LShift_singleton);
517 Py_VISIT(astmodulestate(module)->LShift_type);
518 Py_VISIT(astmodulestate(module)->Lambda_type);
519 Py_VISIT(astmodulestate(module)->ListComp_type);
520 Py_VISIT(astmodulestate(module)->List_type);
521 Py_VISIT(astmodulestate(module)->Load_singleton);
522 Py_VISIT(astmodulestate(module)->Load_type);
523 Py_VISIT(astmodulestate(module)->LtE_singleton);
524 Py_VISIT(astmodulestate(module)->LtE_type);
525 Py_VISIT(astmodulestate(module)->Lt_singleton);
526 Py_VISIT(astmodulestate(module)->Lt_type);
527 Py_VISIT(astmodulestate(module)->MatMult_singleton);
528 Py_VISIT(astmodulestate(module)->MatMult_type);
529 Py_VISIT(astmodulestate(module)->Mod_singleton);
530 Py_VISIT(astmodulestate(module)->Mod_type);
531 Py_VISIT(astmodulestate(module)->Module_type);
532 Py_VISIT(astmodulestate(module)->Mult_singleton);
533 Py_VISIT(astmodulestate(module)->Mult_type);
534 Py_VISIT(astmodulestate(module)->Name_type);
535 Py_VISIT(astmodulestate(module)->NamedExpr_type);
536 Py_VISIT(astmodulestate(module)->Nonlocal_type);
537 Py_VISIT(astmodulestate(module)->NotEq_singleton);
538 Py_VISIT(astmodulestate(module)->NotEq_type);
539 Py_VISIT(astmodulestate(module)->NotIn_singleton);
540 Py_VISIT(astmodulestate(module)->NotIn_type);
541 Py_VISIT(astmodulestate(module)->Not_singleton);
542 Py_VISIT(astmodulestate(module)->Not_type);
543 Py_VISIT(astmodulestate(module)->Or_singleton);
544 Py_VISIT(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700545 Py_VISIT(astmodulestate(module)->Pass_type);
546 Py_VISIT(astmodulestate(module)->Pow_singleton);
547 Py_VISIT(astmodulestate(module)->Pow_type);
548 Py_VISIT(astmodulestate(module)->RShift_singleton);
549 Py_VISIT(astmodulestate(module)->RShift_type);
550 Py_VISIT(astmodulestate(module)->Raise_type);
551 Py_VISIT(astmodulestate(module)->Return_type);
552 Py_VISIT(astmodulestate(module)->SetComp_type);
553 Py_VISIT(astmodulestate(module)->Set_type);
554 Py_VISIT(astmodulestate(module)->Slice_type);
555 Py_VISIT(astmodulestate(module)->Starred_type);
556 Py_VISIT(astmodulestate(module)->Store_singleton);
557 Py_VISIT(astmodulestate(module)->Store_type);
558 Py_VISIT(astmodulestate(module)->Sub_singleton);
559 Py_VISIT(astmodulestate(module)->Sub_type);
560 Py_VISIT(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700561 Py_VISIT(astmodulestate(module)->Try_type);
562 Py_VISIT(astmodulestate(module)->Tuple_type);
563 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
564 Py_VISIT(astmodulestate(module)->UAdd_singleton);
565 Py_VISIT(astmodulestate(module)->UAdd_type);
566 Py_VISIT(astmodulestate(module)->USub_singleton);
567 Py_VISIT(astmodulestate(module)->USub_type);
568 Py_VISIT(astmodulestate(module)->UnaryOp_type);
569 Py_VISIT(astmodulestate(module)->While_type);
570 Py_VISIT(astmodulestate(module)->With_type);
571 Py_VISIT(astmodulestate(module)->YieldFrom_type);
572 Py_VISIT(astmodulestate(module)->Yield_type);
573 Py_VISIT(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300574 Py_VISIT(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700575 Py_VISIT(astmodulestate(module)->__module__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700576 Py_VISIT(astmodulestate(module)->_attributes);
577 Py_VISIT(astmodulestate(module)->_fields);
578 Py_VISIT(astmodulestate(module)->alias_type);
579 Py_VISIT(astmodulestate(module)->annotation);
580 Py_VISIT(astmodulestate(module)->arg);
581 Py_VISIT(astmodulestate(module)->arg_type);
582 Py_VISIT(astmodulestate(module)->args);
583 Py_VISIT(astmodulestate(module)->argtypes);
584 Py_VISIT(astmodulestate(module)->arguments_type);
585 Py_VISIT(astmodulestate(module)->asname);
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200586 Py_VISIT(astmodulestate(module)->ast);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700587 Py_VISIT(astmodulestate(module)->attr);
588 Py_VISIT(astmodulestate(module)->bases);
589 Py_VISIT(astmodulestate(module)->body);
590 Py_VISIT(astmodulestate(module)->boolop_type);
591 Py_VISIT(astmodulestate(module)->cause);
592 Py_VISIT(astmodulestate(module)->cmpop_type);
593 Py_VISIT(astmodulestate(module)->col_offset);
594 Py_VISIT(astmodulestate(module)->comparators);
595 Py_VISIT(astmodulestate(module)->comprehension_type);
596 Py_VISIT(astmodulestate(module)->context_expr);
597 Py_VISIT(astmodulestate(module)->conversion);
598 Py_VISIT(astmodulestate(module)->ctx);
599 Py_VISIT(astmodulestate(module)->decorator_list);
600 Py_VISIT(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700601 Py_VISIT(astmodulestate(module)->elt);
602 Py_VISIT(astmodulestate(module)->elts);
603 Py_VISIT(astmodulestate(module)->end_col_offset);
604 Py_VISIT(astmodulestate(module)->end_lineno);
605 Py_VISIT(astmodulestate(module)->exc);
606 Py_VISIT(astmodulestate(module)->excepthandler_type);
607 Py_VISIT(astmodulestate(module)->expr_context_type);
608 Py_VISIT(astmodulestate(module)->expr_type);
609 Py_VISIT(astmodulestate(module)->finalbody);
610 Py_VISIT(astmodulestate(module)->format_spec);
611 Py_VISIT(astmodulestate(module)->func);
612 Py_VISIT(astmodulestate(module)->generators);
613 Py_VISIT(astmodulestate(module)->handlers);
614 Py_VISIT(astmodulestate(module)->id);
615 Py_VISIT(astmodulestate(module)->ifs);
616 Py_VISIT(astmodulestate(module)->is_async);
617 Py_VISIT(astmodulestate(module)->items);
618 Py_VISIT(astmodulestate(module)->iter);
619 Py_VISIT(astmodulestate(module)->key);
620 Py_VISIT(astmodulestate(module)->keys);
621 Py_VISIT(astmodulestate(module)->keyword_type);
622 Py_VISIT(astmodulestate(module)->keywords);
623 Py_VISIT(astmodulestate(module)->kind);
624 Py_VISIT(astmodulestate(module)->kw_defaults);
625 Py_VISIT(astmodulestate(module)->kwarg);
626 Py_VISIT(astmodulestate(module)->kwonlyargs);
627 Py_VISIT(astmodulestate(module)->left);
628 Py_VISIT(astmodulestate(module)->level);
629 Py_VISIT(astmodulestate(module)->lineno);
630 Py_VISIT(astmodulestate(module)->lower);
631 Py_VISIT(astmodulestate(module)->mod_type);
632 Py_VISIT(astmodulestate(module)->module);
633 Py_VISIT(astmodulestate(module)->msg);
634 Py_VISIT(astmodulestate(module)->name);
635 Py_VISIT(astmodulestate(module)->names);
636 Py_VISIT(astmodulestate(module)->op);
637 Py_VISIT(astmodulestate(module)->operand);
638 Py_VISIT(astmodulestate(module)->operator_type);
639 Py_VISIT(astmodulestate(module)->ops);
640 Py_VISIT(astmodulestate(module)->optional_vars);
641 Py_VISIT(astmodulestate(module)->orelse);
642 Py_VISIT(astmodulestate(module)->posonlyargs);
643 Py_VISIT(astmodulestate(module)->returns);
644 Py_VISIT(astmodulestate(module)->right);
645 Py_VISIT(astmodulestate(module)->simple);
646 Py_VISIT(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700647 Py_VISIT(astmodulestate(module)->step);
648 Py_VISIT(astmodulestate(module)->stmt_type);
649 Py_VISIT(astmodulestate(module)->tag);
650 Py_VISIT(astmodulestate(module)->target);
651 Py_VISIT(astmodulestate(module)->targets);
652 Py_VISIT(astmodulestate(module)->test);
653 Py_VISIT(astmodulestate(module)->type);
654 Py_VISIT(astmodulestate(module)->type_comment);
655 Py_VISIT(astmodulestate(module)->type_ignore_type);
656 Py_VISIT(astmodulestate(module)->type_ignores);
657 Py_VISIT(astmodulestate(module)->unaryop_type);
658 Py_VISIT(astmodulestate(module)->upper);
659 Py_VISIT(astmodulestate(module)->value);
660 Py_VISIT(astmodulestate(module)->values);
661 Py_VISIT(astmodulestate(module)->vararg);
662 Py_VISIT(astmodulestate(module)->withitem_type);
663
664 return 0;
665}
666
667static void astmodule_free(void* module) {
668 astmodule_clear((PyObject*)module);
669}
670
671static struct PyModuleDef _astmodule = {
672 PyModuleDef_HEAD_INIT,
673 "_ast",
674 NULL,
675 sizeof(astmodulestate),
676 NULL,
677 NULL,
678 astmodule_traverse,
679 astmodule_clear,
680 astmodule_free,
681};
682
683#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
684
685static int init_identifiers(void)
686{
687 astmodulestate *state = astmodulestate_global;
688 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300689 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700690 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700691 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
692 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
693 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
694 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
695 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
696 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
697 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200698 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700699 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
700 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
701 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
702 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
703 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
704 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
705 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
706 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
707 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
708 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
709 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700710 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
711 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
712 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
713 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
714 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
715 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
716 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
717 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
718 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
719 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
720 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
721 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
722 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
723 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
724 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
725 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
726 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
727 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
728 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
729 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
730 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
731 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
732 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
733 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
734 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
735 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
736 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
737 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
738 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
739 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
740 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
741 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
742 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
743 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
744 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
745 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
746 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
747 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
748 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
749 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
750 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
751 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
752 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
753 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
754 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
755 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
756 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
757 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
758 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
759 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
760 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
761 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
762 return 1;
763};
764
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000765static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300766static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200767 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800768 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000769};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300770static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200771 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000772};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300773static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200774 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000775};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300776static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800777 "argtypes",
778 "returns",
779};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300780static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200781 "lineno",
782 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000783 "end_lineno",
784 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000785};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000786static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300787static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200788 "name",
789 "args",
790 "body",
791 "decorator_list",
792 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800793 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000794};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300795static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400796 "name",
797 "args",
798 "body",
799 "decorator_list",
800 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800801 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400802};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300803static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200804 "name",
805 "bases",
806 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200807 "body",
808 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000809};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300810static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200811 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000812};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300813static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200814 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000815};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300816static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200817 "targets",
818 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800819 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000820};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300821static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200822 "target",
823 "op",
824 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000825};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300826static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700827 "target",
828 "annotation",
829 "value",
830 "simple",
831};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300832static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200833 "target",
834 "iter",
835 "body",
836 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800837 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000838};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300839static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400840 "target",
841 "iter",
842 "body",
843 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800844 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400845};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300846static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200847 "test",
848 "body",
849 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000850};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300851static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200852 "test",
853 "body",
854 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000855};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300856static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200857 "items",
858 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800859 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000860};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300861static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400862 "items",
863 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800864 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400865};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300866static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200867 "exc",
868 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000869};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300870static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200871 "body",
872 "handlers",
873 "orelse",
874 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000875};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300876static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200877 "test",
878 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000879};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300880static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200881 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000882};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300883static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200884 "module",
885 "names",
886 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000887};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300888static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200889 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000890};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300891static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200892 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000893};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300894static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200895 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000896};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300897static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200898 "lineno",
899 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000900 "end_lineno",
901 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000902};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000903static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300904static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200905 "op",
906 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000907};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300908static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700909 "target",
910 "value",
911};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300912static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200913 "left",
914 "op",
915 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000916};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300917static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200918 "op",
919 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000920};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300921static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200922 "args",
923 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000924};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300925static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200926 "test",
927 "body",
928 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000929};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300930static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200931 "keys",
932 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000933};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300934static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200935 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000936};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300937static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200938 "elt",
939 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000940};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300941static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200942 "elt",
943 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000944};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300945static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200946 "key",
947 "value",
948 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000949};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300950static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200951 "elt",
952 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000953};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300954static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400955 "value",
956};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300957static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200958 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500959};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300960static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200961 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000962};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300963static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200964 "left",
965 "ops",
966 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000967};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300968static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200969 "func",
970 "args",
971 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000972};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300973static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400974 "value",
975 "conversion",
976 "format_spec",
977};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300978static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400979 "values",
980};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300981static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100982 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -0700983 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100984};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300985static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200986 "value",
987 "attr",
988 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000989};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300990static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200991 "value",
992 "slice",
993 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000994};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300995static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200996 "value",
997 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +0000998};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300999static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001000 "id",
1001 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001002};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001003static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001004 "elts",
1005 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001006};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001007static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001008 "elts",
1009 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001010};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001011static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001012 "lower",
1013 "upper",
1014 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001015};
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001016static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001017static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001018static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001019static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001020static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001021static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001022static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001023 "target",
1024 "iter",
1025 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001026 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001027};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001028static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001029 "lineno",
1030 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001031 "end_lineno",
1032 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001033};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001034static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001035static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001036 "type",
1037 "name",
1038 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001039};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001040static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001041static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001042 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001043 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001044 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001045 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001046 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001047 "kwarg",
1048 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001049};
Neal Norwitzc1505362006-12-28 06:47:50 +00001050static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001051static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001052 "lineno",
1053 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001054 "end_lineno",
1055 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001056};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001057static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001058 "arg",
1059 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001060 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001061};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001062static PyObject* ast2obj_keyword(void*);
Pablo Galindo168660b2020-04-02 00:47:39 +01001063static const char * const keyword_attributes[] = {
1064 "lineno",
1065 "col_offset",
1066 "end_lineno",
1067 "end_col_offset",
1068};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001069static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001070 "arg",
1071 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001072};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001073static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001074static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001075 "name",
1076 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001077};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001078static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001079static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001080 "context_expr",
1081 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001082};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001083static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001084static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001085 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001086 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001087};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001088
1089
INADA Naokifc489082017-01-25 22:33:43 +09001090
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001091typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001092 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001093 PyObject *dict;
1094} AST_object;
1095
Benjamin Peterson1767e022012-03-14 21:50:29 -05001096static void
1097ast_dealloc(AST_object *self)
1098{
INADA Naokia6296d32017-08-24 14:55:17 +09001099 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001100 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001101 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001102 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001103 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1104 assert(free_func != NULL);
1105 free_func(self);
1106 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001107}
1108
Neal Norwitz207c9f32008-03-31 04:42:11 +00001109static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001110ast_traverse(AST_object *self, visitproc visit, void *arg)
1111{
1112 Py_VISIT(self->dict);
1113 return 0;
1114}
1115
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001116static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001117ast_clear(AST_object *self)
1118{
1119 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001120 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001121}
1122
1123static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001124ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1125{
1126 Py_ssize_t i, numfields = 0;
1127 int res = -1;
1128 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001129 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001130 goto cleanup;
1131 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001132 if (fields) {
1133 numfields = PySequence_Size(fields);
1134 if (numfields == -1)
1135 goto cleanup;
1136 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001137
Neal Norwitz207c9f32008-03-31 04:42:11 +00001138 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001139 if (numfields < PyTuple_GET_SIZE(args)) {
1140 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1141 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001142 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001143 numfields, numfields == 1 ? "" : "s");
1144 res = -1;
1145 goto cleanup;
1146 }
1147 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1148 /* cannot be reached when fields is NULL */
1149 PyObject *name = PySequence_GetItem(fields, i);
1150 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001151 res = -1;
1152 goto cleanup;
1153 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001154 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1155 Py_DECREF(name);
1156 if (res < 0)
1157 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001158 }
1159 if (kw) {
1160 i = 0; /* needed by PyDict_Next */
1161 while (PyDict_Next(kw, &i, &key, &value)) {
1162 res = PyObject_SetAttr(self, key, value);
1163 if (res < 0)
1164 goto cleanup;
1165 }
1166 }
1167 cleanup:
1168 Py_XDECREF(fields);
1169 return res;
1170}
1171
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001172/* Pickling support */
1173static PyObject *
1174ast_type_reduce(PyObject *self, PyObject *unused)
1175{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001176 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001177 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001178 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001179 }
1180 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001181 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001182 }
1183 return Py_BuildValue("O()", Py_TYPE(self));
1184}
1185
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001186static PyMemberDef ast_type_members[] = {
1187 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1188 {NULL} /* Sentinel */
1189};
1190
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001191static PyMethodDef ast_type_methods[] = {
1192 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1193 {NULL}
1194};
1195
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001196static PyGetSetDef ast_type_getsets[] = {
1197 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1198 {NULL}
1199};
1200
Dino Viehlandac46eb42019-09-11 10:16:34 -07001201static PyType_Slot AST_type_slots[] = {
1202 {Py_tp_dealloc, ast_dealloc},
1203 {Py_tp_getattro, PyObject_GenericGetAttr},
1204 {Py_tp_setattro, PyObject_GenericSetAttr},
1205 {Py_tp_traverse, ast_traverse},
1206 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001207 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001208 {Py_tp_methods, ast_type_methods},
1209 {Py_tp_getset, ast_type_getsets},
1210 {Py_tp_init, ast_type_init},
1211 {Py_tp_alloc, PyType_GenericAlloc},
1212 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001213 {Py_tp_free, PyObject_GC_Del},
1214 {0, 0},
1215};
1216
1217static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001218 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001219 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001220 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001221 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1222 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001223};
1224
Dino Viehlandac46eb42019-09-11 10:16:34 -07001225static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001226make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001227{
1228 PyObject *fnames, *result;
1229 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001230 fnames = PyTuple_New(num_fields);
1231 if (!fnames) return NULL;
1232 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001233 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001234 if (!field) {
1235 Py_DECREF(fnames);
1236 return NULL;
1237 }
1238 PyTuple_SET_ITEM(fnames, i, field);
1239 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001240 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001241 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001242 astmodulestate_global->_fields, fnames,
1243 astmodulestate_global->__module__,
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001244 astmodulestate_global->ast,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001245 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001246 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001247 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001248}
1249
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001250static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001251add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001252{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001253 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001254 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001255 if (!l)
1256 return 0;
1257 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001258 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001259 if (!s) {
1260 Py_DECREF(l);
1261 return 0;
1262 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001263 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001265 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001266 Py_DECREF(l);
1267 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001268}
1269
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001270/* Conversion AST -> Python */
1271
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001272static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1273{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001274 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001275 PyObject *result = PyList_New(n);
1276 PyObject *value;
1277 if (!result)
1278 return NULL;
1279 for (i = 0; i < n; i++) {
1280 value = func(asdl_seq_GET(seq, i));
1281 if (!value) {
1282 Py_DECREF(result);
1283 return NULL;
1284 }
1285 PyList_SET_ITEM(result, i, value);
1286 }
1287 return result;
1288}
1289
1290static PyObject* ast2obj_object(void *o)
1291{
1292 if (!o)
1293 o = Py_None;
1294 Py_INCREF((PyObject*)o);
1295 return (PyObject*)o;
1296}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001297#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001298#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001299#define ast2obj_identifier ast2obj_object
1300#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001301#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001302
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001303static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001304{
Christian Heimes217cfd12007-12-02 14:31:20 +00001305 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001306}
1307
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001308/* Conversion Python -> AST */
1309
1310static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1311{
1312 if (obj == Py_None)
1313 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001314 if (obj) {
1315 if (PyArena_AddPyObject(arena, obj) < 0) {
1316 *out = NULL;
1317 return -1;
1318 }
1319 Py_INCREF(obj);
1320 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001321 *out = obj;
1322 return 0;
1323}
1324
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001325static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1326{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001327 if (PyArena_AddPyObject(arena, obj) < 0) {
1328 *out = NULL;
1329 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001330 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001331 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001332 *out = obj;
1333 return 0;
1334}
1335
Benjamin Peterson180e6352011-07-22 11:09:07 -05001336static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001337{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001338 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1339 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001340 return 1;
1341 }
1342 return obj2ast_object(obj, out, arena);
1343}
1344
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001345static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1346{
1347 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1348 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1349 return 1;
1350 }
1351 return obj2ast_object(obj, out, arena);
1352}
1353
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001354static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1355{
1356 int i;
1357 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001358 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001359 return 1;
1360 }
1361
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001362 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001363 if (i == -1 && PyErr_Occurred())
1364 return 1;
1365 *out = i;
1366 return 0;
1367}
1368
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001369static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001370{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001371 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001372 empty_tuple = PyTuple_New(0);
1373 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001374 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1375 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001376 Py_XDECREF(empty_tuple);
1377 return -1;
1378 }
1379 Py_DECREF(empty_tuple);
1380 return 0;
1381}
1382
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001383
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001384static int init_types(void)
1385{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001386 PyObject *m;
1387 if (PyState_FindModule(&_astmodule) == NULL) {
1388 m = PyModule_Create(&_astmodule);
1389 if (!m) return 0;
1390 PyState_AddModule(m, &_astmodule);
1391 }
1392 astmodulestate *state = astmodulestate_global;
1393 if (state->initialized) return 1;
1394 if (init_identifiers() < 0) return 0;
1395 state->AST_type = PyType_FromSpec(&AST_type_spec);
1396 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001397 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001398 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1399 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1400 " | Interactive(stmt* body)\n"
1401 " | Expression(expr body)\n"
1402 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001403 if (!state->mod_type) return 0;
1404 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001405 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1406 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001407 if (!state->Module_type) return 0;
1408 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001409 Interactive_fields, 1,
1410 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001411 if (!state->Interactive_type) return 0;
1412 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001413 Expression_fields, 1,
1414 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001415 if (!state->Expression_type) return 0;
1416 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001417 FunctionType_fields, 2,
1418 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001419 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001420 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1421 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1422 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1423 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1424 " | Return(expr? value)\n"
1425 " | Delete(expr* targets)\n"
1426 " | Assign(expr* targets, expr value, string? type_comment)\n"
1427 " | AugAssign(expr target, operator op, expr value)\n"
1428 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1429 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1430 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1431 " | While(expr test, stmt* body, stmt* orelse)\n"
1432 " | If(expr test, stmt* body, stmt* orelse)\n"
1433 " | With(withitem* items, stmt* body, string? type_comment)\n"
1434 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1435 " | Raise(expr? exc, expr? cause)\n"
1436 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1437 " | Assert(expr test, expr? msg)\n"
1438 " | Import(alias* names)\n"
1439 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1440 " | Global(identifier* names)\n"
1441 " | Nonlocal(identifier* names)\n"
1442 " | Expr(expr value)\n"
1443 " | Pass\n"
1444 " | Break\n"
1445 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001446 if (!state->stmt_type) return 0;
1447 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001448 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1449 return 0;
1450 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1451 -1)
1452 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001453 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001454 FunctionDef_fields, 6,
1455 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001456 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001457 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1458 -1)
1459 return 0;
1460 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1461 == -1)
1462 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001463 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1464 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001465 AsyncFunctionDef_fields, 6,
1466 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001467 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001468 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1469 == -1)
1470 return 0;
1471 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1472 Py_None) == -1)
1473 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001474 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001475 ClassDef_fields, 5,
1476 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001477 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001478 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1479 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001480 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001481 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1482 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001483 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1484 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001485 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001486 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1487 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001488 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001489 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1490 -1)
1491 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001492 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001493 AugAssign_fields, 3,
1494 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001495 if (!state->AugAssign_type) return 0;
1496 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001497 AnnAssign_fields, 4,
1498 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001499 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001500 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1501 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001502 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1503 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001504 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001505 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1506 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001507 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001508 AsyncFor_fields, 5,
1509 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001510 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001511 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1512 -1)
1513 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001514 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1515 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001516 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001517 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1518 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001519 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001520 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1521 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001522 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001523 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1524 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001525 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001526 AsyncWith_fields, 3,
1527 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001528 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001529 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1530 == -1)
1531 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001532 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1533 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001534 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001535 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1536 return 0;
1537 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1538 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001539 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1540 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001541 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001542 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1543 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001544 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001545 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1546 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001547 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1548 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001549 if (!state->Import_type) return 0;
1550 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001551 ImportFrom_fields, 3,
1552 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001553 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001554 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1555 return 0;
1556 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1557 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001558 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1559 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001560 if (!state->Global_type) return 0;
1561 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001562 Nonlocal_fields, 1,
1563 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001564 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001565 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1566 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001567 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001568 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1569 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001570 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001571 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1572 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001573 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001574 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1575 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001576 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001577 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1578 "expr = BoolOp(boolop op, expr* values)\n"
1579 " | NamedExpr(expr target, expr value)\n"
1580 " | BinOp(expr left, operator op, expr right)\n"
1581 " | UnaryOp(unaryop op, expr operand)\n"
1582 " | Lambda(arguments args, expr body)\n"
1583 " | IfExp(expr test, expr body, expr orelse)\n"
1584 " | Dict(expr* keys, expr* values)\n"
1585 " | Set(expr* elts)\n"
1586 " | ListComp(expr elt, comprehension* generators)\n"
1587 " | SetComp(expr elt, comprehension* generators)\n"
1588 " | DictComp(expr key, expr value, comprehension* generators)\n"
1589 " | GeneratorExp(expr elt, comprehension* generators)\n"
1590 " | Await(expr value)\n"
1591 " | Yield(expr? value)\n"
1592 " | YieldFrom(expr value)\n"
1593 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1594 " | Call(expr func, expr* args, keyword* keywords)\n"
1595 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1596 " | JoinedStr(expr* values)\n"
1597 " | Constant(constant value, string? kind)\n"
1598 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1599 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1600 " | Starred(expr value, expr_context ctx)\n"
1601 " | Name(identifier id, expr_context ctx)\n"
1602 " | List(expr* elts, expr_context ctx)\n"
1603 " | Tuple(expr* elts, expr_context ctx)\n"
1604 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001605 if (!state->expr_type) return 0;
1606 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001607 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1608 return 0;
1609 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1610 -1)
1611 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001612 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1613 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001614 if (!state->BoolOp_type) return 0;
1615 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001616 NamedExpr_fields, 2,
1617 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001618 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001619 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1620 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001621 if (!state->BinOp_type) return 0;
1622 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001623 UnaryOp_fields, 2,
1624 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001625 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001626 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1627 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001628 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001629 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1630 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001631 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001632 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1633 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001634 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001635 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1636 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001637 if (!state->Set_type) return 0;
1638 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001639 ListComp_fields, 2,
1640 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001641 if (!state->ListComp_type) return 0;
1642 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001643 SetComp_fields, 2,
1644 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001645 if (!state->SetComp_type) return 0;
1646 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001647 DictComp_fields, 3,
1648 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001649 if (!state->DictComp_type) return 0;
1650 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001651 GeneratorExp_fields, 2,
1652 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001653 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001654 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1655 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001656 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001657 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1658 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001659 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001660 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1661 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001662 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001663 YieldFrom_fields, 1,
1664 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001665 if (!state->YieldFrom_type) return 0;
1666 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001667 Compare_fields, 3,
1668 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001669 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001670 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1671 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001672 if (!state->Call_type) return 0;
1673 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001674 FormattedValue_fields, 3,
1675 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001676 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001677 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1678 Py_None) == -1)
1679 return 0;
1680 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1681 Py_None) == -1)
1682 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001683 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001684 JoinedStr_fields, 1,
1685 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001686 if (!state->JoinedStr_type) return 0;
1687 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001688 Constant_fields, 2,
1689 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001690 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001691 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1692 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001693 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001694 Attribute_fields, 3,
1695 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001696 if (!state->Attribute_type) return 0;
1697 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001698 Subscript_fields, 3,
1699 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001700 if (!state->Subscript_type) return 0;
1701 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001702 Starred_fields, 2,
1703 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001704 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001705 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1706 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001707 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001708 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1709 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001710 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001711 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1712 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001713 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001714 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1715 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001716 if (!state->Slice_type) return 0;
1717 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1718 return 0;
1719 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1720 return 0;
1721 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1722 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001723 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001724 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001725 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001726 if (!state->expr_context_type) return 0;
1727 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001728 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1729 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001730 if (!state->Load_type) return 0;
1731 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1732 NULL, NULL);
1733 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001734 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1735 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001736 if (!state->Store_type) return 0;
1737 state->Store_singleton = PyType_GenericNew((PyTypeObject
1738 *)state->Store_type, NULL, NULL);
1739 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001740 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1741 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001742 if (!state->Del_type) return 0;
1743 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1744 NULL, NULL);
1745 if (!state->Del_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001746 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1747 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001748 if (!state->boolop_type) return 0;
1749 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001750 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1751 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001752 if (!state->And_type) return 0;
1753 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1754 NULL, NULL);
1755 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001756 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1757 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001758 if (!state->Or_type) return 0;
1759 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1760 NULL, NULL);
1761 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001762 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1763 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001764 if (!state->operator_type) return 0;
1765 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001766 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1767 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001768 if (!state->Add_type) return 0;
1769 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1770 NULL, NULL);
1771 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001772 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1773 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001774 if (!state->Sub_type) return 0;
1775 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1776 NULL, NULL);
1777 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001778 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1779 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001780 if (!state->Mult_type) return 0;
1781 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1782 NULL, NULL);
1783 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001784 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1785 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001786 if (!state->MatMult_type) return 0;
1787 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1788 *)state->MatMult_type, NULL,
1789 NULL);
1790 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001791 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1792 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001793 if (!state->Div_type) return 0;
1794 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1795 NULL, NULL);
1796 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001797 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1798 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001799 if (!state->Mod_type) return 0;
1800 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1801 NULL, NULL);
1802 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001803 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1804 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001805 if (!state->Pow_type) return 0;
1806 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1807 NULL, NULL);
1808 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001809 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1810 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001811 if (!state->LShift_type) return 0;
1812 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1813 *)state->LShift_type, NULL,
1814 NULL);
1815 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001816 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1817 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001818 if (!state->RShift_type) return 0;
1819 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1820 *)state->RShift_type, NULL,
1821 NULL);
1822 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001823 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1824 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001825 if (!state->BitOr_type) return 0;
1826 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1827 *)state->BitOr_type, NULL, NULL);
1828 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001829 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1830 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001831 if (!state->BitXor_type) return 0;
1832 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1833 *)state->BitXor_type, NULL,
1834 NULL);
1835 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001836 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1837 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001838 if (!state->BitAnd_type) return 0;
1839 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1840 *)state->BitAnd_type, NULL,
1841 NULL);
1842 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001843 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1844 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001845 if (!state->FloorDiv_type) return 0;
1846 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1847 *)state->FloorDiv_type, NULL,
1848 NULL);
1849 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001850 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1851 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001852 if (!state->unaryop_type) return 0;
1853 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001854 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1855 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001856 if (!state->Invert_type) return 0;
1857 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1858 *)state->Invert_type, NULL,
1859 NULL);
1860 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001861 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1862 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001863 if (!state->Not_type) return 0;
1864 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1865 NULL, NULL);
1866 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001867 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1868 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001869 if (!state->UAdd_type) return 0;
1870 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1871 NULL, NULL);
1872 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001873 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1874 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001875 if (!state->USub_type) return 0;
1876 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1877 NULL, NULL);
1878 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001879 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1880 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001881 if (!state->cmpop_type) return 0;
1882 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001883 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1884 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001885 if (!state->Eq_type) return 0;
1886 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1887 NULL, NULL);
1888 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001889 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1890 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001891 if (!state->NotEq_type) return 0;
1892 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1893 *)state->NotEq_type, NULL, NULL);
1894 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001895 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1896 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001897 if (!state->Lt_type) return 0;
1898 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1899 NULL, NULL);
1900 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001901 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1902 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001903 if (!state->LtE_type) return 0;
1904 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1905 NULL, NULL);
1906 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001907 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1908 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001909 if (!state->Gt_type) return 0;
1910 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1911 NULL, NULL);
1912 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001913 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1914 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001915 if (!state->GtE_type) return 0;
1916 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1917 NULL, NULL);
1918 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001919 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1920 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001921 if (!state->Is_type) return 0;
1922 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1923 NULL, NULL);
1924 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001925 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1926 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001927 if (!state->IsNot_type) return 0;
1928 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1929 *)state->IsNot_type, NULL, NULL);
1930 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001931 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1932 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001933 if (!state->In_type) return 0;
1934 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1935 NULL, NULL);
1936 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001937 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1938 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001939 if (!state->NotIn_type) return 0;
1940 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1941 *)state->NotIn_type, NULL, NULL);
1942 if (!state->NotIn_singleton) return 0;
1943 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001944 comprehension_fields, 4,
1945 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001946 if (!state->comprehension_type) return 0;
1947 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1948 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001949 NULL, 0,
1950 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001951 if (!state->excepthandler_type) return 0;
1952 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1953 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001954 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1955 == -1)
1956 return 0;
1957 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1958 Py_None) == -1)
1959 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001960 state->ExceptHandler_type = make_type("ExceptHandler",
1961 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001962 ExceptHandler_fields, 3,
1963 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001964 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001965 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1966 return 0;
1967 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1968 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001969 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001970 arguments_fields, 7,
1971 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001972 if (!state->arguments_type) return 0;
1973 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001974 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1975 return 0;
1976 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1977 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001978 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
1979 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001980 if (!state->arg_type) return 0;
1981 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001982 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1983 return 0;
1984 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1985 return 0;
1986 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1987 return 0;
1988 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1989 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001990 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001991 2,
1992 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001993 if (!state->keyword_type) return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001994 if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001995 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1996 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001997 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1998 return 0;
1999 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
2000 == -1)
2001 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002002 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
2003 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002004 if (!state->alias_type) return 0;
2005 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002006 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
2007 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002008 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002009 withitem_fields, 2,
2010 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002011 if (!state->withitem_type) return 0;
2012 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002013 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2014 == -1)
2015 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002016 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2017 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002018 if (!state->type_ignore_type) return 0;
2019 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2020 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002021 TypeIgnore_fields, 2,
2022 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002023 if (!state->TypeIgnore_type) return 0;
2024 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002025 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002026}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002027
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002028static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2029static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2030static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2031static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2032 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002033static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2034static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2035static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2036static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2037static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2038 arena);
2039static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2040 arena);
2041static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2042static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2043static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2044static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002045static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002046static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2047 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002048
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002049mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002050Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002051{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002052 mod_ty p;
2053 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2054 if (!p)
2055 return NULL;
2056 p->kind = Module_kind;
2057 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002058 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002059 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002060}
2061
2062mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002063Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002064{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002065 mod_ty p;
2066 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2067 if (!p)
2068 return NULL;
2069 p->kind = Interactive_kind;
2070 p->v.Interactive.body = body;
2071 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002072}
2073
2074mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002075Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002076{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002077 mod_ty p;
2078 if (!body) {
2079 PyErr_SetString(PyExc_ValueError,
2080 "field body is required for Expression");
2081 return NULL;
2082 }
2083 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2084 if (!p)
2085 return NULL;
2086 p->kind = Expression_kind;
2087 p->v.Expression.body = body;
2088 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002089}
2090
2091mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002092FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2093{
2094 mod_ty p;
2095 if (!returns) {
2096 PyErr_SetString(PyExc_ValueError,
2097 "field returns is required for FunctionType");
2098 return NULL;
2099 }
2100 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2101 if (!p)
2102 return NULL;
2103 p->kind = FunctionType_kind;
2104 p->v.FunctionType.argtypes = argtypes;
2105 p->v.FunctionType.returns = returns;
2106 return p;
2107}
2108
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002109stmt_ty
2110FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002111 decorator_list, expr_ty returns, string type_comment, int lineno,
2112 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002113{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002114 stmt_ty p;
2115 if (!name) {
2116 PyErr_SetString(PyExc_ValueError,
2117 "field name is required for FunctionDef");
2118 return NULL;
2119 }
2120 if (!args) {
2121 PyErr_SetString(PyExc_ValueError,
2122 "field args is required for FunctionDef");
2123 return NULL;
2124 }
2125 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2126 if (!p)
2127 return NULL;
2128 p->kind = FunctionDef_kind;
2129 p->v.FunctionDef.name = name;
2130 p->v.FunctionDef.args = args;
2131 p->v.FunctionDef.body = body;
2132 p->v.FunctionDef.decorator_list = decorator_list;
2133 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002134 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002135 p->lineno = lineno;
2136 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002137 p->end_lineno = end_lineno;
2138 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002139 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002140}
2141
2142stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002143AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002144 * decorator_list, expr_ty returns, string type_comment, int
2145 lineno, int col_offset, int end_lineno, int end_col_offset,
2146 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002147{
2148 stmt_ty p;
2149 if (!name) {
2150 PyErr_SetString(PyExc_ValueError,
2151 "field name is required for AsyncFunctionDef");
2152 return NULL;
2153 }
2154 if (!args) {
2155 PyErr_SetString(PyExc_ValueError,
2156 "field args is required for AsyncFunctionDef");
2157 return NULL;
2158 }
2159 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2160 if (!p)
2161 return NULL;
2162 p->kind = AsyncFunctionDef_kind;
2163 p->v.AsyncFunctionDef.name = name;
2164 p->v.AsyncFunctionDef.args = args;
2165 p->v.AsyncFunctionDef.body = body;
2166 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2167 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002168 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002169 p->lineno = lineno;
2170 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002171 p->end_lineno = end_lineno;
2172 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002173 return p;
2174}
2175
2176stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002177ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002178 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2179 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002180{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002181 stmt_ty p;
2182 if (!name) {
2183 PyErr_SetString(PyExc_ValueError,
2184 "field name is required for ClassDef");
2185 return NULL;
2186 }
2187 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2188 if (!p)
2189 return NULL;
2190 p->kind = ClassDef_kind;
2191 p->v.ClassDef.name = name;
2192 p->v.ClassDef.bases = bases;
2193 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002194 p->v.ClassDef.body = body;
2195 p->v.ClassDef.decorator_list = decorator_list;
2196 p->lineno = lineno;
2197 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002198 p->end_lineno = end_lineno;
2199 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002200 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002201}
2202
2203stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002204Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2205 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002206{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002207 stmt_ty p;
2208 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2209 if (!p)
2210 return NULL;
2211 p->kind = Return_kind;
2212 p->v.Return.value = value;
2213 p->lineno = lineno;
2214 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002215 p->end_lineno = end_lineno;
2216 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002217 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218}
2219
2220stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002221Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2222 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002223{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002224 stmt_ty p;
2225 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2226 if (!p)
2227 return NULL;
2228 p->kind = Delete_kind;
2229 p->v.Delete.targets = targets;
2230 p->lineno = lineno;
2231 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002232 p->end_lineno = end_lineno;
2233 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002234 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002235}
2236
2237stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002238Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2239 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002240{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002241 stmt_ty p;
2242 if (!value) {
2243 PyErr_SetString(PyExc_ValueError,
2244 "field value is required for Assign");
2245 return NULL;
2246 }
2247 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2248 if (!p)
2249 return NULL;
2250 p->kind = Assign_kind;
2251 p->v.Assign.targets = targets;
2252 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002253 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002254 p->lineno = lineno;
2255 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002256 p->end_lineno = end_lineno;
2257 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002258 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259}
2260
2261stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002262AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002263 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002264{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002265 stmt_ty p;
2266 if (!target) {
2267 PyErr_SetString(PyExc_ValueError,
2268 "field target is required for AugAssign");
2269 return NULL;
2270 }
2271 if (!op) {
2272 PyErr_SetString(PyExc_ValueError,
2273 "field op is required for AugAssign");
2274 return NULL;
2275 }
2276 if (!value) {
2277 PyErr_SetString(PyExc_ValueError,
2278 "field value is required for AugAssign");
2279 return NULL;
2280 }
2281 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2282 if (!p)
2283 return NULL;
2284 p->kind = AugAssign_kind;
2285 p->v.AugAssign.target = target;
2286 p->v.AugAssign.op = op;
2287 p->v.AugAssign.value = value;
2288 p->lineno = lineno;
2289 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002290 p->end_lineno = end_lineno;
2291 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002292 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002293}
2294
2295stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002296AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002297 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2298 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002299{
2300 stmt_ty p;
2301 if (!target) {
2302 PyErr_SetString(PyExc_ValueError,
2303 "field target is required for AnnAssign");
2304 return NULL;
2305 }
2306 if (!annotation) {
2307 PyErr_SetString(PyExc_ValueError,
2308 "field annotation is required for AnnAssign");
2309 return NULL;
2310 }
2311 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2312 if (!p)
2313 return NULL;
2314 p->kind = AnnAssign_kind;
2315 p->v.AnnAssign.target = target;
2316 p->v.AnnAssign.annotation = annotation;
2317 p->v.AnnAssign.value = value;
2318 p->v.AnnAssign.simple = simple;
2319 p->lineno = lineno;
2320 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002321 p->end_lineno = end_lineno;
2322 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002323 return p;
2324}
2325
2326stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002327For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2328 type_comment, int lineno, int col_offset, int end_lineno, int
2329 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002330{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002331 stmt_ty p;
2332 if (!target) {
2333 PyErr_SetString(PyExc_ValueError,
2334 "field target is required for For");
2335 return NULL;
2336 }
2337 if (!iter) {
2338 PyErr_SetString(PyExc_ValueError,
2339 "field iter is required for For");
2340 return NULL;
2341 }
2342 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2343 if (!p)
2344 return NULL;
2345 p->kind = For_kind;
2346 p->v.For.target = target;
2347 p->v.For.iter = iter;
2348 p->v.For.body = body;
2349 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002350 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002351 p->lineno = lineno;
2352 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002353 p->end_lineno = end_lineno;
2354 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002355 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002356}
2357
2358stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002359AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2360 string type_comment, int lineno, int col_offset, int end_lineno, int
2361 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002362{
2363 stmt_ty p;
2364 if (!target) {
2365 PyErr_SetString(PyExc_ValueError,
2366 "field target is required for AsyncFor");
2367 return NULL;
2368 }
2369 if (!iter) {
2370 PyErr_SetString(PyExc_ValueError,
2371 "field iter is required for AsyncFor");
2372 return NULL;
2373 }
2374 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2375 if (!p)
2376 return NULL;
2377 p->kind = AsyncFor_kind;
2378 p->v.AsyncFor.target = target;
2379 p->v.AsyncFor.iter = iter;
2380 p->v.AsyncFor.body = body;
2381 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002382 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002383 p->lineno = lineno;
2384 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002385 p->end_lineno = end_lineno;
2386 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002387 return p;
2388}
2389
2390stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002391While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002392 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002393{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002394 stmt_ty p;
2395 if (!test) {
2396 PyErr_SetString(PyExc_ValueError,
2397 "field test is required for While");
2398 return NULL;
2399 }
2400 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2401 if (!p)
2402 return NULL;
2403 p->kind = While_kind;
2404 p->v.While.test = test;
2405 p->v.While.body = body;
2406 p->v.While.orelse = orelse;
2407 p->lineno = lineno;
2408 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002409 p->end_lineno = end_lineno;
2410 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002411 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002412}
2413
2414stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002415If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002416 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002417{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002418 stmt_ty p;
2419 if (!test) {
2420 PyErr_SetString(PyExc_ValueError,
2421 "field test is required for If");
2422 return NULL;
2423 }
2424 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2425 if (!p)
2426 return NULL;
2427 p->kind = If_kind;
2428 p->v.If.test = test;
2429 p->v.If.body = body;
2430 p->v.If.orelse = orelse;
2431 p->lineno = lineno;
2432 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002433 p->end_lineno = end_lineno;
2434 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002435 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436}
2437
2438stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002439With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2440 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002441{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002442 stmt_ty p;
2443 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2444 if (!p)
2445 return NULL;
2446 p->kind = With_kind;
2447 p->v.With.items = items;
2448 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002449 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002450 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;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002455}
2456
2457stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002458AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2459 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002460{
2461 stmt_ty p;
2462 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2463 if (!p)
2464 return NULL;
2465 p->kind = AsyncWith_kind;
2466 p->v.AsyncWith.items = items;
2467 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002468 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002469 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;
Yury Selivanov75445082015-05-11 22:57:16 -04002473 return p;
2474}
2475
2476stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002477Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2478 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002480 stmt_ty p;
2481 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2482 if (!p)
2483 return NULL;
2484 p->kind = Raise_kind;
2485 p->v.Raise.exc = exc;
2486 p->v.Raise.cause = cause;
2487 p->lineno = lineno;
2488 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002489 p->end_lineno = end_lineno;
2490 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002491 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002492}
2493
2494stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002495Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002496 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2497 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 = Try_kind;
2504 p->v.Try.body = body;
2505 p->v.Try.handlers = handlers;
2506 p->v.Try.orelse = orelse;
2507 p->v.Try.finalbody = finalbody;
2508 p->lineno = lineno;
2509 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002510 p->end_lineno = end_lineno;
2511 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002512 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002513}
2514
2515stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002516Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2517 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002518{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002519 stmt_ty p;
2520 if (!test) {
2521 PyErr_SetString(PyExc_ValueError,
2522 "field test is required for Assert");
2523 return NULL;
2524 }
2525 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2526 if (!p)
2527 return NULL;
2528 p->kind = Assert_kind;
2529 p->v.Assert.test = test;
2530 p->v.Assert.msg = msg;
2531 p->lineno = lineno;
2532 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002533 p->end_lineno = end_lineno;
2534 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002535 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002536}
2537
2538stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002539Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2540 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002541{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002542 stmt_ty p;
2543 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2544 if (!p)
2545 return NULL;
2546 p->kind = Import_kind;
2547 p->v.Import.names = names;
2548 p->lineno = lineno;
2549 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002550 p->end_lineno = end_lineno;
2551 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002552 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002553}
2554
2555stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002556ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002557 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002558{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002559 stmt_ty p;
2560 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2561 if (!p)
2562 return NULL;
2563 p->kind = ImportFrom_kind;
2564 p->v.ImportFrom.module = module;
2565 p->v.ImportFrom.names = names;
2566 p->v.ImportFrom.level = level;
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
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002575Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2576 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 = Global_kind;
2583 p->v.Global.names = names;
2584 p->lineno = lineno;
2585 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002586 p->end_lineno = end_lineno;
2587 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002588 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589}
2590
2591stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002592Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2593 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002594{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002595 stmt_ty p;
2596 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2597 if (!p)
2598 return NULL;
2599 p->kind = Nonlocal_kind;
2600 p->v.Nonlocal.names = names;
2601 p->lineno = lineno;
2602 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002603 p->end_lineno = end_lineno;
2604 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002605 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002606}
2607
2608stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002609Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2610 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002611{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002612 stmt_ty p;
2613 if (!value) {
2614 PyErr_SetString(PyExc_ValueError,
2615 "field value is required for Expr");
2616 return NULL;
2617 }
2618 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2619 if (!p)
2620 return NULL;
2621 p->kind = Expr_kind;
2622 p->v.Expr.value = value;
2623 p->lineno = lineno;
2624 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002625 p->end_lineno = end_lineno;
2626 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002627 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002628}
2629
2630stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002631Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2632 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002633{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002634 stmt_ty p;
2635 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2636 if (!p)
2637 return NULL;
2638 p->kind = Pass_kind;
2639 p->lineno = lineno;
2640 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002641 p->end_lineno = end_lineno;
2642 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002643 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002644}
2645
2646stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002647Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2648 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002649{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002650 stmt_ty p;
2651 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2652 if (!p)
2653 return NULL;
2654 p->kind = Break_kind;
2655 p->lineno = lineno;
2656 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002657 p->end_lineno = end_lineno;
2658 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002659 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002660}
2661
2662stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002663Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2664 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002666 stmt_ty p;
2667 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2668 if (!p)
2669 return NULL;
2670 p->kind = Continue_kind;
2671 p->lineno = lineno;
2672 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002673 p->end_lineno = end_lineno;
2674 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002675 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002676}
2677
2678expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002679BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2680 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002681{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002682 expr_ty p;
2683 if (!op) {
2684 PyErr_SetString(PyExc_ValueError,
2685 "field op is required for BoolOp");
2686 return NULL;
2687 }
2688 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2689 if (!p)
2690 return NULL;
2691 p->kind = BoolOp_kind;
2692 p->v.BoolOp.op = op;
2693 p->v.BoolOp.values = values;
2694 p->lineno = lineno;
2695 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002696 p->end_lineno = end_lineno;
2697 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002698 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002699}
2700
2701expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002702NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2703 end_lineno, int end_col_offset, PyArena *arena)
2704{
2705 expr_ty p;
2706 if (!target) {
2707 PyErr_SetString(PyExc_ValueError,
2708 "field target is required for NamedExpr");
2709 return NULL;
2710 }
2711 if (!value) {
2712 PyErr_SetString(PyExc_ValueError,
2713 "field value is required for NamedExpr");
2714 return NULL;
2715 }
2716 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2717 if (!p)
2718 return NULL;
2719 p->kind = NamedExpr_kind;
2720 p->v.NamedExpr.target = target;
2721 p->v.NamedExpr.value = value;
2722 p->lineno = lineno;
2723 p->col_offset = col_offset;
2724 p->end_lineno = end_lineno;
2725 p->end_col_offset = end_col_offset;
2726 return p;
2727}
2728
2729expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002730BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002731 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002732{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002733 expr_ty p;
2734 if (!left) {
2735 PyErr_SetString(PyExc_ValueError,
2736 "field left is required for BinOp");
2737 return NULL;
2738 }
2739 if (!op) {
2740 PyErr_SetString(PyExc_ValueError,
2741 "field op is required for BinOp");
2742 return NULL;
2743 }
2744 if (!right) {
2745 PyErr_SetString(PyExc_ValueError,
2746 "field right is required for BinOp");
2747 return NULL;
2748 }
2749 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2750 if (!p)
2751 return NULL;
2752 p->kind = BinOp_kind;
2753 p->v.BinOp.left = left;
2754 p->v.BinOp.op = op;
2755 p->v.BinOp.right = right;
2756 p->lineno = lineno;
2757 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002758 p->end_lineno = end_lineno;
2759 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002760 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002761}
2762
2763expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002764UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2765 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002766{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002767 expr_ty p;
2768 if (!op) {
2769 PyErr_SetString(PyExc_ValueError,
2770 "field op is required for UnaryOp");
2771 return NULL;
2772 }
2773 if (!operand) {
2774 PyErr_SetString(PyExc_ValueError,
2775 "field operand is required for UnaryOp");
2776 return NULL;
2777 }
2778 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2779 if (!p)
2780 return NULL;
2781 p->kind = UnaryOp_kind;
2782 p->v.UnaryOp.op = op;
2783 p->v.UnaryOp.operand = operand;
2784 p->lineno = lineno;
2785 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002786 p->end_lineno = end_lineno;
2787 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002788 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002789}
2790
2791expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002792Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2793 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002794{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002795 expr_ty p;
2796 if (!args) {
2797 PyErr_SetString(PyExc_ValueError,
2798 "field args is required for Lambda");
2799 return NULL;
2800 }
2801 if (!body) {
2802 PyErr_SetString(PyExc_ValueError,
2803 "field body is required for Lambda");
2804 return NULL;
2805 }
2806 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2807 if (!p)
2808 return NULL;
2809 p->kind = Lambda_kind;
2810 p->v.Lambda.args = args;
2811 p->v.Lambda.body = body;
2812 p->lineno = lineno;
2813 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002814 p->end_lineno = end_lineno;
2815 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002816 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002817}
2818
2819expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002820IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002821 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002822{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002823 expr_ty p;
2824 if (!test) {
2825 PyErr_SetString(PyExc_ValueError,
2826 "field test is required for IfExp");
2827 return NULL;
2828 }
2829 if (!body) {
2830 PyErr_SetString(PyExc_ValueError,
2831 "field body is required for IfExp");
2832 return NULL;
2833 }
2834 if (!orelse) {
2835 PyErr_SetString(PyExc_ValueError,
2836 "field orelse is required for IfExp");
2837 return NULL;
2838 }
2839 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2840 if (!p)
2841 return NULL;
2842 p->kind = IfExp_kind;
2843 p->v.IfExp.test = test;
2844 p->v.IfExp.body = body;
2845 p->v.IfExp.orelse = orelse;
2846 p->lineno = lineno;
2847 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002848 p->end_lineno = end_lineno;
2849 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002850 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002851}
2852
2853expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002854Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2855 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002856{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002857 expr_ty p;
2858 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2859 if (!p)
2860 return NULL;
2861 p->kind = Dict_kind;
2862 p->v.Dict.keys = keys;
2863 p->v.Dict.values = values;
2864 p->lineno = lineno;
2865 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002866 p->end_lineno = end_lineno;
2867 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002868 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002869}
2870
2871expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002872Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2873 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002874{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002875 expr_ty p;
2876 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2877 if (!p)
2878 return NULL;
2879 p->kind = Set_kind;
2880 p->v.Set.elts = elts;
2881 p->lineno = lineno;
2882 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002883 p->end_lineno = end_lineno;
2884 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002885 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002886}
2887
2888expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002889ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2890 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002891{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002892 expr_ty p;
2893 if (!elt) {
2894 PyErr_SetString(PyExc_ValueError,
2895 "field elt is required for ListComp");
2896 return NULL;
2897 }
2898 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2899 if (!p)
2900 return NULL;
2901 p->kind = ListComp_kind;
2902 p->v.ListComp.elt = elt;
2903 p->v.ListComp.generators = generators;
2904 p->lineno = lineno;
2905 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002906 p->end_lineno = end_lineno;
2907 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002908 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002909}
2910
2911expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002912SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2913 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002914{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002915 expr_ty p;
2916 if (!elt) {
2917 PyErr_SetString(PyExc_ValueError,
2918 "field elt is required for SetComp");
2919 return NULL;
2920 }
2921 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2922 if (!p)
2923 return NULL;
2924 p->kind = SetComp_kind;
2925 p->v.SetComp.elt = elt;
2926 p->v.SetComp.generators = generators;
2927 p->lineno = lineno;
2928 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002929 p->end_lineno = end_lineno;
2930 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002931 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002932}
2933
2934expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002935DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002936 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002937{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002938 expr_ty p;
2939 if (!key) {
2940 PyErr_SetString(PyExc_ValueError,
2941 "field key is required for DictComp");
2942 return NULL;
2943 }
2944 if (!value) {
2945 PyErr_SetString(PyExc_ValueError,
2946 "field value is required for DictComp");
2947 return NULL;
2948 }
2949 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2950 if (!p)
2951 return NULL;
2952 p->kind = DictComp_kind;
2953 p->v.DictComp.key = key;
2954 p->v.DictComp.value = value;
2955 p->v.DictComp.generators = generators;
2956 p->lineno = lineno;
2957 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002958 p->end_lineno = end_lineno;
2959 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002960 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002961}
2962
2963expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002964GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002965 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002966{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002967 expr_ty p;
2968 if (!elt) {
2969 PyErr_SetString(PyExc_ValueError,
2970 "field elt is required for GeneratorExp");
2971 return NULL;
2972 }
2973 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2974 if (!p)
2975 return NULL;
2976 p->kind = GeneratorExp_kind;
2977 p->v.GeneratorExp.elt = elt;
2978 p->v.GeneratorExp.generators = generators;
2979 p->lineno = lineno;
2980 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002981 p->end_lineno = end_lineno;
2982 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002983 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002984}
2985
2986expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002987Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2988 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002989{
2990 expr_ty p;
2991 if (!value) {
2992 PyErr_SetString(PyExc_ValueError,
2993 "field value is required for Await");
2994 return NULL;
2995 }
2996 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2997 if (!p)
2998 return NULL;
2999 p->kind = Await_kind;
3000 p->v.Await.value = value;
3001 p->lineno = lineno;
3002 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003003 p->end_lineno = end_lineno;
3004 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04003005 return p;
3006}
3007
3008expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003009Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3010 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003011{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003012 expr_ty p;
3013 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3014 if (!p)
3015 return NULL;
3016 p->kind = Yield_kind;
3017 p->v.Yield.value = value;
3018 p->lineno = lineno;
3019 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003020 p->end_lineno = end_lineno;
3021 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003022 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003023}
3024
3025expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003026YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3027 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003028{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003029 expr_ty p;
3030 if (!value) {
3031 PyErr_SetString(PyExc_ValueError,
3032 "field value is required for YieldFrom");
3033 return NULL;
3034 }
3035 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3036 if (!p)
3037 return NULL;
3038 p->kind = YieldFrom_kind;
3039 p->v.YieldFrom.value = value;
3040 p->lineno = lineno;
3041 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003042 p->end_lineno = end_lineno;
3043 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003044 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003045}
3046
3047expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003048Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003049 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003050{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003051 expr_ty p;
3052 if (!left) {
3053 PyErr_SetString(PyExc_ValueError,
3054 "field left is required for Compare");
3055 return NULL;
3056 }
3057 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3058 if (!p)
3059 return NULL;
3060 p->kind = Compare_kind;
3061 p->v.Compare.left = left;
3062 p->v.Compare.ops = ops;
3063 p->v.Compare.comparators = comparators;
3064 p->lineno = lineno;
3065 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003066 p->end_lineno = end_lineno;
3067 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003068 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003069}
3070
3071expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003072Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003073 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003074{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003075 expr_ty p;
3076 if (!func) {
3077 PyErr_SetString(PyExc_ValueError,
3078 "field func is required for Call");
3079 return NULL;
3080 }
3081 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3082 if (!p)
3083 return NULL;
3084 p->kind = Call_kind;
3085 p->v.Call.func = func;
3086 p->v.Call.args = args;
3087 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003088 p->lineno = lineno;
3089 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003090 p->end_lineno = end_lineno;
3091 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003092 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003093}
3094
3095expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003096FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3097 int col_offset, int end_lineno, int end_col_offset, PyArena
3098 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003099{
3100 expr_ty p;
3101 if (!value) {
3102 PyErr_SetString(PyExc_ValueError,
3103 "field value is required for FormattedValue");
3104 return NULL;
3105 }
3106 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3107 if (!p)
3108 return NULL;
3109 p->kind = FormattedValue_kind;
3110 p->v.FormattedValue.value = value;
3111 p->v.FormattedValue.conversion = conversion;
3112 p->v.FormattedValue.format_spec = format_spec;
3113 p->lineno = lineno;
3114 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003115 p->end_lineno = end_lineno;
3116 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003117 return p;
3118}
3119
3120expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003121JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3122 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003123{
3124 expr_ty p;
3125 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3126 if (!p)
3127 return NULL;
3128 p->kind = JoinedStr_kind;
3129 p->v.JoinedStr.values = values;
3130 p->lineno = lineno;
3131 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003132 p->end_lineno = end_lineno;
3133 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003134 return p;
3135}
3136
3137expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003138Constant(constant value, string kind, int lineno, int col_offset, int
3139 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003140{
3141 expr_ty p;
3142 if (!value) {
3143 PyErr_SetString(PyExc_ValueError,
3144 "field value is required for Constant");
3145 return NULL;
3146 }
3147 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3148 if (!p)
3149 return NULL;
3150 p->kind = Constant_kind;
3151 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003152 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003153 p->lineno = lineno;
3154 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003155 p->end_lineno = end_lineno;
3156 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003157 return p;
3158}
3159
3160expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003161Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003162 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003163{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003164 expr_ty p;
3165 if (!value) {
3166 PyErr_SetString(PyExc_ValueError,
3167 "field value is required for Attribute");
3168 return NULL;
3169 }
3170 if (!attr) {
3171 PyErr_SetString(PyExc_ValueError,
3172 "field attr is required for Attribute");
3173 return NULL;
3174 }
3175 if (!ctx) {
3176 PyErr_SetString(PyExc_ValueError,
3177 "field ctx is required for Attribute");
3178 return NULL;
3179 }
3180 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3181 if (!p)
3182 return NULL;
3183 p->kind = Attribute_kind;
3184 p->v.Attribute.value = value;
3185 p->v.Attribute.attr = attr;
3186 p->v.Attribute.ctx = ctx;
3187 p->lineno = lineno;
3188 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003189 p->end_lineno = end_lineno;
3190 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003191 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003192}
3193
3194expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003195Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003196 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003197{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003198 expr_ty p;
3199 if (!value) {
3200 PyErr_SetString(PyExc_ValueError,
3201 "field value is required for Subscript");
3202 return NULL;
3203 }
3204 if (!slice) {
3205 PyErr_SetString(PyExc_ValueError,
3206 "field slice is required for Subscript");
3207 return NULL;
3208 }
3209 if (!ctx) {
3210 PyErr_SetString(PyExc_ValueError,
3211 "field ctx is required for Subscript");
3212 return NULL;
3213 }
3214 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3215 if (!p)
3216 return NULL;
3217 p->kind = Subscript_kind;
3218 p->v.Subscript.value = value;
3219 p->v.Subscript.slice = slice;
3220 p->v.Subscript.ctx = ctx;
3221 p->lineno = lineno;
3222 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003223 p->end_lineno = end_lineno;
3224 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003225 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003226}
3227
3228expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003229Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3230 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003231{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003232 expr_ty p;
3233 if (!value) {
3234 PyErr_SetString(PyExc_ValueError,
3235 "field value is required for Starred");
3236 return NULL;
3237 }
3238 if (!ctx) {
3239 PyErr_SetString(PyExc_ValueError,
3240 "field ctx is required for Starred");
3241 return NULL;
3242 }
3243 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3244 if (!p)
3245 return NULL;
3246 p->kind = Starred_kind;
3247 p->v.Starred.value = value;
3248 p->v.Starred.ctx = ctx;
3249 p->lineno = lineno;
3250 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003251 p->end_lineno = end_lineno;
3252 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003253 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003254}
3255
3256expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003257Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3258 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003259{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003260 expr_ty p;
3261 if (!id) {
3262 PyErr_SetString(PyExc_ValueError,
3263 "field id is required for Name");
3264 return NULL;
3265 }
3266 if (!ctx) {
3267 PyErr_SetString(PyExc_ValueError,
3268 "field ctx is required for Name");
3269 return NULL;
3270 }
3271 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3272 if (!p)
3273 return NULL;
3274 p->kind = Name_kind;
3275 p->v.Name.id = id;
3276 p->v.Name.ctx = ctx;
3277 p->lineno = lineno;
3278 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003279 p->end_lineno = end_lineno;
3280 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003281 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003282}
3283
3284expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003285List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3286 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003287{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003288 expr_ty p;
3289 if (!ctx) {
3290 PyErr_SetString(PyExc_ValueError,
3291 "field ctx is required for List");
3292 return NULL;
3293 }
3294 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3295 if (!p)
3296 return NULL;
3297 p->kind = List_kind;
3298 p->v.List.elts = elts;
3299 p->v.List.ctx = ctx;
3300 p->lineno = lineno;
3301 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003302 p->end_lineno = end_lineno;
3303 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003304 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003305}
3306
3307expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003308Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3309 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003310{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003311 expr_ty p;
3312 if (!ctx) {
3313 PyErr_SetString(PyExc_ValueError,
3314 "field ctx is required for Tuple");
3315 return NULL;
3316 }
3317 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3318 if (!p)
3319 return NULL;
3320 p->kind = Tuple_kind;
3321 p->v.Tuple.elts = elts;
3322 p->v.Tuple.ctx = ctx;
3323 p->lineno = lineno;
3324 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003325 p->end_lineno = end_lineno;
3326 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003327 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003328}
3329
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003330expr_ty
3331Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3332 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003333{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003334 expr_ty p;
3335 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003336 if (!p)
3337 return NULL;
3338 p->kind = Slice_kind;
3339 p->v.Slice.lower = lower;
3340 p->v.Slice.upper = upper;
3341 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003342 p->lineno = lineno;
3343 p->col_offset = col_offset;
3344 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
3349comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003350comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3351 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003352{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003353 comprehension_ty p;
3354 if (!target) {
3355 PyErr_SetString(PyExc_ValueError,
3356 "field target is required for comprehension");
3357 return NULL;
3358 }
3359 if (!iter) {
3360 PyErr_SetString(PyExc_ValueError,
3361 "field iter is required for comprehension");
3362 return NULL;
3363 }
3364 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3365 if (!p)
3366 return NULL;
3367 p->target = target;
3368 p->iter = iter;
3369 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003370 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003371 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003372}
3373
3374excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003375ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003376 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003377{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003378 excepthandler_ty p;
3379 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3380 if (!p)
3381 return NULL;
3382 p->kind = ExceptHandler_kind;
3383 p->v.ExceptHandler.type = type;
3384 p->v.ExceptHandler.name = name;
3385 p->v.ExceptHandler.body = body;
3386 p->lineno = lineno;
3387 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003388 p->end_lineno = end_lineno;
3389 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003390 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003391}
3392
3393arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003394arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003395 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3396 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003397{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003398 arguments_ty p;
3399 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3400 if (!p)
3401 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003402 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003403 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003404 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003405 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003406 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003407 p->kwarg = kwarg;
3408 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003409 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003410}
3411
Neal Norwitzc1505362006-12-28 06:47:50 +00003412arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003413arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3414 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003415{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003416 arg_ty p;
3417 if (!arg) {
3418 PyErr_SetString(PyExc_ValueError,
3419 "field arg is required for arg");
3420 return NULL;
3421 }
3422 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3423 if (!p)
3424 return NULL;
3425 p->arg = arg;
3426 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003427 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003428 p->lineno = lineno;
3429 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003430 p->end_lineno = end_lineno;
3431 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003432 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003433}
3434
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003435keyword_ty
Pablo Galindo168660b2020-04-02 00:47:39 +01003436keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3437 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003438{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003439 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003440 if (!value) {
3441 PyErr_SetString(PyExc_ValueError,
3442 "field value is required for keyword");
3443 return NULL;
3444 }
3445 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3446 if (!p)
3447 return NULL;
3448 p->arg = arg;
3449 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003450 p->lineno = lineno;
3451 p->col_offset = col_offset;
3452 p->end_lineno = end_lineno;
3453 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003454 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003455}
3456
3457alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003458alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003459{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003460 alias_ty p;
3461 if (!name) {
3462 PyErr_SetString(PyExc_ValueError,
3463 "field name is required for alias");
3464 return NULL;
3465 }
3466 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3467 if (!p)
3468 return NULL;
3469 p->name = name;
3470 p->asname = asname;
3471 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003472}
3473
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003474withitem_ty
3475withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3476{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003477 withitem_ty p;
3478 if (!context_expr) {
3479 PyErr_SetString(PyExc_ValueError,
3480 "field context_expr is required for withitem");
3481 return NULL;
3482 }
3483 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3484 if (!p)
3485 return NULL;
3486 p->context_expr = context_expr;
3487 p->optional_vars = optional_vars;
3488 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003489}
3490
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003491type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003492TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003493{
3494 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003495 if (!tag) {
3496 PyErr_SetString(PyExc_ValueError,
3497 "field tag is required for TypeIgnore");
3498 return NULL;
3499 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003500 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3501 if (!p)
3502 return NULL;
3503 p->kind = TypeIgnore_kind;
3504 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003505 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003506 return p;
3507}
3508
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003509
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003510PyObject*
3511ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003512{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003513 mod_ty o = (mod_ty)_o;
3514 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003515 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003516 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003517 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003518 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003519
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003520 switch (o->kind) {
3521 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003522 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3523 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 if (!result) goto failed;
3525 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3526 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003527 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 goto failed;
3529 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003530 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3531 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003532 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3533 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003534 goto failed;
3535 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003536 break;
3537 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003538 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3539 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003540 if (!result) goto failed;
3541 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3542 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003543 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003544 goto failed;
3545 Py_DECREF(value);
3546 break;
3547 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003548 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3549 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003550 if (!result) goto failed;
3551 value = ast2obj_expr(o->v.Expression.body);
3552 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003553 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003554 goto failed;
3555 Py_DECREF(value);
3556 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003557 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003558 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3559 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003560 if (!result) goto failed;
3561 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3562 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003563 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3564 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003565 goto failed;
3566 Py_DECREF(value);
3567 value = ast2obj_expr(o->v.FunctionType.returns);
3568 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003569 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3570 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003571 goto failed;
3572 Py_DECREF(value);
3573 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003574 }
3575 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003576failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003577 Py_XDECREF(value);
3578 Py_XDECREF(result);
3579 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003580}
3581
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003582PyObject*
3583ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003584{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003585 stmt_ty o = (stmt_ty)_o;
3586 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003587 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003588 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003589 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003590 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003591
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003592 switch (o->kind) {
3593 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003594 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3595 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003596 if (!result) goto failed;
3597 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003598 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003599 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003601 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003602 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003603 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003604 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003605 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003606 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003607 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3608 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003609 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003610 goto failed;
3611 Py_DECREF(value);
3612 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3613 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003614 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3615 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003616 goto failed;
3617 Py_DECREF(value);
3618 value = ast2obj_expr(o->v.FunctionDef.returns);
3619 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003620 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3621 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003622 goto failed;
3623 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003624 value = ast2obj_string(o->v.FunctionDef.type_comment);
3625 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003626 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3627 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003628 goto failed;
3629 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003630 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003631 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003632 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3633 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003634 if (!result) goto failed;
3635 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3636 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003637 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003638 goto failed;
3639 Py_DECREF(value);
3640 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3641 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003642 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003643 goto failed;
3644 Py_DECREF(value);
3645 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3646 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003647 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003648 goto failed;
3649 Py_DECREF(value);
3650 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3651 ast2obj_expr);
3652 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003653 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3654 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003655 goto failed;
3656 Py_DECREF(value);
3657 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3658 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003659 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3660 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003661 goto failed;
3662 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003663 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3664 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003665 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3666 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003667 goto failed;
3668 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003669 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003670 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003671 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3672 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003673 if (!result) goto failed;
3674 value = ast2obj_identifier(o->v.ClassDef.name);
3675 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003676 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 goto failed;
3678 Py_DECREF(value);
3679 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3680 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003681 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003682 goto failed;
3683 Py_DECREF(value);
3684 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3685 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003686 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3687 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003688 goto failed;
3689 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003690 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3691 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003692 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003693 goto failed;
3694 Py_DECREF(value);
3695 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3696 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003697 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3698 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003699 goto failed;
3700 Py_DECREF(value);
3701 break;
3702 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003703 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3704 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003705 if (!result) goto failed;
3706 value = ast2obj_expr(o->v.Return.value);
3707 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003708 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003709 goto failed;
3710 Py_DECREF(value);
3711 break;
3712 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003713 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3714 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003715 if (!result) goto failed;
3716 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3717 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003718 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3719 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003720 goto failed;
3721 Py_DECREF(value);
3722 break;
3723 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003724 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3725 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003726 if (!result) goto failed;
3727 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3728 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003729 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3730 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003731 goto failed;
3732 Py_DECREF(value);
3733 value = ast2obj_expr(o->v.Assign.value);
3734 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003735 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003736 goto failed;
3737 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003738 value = ast2obj_string(o->v.Assign.type_comment);
3739 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003740 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3741 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003742 goto failed;
3743 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003744 break;
3745 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003746 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3747 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003748 if (!result) goto failed;
3749 value = ast2obj_expr(o->v.AugAssign.target);
3750 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003751 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3752 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003753 goto failed;
3754 Py_DECREF(value);
3755 value = ast2obj_operator(o->v.AugAssign.op);
3756 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003757 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003758 goto failed;
3759 Py_DECREF(value);
3760 value = ast2obj_expr(o->v.AugAssign.value);
3761 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003762 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003763 goto failed;
3764 Py_DECREF(value);
3765 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003766 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003767 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3768 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003769 if (!result) goto failed;
3770 value = ast2obj_expr(o->v.AnnAssign.target);
3771 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003772 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3773 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003774 goto failed;
3775 Py_DECREF(value);
3776 value = ast2obj_expr(o->v.AnnAssign.annotation);
3777 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003778 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3779 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003780 goto failed;
3781 Py_DECREF(value);
3782 value = ast2obj_expr(o->v.AnnAssign.value);
3783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003784 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003785 goto failed;
3786 Py_DECREF(value);
3787 value = ast2obj_int(o->v.AnnAssign.simple);
3788 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003789 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3790 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003791 goto failed;
3792 Py_DECREF(value);
3793 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003794 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 tp = (PyTypeObject *)astmodulestate_global->For_type;
3796 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003797 if (!result) goto failed;
3798 value = ast2obj_expr(o->v.For.target);
3799 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003800 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3801 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003802 goto failed;
3803 Py_DECREF(value);
3804 value = ast2obj_expr(o->v.For.iter);
3805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003807 goto failed;
3808 Py_DECREF(value);
3809 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3810 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003811 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003812 goto failed;
3813 Py_DECREF(value);
3814 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003816 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3817 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003818 goto failed;
3819 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003820 value = ast2obj_string(o->v.For.type_comment);
3821 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003822 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3823 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003824 goto failed;
3825 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003826 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003827 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003828 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3829 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003830 if (!result) goto failed;
3831 value = ast2obj_expr(o->v.AsyncFor.target);
3832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003833 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3834 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003835 goto failed;
3836 Py_DECREF(value);
3837 value = ast2obj_expr(o->v.AsyncFor.iter);
3838 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003839 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003840 goto failed;
3841 Py_DECREF(value);
3842 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3843 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003844 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003845 goto failed;
3846 Py_DECREF(value);
3847 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003849 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3850 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003851 goto failed;
3852 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003853 value = ast2obj_string(o->v.AsyncFor.type_comment);
3854 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003855 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3856 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003857 goto failed;
3858 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003859 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003860 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003861 tp = (PyTypeObject *)astmodulestate_global->While_type;
3862 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003863 if (!result) goto failed;
3864 value = ast2obj_expr(o->v.While.test);
3865 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003866 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003867 goto failed;
3868 Py_DECREF(value);
3869 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3870 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003871 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003872 goto failed;
3873 Py_DECREF(value);
3874 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3875 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003876 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3877 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003878 goto failed;
3879 Py_DECREF(value);
3880 break;
3881 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003882 tp = (PyTypeObject *)astmodulestate_global->If_type;
3883 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003884 if (!result) goto failed;
3885 value = ast2obj_expr(o->v.If.test);
3886 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003887 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003888 goto failed;
3889 Py_DECREF(value);
3890 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3891 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003892 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003893 goto failed;
3894 Py_DECREF(value);
3895 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3896 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003897 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3898 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003899 goto failed;
3900 Py_DECREF(value);
3901 break;
3902 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003903 tp = (PyTypeObject *)astmodulestate_global->With_type;
3904 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003905 if (!result) goto failed;
3906 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3907 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003908 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003909 goto failed;
3910 Py_DECREF(value);
3911 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3912 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003913 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003914 goto failed;
3915 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003916 value = ast2obj_string(o->v.With.type_comment);
3917 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003918 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3919 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003920 goto failed;
3921 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003922 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003923 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003924 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3925 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003926 if (!result) goto failed;
3927 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3928 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003929 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003930 goto failed;
3931 Py_DECREF(value);
3932 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003934 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003935 goto failed;
3936 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003937 value = ast2obj_string(o->v.AsyncWith.type_comment);
3938 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003939 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3940 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003941 goto failed;
3942 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003943 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003944 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003945 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3946 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003947 if (!result) goto failed;
3948 value = ast2obj_expr(o->v.Raise.exc);
3949 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003950 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003951 goto failed;
3952 Py_DECREF(value);
3953 value = ast2obj_expr(o->v.Raise.cause);
3954 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003955 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 goto failed;
3957 Py_DECREF(value);
3958 break;
3959 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003960 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3961 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003962 if (!result) goto failed;
3963 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3964 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003965 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003966 goto failed;
3967 Py_DECREF(value);
3968 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3969 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003970 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3971 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003972 goto failed;
3973 Py_DECREF(value);
3974 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3975 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003976 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3977 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003978 goto failed;
3979 Py_DECREF(value);
3980 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3981 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003982 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3983 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003984 goto failed;
3985 Py_DECREF(value);
3986 break;
3987 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003988 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3989 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003990 if (!result) goto failed;
3991 value = ast2obj_expr(o->v.Assert.test);
3992 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003993 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003994 goto failed;
3995 Py_DECREF(value);
3996 value = ast2obj_expr(o->v.Assert.msg);
3997 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003998 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003999 goto failed;
4000 Py_DECREF(value);
4001 break;
4002 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004003 tp = (PyTypeObject *)astmodulestate_global->Import_type;
4004 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004005 if (!result) goto failed;
4006 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
4007 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004008 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 goto failed;
4010 Py_DECREF(value);
4011 break;
4012 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004013 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
4014 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004015 if (!result) goto failed;
4016 value = ast2obj_identifier(o->v.ImportFrom.module);
4017 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004018 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4019 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004020 goto failed;
4021 Py_DECREF(value);
4022 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4023 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004024 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004025 goto failed;
4026 Py_DECREF(value);
4027 value = ast2obj_int(o->v.ImportFrom.level);
4028 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004029 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004030 goto failed;
4031 Py_DECREF(value);
4032 break;
4033 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004034 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4035 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004036 if (!result) goto failed;
4037 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4038 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004039 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 goto failed;
4041 Py_DECREF(value);
4042 break;
4043 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004044 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4045 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004046 if (!result) goto failed;
4047 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4048 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004049 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004050 goto failed;
4051 Py_DECREF(value);
4052 break;
4053 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004054 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4055 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004056 if (!result) goto failed;
4057 value = ast2obj_expr(o->v.Expr.value);
4058 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004059 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 goto failed;
4061 Py_DECREF(value);
4062 break;
4063 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004064 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4065 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004066 if (!result) goto failed;
4067 break;
4068 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004069 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4070 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004071 if (!result) goto failed;
4072 break;
4073 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004074 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4075 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 if (!result) goto failed;
4077 break;
4078 }
4079 value = ast2obj_int(o->lineno);
4080 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004081 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004082 goto failed;
4083 Py_DECREF(value);
4084 value = ast2obj_int(o->col_offset);
4085 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004086 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004087 goto failed;
4088 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004089 value = ast2obj_int(o->end_lineno);
4090 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004091 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004092 goto failed;
4093 Py_DECREF(value);
4094 value = ast2obj_int(o->end_col_offset);
4095 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004096 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4097 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004098 goto failed;
4099 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004100 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004101failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 Py_XDECREF(value);
4103 Py_XDECREF(result);
4104 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004105}
4106
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004107PyObject*
4108ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004109{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004110 expr_ty o = (expr_ty)_o;
4111 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004112 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004113 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004114 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004115 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004116
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004117 switch (o->kind) {
4118 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004119 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4120 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004121 if (!result) goto failed;
4122 value = ast2obj_boolop(o->v.BoolOp.op);
4123 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004124 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004125 goto failed;
4126 Py_DECREF(value);
4127 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4128 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004129 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4130 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004131 goto failed;
4132 Py_DECREF(value);
4133 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004134 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004135 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4136 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004137 if (!result) goto failed;
4138 value = ast2obj_expr(o->v.NamedExpr.target);
4139 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004140 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4141 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004142 goto failed;
4143 Py_DECREF(value);
4144 value = ast2obj_expr(o->v.NamedExpr.value);
4145 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004146 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004147 goto failed;
4148 Py_DECREF(value);
4149 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004150 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004151 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4152 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004153 if (!result) goto failed;
4154 value = ast2obj_expr(o->v.BinOp.left);
4155 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004156 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004157 goto failed;
4158 Py_DECREF(value);
4159 value = ast2obj_operator(o->v.BinOp.op);
4160 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004161 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004162 goto failed;
4163 Py_DECREF(value);
4164 value = ast2obj_expr(o->v.BinOp.right);
4165 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004166 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004167 goto failed;
4168 Py_DECREF(value);
4169 break;
4170 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004171 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4172 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004173 if (!result) goto failed;
4174 value = ast2obj_unaryop(o->v.UnaryOp.op);
4175 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004176 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 goto failed;
4178 Py_DECREF(value);
4179 value = ast2obj_expr(o->v.UnaryOp.operand);
4180 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004181 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4182 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004183 goto failed;
4184 Py_DECREF(value);
4185 break;
4186 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004187 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4188 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004189 if (!result) goto failed;
4190 value = ast2obj_arguments(o->v.Lambda.args);
4191 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004192 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004193 goto failed;
4194 Py_DECREF(value);
4195 value = ast2obj_expr(o->v.Lambda.body);
4196 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004197 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004198 goto failed;
4199 Py_DECREF(value);
4200 break;
4201 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004202 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4203 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004204 if (!result) goto failed;
4205 value = ast2obj_expr(o->v.IfExp.test);
4206 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004207 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004208 goto failed;
4209 Py_DECREF(value);
4210 value = ast2obj_expr(o->v.IfExp.body);
4211 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004212 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004213 goto failed;
4214 Py_DECREF(value);
4215 value = ast2obj_expr(o->v.IfExp.orelse);
4216 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004217 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4218 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004219 goto failed;
4220 Py_DECREF(value);
4221 break;
4222 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004223 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4224 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 if (!result) goto failed;
4226 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4227 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004228 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 goto failed;
4230 Py_DECREF(value);
4231 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4232 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004233 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4234 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004235 goto failed;
4236 Py_DECREF(value);
4237 break;
4238 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004239 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4240 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004241 if (!result) goto failed;
4242 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4243 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004244 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004245 goto failed;
4246 Py_DECREF(value);
4247 break;
4248 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004249 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4250 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004251 if (!result) goto failed;
4252 value = ast2obj_expr(o->v.ListComp.elt);
4253 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004254 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004255 goto failed;
4256 Py_DECREF(value);
4257 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4258 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004259 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4260 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004261 goto failed;
4262 Py_DECREF(value);
4263 break;
4264 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004265 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4266 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004267 if (!result) goto failed;
4268 value = ast2obj_expr(o->v.SetComp.elt);
4269 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004270 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004271 goto failed;
4272 Py_DECREF(value);
4273 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4274 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004275 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4276 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004277 goto failed;
4278 Py_DECREF(value);
4279 break;
4280 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004281 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4282 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004283 if (!result) goto failed;
4284 value = ast2obj_expr(o->v.DictComp.key);
4285 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004286 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004287 goto failed;
4288 Py_DECREF(value);
4289 value = ast2obj_expr(o->v.DictComp.value);
4290 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004291 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004292 goto failed;
4293 Py_DECREF(value);
4294 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4295 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004296 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4297 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004298 goto failed;
4299 Py_DECREF(value);
4300 break;
4301 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004302 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4303 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004304 if (!result) goto failed;
4305 value = ast2obj_expr(o->v.GeneratorExp.elt);
4306 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004307 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004308 goto failed;
4309 Py_DECREF(value);
4310 value = ast2obj_list(o->v.GeneratorExp.generators,
4311 ast2obj_comprehension);
4312 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004313 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4314 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004315 goto failed;
4316 Py_DECREF(value);
4317 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004318 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004319 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4320 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004321 if (!result) goto failed;
4322 value = ast2obj_expr(o->v.Await.value);
4323 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004324 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004325 goto failed;
4326 Py_DECREF(value);
4327 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004328 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004329 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4330 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004331 if (!result) goto failed;
4332 value = ast2obj_expr(o->v.Yield.value);
4333 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004334 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004335 goto failed;
4336 Py_DECREF(value);
4337 break;
4338 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004339 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4340 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004341 if (!result) goto failed;
4342 value = ast2obj_expr(o->v.YieldFrom.value);
4343 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004344 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004345 goto failed;
4346 Py_DECREF(value);
4347 break;
4348 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004349 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4350 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004351 if (!result) goto failed;
4352 value = ast2obj_expr(o->v.Compare.left);
4353 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004354 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004355 goto failed;
4356 Py_DECREF(value);
4357 {
4358 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4359 value = PyList_New(n);
4360 if (!value) goto failed;
4361 for(i = 0; i < n; i++)
4362 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004363 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004364 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004365 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004367 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004368 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004369 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004370 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4371 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004372 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004373 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004374 break;
4375 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004376 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4377 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004378 if (!result) goto failed;
4379 value = ast2obj_expr(o->v.Call.func);
4380 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004382 goto failed;
4383 Py_DECREF(value);
4384 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4385 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004386 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004387 goto failed;
4388 Py_DECREF(value);
4389 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4390 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4392 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004393 goto failed;
4394 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004395 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004396 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004397 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4398 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004399 if (!result) goto failed;
4400 value = ast2obj_expr(o->v.FormattedValue.value);
4401 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004402 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004403 goto failed;
4404 Py_DECREF(value);
4405 value = ast2obj_int(o->v.FormattedValue.conversion);
4406 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004407 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4408 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004409 goto failed;
4410 Py_DECREF(value);
4411 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4412 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004413 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4414 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004415 goto failed;
4416 Py_DECREF(value);
4417 break;
4418 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004419 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4420 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004421 if (!result) goto failed;
4422 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4423 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004424 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4425 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004426 goto failed;
4427 Py_DECREF(value);
4428 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004429 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004430 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4431 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004432 if (!result) goto failed;
4433 value = ast2obj_constant(o->v.Constant.value);
4434 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004435 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004436 goto failed;
4437 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004438 value = ast2obj_string(o->v.Constant.kind);
4439 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004440 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004441 goto failed;
4442 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004443 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004444 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004445 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4446 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004447 if (!result) goto failed;
4448 value = ast2obj_expr(o->v.Attribute.value);
4449 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004450 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004451 goto failed;
4452 Py_DECREF(value);
4453 value = ast2obj_identifier(o->v.Attribute.attr);
4454 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004455 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004456 goto failed;
4457 Py_DECREF(value);
4458 value = ast2obj_expr_context(o->v.Attribute.ctx);
4459 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004460 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 goto failed;
4462 Py_DECREF(value);
4463 break;
4464 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004465 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4466 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004467 if (!result) goto failed;
4468 value = ast2obj_expr(o->v.Subscript.value);
4469 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004470 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004471 goto failed;
4472 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004473 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004474 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004475 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004476 goto failed;
4477 Py_DECREF(value);
4478 value = ast2obj_expr_context(o->v.Subscript.ctx);
4479 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004480 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004481 goto failed;
4482 Py_DECREF(value);
4483 break;
4484 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004485 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4486 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004487 if (!result) goto failed;
4488 value = ast2obj_expr(o->v.Starred.value);
4489 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004490 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004491 goto failed;
4492 Py_DECREF(value);
4493 value = ast2obj_expr_context(o->v.Starred.ctx);
4494 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004495 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004496 goto failed;
4497 Py_DECREF(value);
4498 break;
4499 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004500 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4501 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004502 if (!result) goto failed;
4503 value = ast2obj_identifier(o->v.Name.id);
4504 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004505 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004506 goto failed;
4507 Py_DECREF(value);
4508 value = ast2obj_expr_context(o->v.Name.ctx);
4509 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004510 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004511 goto failed;
4512 Py_DECREF(value);
4513 break;
4514 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004515 tp = (PyTypeObject *)astmodulestate_global->List_type;
4516 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004517 if (!result) goto failed;
4518 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4519 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004520 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004521 goto failed;
4522 Py_DECREF(value);
4523 value = ast2obj_expr_context(o->v.List.ctx);
4524 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004525 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004526 goto failed;
4527 Py_DECREF(value);
4528 break;
4529 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004530 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4531 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004532 if (!result) goto failed;
4533 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4534 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004535 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004536 goto failed;
4537 Py_DECREF(value);
4538 value = ast2obj_expr_context(o->v.Tuple.ctx);
4539 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004540 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004541 goto failed;
4542 Py_DECREF(value);
4543 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004544 case Slice_kind:
4545 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4546 result = PyType_GenericNew(tp, NULL, NULL);
4547 if (!result) goto failed;
4548 value = ast2obj_expr(o->v.Slice.lower);
4549 if (!value) goto failed;
4550 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4551 goto failed;
4552 Py_DECREF(value);
4553 value = ast2obj_expr(o->v.Slice.upper);
4554 if (!value) goto failed;
4555 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4556 goto failed;
4557 Py_DECREF(value);
4558 value = ast2obj_expr(o->v.Slice.step);
4559 if (!value) goto failed;
4560 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4561 goto failed;
4562 Py_DECREF(value);
4563 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004564 }
4565 value = ast2obj_int(o->lineno);
4566 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004567 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004568 goto failed;
4569 Py_DECREF(value);
4570 value = ast2obj_int(o->col_offset);
4571 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004572 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004573 goto failed;
4574 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004575 value = ast2obj_int(o->end_lineno);
4576 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004577 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004578 goto failed;
4579 Py_DECREF(value);
4580 value = ast2obj_int(o->end_col_offset);
4581 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004582 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4583 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004584 goto failed;
4585 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004587failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004588 Py_XDECREF(value);
4589 Py_XDECREF(result);
4590 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004591}
4592
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004593PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004594{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004595 switch(o) {
4596 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004597 Py_INCREF(astmodulestate_global->Load_singleton);
4598 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004599 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004600 Py_INCREF(astmodulestate_global->Store_singleton);
4601 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004602 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004603 Py_INCREF(astmodulestate_global->Del_singleton);
4604 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004605 default:
4606 /* should never happen, but just in case ... */
4607 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4608 return NULL;
4609 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004610}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004611PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004612{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004613 switch(o) {
4614 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004615 Py_INCREF(astmodulestate_global->And_singleton);
4616 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004618 Py_INCREF(astmodulestate_global->Or_singleton);
4619 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 default:
4621 /* should never happen, but just in case ... */
4622 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4623 return NULL;
4624 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004625}
4626PyObject* ast2obj_operator(operator_ty o)
4627{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004628 switch(o) {
4629 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004630 Py_INCREF(astmodulestate_global->Add_singleton);
4631 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004632 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004633 Py_INCREF(astmodulestate_global->Sub_singleton);
4634 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004635 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004636 Py_INCREF(astmodulestate_global->Mult_singleton);
4637 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004638 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004639 Py_INCREF(astmodulestate_global->MatMult_singleton);
4640 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004642 Py_INCREF(astmodulestate_global->Div_singleton);
4643 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004644 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004645 Py_INCREF(astmodulestate_global->Mod_singleton);
4646 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004647 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004648 Py_INCREF(astmodulestate_global->Pow_singleton);
4649 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004651 Py_INCREF(astmodulestate_global->LShift_singleton);
4652 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004654 Py_INCREF(astmodulestate_global->RShift_singleton);
4655 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004656 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004657 Py_INCREF(astmodulestate_global->BitOr_singleton);
4658 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004659 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004660 Py_INCREF(astmodulestate_global->BitXor_singleton);
4661 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004662 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004663 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4664 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004665 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004666 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4667 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004668 default:
4669 /* should never happen, but just in case ... */
4670 PyErr_Format(PyExc_SystemError, "unknown operator found");
4671 return NULL;
4672 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004673}
4674PyObject* ast2obj_unaryop(unaryop_ty o)
4675{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004676 switch(o) {
4677 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004678 Py_INCREF(astmodulestate_global->Invert_singleton);
4679 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004680 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004681 Py_INCREF(astmodulestate_global->Not_singleton);
4682 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004684 Py_INCREF(astmodulestate_global->UAdd_singleton);
4685 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004686 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004687 Py_INCREF(astmodulestate_global->USub_singleton);
4688 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004689 default:
4690 /* should never happen, but just in case ... */
4691 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4692 return NULL;
4693 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004694}
4695PyObject* ast2obj_cmpop(cmpop_ty o)
4696{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004697 switch(o) {
4698 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004699 Py_INCREF(astmodulestate_global->Eq_singleton);
4700 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004701 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004702 Py_INCREF(astmodulestate_global->NotEq_singleton);
4703 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004705 Py_INCREF(astmodulestate_global->Lt_singleton);
4706 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004707 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004708 Py_INCREF(astmodulestate_global->LtE_singleton);
4709 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004710 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004711 Py_INCREF(astmodulestate_global->Gt_singleton);
4712 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004713 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004714 Py_INCREF(astmodulestate_global->GtE_singleton);
4715 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004716 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004717 Py_INCREF(astmodulestate_global->Is_singleton);
4718 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004719 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004720 Py_INCREF(astmodulestate_global->IsNot_singleton);
4721 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004722 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004723 Py_INCREF(astmodulestate_global->In_singleton);
4724 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004725 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004726 Py_INCREF(astmodulestate_global->NotIn_singleton);
4727 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004728 default:
4729 /* should never happen, but just in case ... */
4730 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4731 return NULL;
4732 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004733}
4734PyObject*
4735ast2obj_comprehension(void* _o)
4736{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004737 comprehension_ty o = (comprehension_ty)_o;
4738 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004739 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004740 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004741 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004742 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004743
Dino Viehlandac46eb42019-09-11 10:16:34 -07004744 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4745 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004746 if (!result) return NULL;
4747 value = ast2obj_expr(o->target);
4748 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004749 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 goto failed;
4751 Py_DECREF(value);
4752 value = ast2obj_expr(o->iter);
4753 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004754 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004755 goto failed;
4756 Py_DECREF(value);
4757 value = ast2obj_list(o->ifs, ast2obj_expr);
4758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004759 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 goto failed;
4761 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004762 value = ast2obj_int(o->is_async);
4763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004764 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004765 goto failed;
4766 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004767 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004768failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004769 Py_XDECREF(value);
4770 Py_XDECREF(result);
4771 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004772}
4773
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004774PyObject*
4775ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004776{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 excepthandler_ty o = (excepthandler_ty)_o;
4778 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004779 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004781 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004783
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004784 switch (o->kind) {
4785 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004786 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4787 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004788 if (!result) goto failed;
4789 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004790 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004791 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004792 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004793 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004794 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004795 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004796 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004798 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004801 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004802 goto failed;
4803 Py_DECREF(value);
4804 break;
4805 }
4806 value = ast2obj_int(o->lineno);
4807 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004808 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004809 goto failed;
4810 Py_DECREF(value);
4811 value = ast2obj_int(o->col_offset);
4812 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004813 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004814 goto failed;
4815 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004816 value = ast2obj_int(o->end_lineno);
4817 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004818 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004819 goto failed;
4820 Py_DECREF(value);
4821 value = ast2obj_int(o->end_col_offset);
4822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004823 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4824 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004825 goto failed;
4826 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004827 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004828failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004829 Py_XDECREF(value);
4830 Py_XDECREF(result);
4831 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004832}
4833
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004834PyObject*
4835ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004836{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004837 arguments_ty o = (arguments_ty)_o;
4838 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004839 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004840 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004841 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004842 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004843
Dino Viehlandac46eb42019-09-11 10:16:34 -07004844 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4845 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004847 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004849 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4850 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004851 goto failed;
4852 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004853 value = ast2obj_list(o->args, ast2obj_arg);
4854 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004855 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004856 goto failed;
4857 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004858 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004859 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004860 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 goto failed;
4862 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004863 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4864 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004865 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4866 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 goto failed;
4868 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004869 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004871 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4872 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004873 goto failed;
4874 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004875 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004876 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004877 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 goto failed;
4879 Py_DECREF(value);
4880 value = ast2obj_list(o->defaults, ast2obj_expr);
4881 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004882 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 goto failed;
4884 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004885 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004886failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 Py_XDECREF(value);
4888 Py_XDECREF(result);
4889 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004890}
4891
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004892PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004893ast2obj_arg(void* _o)
4894{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004895 arg_ty o = (arg_ty)_o;
4896 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004897 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004898 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004899 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004901
Dino Viehlandac46eb42019-09-11 10:16:34 -07004902 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4903 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004904 if (!result) return NULL;
4905 value = ast2obj_identifier(o->arg);
4906 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004907 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 goto failed;
4909 Py_DECREF(value);
4910 value = ast2obj_expr(o->annotation);
4911 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004912 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4913 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004914 goto failed;
4915 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004916 value = ast2obj_string(o->type_comment);
4917 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004918 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4919 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004920 goto failed;
4921 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004922 value = ast2obj_int(o->lineno);
4923 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004924 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004925 goto failed;
4926 Py_DECREF(value);
4927 value = ast2obj_int(o->col_offset);
4928 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004929 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004930 goto failed;
4931 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004932 value = ast2obj_int(o->end_lineno);
4933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004934 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004935 goto failed;
4936 Py_DECREF(value);
4937 value = ast2obj_int(o->end_col_offset);
4938 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004939 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4940 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004941 goto failed;
4942 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004943 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004944failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004945 Py_XDECREF(value);
4946 Py_XDECREF(result);
4947 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004948}
4949
4950PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004951ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004952{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004953 keyword_ty o = (keyword_ty)_o;
4954 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004955 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004956 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004957 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004958 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004959
Dino Viehlandac46eb42019-09-11 10:16:34 -07004960 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4961 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004962 if (!result) return NULL;
4963 value = ast2obj_identifier(o->arg);
4964 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004965 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004966 goto failed;
4967 Py_DECREF(value);
4968 value = ast2obj_expr(o->value);
4969 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004970 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004971 goto failed;
4972 Py_DECREF(value);
Pablo Galindo168660b2020-04-02 00:47:39 +01004973 value = ast2obj_int(o->lineno);
4974 if (!value) goto failed;
4975 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
4976 goto failed;
4977 Py_DECREF(value);
4978 value = ast2obj_int(o->col_offset);
4979 if (!value) goto failed;
4980 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
4981 goto failed;
4982 Py_DECREF(value);
4983 value = ast2obj_int(o->end_lineno);
4984 if (!value) goto failed;
4985 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
4986 goto failed;
4987 Py_DECREF(value);
4988 value = ast2obj_int(o->end_col_offset);
4989 if (!value) goto failed;
4990 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4991 < 0)
4992 goto failed;
4993 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004994 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004995failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004996 Py_XDECREF(value);
4997 Py_XDECREF(result);
4998 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004999}
5000
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005001PyObject*
5002ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005003{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005004 alias_ty o = (alias_ty)_o;
5005 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005006 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005007 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005008 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005009 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005010
Dino Viehlandac46eb42019-09-11 10:16:34 -07005011 tp = (PyTypeObject *)astmodulestate_global->alias_type;
5012 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005013 if (!result) return NULL;
5014 value = ast2obj_identifier(o->name);
5015 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005016 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005017 goto failed;
5018 Py_DECREF(value);
5019 value = ast2obj_identifier(o->asname);
5020 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005021 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005022 goto failed;
5023 Py_DECREF(value);
5024 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005025failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005026 Py_XDECREF(value);
5027 Py_XDECREF(result);
5028 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005029}
5030
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005031PyObject*
5032ast2obj_withitem(void* _o)
5033{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005034 withitem_ty o = (withitem_ty)_o;
5035 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005036 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005037 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005038 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005039 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005040
Dino Viehlandac46eb42019-09-11 10:16:34 -07005041 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5042 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005043 if (!result) return NULL;
5044 value = ast2obj_expr(o->context_expr);
5045 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005046 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5047 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005048 goto failed;
5049 Py_DECREF(value);
5050 value = ast2obj_expr(o->optional_vars);
5051 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005052 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5053 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005054 goto failed;
5055 Py_DECREF(value);
5056 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005057failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005058 Py_XDECREF(value);
5059 Py_XDECREF(result);
5060 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005061}
5062
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005063PyObject*
5064ast2obj_type_ignore(void* _o)
5065{
5066 type_ignore_ty o = (type_ignore_ty)_o;
5067 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005068 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005069 if (!o) {
5070 Py_RETURN_NONE;
5071 }
5072
5073 switch (o->kind) {
5074 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005075 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5076 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005077 if (!result) goto failed;
5078 value = ast2obj_int(o->v.TypeIgnore.lineno);
5079 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005080 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5081 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005082 goto failed;
5083 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005084 value = ast2obj_string(o->v.TypeIgnore.tag);
5085 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005086 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005087 goto failed;
5088 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005089 break;
5090 }
5091 return result;
5092failed:
5093 Py_XDECREF(value);
5094 Py_XDECREF(result);
5095 return NULL;
5096}
5097
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005098
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005099int
5100obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5101{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005102 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005103
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005104 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005105 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005106
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005107 if (obj == Py_None) {
5108 *out = NULL;
5109 return 0;
5110 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005111 tp = astmodulestate_global->Module_type;
5112 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005113 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005114 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005115 }
5116 if (isinstance) {
5117 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005118 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005119
Dino Viehlandac46eb42019-09-11 10:16:34 -07005120 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005121 return 1;
5122 }
5123 if (tmp == NULL) {
5124 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5125 return 1;
5126 }
5127 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005128 int res;
5129 Py_ssize_t len;
5130 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005131 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005132 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 +02005133 goto failed;
5134 }
5135 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005136 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005137 if (body == NULL) goto failed;
5138 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005139 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005140 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5141 Py_INCREF(tmp2);
5142 res = obj2ast_stmt(tmp2, &val, arena);
5143 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005144 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005145 if (len != PyList_GET_SIZE(tmp)) {
5146 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5147 goto failed;
5148 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005149 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005150 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005151 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005153 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5154 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005155 return 1;
5156 }
5157 if (tmp == NULL) {
5158 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5159 return 1;
5160 }
5161 else {
5162 int res;
5163 Py_ssize_t len;
5164 Py_ssize_t i;
5165 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005166 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 -08005167 goto failed;
5168 }
5169 len = PyList_GET_SIZE(tmp);
5170 type_ignores = _Py_asdl_seq_new(len, arena);
5171 if (type_ignores == NULL) goto failed;
5172 for (i = 0; i < len; i++) {
5173 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005174 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5175 Py_INCREF(tmp2);
5176 res = obj2ast_type_ignore(tmp2, &val, arena);
5177 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005178 if (res != 0) goto failed;
5179 if (len != PyList_GET_SIZE(tmp)) {
5180 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5181 goto failed;
5182 }
5183 asdl_seq_SET(type_ignores, i, val);
5184 }
5185 Py_CLEAR(tmp);
5186 }
5187 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005188 if (*out == NULL) goto failed;
5189 return 0;
5190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005191 tp = astmodulestate_global->Interactive_type;
5192 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005193 if (isinstance == -1) {
5194 return 1;
5195 }
5196 if (isinstance) {
5197 asdl_seq* body;
5198
Dino Viehlandac46eb42019-09-11 10:16:34 -07005199 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005200 return 1;
5201 }
5202 if (tmp == NULL) {
5203 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5204 return 1;
5205 }
5206 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005207 int res;
5208 Py_ssize_t len;
5209 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005210 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005211 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 +02005212 goto failed;
5213 }
5214 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005215 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005216 if (body == NULL) goto failed;
5217 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005218 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005219 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5220 Py_INCREF(tmp2);
5221 res = obj2ast_stmt(tmp2, &val, arena);
5222 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005223 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005224 if (len != PyList_GET_SIZE(tmp)) {
5225 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5226 goto failed;
5227 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005228 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005229 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005230 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005231 }
5232 *out = Interactive(body, arena);
5233 if (*out == NULL) goto failed;
5234 return 0;
5235 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005236 tp = astmodulestate_global->Expression_type;
5237 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005238 if (isinstance == -1) {
5239 return 1;
5240 }
5241 if (isinstance) {
5242 expr_ty body;
5243
Dino Viehlandac46eb42019-09-11 10:16:34 -07005244 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005245 return 1;
5246 }
5247 if (tmp == NULL) {
5248 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5249 return 1;
5250 }
5251 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005252 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005253 res = obj2ast_expr(tmp, &body, arena);
5254 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005255 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005256 }
5257 *out = Expression(body, arena);
5258 if (*out == NULL) goto failed;
5259 return 0;
5260 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005261 tp = astmodulestate_global->FunctionType_type;
5262 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005263 if (isinstance == -1) {
5264 return 1;
5265 }
5266 if (isinstance) {
5267 asdl_seq* argtypes;
5268 expr_ty returns;
5269
Dino Viehlandac46eb42019-09-11 10:16:34 -07005270 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5271 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005272 return 1;
5273 }
5274 if (tmp == NULL) {
5275 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5276 return 1;
5277 }
5278 else {
5279 int res;
5280 Py_ssize_t len;
5281 Py_ssize_t i;
5282 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005283 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 -08005284 goto failed;
5285 }
5286 len = PyList_GET_SIZE(tmp);
5287 argtypes = _Py_asdl_seq_new(len, arena);
5288 if (argtypes == NULL) goto failed;
5289 for (i = 0; i < len; i++) {
5290 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005291 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5292 Py_INCREF(tmp2);
5293 res = obj2ast_expr(tmp2, &val, arena);
5294 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005295 if (res != 0) goto failed;
5296 if (len != PyList_GET_SIZE(tmp)) {
5297 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5298 goto failed;
5299 }
5300 asdl_seq_SET(argtypes, i, val);
5301 }
5302 Py_CLEAR(tmp);
5303 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005304 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5305 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005306 return 1;
5307 }
5308 if (tmp == NULL) {
5309 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5310 return 1;
5311 }
5312 else {
5313 int res;
5314 res = obj2ast_expr(tmp, &returns, arena);
5315 if (res != 0) goto failed;
5316 Py_CLEAR(tmp);
5317 }
5318 *out = FunctionType(argtypes, returns, arena);
5319 if (*out == NULL) goto failed;
5320 return 0;
5321 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005322
5323 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5324 failed:
5325 Py_XDECREF(tmp);
5326 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005327}
5328
5329int
5330obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5331{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005332 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005333
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005334 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005335 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005336 int lineno;
5337 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005338 int end_lineno;
5339 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005340
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005341 if (obj == Py_None) {
5342 *out = NULL;
5343 return 0;
5344 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005345 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005346 return 1;
5347 }
5348 if (tmp == NULL) {
5349 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5350 return 1;
5351 }
5352 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005353 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005354 res = obj2ast_int(tmp, &lineno, arena);
5355 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005356 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005357 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005358 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5359 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005360 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005361 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005362 if (tmp == NULL) {
5363 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5364 return 1;
5365 }
5366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005367 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 res = obj2ast_int(tmp, &col_offset, arena);
5369 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005370 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005371 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005372 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5373 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005374 return 1;
5375 }
5376 if (tmp == NULL || tmp == Py_None) {
5377 Py_CLEAR(tmp);
5378 end_lineno = 0;
5379 }
5380 else {
5381 int res;
5382 res = obj2ast_int(tmp, &end_lineno, arena);
5383 if (res != 0) goto failed;
5384 Py_CLEAR(tmp);
5385 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005386 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5387 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005388 return 1;
5389 }
5390 if (tmp == NULL || tmp == Py_None) {
5391 Py_CLEAR(tmp);
5392 end_col_offset = 0;
5393 }
5394 else {
5395 int res;
5396 res = obj2ast_int(tmp, &end_col_offset, arena);
5397 if (res != 0) goto failed;
5398 Py_CLEAR(tmp);
5399 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005400 tp = astmodulestate_global->FunctionDef_type;
5401 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005402 if (isinstance == -1) {
5403 return 1;
5404 }
5405 if (isinstance) {
5406 identifier name;
5407 arguments_ty args;
5408 asdl_seq* body;
5409 asdl_seq* decorator_list;
5410 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005411 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005412
Dino Viehlandac46eb42019-09-11 10:16:34 -07005413 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005414 return 1;
5415 }
5416 if (tmp == NULL) {
5417 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5418 return 1;
5419 }
5420 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005421 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005422 res = obj2ast_identifier(tmp, &name, arena);
5423 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005424 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005425 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005426 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005427 return 1;
5428 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005429 if (tmp == NULL) {
5430 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5431 return 1;
5432 }
5433 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005434 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005435 res = obj2ast_arguments(tmp, &args, arena);
5436 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005437 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005438 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005439 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005440 return 1;
5441 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005442 if (tmp == NULL) {
5443 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5444 return 1;
5445 }
5446 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005447 int res;
5448 Py_ssize_t len;
5449 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005450 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005451 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 +02005452 goto failed;
5453 }
5454 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005455 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005456 if (body == NULL) goto failed;
5457 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005458 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005459 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5460 Py_INCREF(tmp2);
5461 res = obj2ast_stmt(tmp2, &val, arena);
5462 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005463 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005464 if (len != PyList_GET_SIZE(tmp)) {
5465 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5466 goto failed;
5467 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005468 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005469 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005470 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005471 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005472 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5473 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005474 return 1;
5475 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005476 if (tmp == NULL) {
5477 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5478 return 1;
5479 }
5480 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005481 int res;
5482 Py_ssize_t len;
5483 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005484 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005485 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 +02005486 goto failed;
5487 }
5488 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005489 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005490 if (decorator_list == NULL) goto failed;
5491 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005492 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005493 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5494 Py_INCREF(tmp2);
5495 res = obj2ast_expr(tmp2, &val, arena);
5496 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005497 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005498 if (len != PyList_GET_SIZE(tmp)) {
5499 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5500 goto failed;
5501 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005502 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005503 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005504 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005505 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005506 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5507 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005508 return 1;
5509 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005510 if (tmp == NULL || tmp == Py_None) {
5511 Py_CLEAR(tmp);
5512 returns = NULL;
5513 }
5514 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005515 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005516 res = obj2ast_expr(tmp, &returns, arena);
5517 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005518 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005519 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005520 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5521 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005522 return 1;
5523 }
5524 if (tmp == NULL || tmp == Py_None) {
5525 Py_CLEAR(tmp);
5526 type_comment = NULL;
5527 }
5528 else {
5529 int res;
5530 res = obj2ast_string(tmp, &type_comment, arena);
5531 if (res != 0) goto failed;
5532 Py_CLEAR(tmp);
5533 }
5534 *out = FunctionDef(name, args, body, decorator_list, returns,
5535 type_comment, lineno, col_offset, end_lineno,
5536 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005537 if (*out == NULL) goto failed;
5538 return 0;
5539 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005540 tp = astmodulestate_global->AsyncFunctionDef_type;
5541 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005542 if (isinstance == -1) {
5543 return 1;
5544 }
5545 if (isinstance) {
5546 identifier name;
5547 arguments_ty args;
5548 asdl_seq* body;
5549 asdl_seq* decorator_list;
5550 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005551 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005552
Dino Viehlandac46eb42019-09-11 10:16:34 -07005553 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005554 return 1;
5555 }
5556 if (tmp == NULL) {
5557 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5558 return 1;
5559 }
5560 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005561 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005562 res = obj2ast_identifier(tmp, &name, arena);
5563 if (res != 0) goto failed;
5564 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005565 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005566 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005567 return 1;
5568 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005569 if (tmp == NULL) {
5570 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5571 return 1;
5572 }
5573 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005574 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005575 res = obj2ast_arguments(tmp, &args, arena);
5576 if (res != 0) goto failed;
5577 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005578 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005579 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005580 return 1;
5581 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005582 if (tmp == NULL) {
5583 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5584 return 1;
5585 }
5586 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005587 int res;
5588 Py_ssize_t len;
5589 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005590 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005591 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 -04005592 goto failed;
5593 }
5594 len = PyList_GET_SIZE(tmp);
5595 body = _Py_asdl_seq_new(len, arena);
5596 if (body == NULL) goto failed;
5597 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005598 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005599 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5600 Py_INCREF(tmp2);
5601 res = obj2ast_stmt(tmp2, &val, arena);
5602 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005603 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005604 if (len != PyList_GET_SIZE(tmp)) {
5605 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5606 goto failed;
5607 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005608 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005609 }
5610 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005611 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005612 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5613 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005614 return 1;
5615 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005616 if (tmp == NULL) {
5617 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5618 return 1;
5619 }
5620 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005621 int res;
5622 Py_ssize_t len;
5623 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005624 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005625 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 -04005626 goto failed;
5627 }
5628 len = PyList_GET_SIZE(tmp);
5629 decorator_list = _Py_asdl_seq_new(len, arena);
5630 if (decorator_list == NULL) goto failed;
5631 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005632 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005633 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5634 Py_INCREF(tmp2);
5635 res = obj2ast_expr(tmp2, &val, arena);
5636 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005637 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005638 if (len != PyList_GET_SIZE(tmp)) {
5639 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5640 goto failed;
5641 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005642 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005643 }
5644 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005645 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005646 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5647 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005648 return 1;
5649 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005650 if (tmp == NULL || tmp == Py_None) {
5651 Py_CLEAR(tmp);
5652 returns = NULL;
5653 }
5654 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005655 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005656 res = obj2ast_expr(tmp, &returns, arena);
5657 if (res != 0) goto failed;
5658 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005659 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005660 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5661 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005662 return 1;
5663 }
5664 if (tmp == NULL || tmp == Py_None) {
5665 Py_CLEAR(tmp);
5666 type_comment = NULL;
5667 }
5668 else {
5669 int res;
5670 res = obj2ast_string(tmp, &type_comment, arena);
5671 if (res != 0) goto failed;
5672 Py_CLEAR(tmp);
5673 }
Yury Selivanov75445082015-05-11 22:57:16 -04005674 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005675 type_comment, lineno, col_offset, end_lineno,
5676 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005677 if (*out == NULL) goto failed;
5678 return 0;
5679 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005680 tp = astmodulestate_global->ClassDef_type;
5681 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005682 if (isinstance == -1) {
5683 return 1;
5684 }
5685 if (isinstance) {
5686 identifier name;
5687 asdl_seq* bases;
5688 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005689 asdl_seq* body;
5690 asdl_seq* decorator_list;
5691
Dino Viehlandac46eb42019-09-11 10:16:34 -07005692 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005693 return 1;
5694 }
5695 if (tmp == NULL) {
5696 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5697 return 1;
5698 }
5699 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005700 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005701 res = obj2ast_identifier(tmp, &name, arena);
5702 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005703 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005704 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005705 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005706 return 1;
5707 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005708 if (tmp == NULL) {
5709 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5710 return 1;
5711 }
5712 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005713 int res;
5714 Py_ssize_t len;
5715 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005716 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005717 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 +02005718 goto failed;
5719 }
5720 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005721 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005722 if (bases == NULL) goto failed;
5723 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005724 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005725 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5726 Py_INCREF(tmp2);
5727 res = obj2ast_expr(tmp2, &val, arena);
5728 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005729 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005730 if (len != PyList_GET_SIZE(tmp)) {
5731 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5732 goto failed;
5733 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005734 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005735 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005736 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005737 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005738 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5739 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005740 return 1;
5741 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005742 if (tmp == NULL) {
5743 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5744 return 1;
5745 }
5746 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005747 int res;
5748 Py_ssize_t len;
5749 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005750 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005751 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 +02005752 goto failed;
5753 }
5754 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005755 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005756 if (keywords == NULL) goto failed;
5757 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005758 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005759 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5760 Py_INCREF(tmp2);
5761 res = obj2ast_keyword(tmp2, &val, arena);
5762 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005764 if (len != PyList_GET_SIZE(tmp)) {
5765 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5766 goto failed;
5767 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005768 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005769 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005770 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005771 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005772 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005773 return 1;
5774 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005775 if (tmp == NULL) {
5776 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5777 return 1;
5778 }
5779 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005780 int res;
5781 Py_ssize_t len;
5782 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005783 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005784 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 +02005785 goto failed;
5786 }
5787 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005788 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005789 if (body == NULL) goto failed;
5790 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005791 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005792 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5793 Py_INCREF(tmp2);
5794 res = obj2ast_stmt(tmp2, &val, arena);
5795 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005796 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005797 if (len != PyList_GET_SIZE(tmp)) {
5798 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5799 goto failed;
5800 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005801 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005802 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005803 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005804 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005805 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5806 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005807 return 1;
5808 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005809 if (tmp == NULL) {
5810 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5811 return 1;
5812 }
5813 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005814 int res;
5815 Py_ssize_t len;
5816 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005817 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005818 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 +02005819 goto failed;
5820 }
5821 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005822 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005823 if (decorator_list == NULL) goto failed;
5824 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005825 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005826 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5827 Py_INCREF(tmp2);
5828 res = obj2ast_expr(tmp2, &val, arena);
5829 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005830 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005831 if (len != PyList_GET_SIZE(tmp)) {
5832 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5833 goto failed;
5834 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005835 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005836 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005837 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005838 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005839 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005840 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005841 if (*out == NULL) goto failed;
5842 return 0;
5843 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005844 tp = astmodulestate_global->Return_type;
5845 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005846 if (isinstance == -1) {
5847 return 1;
5848 }
5849 if (isinstance) {
5850 expr_ty value;
5851
Dino Viehlandac46eb42019-09-11 10:16:34 -07005852 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005853 return 1;
5854 }
5855 if (tmp == NULL || tmp == Py_None) {
5856 Py_CLEAR(tmp);
5857 value = NULL;
5858 }
5859 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005860 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005861 res = obj2ast_expr(tmp, &value, arena);
5862 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005863 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005865 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5866 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005867 if (*out == NULL) goto failed;
5868 return 0;
5869 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005870 tp = astmodulestate_global->Delete_type;
5871 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872 if (isinstance == -1) {
5873 return 1;
5874 }
5875 if (isinstance) {
5876 asdl_seq* targets;
5877
Dino Viehlandac46eb42019-09-11 10:16:34 -07005878 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5879 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005880 return 1;
5881 }
5882 if (tmp == NULL) {
5883 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5884 return 1;
5885 }
5886 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005887 int res;
5888 Py_ssize_t len;
5889 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005890 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005891 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 +02005892 goto failed;
5893 }
5894 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005895 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005896 if (targets == NULL) goto failed;
5897 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005898 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005899 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5900 Py_INCREF(tmp2);
5901 res = obj2ast_expr(tmp2, &val, arena);
5902 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005903 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005904 if (len != PyList_GET_SIZE(tmp)) {
5905 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5906 goto failed;
5907 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005908 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005909 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005910 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005911 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005912 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5913 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005914 if (*out == NULL) goto failed;
5915 return 0;
5916 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005917 tp = astmodulestate_global->Assign_type;
5918 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005919 if (isinstance == -1) {
5920 return 1;
5921 }
5922 if (isinstance) {
5923 asdl_seq* targets;
5924 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005925 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005926
Dino Viehlandac46eb42019-09-11 10:16:34 -07005927 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5928 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005929 return 1;
5930 }
5931 if (tmp == NULL) {
5932 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5933 return 1;
5934 }
5935 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 int res;
5937 Py_ssize_t len;
5938 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005939 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005940 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 +02005941 goto failed;
5942 }
5943 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005944 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005945 if (targets == NULL) goto failed;
5946 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005947 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005948 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5949 Py_INCREF(tmp2);
5950 res = obj2ast_expr(tmp2, &val, arena);
5951 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005952 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005953 if (len != PyList_GET_SIZE(tmp)) {
5954 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5955 goto failed;
5956 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005957 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005958 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005959 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005961 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005962 return 1;
5963 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005964 if (tmp == NULL) {
5965 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5966 return 1;
5967 }
5968 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005969 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005970 res = obj2ast_expr(tmp, &value, arena);
5971 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005972 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005974 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5975 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005976 return 1;
5977 }
5978 if (tmp == NULL || tmp == Py_None) {
5979 Py_CLEAR(tmp);
5980 type_comment = NULL;
5981 }
5982 else {
5983 int res;
5984 res = obj2ast_string(tmp, &type_comment, arena);
5985 if (res != 0) goto failed;
5986 Py_CLEAR(tmp);
5987 }
5988 *out = Assign(targets, value, type_comment, lineno, col_offset,
5989 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005990 if (*out == NULL) goto failed;
5991 return 0;
5992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005993 tp = astmodulestate_global->AugAssign_type;
5994 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005995 if (isinstance == -1) {
5996 return 1;
5997 }
5998 if (isinstance) {
5999 expr_ty target;
6000 operator_ty op;
6001 expr_ty value;
6002
Dino Viehlandac46eb42019-09-11 10:16:34 -07006003 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6004 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006005 return 1;
6006 }
6007 if (tmp == NULL) {
6008 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6009 return 1;
6010 }
6011 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006012 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006013 res = obj2ast_expr(tmp, &target, arena);
6014 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006015 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006016 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006017 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006018 return 1;
6019 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006020 if (tmp == NULL) {
6021 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6022 return 1;
6023 }
6024 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006025 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006026 res = obj2ast_operator(tmp, &op, arena);
6027 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006028 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006030 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006031 return 1;
6032 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006033 if (tmp == NULL) {
6034 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6035 return 1;
6036 }
6037 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006038 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006039 res = obj2ast_expr(tmp, &value, arena);
6040 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006041 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006042 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006043 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6044 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006045 if (*out == NULL) goto failed;
6046 return 0;
6047 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006048 tp = astmodulestate_global->AnnAssign_type;
6049 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006050 if (isinstance == -1) {
6051 return 1;
6052 }
6053 if (isinstance) {
6054 expr_ty target;
6055 expr_ty annotation;
6056 expr_ty value;
6057 int simple;
6058
Dino Viehlandac46eb42019-09-11 10:16:34 -07006059 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6060 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006061 return 1;
6062 }
6063 if (tmp == NULL) {
6064 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6065 return 1;
6066 }
6067 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006068 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006069 res = obj2ast_expr(tmp, &target, arena);
6070 if (res != 0) goto failed;
6071 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006073 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6074 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006075 return 1;
6076 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006077 if (tmp == NULL) {
6078 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6079 return 1;
6080 }
6081 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006082 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006083 res = obj2ast_expr(tmp, &annotation, arena);
6084 if (res != 0) goto failed;
6085 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006087 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006088 return 1;
6089 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006090 if (tmp == NULL || tmp == Py_None) {
6091 Py_CLEAR(tmp);
6092 value = NULL;
6093 }
6094 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006095 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006096 res = obj2ast_expr(tmp, &value, arena);
6097 if (res != 0) goto failed;
6098 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006099 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006100 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6101 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006102 return 1;
6103 }
6104 if (tmp == NULL) {
6105 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6106 return 1;
6107 }
6108 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006109 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006110 res = obj2ast_int(tmp, &simple, arena);
6111 if (res != 0) goto failed;
6112 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006113 }
6114 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006115 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006116 if (*out == NULL) goto failed;
6117 return 0;
6118 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006119 tp = astmodulestate_global->For_type;
6120 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006121 if (isinstance == -1) {
6122 return 1;
6123 }
6124 if (isinstance) {
6125 expr_ty target;
6126 expr_ty iter;
6127 asdl_seq* body;
6128 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006129 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006130
Dino Viehlandac46eb42019-09-11 10:16:34 -07006131 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6132 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006133 return 1;
6134 }
6135 if (tmp == NULL) {
6136 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6137 return 1;
6138 }
6139 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006140 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006141 res = obj2ast_expr(tmp, &target, arena);
6142 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006143 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006145 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006146 return 1;
6147 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006148 if (tmp == NULL) {
6149 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6150 return 1;
6151 }
6152 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006153 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006154 res = obj2ast_expr(tmp, &iter, arena);
6155 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006156 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006158 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006159 return 1;
6160 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006161 if (tmp == NULL) {
6162 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6163 return 1;
6164 }
6165 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006166 int res;
6167 Py_ssize_t len;
6168 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006169 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006170 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 +02006171 goto failed;
6172 }
6173 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006174 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006175 if (body == NULL) goto failed;
6176 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006177 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006178 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6179 Py_INCREF(tmp2);
6180 res = obj2ast_stmt(tmp2, &val, arena);
6181 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006182 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006183 if (len != PyList_GET_SIZE(tmp)) {
6184 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6185 goto failed;
6186 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006187 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006188 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006189 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006191 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6192 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006193 return 1;
6194 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006195 if (tmp == NULL) {
6196 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6197 return 1;
6198 }
6199 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006200 int res;
6201 Py_ssize_t len;
6202 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006203 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006204 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 +02006205 goto failed;
6206 }
6207 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006208 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006209 if (orelse == NULL) goto failed;
6210 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006211 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006212 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6213 Py_INCREF(tmp2);
6214 res = obj2ast_stmt(tmp2, &val, arena);
6215 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006216 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006217 if (len != PyList_GET_SIZE(tmp)) {
6218 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6219 goto failed;
6220 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006221 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006222 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006223 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006225 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6226 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006227 return 1;
6228 }
6229 if (tmp == NULL || tmp == Py_None) {
6230 Py_CLEAR(tmp);
6231 type_comment = NULL;
6232 }
6233 else {
6234 int res;
6235 res = obj2ast_string(tmp, &type_comment, arena);
6236 if (res != 0) goto failed;
6237 Py_CLEAR(tmp);
6238 }
6239 *out = For(target, iter, body, orelse, type_comment, lineno,
6240 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006241 if (*out == NULL) goto failed;
6242 return 0;
6243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006244 tp = astmodulestate_global->AsyncFor_type;
6245 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006246 if (isinstance == -1) {
6247 return 1;
6248 }
6249 if (isinstance) {
6250 expr_ty target;
6251 expr_ty iter;
6252 asdl_seq* body;
6253 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006254 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006255
Dino Viehlandac46eb42019-09-11 10:16:34 -07006256 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6257 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006258 return 1;
6259 }
6260 if (tmp == NULL) {
6261 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6262 return 1;
6263 }
6264 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006265 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006266 res = obj2ast_expr(tmp, &target, arena);
6267 if (res != 0) goto failed;
6268 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006269 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006270 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006271 return 1;
6272 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006273 if (tmp == NULL) {
6274 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6275 return 1;
6276 }
6277 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006278 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006279 res = obj2ast_expr(tmp, &iter, arena);
6280 if (res != 0) goto failed;
6281 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006282 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006283 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006284 return 1;
6285 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006286 if (tmp == NULL) {
6287 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6288 return 1;
6289 }
6290 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006291 int res;
6292 Py_ssize_t len;
6293 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006294 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006295 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 -04006296 goto failed;
6297 }
6298 len = PyList_GET_SIZE(tmp);
6299 body = _Py_asdl_seq_new(len, arena);
6300 if (body == NULL) goto failed;
6301 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006302 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006303 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6304 Py_INCREF(tmp2);
6305 res = obj2ast_stmt(tmp2, &val, arena);
6306 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006307 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006308 if (len != PyList_GET_SIZE(tmp)) {
6309 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6310 goto failed;
6311 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006312 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006313 }
6314 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006315 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006316 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6317 {
Yury Selivanov75445082015-05-11 22:57:16 -04006318 return 1;
6319 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006320 if (tmp == NULL) {
6321 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6322 return 1;
6323 }
6324 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006325 int res;
6326 Py_ssize_t len;
6327 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006328 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006329 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 -04006330 goto failed;
6331 }
6332 len = PyList_GET_SIZE(tmp);
6333 orelse = _Py_asdl_seq_new(len, arena);
6334 if (orelse == NULL) goto failed;
6335 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006336 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006337 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6338 Py_INCREF(tmp2);
6339 res = obj2ast_stmt(tmp2, &val, arena);
6340 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006341 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006342 if (len != PyList_GET_SIZE(tmp)) {
6343 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6344 goto failed;
6345 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006346 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006347 }
6348 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006349 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006350 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6351 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006352 return 1;
6353 }
6354 if (tmp == NULL || tmp == Py_None) {
6355 Py_CLEAR(tmp);
6356 type_comment = NULL;
6357 }
6358 else {
6359 int res;
6360 res = obj2ast_string(tmp, &type_comment, arena);
6361 if (res != 0) goto failed;
6362 Py_CLEAR(tmp);
6363 }
6364 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6365 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006366 if (*out == NULL) goto failed;
6367 return 0;
6368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006369 tp = astmodulestate_global->While_type;
6370 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006371 if (isinstance == -1) {
6372 return 1;
6373 }
6374 if (isinstance) {
6375 expr_ty test;
6376 asdl_seq* body;
6377 asdl_seq* orelse;
6378
Dino Viehlandac46eb42019-09-11 10:16:34 -07006379 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006380 return 1;
6381 }
6382 if (tmp == NULL) {
6383 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6384 return 1;
6385 }
6386 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006387 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006388 res = obj2ast_expr(tmp, &test, arena);
6389 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006390 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006391 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006392 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006393 return 1;
6394 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006395 if (tmp == NULL) {
6396 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6397 return 1;
6398 }
6399 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006400 int res;
6401 Py_ssize_t len;
6402 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006403 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006404 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 +02006405 goto failed;
6406 }
6407 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006408 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006409 if (body == NULL) goto failed;
6410 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006411 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006412 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6413 Py_INCREF(tmp2);
6414 res = obj2ast_stmt(tmp2, &val, arena);
6415 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006416 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006417 if (len != PyList_GET_SIZE(tmp)) {
6418 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6419 goto failed;
6420 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006421 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006422 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006423 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006424 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006425 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6426 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006427 return 1;
6428 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006429 if (tmp == NULL) {
6430 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6431 return 1;
6432 }
6433 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006434 int res;
6435 Py_ssize_t len;
6436 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006437 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006438 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 +02006439 goto failed;
6440 }
6441 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006442 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006443 if (orelse == NULL) goto failed;
6444 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006445 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006446 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6447 Py_INCREF(tmp2);
6448 res = obj2ast_stmt(tmp2, &val, arena);
6449 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006450 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006451 if (len != PyList_GET_SIZE(tmp)) {
6452 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6453 goto failed;
6454 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006455 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006456 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006457 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006458 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006459 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6460 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006461 if (*out == NULL) goto failed;
6462 return 0;
6463 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006464 tp = astmodulestate_global->If_type;
6465 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006466 if (isinstance == -1) {
6467 return 1;
6468 }
6469 if (isinstance) {
6470 expr_ty test;
6471 asdl_seq* body;
6472 asdl_seq* orelse;
6473
Dino Viehlandac46eb42019-09-11 10:16:34 -07006474 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006475 return 1;
6476 }
6477 if (tmp == NULL) {
6478 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6479 return 1;
6480 }
6481 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006482 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006483 res = obj2ast_expr(tmp, &test, arena);
6484 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006485 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006486 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006487 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006488 return 1;
6489 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006490 if (tmp == NULL) {
6491 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6492 return 1;
6493 }
6494 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006495 int res;
6496 Py_ssize_t len;
6497 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006498 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006499 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 +02006500 goto failed;
6501 }
6502 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006503 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006504 if (body == NULL) goto failed;
6505 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006506 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006507 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6508 Py_INCREF(tmp2);
6509 res = obj2ast_stmt(tmp2, &val, arena);
6510 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006511 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006512 if (len != PyList_GET_SIZE(tmp)) {
6513 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6514 goto failed;
6515 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006516 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006517 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006518 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006519 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006520 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6521 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006522 return 1;
6523 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006524 if (tmp == NULL) {
6525 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6526 return 1;
6527 }
6528 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006529 int res;
6530 Py_ssize_t len;
6531 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006532 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006533 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 +02006534 goto failed;
6535 }
6536 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006537 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006538 if (orelse == NULL) goto failed;
6539 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006540 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006541 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6542 Py_INCREF(tmp2);
6543 res = obj2ast_stmt(tmp2, &val, arena);
6544 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006545 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006546 if (len != PyList_GET_SIZE(tmp)) {
6547 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6548 goto failed;
6549 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006550 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006551 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006552 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006553 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006554 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6555 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006556 if (*out == NULL) goto failed;
6557 return 0;
6558 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006559 tp = astmodulestate_global->With_type;
6560 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006561 if (isinstance == -1) {
6562 return 1;
6563 }
6564 if (isinstance) {
6565 asdl_seq* items;
6566 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006567 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006568
Dino Viehlandac46eb42019-09-11 10:16:34 -07006569 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006570 return 1;
6571 }
6572 if (tmp == NULL) {
6573 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6574 return 1;
6575 }
6576 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006577 int res;
6578 Py_ssize_t len;
6579 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006580 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006581 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 +02006582 goto failed;
6583 }
6584 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006585 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006586 if (items == NULL) goto failed;
6587 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006588 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006589 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6590 Py_INCREF(tmp2);
6591 res = obj2ast_withitem(tmp2, &val, arena);
6592 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006593 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006594 if (len != PyList_GET_SIZE(tmp)) {
6595 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6596 goto failed;
6597 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006598 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006599 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006600 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006601 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006602 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006603 return 1;
6604 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006605 if (tmp == NULL) {
6606 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6607 return 1;
6608 }
6609 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006610 int res;
6611 Py_ssize_t len;
6612 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006613 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006614 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 +02006615 goto failed;
6616 }
6617 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006618 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006619 if (body == NULL) goto failed;
6620 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006621 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006622 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6623 Py_INCREF(tmp2);
6624 res = obj2ast_stmt(tmp2, &val, arena);
6625 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006626 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006627 if (len != PyList_GET_SIZE(tmp)) {
6628 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6629 goto failed;
6630 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006631 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006632 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006633 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006634 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006635 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6636 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006637 return 1;
6638 }
6639 if (tmp == NULL || tmp == Py_None) {
6640 Py_CLEAR(tmp);
6641 type_comment = NULL;
6642 }
6643 else {
6644 int res;
6645 res = obj2ast_string(tmp, &type_comment, arena);
6646 if (res != 0) goto failed;
6647 Py_CLEAR(tmp);
6648 }
6649 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006650 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006651 if (*out == NULL) goto failed;
6652 return 0;
6653 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006654 tp = astmodulestate_global->AsyncWith_type;
6655 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006656 if (isinstance == -1) {
6657 return 1;
6658 }
6659 if (isinstance) {
6660 asdl_seq* items;
6661 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006662 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006663
Dino Viehlandac46eb42019-09-11 10:16:34 -07006664 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006665 return 1;
6666 }
6667 if (tmp == NULL) {
6668 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6669 return 1;
6670 }
6671 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006672 int res;
6673 Py_ssize_t len;
6674 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006675 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006676 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 -04006677 goto failed;
6678 }
6679 len = PyList_GET_SIZE(tmp);
6680 items = _Py_asdl_seq_new(len, arena);
6681 if (items == NULL) goto failed;
6682 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006683 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006684 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6685 Py_INCREF(tmp2);
6686 res = obj2ast_withitem(tmp2, &val, arena);
6687 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006688 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006689 if (len != PyList_GET_SIZE(tmp)) {
6690 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6691 goto failed;
6692 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006693 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006694 }
6695 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006696 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006697 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006698 return 1;
6699 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006700 if (tmp == NULL) {
6701 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6702 return 1;
6703 }
6704 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006705 int res;
6706 Py_ssize_t len;
6707 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006708 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006709 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 -04006710 goto failed;
6711 }
6712 len = PyList_GET_SIZE(tmp);
6713 body = _Py_asdl_seq_new(len, arena);
6714 if (body == NULL) goto failed;
6715 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006716 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006717 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6718 Py_INCREF(tmp2);
6719 res = obj2ast_stmt(tmp2, &val, arena);
6720 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006721 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006722 if (len != PyList_GET_SIZE(tmp)) {
6723 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6724 goto failed;
6725 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006726 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006727 }
6728 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006729 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006730 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6731 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006732 return 1;
6733 }
6734 if (tmp == NULL || tmp == Py_None) {
6735 Py_CLEAR(tmp);
6736 type_comment = NULL;
6737 }
6738 else {
6739 int res;
6740 res = obj2ast_string(tmp, &type_comment, arena);
6741 if (res != 0) goto failed;
6742 Py_CLEAR(tmp);
6743 }
6744 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6745 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006746 if (*out == NULL) goto failed;
6747 return 0;
6748 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006749 tp = astmodulestate_global->Raise_type;
6750 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006751 if (isinstance == -1) {
6752 return 1;
6753 }
6754 if (isinstance) {
6755 expr_ty exc;
6756 expr_ty cause;
6757
Dino Viehlandac46eb42019-09-11 10:16:34 -07006758 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006759 return 1;
6760 }
6761 if (tmp == NULL || tmp == Py_None) {
6762 Py_CLEAR(tmp);
6763 exc = NULL;
6764 }
6765 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006766 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006767 res = obj2ast_expr(tmp, &exc, arena);
6768 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006769 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006770 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006771 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006772 return 1;
6773 }
6774 if (tmp == NULL || tmp == Py_None) {
6775 Py_CLEAR(tmp);
6776 cause = NULL;
6777 }
6778 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006779 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006780 res = obj2ast_expr(tmp, &cause, arena);
6781 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006782 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006783 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006784 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6785 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006786 if (*out == NULL) goto failed;
6787 return 0;
6788 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006789 tp = astmodulestate_global->Try_type;
6790 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 if (isinstance == -1) {
6792 return 1;
6793 }
6794 if (isinstance) {
6795 asdl_seq* body;
6796 asdl_seq* handlers;
6797 asdl_seq* orelse;
6798 asdl_seq* finalbody;
6799
Dino Viehlandac46eb42019-09-11 10:16:34 -07006800 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006801 return 1;
6802 }
6803 if (tmp == NULL) {
6804 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6805 return 1;
6806 }
6807 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006808 int res;
6809 Py_ssize_t len;
6810 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006811 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006812 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 +02006813 goto failed;
6814 }
6815 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006816 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006817 if (body == NULL) goto failed;
6818 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006819 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006820 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6821 Py_INCREF(tmp2);
6822 res = obj2ast_stmt(tmp2, &val, arena);
6823 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006824 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006825 if (len != PyList_GET_SIZE(tmp)) {
6826 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6827 goto failed;
6828 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006829 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006830 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006831 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006832 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006833 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6834 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006835 return 1;
6836 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006837 if (tmp == NULL) {
6838 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6839 return 1;
6840 }
6841 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006842 int res;
6843 Py_ssize_t len;
6844 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006845 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006846 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 +02006847 goto failed;
6848 }
6849 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006850 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006851 if (handlers == NULL) goto failed;
6852 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006853 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006854 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6855 Py_INCREF(tmp2);
6856 res = obj2ast_excepthandler(tmp2, &val, arena);
6857 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006858 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006859 if (len != PyList_GET_SIZE(tmp)) {
6860 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6861 goto failed;
6862 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006863 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006864 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006865 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006867 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6868 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006869 return 1;
6870 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006871 if (tmp == NULL) {
6872 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6873 return 1;
6874 }
6875 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006876 int res;
6877 Py_ssize_t len;
6878 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006879 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006880 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 +02006881 goto failed;
6882 }
6883 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006884 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006885 if (orelse == NULL) goto failed;
6886 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006887 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006888 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6889 Py_INCREF(tmp2);
6890 res = obj2ast_stmt(tmp2, &val, arena);
6891 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006892 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006893 if (len != PyList_GET_SIZE(tmp)) {
6894 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6895 goto failed;
6896 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006897 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006898 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006899 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006900 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006901 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6902 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006903 return 1;
6904 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006905 if (tmp == NULL) {
6906 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6907 return 1;
6908 }
6909 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006910 int res;
6911 Py_ssize_t len;
6912 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006913 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006914 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 +02006915 goto failed;
6916 }
6917 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006918 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006919 if (finalbody == NULL) goto failed;
6920 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006921 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006922 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6923 Py_INCREF(tmp2);
6924 res = obj2ast_stmt(tmp2, &val, arena);
6925 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006926 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006927 if (len != PyList_GET_SIZE(tmp)) {
6928 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6929 goto failed;
6930 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006931 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006932 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006933 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006934 }
6935 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006936 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006937 if (*out == NULL) goto failed;
6938 return 0;
6939 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006940 tp = astmodulestate_global->Assert_type;
6941 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006942 if (isinstance == -1) {
6943 return 1;
6944 }
6945 if (isinstance) {
6946 expr_ty test;
6947 expr_ty msg;
6948
Dino Viehlandac46eb42019-09-11 10:16:34 -07006949 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006950 return 1;
6951 }
6952 if (tmp == NULL) {
6953 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6954 return 1;
6955 }
6956 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006957 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006958 res = obj2ast_expr(tmp, &test, arena);
6959 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006960 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006961 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006962 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006963 return 1;
6964 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006965 if (tmp == NULL || tmp == Py_None) {
6966 Py_CLEAR(tmp);
6967 msg = NULL;
6968 }
6969 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006970 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006971 res = obj2ast_expr(tmp, &msg, arena);
6972 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006973 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006975 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6976 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006977 if (*out == NULL) goto failed;
6978 return 0;
6979 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006980 tp = astmodulestate_global->Import_type;
6981 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 if (isinstance == -1) {
6983 return 1;
6984 }
6985 if (isinstance) {
6986 asdl_seq* names;
6987
Dino Viehlandac46eb42019-09-11 10:16:34 -07006988 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006989 return 1;
6990 }
6991 if (tmp == NULL) {
6992 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6993 return 1;
6994 }
6995 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006996 int res;
6997 Py_ssize_t len;
6998 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006999 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007000 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 +02007001 goto failed;
7002 }
7003 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007004 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007005 if (names == NULL) goto failed;
7006 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007007 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007008 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7009 Py_INCREF(tmp2);
7010 res = obj2ast_alias(tmp2, &val, arena);
7011 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007012 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007013 if (len != PyList_GET_SIZE(tmp)) {
7014 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7015 goto failed;
7016 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007017 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007018 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007019 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007020 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007021 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
7022 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007023 if (*out == NULL) goto failed;
7024 return 0;
7025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007026 tp = astmodulestate_global->ImportFrom_type;
7027 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007028 if (isinstance == -1) {
7029 return 1;
7030 }
7031 if (isinstance) {
7032 identifier module;
7033 asdl_seq* names;
7034 int level;
7035
Dino Viehlandac46eb42019-09-11 10:16:34 -07007036 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7037 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007038 return 1;
7039 }
7040 if (tmp == NULL || tmp == Py_None) {
7041 Py_CLEAR(tmp);
7042 module = NULL;
7043 }
7044 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007045 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007046 res = obj2ast_identifier(tmp, &module, arena);
7047 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007048 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007050 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007051 return 1;
7052 }
7053 if (tmp == NULL) {
7054 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7055 return 1;
7056 }
7057 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007058 int res;
7059 Py_ssize_t len;
7060 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007061 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007062 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 +02007063 goto failed;
7064 }
7065 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007066 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007067 if (names == NULL) goto failed;
7068 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007069 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007070 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7071 Py_INCREF(tmp2);
7072 res = obj2ast_alias(tmp2, &val, arena);
7073 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007074 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007075 if (len != PyList_GET_SIZE(tmp)) {
7076 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7077 goto failed;
7078 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007079 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007080 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007081 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007083 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007084 return 1;
7085 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007086 if (tmp == NULL || tmp == Py_None) {
7087 Py_CLEAR(tmp);
7088 level = 0;
7089 }
7090 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007091 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007092 res = obj2ast_int(tmp, &level, arena);
7093 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007094 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007095 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007096 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7097 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007098 if (*out == NULL) goto failed;
7099 return 0;
7100 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007101 tp = astmodulestate_global->Global_type;
7102 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007103 if (isinstance == -1) {
7104 return 1;
7105 }
7106 if (isinstance) {
7107 asdl_seq* names;
7108
Dino Viehlandac46eb42019-09-11 10:16:34 -07007109 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007110 return 1;
7111 }
7112 if (tmp == NULL) {
7113 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7114 return 1;
7115 }
7116 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007117 int res;
7118 Py_ssize_t len;
7119 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007120 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007121 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 +02007122 goto failed;
7123 }
7124 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007125 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007126 if (names == NULL) goto failed;
7127 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007128 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007129 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7130 Py_INCREF(tmp2);
7131 res = obj2ast_identifier(tmp2, &val, arena);
7132 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007133 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007134 if (len != PyList_GET_SIZE(tmp)) {
7135 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7136 goto failed;
7137 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007138 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007139 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007140 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007141 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007142 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7143 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007144 if (*out == NULL) goto failed;
7145 return 0;
7146 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007147 tp = astmodulestate_global->Nonlocal_type;
7148 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007149 if (isinstance == -1) {
7150 return 1;
7151 }
7152 if (isinstance) {
7153 asdl_seq* names;
7154
Dino Viehlandac46eb42019-09-11 10:16:34 -07007155 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007156 return 1;
7157 }
7158 if (tmp == NULL) {
7159 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7160 return 1;
7161 }
7162 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007163 int res;
7164 Py_ssize_t len;
7165 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007166 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007167 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 +02007168 goto failed;
7169 }
7170 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007171 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007172 if (names == NULL) goto failed;
7173 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007174 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007175 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7176 Py_INCREF(tmp2);
7177 res = obj2ast_identifier(tmp2, &val, arena);
7178 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007179 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007180 if (len != PyList_GET_SIZE(tmp)) {
7181 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7182 goto failed;
7183 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007184 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007185 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007186 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007187 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007188 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7189 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007190 if (*out == NULL) goto failed;
7191 return 0;
7192 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007193 tp = astmodulestate_global->Expr_type;
7194 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007195 if (isinstance == -1) {
7196 return 1;
7197 }
7198 if (isinstance) {
7199 expr_ty value;
7200
Dino Viehlandac46eb42019-09-11 10:16:34 -07007201 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007202 return 1;
7203 }
7204 if (tmp == NULL) {
7205 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7206 return 1;
7207 }
7208 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007209 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 res = obj2ast_expr(tmp, &value, arena);
7211 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007212 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007213 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007214 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7215 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007216 if (*out == NULL) goto failed;
7217 return 0;
7218 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007219 tp = astmodulestate_global->Pass_type;
7220 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007221 if (isinstance == -1) {
7222 return 1;
7223 }
7224 if (isinstance) {
7225
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007226 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007227 if (*out == NULL) goto failed;
7228 return 0;
7229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007230 tp = astmodulestate_global->Break_type;
7231 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007232 if (isinstance == -1) {
7233 return 1;
7234 }
7235 if (isinstance) {
7236
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007237 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007238 if (*out == NULL) goto failed;
7239 return 0;
7240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007241 tp = astmodulestate_global->Continue_type;
7242 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007243 if (isinstance == -1) {
7244 return 1;
7245 }
7246 if (isinstance) {
7247
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007248 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007249 if (*out == NULL) goto failed;
7250 return 0;
7251 }
7252
7253 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7254 failed:
7255 Py_XDECREF(tmp);
7256 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007257}
7258
7259int
7260obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7261{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007262 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007263
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007264 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007265 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007266 int lineno;
7267 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007268 int end_lineno;
7269 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007270
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007271 if (obj == Py_None) {
7272 *out = NULL;
7273 return 0;
7274 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007275 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007276 return 1;
7277 }
7278 if (tmp == NULL) {
7279 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7280 return 1;
7281 }
7282 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007283 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007284 res = obj2ast_int(tmp, &lineno, arena);
7285 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007286 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007288 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7289 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007290 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007291 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007292 if (tmp == NULL) {
7293 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7294 return 1;
7295 }
7296 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007297 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007298 res = obj2ast_int(tmp, &col_offset, arena);
7299 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007300 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007301 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007302 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7303 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007304 return 1;
7305 }
7306 if (tmp == NULL || tmp == Py_None) {
7307 Py_CLEAR(tmp);
7308 end_lineno = 0;
7309 }
7310 else {
7311 int res;
7312 res = obj2ast_int(tmp, &end_lineno, arena);
7313 if (res != 0) goto failed;
7314 Py_CLEAR(tmp);
7315 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007316 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7317 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007318 return 1;
7319 }
7320 if (tmp == NULL || tmp == Py_None) {
7321 Py_CLEAR(tmp);
7322 end_col_offset = 0;
7323 }
7324 else {
7325 int res;
7326 res = obj2ast_int(tmp, &end_col_offset, arena);
7327 if (res != 0) goto failed;
7328 Py_CLEAR(tmp);
7329 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007330 tp = astmodulestate_global->BoolOp_type;
7331 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007332 if (isinstance == -1) {
7333 return 1;
7334 }
7335 if (isinstance) {
7336 boolop_ty op;
7337 asdl_seq* values;
7338
Dino Viehlandac46eb42019-09-11 10:16:34 -07007339 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007340 return 1;
7341 }
7342 if (tmp == NULL) {
7343 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7344 return 1;
7345 }
7346 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007347 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007348 res = obj2ast_boolop(tmp, &op, arena);
7349 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007350 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007351 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007352 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7353 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007354 return 1;
7355 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007356 if (tmp == NULL) {
7357 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7358 return 1;
7359 }
7360 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007361 int res;
7362 Py_ssize_t len;
7363 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007364 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007365 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 +02007366 goto failed;
7367 }
7368 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007369 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007370 if (values == NULL) goto failed;
7371 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007372 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007373 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7374 Py_INCREF(tmp2);
7375 res = obj2ast_expr(tmp2, &val, arena);
7376 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007377 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007378 if (len != PyList_GET_SIZE(tmp)) {
7379 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7380 goto failed;
7381 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007382 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007383 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007384 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007385 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007386 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7387 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007388 if (*out == NULL) goto failed;
7389 return 0;
7390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007391 tp = astmodulestate_global->NamedExpr_type;
7392 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007393 if (isinstance == -1) {
7394 return 1;
7395 }
7396 if (isinstance) {
7397 expr_ty target;
7398 expr_ty value;
7399
Dino Viehlandac46eb42019-09-11 10:16:34 -07007400 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7401 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007402 return 1;
7403 }
7404 if (tmp == NULL) {
7405 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7406 return 1;
7407 }
7408 else {
7409 int res;
7410 res = obj2ast_expr(tmp, &target, arena);
7411 if (res != 0) goto failed;
7412 Py_CLEAR(tmp);
7413 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007414 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007415 return 1;
7416 }
7417 if (tmp == NULL) {
7418 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7419 return 1;
7420 }
7421 else {
7422 int res;
7423 res = obj2ast_expr(tmp, &value, arena);
7424 if (res != 0) goto failed;
7425 Py_CLEAR(tmp);
7426 }
7427 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7428 end_col_offset, arena);
7429 if (*out == NULL) goto failed;
7430 return 0;
7431 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007432 tp = astmodulestate_global->BinOp_type;
7433 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007434 if (isinstance == -1) {
7435 return 1;
7436 }
7437 if (isinstance) {
7438 expr_ty left;
7439 operator_ty op;
7440 expr_ty right;
7441
Dino Viehlandac46eb42019-09-11 10:16:34 -07007442 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007443 return 1;
7444 }
7445 if (tmp == NULL) {
7446 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7447 return 1;
7448 }
7449 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007450 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007451 res = obj2ast_expr(tmp, &left, arena);
7452 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007453 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007455 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007456 return 1;
7457 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007458 if (tmp == NULL) {
7459 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7460 return 1;
7461 }
7462 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007463 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007464 res = obj2ast_operator(tmp, &op, arena);
7465 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007466 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007468 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007469 return 1;
7470 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007471 if (tmp == NULL) {
7472 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7473 return 1;
7474 }
7475 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007476 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 res = obj2ast_expr(tmp, &right, arena);
7478 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007479 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007481 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7482 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007483 if (*out == NULL) goto failed;
7484 return 0;
7485 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007486 tp = astmodulestate_global->UnaryOp_type;
7487 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007488 if (isinstance == -1) {
7489 return 1;
7490 }
7491 if (isinstance) {
7492 unaryop_ty op;
7493 expr_ty operand;
7494
Dino Viehlandac46eb42019-09-11 10:16:34 -07007495 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007496 return 1;
7497 }
7498 if (tmp == NULL) {
7499 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7500 return 1;
7501 }
7502 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007503 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007504 res = obj2ast_unaryop(tmp, &op, arena);
7505 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007506 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007507 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007508 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7509 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007510 return 1;
7511 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007512 if (tmp == NULL) {
7513 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7514 return 1;
7515 }
7516 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007517 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007518 res = obj2ast_expr(tmp, &operand, arena);
7519 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007520 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007521 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007522 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7523 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007524 if (*out == NULL) goto failed;
7525 return 0;
7526 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007527 tp = astmodulestate_global->Lambda_type;
7528 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007529 if (isinstance == -1) {
7530 return 1;
7531 }
7532 if (isinstance) {
7533 arguments_ty args;
7534 expr_ty body;
7535
Dino Viehlandac46eb42019-09-11 10:16:34 -07007536 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007537 return 1;
7538 }
7539 if (tmp == NULL) {
7540 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7541 return 1;
7542 }
7543 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007545 res = obj2ast_arguments(tmp, &args, arena);
7546 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007547 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007549 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007550 return 1;
7551 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007552 if (tmp == NULL) {
7553 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7554 return 1;
7555 }
7556 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007557 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007558 res = obj2ast_expr(tmp, &body, arena);
7559 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007560 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007562 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7563 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007564 if (*out == NULL) goto failed;
7565 return 0;
7566 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007567 tp = astmodulestate_global->IfExp_type;
7568 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 if (isinstance == -1) {
7570 return 1;
7571 }
7572 if (isinstance) {
7573 expr_ty test;
7574 expr_ty body;
7575 expr_ty orelse;
7576
Dino Viehlandac46eb42019-09-11 10:16:34 -07007577 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007578 return 1;
7579 }
7580 if (tmp == NULL) {
7581 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7582 return 1;
7583 }
7584 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007585 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007586 res = obj2ast_expr(tmp, &test, arena);
7587 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007588 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007589 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007590 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007591 return 1;
7592 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007593 if (tmp == NULL) {
7594 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7595 return 1;
7596 }
7597 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007598 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007599 res = obj2ast_expr(tmp, &body, arena);
7600 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007601 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007602 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007603 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7604 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007605 return 1;
7606 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007607 if (tmp == NULL) {
7608 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7609 return 1;
7610 }
7611 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007612 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007613 res = obj2ast_expr(tmp, &orelse, arena);
7614 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007615 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007617 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7618 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007619 if (*out == NULL) goto failed;
7620 return 0;
7621 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007622 tp = astmodulestate_global->Dict_type;
7623 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 if (isinstance == -1) {
7625 return 1;
7626 }
7627 if (isinstance) {
7628 asdl_seq* keys;
7629 asdl_seq* values;
7630
Dino Viehlandac46eb42019-09-11 10:16:34 -07007631 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007632 return 1;
7633 }
7634 if (tmp == NULL) {
7635 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7636 return 1;
7637 }
7638 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007639 int res;
7640 Py_ssize_t len;
7641 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007642 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007643 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 +02007644 goto failed;
7645 }
7646 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007647 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007648 if (keys == NULL) goto failed;
7649 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007650 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007651 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7652 Py_INCREF(tmp2);
7653 res = obj2ast_expr(tmp2, &val, arena);
7654 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007655 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007656 if (len != PyList_GET_SIZE(tmp)) {
7657 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7658 goto failed;
7659 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007660 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007661 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007662 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007663 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007664 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7665 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007666 return 1;
7667 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007668 if (tmp == NULL) {
7669 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7670 return 1;
7671 }
7672 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007673 int res;
7674 Py_ssize_t len;
7675 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007676 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007677 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 +02007678 goto failed;
7679 }
7680 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007681 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007682 if (values == NULL) goto failed;
7683 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007684 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007685 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7686 Py_INCREF(tmp2);
7687 res = obj2ast_expr(tmp2, &val, arena);
7688 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007689 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007690 if (len != PyList_GET_SIZE(tmp)) {
7691 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7692 goto failed;
7693 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007694 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007695 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007696 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007697 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007698 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7699 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007700 if (*out == NULL) goto failed;
7701 return 0;
7702 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007703 tp = astmodulestate_global->Set_type;
7704 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007705 if (isinstance == -1) {
7706 return 1;
7707 }
7708 if (isinstance) {
7709 asdl_seq* elts;
7710
Dino Viehlandac46eb42019-09-11 10:16:34 -07007711 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007712 return 1;
7713 }
7714 if (tmp == NULL) {
7715 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7716 return 1;
7717 }
7718 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007719 int res;
7720 Py_ssize_t len;
7721 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007722 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007723 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 +02007724 goto failed;
7725 }
7726 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007727 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007728 if (elts == NULL) goto failed;
7729 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007730 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007731 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7732 Py_INCREF(tmp2);
7733 res = obj2ast_expr(tmp2, &val, arena);
7734 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007735 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007736 if (len != PyList_GET_SIZE(tmp)) {
7737 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7738 goto failed;
7739 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007740 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007741 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007742 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007743 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007744 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007745 if (*out == NULL) goto failed;
7746 return 0;
7747 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007748 tp = astmodulestate_global->ListComp_type;
7749 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007750 if (isinstance == -1) {
7751 return 1;
7752 }
7753 if (isinstance) {
7754 expr_ty elt;
7755 asdl_seq* generators;
7756
Dino Viehlandac46eb42019-09-11 10:16:34 -07007757 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007758 return 1;
7759 }
7760 if (tmp == NULL) {
7761 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7762 return 1;
7763 }
7764 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007765 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007766 res = obj2ast_expr(tmp, &elt, arena);
7767 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007768 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007769 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007770 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7771 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007772 return 1;
7773 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007774 if (tmp == NULL) {
7775 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7776 return 1;
7777 }
7778 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007779 int res;
7780 Py_ssize_t len;
7781 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007782 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007783 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 +02007784 goto failed;
7785 }
7786 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007787 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007788 if (generators == NULL) goto failed;
7789 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007790 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007791 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7792 Py_INCREF(tmp2);
7793 res = obj2ast_comprehension(tmp2, &val, arena);
7794 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007795 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007796 if (len != PyList_GET_SIZE(tmp)) {
7797 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7798 goto failed;
7799 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007800 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007801 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007802 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007803 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007804 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7805 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007806 if (*out == NULL) goto failed;
7807 return 0;
7808 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007809 tp = astmodulestate_global->SetComp_type;
7810 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007811 if (isinstance == -1) {
7812 return 1;
7813 }
7814 if (isinstance) {
7815 expr_ty elt;
7816 asdl_seq* generators;
7817
Dino Viehlandac46eb42019-09-11 10:16:34 -07007818 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007819 return 1;
7820 }
7821 if (tmp == NULL) {
7822 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7823 return 1;
7824 }
7825 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007826 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007827 res = obj2ast_expr(tmp, &elt, arena);
7828 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007829 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007830 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007831 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7832 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007833 return 1;
7834 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007835 if (tmp == NULL) {
7836 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7837 return 1;
7838 }
7839 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007840 int res;
7841 Py_ssize_t len;
7842 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007843 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007844 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 +02007845 goto failed;
7846 }
7847 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007848 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007849 if (generators == NULL) goto failed;
7850 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007851 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007852 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7853 Py_INCREF(tmp2);
7854 res = obj2ast_comprehension(tmp2, &val, arena);
7855 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007856 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007857 if (len != PyList_GET_SIZE(tmp)) {
7858 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7859 goto failed;
7860 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007861 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007862 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007863 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007864 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007865 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7866 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007867 if (*out == NULL) goto failed;
7868 return 0;
7869 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007870 tp = astmodulestate_global->DictComp_type;
7871 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007872 if (isinstance == -1) {
7873 return 1;
7874 }
7875 if (isinstance) {
7876 expr_ty key;
7877 expr_ty value;
7878 asdl_seq* generators;
7879
Dino Viehlandac46eb42019-09-11 10:16:34 -07007880 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007881 return 1;
7882 }
7883 if (tmp == NULL) {
7884 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7885 return 1;
7886 }
7887 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007888 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007889 res = obj2ast_expr(tmp, &key, arena);
7890 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007891 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007892 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007893 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007894 return 1;
7895 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007896 if (tmp == NULL) {
7897 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7898 return 1;
7899 }
7900 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007901 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007902 res = obj2ast_expr(tmp, &value, arena);
7903 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007904 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007906 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7907 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007908 return 1;
7909 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007910 if (tmp == NULL) {
7911 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7912 return 1;
7913 }
7914 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007915 int res;
7916 Py_ssize_t len;
7917 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007918 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007919 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 +02007920 goto failed;
7921 }
7922 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007923 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007924 if (generators == NULL) goto failed;
7925 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007926 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007927 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7928 Py_INCREF(tmp2);
7929 res = obj2ast_comprehension(tmp2, &val, arena);
7930 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007931 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007932 if (len != PyList_GET_SIZE(tmp)) {
7933 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7934 goto failed;
7935 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007936 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007937 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007938 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007939 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007940 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7941 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007942 if (*out == NULL) goto failed;
7943 return 0;
7944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007945 tp = astmodulestate_global->GeneratorExp_type;
7946 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007947 if (isinstance == -1) {
7948 return 1;
7949 }
7950 if (isinstance) {
7951 expr_ty elt;
7952 asdl_seq* generators;
7953
Dino Viehlandac46eb42019-09-11 10:16:34 -07007954 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007955 return 1;
7956 }
7957 if (tmp == NULL) {
7958 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7959 return 1;
7960 }
7961 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007962 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007963 res = obj2ast_expr(tmp, &elt, arena);
7964 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007965 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007966 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007967 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7968 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007969 return 1;
7970 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007971 if (tmp == NULL) {
7972 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7973 return 1;
7974 }
7975 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 int res;
7977 Py_ssize_t len;
7978 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007979 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007980 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 +02007981 goto failed;
7982 }
7983 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007984 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007985 if (generators == NULL) goto failed;
7986 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007987 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007988 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7989 Py_INCREF(tmp2);
7990 res = obj2ast_comprehension(tmp2, &val, arena);
7991 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007992 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007993 if (len != PyList_GET_SIZE(tmp)) {
7994 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7995 goto failed;
7996 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007997 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007998 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007999 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008000 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008001 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
8002 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008003 if (*out == NULL) goto failed;
8004 return 0;
8005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008006 tp = astmodulestate_global->Await_type;
8007 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008008 if (isinstance == -1) {
8009 return 1;
8010 }
8011 if (isinstance) {
8012 expr_ty value;
8013
Dino Viehlandac46eb42019-09-11 10:16:34 -07008014 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008015 return 1;
8016 }
8017 if (tmp == NULL) {
8018 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8019 return 1;
8020 }
8021 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008022 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04008023 res = obj2ast_expr(tmp, &value, arena);
8024 if (res != 0) goto failed;
8025 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008026 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008027 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
8028 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008029 if (*out == NULL) goto failed;
8030 return 0;
8031 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008032 tp = astmodulestate_global->Yield_type;
8033 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008034 if (isinstance == -1) {
8035 return 1;
8036 }
8037 if (isinstance) {
8038 expr_ty value;
8039
Dino Viehlandac46eb42019-09-11 10:16:34 -07008040 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008041 return 1;
8042 }
8043 if (tmp == NULL || tmp == Py_None) {
8044 Py_CLEAR(tmp);
8045 value = NULL;
8046 }
8047 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008048 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008049 res = obj2ast_expr(tmp, &value, arena);
8050 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008051 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008052 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008053 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8054 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008055 if (*out == NULL) goto failed;
8056 return 0;
8057 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008058 tp = astmodulestate_global->YieldFrom_type;
8059 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008060 if (isinstance == -1) {
8061 return 1;
8062 }
8063 if (isinstance) {
8064 expr_ty value;
8065
Dino Viehlandac46eb42019-09-11 10:16:34 -07008066 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008067 return 1;
8068 }
8069 if (tmp == NULL) {
8070 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8071 return 1;
8072 }
8073 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008074 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008075 res = obj2ast_expr(tmp, &value, arena);
8076 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008077 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008078 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008079 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8080 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008081 if (*out == NULL) goto failed;
8082 return 0;
8083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008084 tp = astmodulestate_global->Compare_type;
8085 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008086 if (isinstance == -1) {
8087 return 1;
8088 }
8089 if (isinstance) {
8090 expr_ty left;
8091 asdl_int_seq* ops;
8092 asdl_seq* comparators;
8093
Dino Viehlandac46eb42019-09-11 10:16:34 -07008094 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008095 return 1;
8096 }
8097 if (tmp == NULL) {
8098 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8099 return 1;
8100 }
8101 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008102 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008103 res = obj2ast_expr(tmp, &left, arena);
8104 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008105 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008107 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008108 return 1;
8109 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008110 if (tmp == NULL) {
8111 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8112 return 1;
8113 }
8114 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008115 int res;
8116 Py_ssize_t len;
8117 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008118 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008119 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 +02008120 goto failed;
8121 }
8122 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008123 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008124 if (ops == NULL) goto failed;
8125 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008126 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008127 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8128 Py_INCREF(tmp2);
8129 res = obj2ast_cmpop(tmp2, &val, arena);
8130 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008131 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008132 if (len != PyList_GET_SIZE(tmp)) {
8133 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8134 goto failed;
8135 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008136 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008137 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008138 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008140 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8141 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008142 return 1;
8143 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008144 if (tmp == NULL) {
8145 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8146 return 1;
8147 }
8148 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008149 int res;
8150 Py_ssize_t len;
8151 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008152 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008153 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 +02008154 goto failed;
8155 }
8156 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008157 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008158 if (comparators == NULL) goto failed;
8159 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008160 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008161 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8162 Py_INCREF(tmp2);
8163 res = obj2ast_expr(tmp2, &val, arena);
8164 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008165 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008166 if (len != PyList_GET_SIZE(tmp)) {
8167 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8168 goto failed;
8169 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008170 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008171 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008172 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008173 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008174 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8175 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008176 if (*out == NULL) goto failed;
8177 return 0;
8178 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008179 tp = astmodulestate_global->Call_type;
8180 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008181 if (isinstance == -1) {
8182 return 1;
8183 }
8184 if (isinstance) {
8185 expr_ty func;
8186 asdl_seq* args;
8187 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008188
Dino Viehlandac46eb42019-09-11 10:16:34 -07008189 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008190 return 1;
8191 }
8192 if (tmp == NULL) {
8193 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8194 return 1;
8195 }
8196 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008197 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008198 res = obj2ast_expr(tmp, &func, arena);
8199 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008200 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008202 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008203 return 1;
8204 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008205 if (tmp == NULL) {
8206 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8207 return 1;
8208 }
8209 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008210 int res;
8211 Py_ssize_t len;
8212 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008213 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008214 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 +02008215 goto failed;
8216 }
8217 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008218 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008219 if (args == NULL) goto failed;
8220 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008221 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008222 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8223 Py_INCREF(tmp2);
8224 res = obj2ast_expr(tmp2, &val, arena);
8225 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008226 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008227 if (len != PyList_GET_SIZE(tmp)) {
8228 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8229 goto failed;
8230 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008231 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008232 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008233 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008235 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8236 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008237 return 1;
8238 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008239 if (tmp == NULL) {
8240 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8241 return 1;
8242 }
8243 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008244 int res;
8245 Py_ssize_t len;
8246 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008247 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008248 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 +02008249 goto failed;
8250 }
8251 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008252 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008253 if (keywords == NULL) goto failed;
8254 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008255 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008256 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8257 Py_INCREF(tmp2);
8258 res = obj2ast_keyword(tmp2, &val, arena);
8259 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008260 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008261 if (len != PyList_GET_SIZE(tmp)) {
8262 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8263 goto failed;
8264 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008265 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008266 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008267 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008268 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008269 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8270 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008271 if (*out == NULL) goto failed;
8272 return 0;
8273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008274 tp = astmodulestate_global->FormattedValue_type;
8275 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008276 if (isinstance == -1) {
8277 return 1;
8278 }
8279 if (isinstance) {
8280 expr_ty value;
8281 int conversion;
8282 expr_ty format_spec;
8283
Dino Viehlandac46eb42019-09-11 10:16:34 -07008284 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008285 return 1;
8286 }
8287 if (tmp == NULL) {
8288 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8289 return 1;
8290 }
8291 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008292 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008293 res = obj2ast_expr(tmp, &value, arena);
8294 if (res != 0) goto failed;
8295 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008296 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008297 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8298 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008299 return 1;
8300 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008301 if (tmp == NULL || tmp == Py_None) {
8302 Py_CLEAR(tmp);
8303 conversion = 0;
8304 }
8305 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008306 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008307 res = obj2ast_int(tmp, &conversion, arena);
8308 if (res != 0) goto failed;
8309 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008310 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008311 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8312 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008313 return 1;
8314 }
8315 if (tmp == NULL || tmp == Py_None) {
8316 Py_CLEAR(tmp);
8317 format_spec = NULL;
8318 }
8319 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008320 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008321 res = obj2ast_expr(tmp, &format_spec, arena);
8322 if (res != 0) goto failed;
8323 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008324 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008325 *out = FormattedValue(value, conversion, format_spec, lineno,
8326 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008327 if (*out == NULL) goto failed;
8328 return 0;
8329 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008330 tp = astmodulestate_global->JoinedStr_type;
8331 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008332 if (isinstance == -1) {
8333 return 1;
8334 }
8335 if (isinstance) {
8336 asdl_seq* values;
8337
Dino Viehlandac46eb42019-09-11 10:16:34 -07008338 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8339 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008340 return 1;
8341 }
8342 if (tmp == NULL) {
8343 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8344 return 1;
8345 }
8346 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008347 int res;
8348 Py_ssize_t len;
8349 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008350 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008351 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 -04008352 goto failed;
8353 }
8354 len = PyList_GET_SIZE(tmp);
8355 values = _Py_asdl_seq_new(len, arena);
8356 if (values == NULL) goto failed;
8357 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008358 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008359 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8360 Py_INCREF(tmp2);
8361 res = obj2ast_expr(tmp2, &val, arena);
8362 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008363 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008364 if (len != PyList_GET_SIZE(tmp)) {
8365 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8366 goto failed;
8367 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008368 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008369 }
8370 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008371 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008372 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8373 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008374 if (*out == NULL) goto failed;
8375 return 0;
8376 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008377 tp = astmodulestate_global->Constant_type;
8378 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008379 if (isinstance == -1) {
8380 return 1;
8381 }
8382 if (isinstance) {
8383 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008384 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008385
Dino Viehlandac46eb42019-09-11 10:16:34 -07008386 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008387 return 1;
8388 }
8389 if (tmp == NULL) {
8390 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8391 return 1;
8392 }
8393 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008394 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008395 res = obj2ast_constant(tmp, &value, arena);
8396 if (res != 0) goto failed;
8397 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008398 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008399 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008400 return 1;
8401 }
8402 if (tmp == NULL || tmp == Py_None) {
8403 Py_CLEAR(tmp);
8404 kind = NULL;
8405 }
8406 else {
8407 int res;
8408 res = obj2ast_string(tmp, &kind, arena);
8409 if (res != 0) goto failed;
8410 Py_CLEAR(tmp);
8411 }
8412 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8413 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008414 if (*out == NULL) goto failed;
8415 return 0;
8416 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008417 tp = astmodulestate_global->Attribute_type;
8418 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008419 if (isinstance == -1) {
8420 return 1;
8421 }
8422 if (isinstance) {
8423 expr_ty value;
8424 identifier attr;
8425 expr_context_ty ctx;
8426
Dino Viehlandac46eb42019-09-11 10:16:34 -07008427 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008428 return 1;
8429 }
8430 if (tmp == NULL) {
8431 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8432 return 1;
8433 }
8434 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008436 res = obj2ast_expr(tmp, &value, arena);
8437 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008438 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008439 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008440 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008441 return 1;
8442 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008443 if (tmp == NULL) {
8444 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8445 return 1;
8446 }
8447 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008448 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008449 res = obj2ast_identifier(tmp, &attr, arena);
8450 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008451 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008452 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008453 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008454 return 1;
8455 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008456 if (tmp == NULL) {
8457 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8458 return 1;
8459 }
8460 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008461 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008462 res = obj2ast_expr_context(tmp, &ctx, arena);
8463 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008464 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008466 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8467 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008468 if (*out == NULL) goto failed;
8469 return 0;
8470 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008471 tp = astmodulestate_global->Subscript_type;
8472 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008473 if (isinstance == -1) {
8474 return 1;
8475 }
8476 if (isinstance) {
8477 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008478 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008479 expr_context_ty ctx;
8480
Dino Viehlandac46eb42019-09-11 10:16:34 -07008481 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008482 return 1;
8483 }
8484 if (tmp == NULL) {
8485 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8486 return 1;
8487 }
8488 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008489 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008490 res = obj2ast_expr(tmp, &value, arena);
8491 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008492 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008493 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008494 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008495 return 1;
8496 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008497 if (tmp == NULL) {
8498 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8499 return 1;
8500 }
8501 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008502 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008503 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008504 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008505 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008506 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008507 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008508 return 1;
8509 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008510 if (tmp == NULL) {
8511 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8512 return 1;
8513 }
8514 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008515 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008516 res = obj2ast_expr_context(tmp, &ctx, arena);
8517 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008518 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008520 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8521 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008522 if (*out == NULL) goto failed;
8523 return 0;
8524 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008525 tp = astmodulestate_global->Starred_type;
8526 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008527 if (isinstance == -1) {
8528 return 1;
8529 }
8530 if (isinstance) {
8531 expr_ty value;
8532 expr_context_ty ctx;
8533
Dino Viehlandac46eb42019-09-11 10:16:34 -07008534 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008535 return 1;
8536 }
8537 if (tmp == NULL) {
8538 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8539 return 1;
8540 }
8541 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008542 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008543 res = obj2ast_expr(tmp, &value, arena);
8544 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008545 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008546 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008547 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008548 return 1;
8549 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008550 if (tmp == NULL) {
8551 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8552 return 1;
8553 }
8554 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008555 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008556 res = obj2ast_expr_context(tmp, &ctx, arena);
8557 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008558 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008559 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008560 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8561 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008562 if (*out == NULL) goto failed;
8563 return 0;
8564 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008565 tp = astmodulestate_global->Name_type;
8566 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008567 if (isinstance == -1) {
8568 return 1;
8569 }
8570 if (isinstance) {
8571 identifier id;
8572 expr_context_ty ctx;
8573
Dino Viehlandac46eb42019-09-11 10:16:34 -07008574 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008575 return 1;
8576 }
8577 if (tmp == NULL) {
8578 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8579 return 1;
8580 }
8581 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008582 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008583 res = obj2ast_identifier(tmp, &id, arena);
8584 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008585 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008586 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008587 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008588 return 1;
8589 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008590 if (tmp == NULL) {
8591 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8592 return 1;
8593 }
8594 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008595 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008596 res = obj2ast_expr_context(tmp, &ctx, arena);
8597 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008598 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008599 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008600 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8601 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008602 if (*out == NULL) goto failed;
8603 return 0;
8604 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008605 tp = astmodulestate_global->List_type;
8606 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008607 if (isinstance == -1) {
8608 return 1;
8609 }
8610 if (isinstance) {
8611 asdl_seq* elts;
8612 expr_context_ty ctx;
8613
Dino Viehlandac46eb42019-09-11 10:16:34 -07008614 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008615 return 1;
8616 }
8617 if (tmp == NULL) {
8618 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8619 return 1;
8620 }
8621 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008622 int res;
8623 Py_ssize_t len;
8624 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008625 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008626 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 +02008627 goto failed;
8628 }
8629 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008630 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631 if (elts == NULL) goto failed;
8632 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008633 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008634 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8635 Py_INCREF(tmp2);
8636 res = obj2ast_expr(tmp2, &val, arena);
8637 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008638 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008639 if (len != PyList_GET_SIZE(tmp)) {
8640 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8641 goto failed;
8642 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008643 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008644 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008645 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008646 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008647 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008648 return 1;
8649 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008650 if (tmp == NULL) {
8651 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8652 return 1;
8653 }
8654 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008655 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008656 res = obj2ast_expr_context(tmp, &ctx, arena);
8657 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008658 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008659 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008660 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8661 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008662 if (*out == NULL) goto failed;
8663 return 0;
8664 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008665 tp = astmodulestate_global->Tuple_type;
8666 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008667 if (isinstance == -1) {
8668 return 1;
8669 }
8670 if (isinstance) {
8671 asdl_seq* elts;
8672 expr_context_ty ctx;
8673
Dino Viehlandac46eb42019-09-11 10:16:34 -07008674 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008675 return 1;
8676 }
8677 if (tmp == NULL) {
8678 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8679 return 1;
8680 }
8681 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008682 int res;
8683 Py_ssize_t len;
8684 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008685 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008686 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 +02008687 goto failed;
8688 }
8689 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008690 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008691 if (elts == NULL) goto failed;
8692 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008693 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008694 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8695 Py_INCREF(tmp2);
8696 res = obj2ast_expr(tmp2, &val, arena);
8697 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008698 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008699 if (len != PyList_GET_SIZE(tmp)) {
8700 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8701 goto failed;
8702 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008703 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008704 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008705 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008706 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008707 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008708 return 1;
8709 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008710 if (tmp == NULL) {
8711 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8712 return 1;
8713 }
8714 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008715 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008716 res = obj2ast_expr_context(tmp, &ctx, arena);
8717 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008718 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008719 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008720 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8721 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008722 if (*out == NULL) goto failed;
8723 return 0;
8724 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008725 tp = astmodulestate_global->Slice_type;
8726 isinstance = PyObject_IsInstance(obj, tp);
8727 if (isinstance == -1) {
8728 return 1;
8729 }
8730 if (isinstance) {
8731 expr_ty lower;
8732 expr_ty upper;
8733 expr_ty step;
8734
8735 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8736 return 1;
8737 }
8738 if (tmp == NULL || tmp == Py_None) {
8739 Py_CLEAR(tmp);
8740 lower = NULL;
8741 }
8742 else {
8743 int res;
8744 res = obj2ast_expr(tmp, &lower, arena);
8745 if (res != 0) goto failed;
8746 Py_CLEAR(tmp);
8747 }
8748 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8749 return 1;
8750 }
8751 if (tmp == NULL || tmp == Py_None) {
8752 Py_CLEAR(tmp);
8753 upper = NULL;
8754 }
8755 else {
8756 int res;
8757 res = obj2ast_expr(tmp, &upper, arena);
8758 if (res != 0) goto failed;
8759 Py_CLEAR(tmp);
8760 }
8761 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8762 return 1;
8763 }
8764 if (tmp == NULL || tmp == Py_None) {
8765 Py_CLEAR(tmp);
8766 step = NULL;
8767 }
8768 else {
8769 int res;
8770 res = obj2ast_expr(tmp, &step, arena);
8771 if (res != 0) goto failed;
8772 Py_CLEAR(tmp);
8773 }
8774 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8775 end_col_offset, arena);
8776 if (*out == NULL) goto failed;
8777 return 0;
8778 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008779
8780 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8781 failed:
8782 Py_XDECREF(tmp);
8783 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008784}
8785
8786int
8787obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8788{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008789 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008790
Dino Viehlandac46eb42019-09-11 10:16:34 -07008791 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008792 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008793 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008794 }
8795 if (isinstance) {
8796 *out = Load;
8797 return 0;
8798 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008799 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008800 if (isinstance == -1) {
8801 return 1;
8802 }
8803 if (isinstance) {
8804 *out = Store;
8805 return 0;
8806 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008807 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008808 if (isinstance == -1) {
8809 return 1;
8810 }
8811 if (isinstance) {
8812 *out = Del;
8813 return 0;
8814 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008815
8816 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8817 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008818}
8819
8820int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008821obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8822{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008823 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008824
Dino Viehlandac46eb42019-09-11 10:16:34 -07008825 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008826 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008827 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008828 }
8829 if (isinstance) {
8830 *out = And;
8831 return 0;
8832 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008833 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008834 if (isinstance == -1) {
8835 return 1;
8836 }
8837 if (isinstance) {
8838 *out = Or;
8839 return 0;
8840 }
8841
8842 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8843 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008844}
8845
8846int
8847obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8848{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008849 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008850
Dino Viehlandac46eb42019-09-11 10:16:34 -07008851 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008852 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008853 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008854 }
8855 if (isinstance) {
8856 *out = Add;
8857 return 0;
8858 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008859 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008860 if (isinstance == -1) {
8861 return 1;
8862 }
8863 if (isinstance) {
8864 *out = Sub;
8865 return 0;
8866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008867 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008868 if (isinstance == -1) {
8869 return 1;
8870 }
8871 if (isinstance) {
8872 *out = Mult;
8873 return 0;
8874 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008875 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008876 if (isinstance == -1) {
8877 return 1;
8878 }
8879 if (isinstance) {
8880 *out = MatMult;
8881 return 0;
8882 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008883 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008884 if (isinstance == -1) {
8885 return 1;
8886 }
8887 if (isinstance) {
8888 *out = Div;
8889 return 0;
8890 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008891 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008892 if (isinstance == -1) {
8893 return 1;
8894 }
8895 if (isinstance) {
8896 *out = Mod;
8897 return 0;
8898 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008899 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008900 if (isinstance == -1) {
8901 return 1;
8902 }
8903 if (isinstance) {
8904 *out = Pow;
8905 return 0;
8906 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008907 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008908 if (isinstance == -1) {
8909 return 1;
8910 }
8911 if (isinstance) {
8912 *out = LShift;
8913 return 0;
8914 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008915 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008916 if (isinstance == -1) {
8917 return 1;
8918 }
8919 if (isinstance) {
8920 *out = RShift;
8921 return 0;
8922 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008923 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008924 if (isinstance == -1) {
8925 return 1;
8926 }
8927 if (isinstance) {
8928 *out = BitOr;
8929 return 0;
8930 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008931 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008932 if (isinstance == -1) {
8933 return 1;
8934 }
8935 if (isinstance) {
8936 *out = BitXor;
8937 return 0;
8938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008939 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008940 if (isinstance == -1) {
8941 return 1;
8942 }
8943 if (isinstance) {
8944 *out = BitAnd;
8945 return 0;
8946 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008947 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008948 if (isinstance == -1) {
8949 return 1;
8950 }
8951 if (isinstance) {
8952 *out = FloorDiv;
8953 return 0;
8954 }
8955
8956 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8957 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008958}
8959
8960int
8961obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8962{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008963 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008964
Dino Viehlandac46eb42019-09-11 10:16:34 -07008965 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008966 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008967 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008968 }
8969 if (isinstance) {
8970 *out = Invert;
8971 return 0;
8972 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008973 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008974 if (isinstance == -1) {
8975 return 1;
8976 }
8977 if (isinstance) {
8978 *out = Not;
8979 return 0;
8980 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008981 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008982 if (isinstance == -1) {
8983 return 1;
8984 }
8985 if (isinstance) {
8986 *out = UAdd;
8987 return 0;
8988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008989 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008990 if (isinstance == -1) {
8991 return 1;
8992 }
8993 if (isinstance) {
8994 *out = USub;
8995 return 0;
8996 }
8997
8998 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
8999 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009000}
9001
9002int
9003obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9004{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009005 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009006
Dino Viehlandac46eb42019-09-11 10:16:34 -07009007 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009008 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009009 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009010 }
9011 if (isinstance) {
9012 *out = Eq;
9013 return 0;
9014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009015 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009016 if (isinstance == -1) {
9017 return 1;
9018 }
9019 if (isinstance) {
9020 *out = NotEq;
9021 return 0;
9022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009023 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009024 if (isinstance == -1) {
9025 return 1;
9026 }
9027 if (isinstance) {
9028 *out = Lt;
9029 return 0;
9030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009031 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009032 if (isinstance == -1) {
9033 return 1;
9034 }
9035 if (isinstance) {
9036 *out = LtE;
9037 return 0;
9038 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009039 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009040 if (isinstance == -1) {
9041 return 1;
9042 }
9043 if (isinstance) {
9044 *out = Gt;
9045 return 0;
9046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009047 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009048 if (isinstance == -1) {
9049 return 1;
9050 }
9051 if (isinstance) {
9052 *out = GtE;
9053 return 0;
9054 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009055 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009056 if (isinstance == -1) {
9057 return 1;
9058 }
9059 if (isinstance) {
9060 *out = Is;
9061 return 0;
9062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009063 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009064 if (isinstance == -1) {
9065 return 1;
9066 }
9067 if (isinstance) {
9068 *out = IsNot;
9069 return 0;
9070 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009071 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009072 if (isinstance == -1) {
9073 return 1;
9074 }
9075 if (isinstance) {
9076 *out = In;
9077 return 0;
9078 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009079 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009080 if (isinstance == -1) {
9081 return 1;
9082 }
9083 if (isinstance) {
9084 *out = NotIn;
9085 return 0;
9086 }
9087
9088 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9089 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009090}
9091
9092int
9093obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9094{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009095 PyObject* tmp = NULL;
9096 expr_ty target;
9097 expr_ty iter;
9098 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009099 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009100
Dino Viehlandac46eb42019-09-11 10:16:34 -07009101 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009102 return 1;
9103 }
9104 if (tmp == NULL) {
9105 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9106 return 1;
9107 }
9108 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009109 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009110 res = obj2ast_expr(tmp, &target, arena);
9111 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009112 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009114 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009115 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009116 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009117 if (tmp == NULL) {
9118 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9119 return 1;
9120 }
9121 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009122 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009123 res = obj2ast_expr(tmp, &iter, arena);
9124 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009125 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009127 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009128 return 1;
9129 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009130 if (tmp == NULL) {
9131 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9132 return 1;
9133 }
9134 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009135 int res;
9136 Py_ssize_t len;
9137 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009138 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009139 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 +02009140 goto failed;
9141 }
9142 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009143 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009144 if (ifs == NULL) goto failed;
9145 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009146 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009147 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9148 Py_INCREF(tmp2);
9149 res = obj2ast_expr(tmp2, &val, arena);
9150 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009151 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009152 if (len != PyList_GET_SIZE(tmp)) {
9153 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9154 goto failed;
9155 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009156 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009157 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009158 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009159 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009160 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009161 return 1;
9162 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009163 if (tmp == NULL) {
9164 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9165 return 1;
9166 }
9167 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009168 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009169 res = obj2ast_int(tmp, &is_async, arena);
9170 if (res != 0) goto failed;
9171 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009172 }
9173 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009174 return 0;
9175failed:
9176 Py_XDECREF(tmp);
9177 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009178}
9179
9180int
9181obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9182{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009183 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009184
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009185 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009186 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009187 int lineno;
9188 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009189 int end_lineno;
9190 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009191
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009192 if (obj == Py_None) {
9193 *out = NULL;
9194 return 0;
9195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009196 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009197 return 1;
9198 }
9199 if (tmp == NULL) {
9200 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9201 return 1;
9202 }
9203 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009204 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009205 res = obj2ast_int(tmp, &lineno, arena);
9206 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009207 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009209 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9210 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009211 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009212 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009213 if (tmp == NULL) {
9214 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9215 return 1;
9216 }
9217 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009219 res = obj2ast_int(tmp, &col_offset, arena);
9220 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009221 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009222 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009223 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9224 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009225 return 1;
9226 }
9227 if (tmp == NULL || tmp == Py_None) {
9228 Py_CLEAR(tmp);
9229 end_lineno = 0;
9230 }
9231 else {
9232 int res;
9233 res = obj2ast_int(tmp, &end_lineno, arena);
9234 if (res != 0) goto failed;
9235 Py_CLEAR(tmp);
9236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009237 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9238 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009239 return 1;
9240 }
9241 if (tmp == NULL || tmp == Py_None) {
9242 Py_CLEAR(tmp);
9243 end_col_offset = 0;
9244 }
9245 else {
9246 int res;
9247 res = obj2ast_int(tmp, &end_col_offset, arena);
9248 if (res != 0) goto failed;
9249 Py_CLEAR(tmp);
9250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009251 tp = astmodulestate_global->ExceptHandler_type;
9252 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009253 if (isinstance == -1) {
9254 return 1;
9255 }
9256 if (isinstance) {
9257 expr_ty type;
9258 identifier name;
9259 asdl_seq* body;
9260
Dino Viehlandac46eb42019-09-11 10:16:34 -07009261 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009262 return 1;
9263 }
9264 if (tmp == NULL || tmp == Py_None) {
9265 Py_CLEAR(tmp);
9266 type = NULL;
9267 }
9268 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009269 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009270 res = obj2ast_expr(tmp, &type, arena);
9271 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009272 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009274 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009275 return 1;
9276 }
9277 if (tmp == NULL || tmp == Py_None) {
9278 Py_CLEAR(tmp);
9279 name = NULL;
9280 }
9281 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009282 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009283 res = obj2ast_identifier(tmp, &name, arena);
9284 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009285 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009287 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009288 return 1;
9289 }
9290 if (tmp == NULL) {
9291 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9292 return 1;
9293 }
9294 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009295 int res;
9296 Py_ssize_t len;
9297 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009298 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009299 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 +02009300 goto failed;
9301 }
9302 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009303 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009304 if (body == NULL) goto failed;
9305 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009306 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009307 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9308 Py_INCREF(tmp2);
9309 res = obj2ast_stmt(tmp2, &val, arena);
9310 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009311 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009312 if (len != PyList_GET_SIZE(tmp)) {
9313 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9314 goto failed;
9315 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009316 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009317 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009318 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009319 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009320 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9321 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009322 if (*out == NULL) goto failed;
9323 return 0;
9324 }
9325
9326 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9327 failed:
9328 Py_XDECREF(tmp);
9329 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009330}
9331
9332int
9333obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9334{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009336 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009337 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009338 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009339 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009340 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009341 arg_ty kwarg;
9342 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009343
Dino Viehlandac46eb42019-09-11 10:16:34 -07009344 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9345 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009346 return 1;
9347 }
9348 if (tmp == NULL) {
9349 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9350 return 1;
9351 }
9352 else {
9353 int res;
9354 Py_ssize_t len;
9355 Py_ssize_t i;
9356 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009357 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 +01009358 goto failed;
9359 }
9360 len = PyList_GET_SIZE(tmp);
9361 posonlyargs = _Py_asdl_seq_new(len, arena);
9362 if (posonlyargs == NULL) goto failed;
9363 for (i = 0; i < len; i++) {
9364 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009365 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9366 Py_INCREF(tmp2);
9367 res = obj2ast_arg(tmp2, &val, arena);
9368 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009369 if (res != 0) goto failed;
9370 if (len != PyList_GET_SIZE(tmp)) {
9371 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9372 goto failed;
9373 }
9374 asdl_seq_SET(posonlyargs, i, val);
9375 }
9376 Py_CLEAR(tmp);
9377 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009378 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009379 return 1;
9380 }
9381 if (tmp == NULL) {
9382 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9383 return 1;
9384 }
9385 else {
9386 int res;
9387 Py_ssize_t len;
9388 Py_ssize_t i;
9389 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009390 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 +02009391 goto failed;
9392 }
9393 len = PyList_GET_SIZE(tmp);
9394 args = _Py_asdl_seq_new(len, arena);
9395 if (args == NULL) goto failed;
9396 for (i = 0; i < len; i++) {
9397 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009398 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9399 Py_INCREF(tmp2);
9400 res = obj2ast_arg(tmp2, &val, arena);
9401 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009402 if (res != 0) goto failed;
9403 if (len != PyList_GET_SIZE(tmp)) {
9404 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9405 goto failed;
9406 }
9407 asdl_seq_SET(args, i, val);
9408 }
9409 Py_CLEAR(tmp);
9410 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009411 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009412 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009413 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009414 if (tmp == NULL || tmp == Py_None) {
9415 Py_CLEAR(tmp);
9416 vararg = NULL;
9417 }
9418 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009419 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009420 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009421 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009422 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009423 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009424 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9425 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009426 return 1;
9427 }
9428 if (tmp == NULL) {
9429 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9430 return 1;
9431 }
9432 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009433 int res;
9434 Py_ssize_t len;
9435 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009436 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009437 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 +02009438 goto failed;
9439 }
9440 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009441 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009442 if (kwonlyargs == NULL) goto failed;
9443 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009444 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009445 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9446 Py_INCREF(tmp2);
9447 res = obj2ast_arg(tmp2, &val, arena);
9448 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009449 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009450 if (len != PyList_GET_SIZE(tmp)) {
9451 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9452 goto failed;
9453 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009454 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009455 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009456 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009457 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009458 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9459 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009460 return 1;
9461 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009462 if (tmp == NULL) {
9463 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9464 return 1;
9465 }
9466 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009467 int res;
9468 Py_ssize_t len;
9469 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009470 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009471 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 +02009472 goto failed;
9473 }
9474 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009475 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009476 if (kw_defaults == NULL) goto failed;
9477 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009478 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009479 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9480 Py_INCREF(tmp2);
9481 res = obj2ast_expr(tmp2, &val, arena);
9482 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009483 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009484 if (len != PyList_GET_SIZE(tmp)) {
9485 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9486 goto failed;
9487 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009488 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009489 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009490 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009491 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009492 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009493 return 1;
9494 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009495 if (tmp == NULL || tmp == Py_None) {
9496 Py_CLEAR(tmp);
9497 kwarg = NULL;
9498 }
9499 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009500 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009501 res = obj2ast_arg(tmp, &kwarg, arena);
9502 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009503 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009504 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009505 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009506 return 1;
9507 }
9508 if (tmp == NULL) {
9509 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9510 return 1;
9511 }
9512 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009513 int res;
9514 Py_ssize_t len;
9515 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009516 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009517 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 +02009518 goto failed;
9519 }
9520 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009521 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009522 if (defaults == NULL) goto failed;
9523 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009524 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009525 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9526 Py_INCREF(tmp2);
9527 res = obj2ast_expr(tmp2, &val, arena);
9528 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009529 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009530 if (len != PyList_GET_SIZE(tmp)) {
9531 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9532 goto failed;
9533 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009534 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009535 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009536 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009537 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009538 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009539 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009540 return 0;
9541failed:
9542 Py_XDECREF(tmp);
9543 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009544}
9545
9546int
9547obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9548{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009549 PyObject* tmp = NULL;
9550 identifier arg;
9551 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009552 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009553 int lineno;
9554 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009555 int end_lineno;
9556 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009557
Dino Viehlandac46eb42019-09-11 10:16:34 -07009558 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009559 return 1;
9560 }
9561 if (tmp == NULL) {
9562 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9563 return 1;
9564 }
9565 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009566 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009567 res = obj2ast_identifier(tmp, &arg, arena);
9568 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009569 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009570 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009571 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9572 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009573 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009574 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009575 if (tmp == NULL || tmp == Py_None) {
9576 Py_CLEAR(tmp);
9577 annotation = NULL;
9578 }
9579 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009580 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009581 res = obj2ast_expr(tmp, &annotation, arena);
9582 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009583 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009584 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009585 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9586 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009587 return 1;
9588 }
9589 if (tmp == NULL || tmp == Py_None) {
9590 Py_CLEAR(tmp);
9591 type_comment = NULL;
9592 }
9593 else {
9594 int res;
9595 res = obj2ast_string(tmp, &type_comment, arena);
9596 if (res != 0) goto failed;
9597 Py_CLEAR(tmp);
9598 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009599 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009600 return 1;
9601 }
9602 if (tmp == NULL) {
9603 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9604 return 1;
9605 }
9606 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009607 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009608 res = obj2ast_int(tmp, &lineno, arena);
9609 if (res != 0) goto failed;
9610 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009611 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009612 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9613 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009614 return 1;
9615 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009616 if (tmp == NULL) {
9617 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9618 return 1;
9619 }
9620 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009621 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009622 res = obj2ast_int(tmp, &col_offset, arena);
9623 if (res != 0) goto failed;
9624 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009626 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9627 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009628 return 1;
9629 }
9630 if (tmp == NULL || tmp == Py_None) {
9631 Py_CLEAR(tmp);
9632 end_lineno = 0;
9633 }
9634 else {
9635 int res;
9636 res = obj2ast_int(tmp, &end_lineno, arena);
9637 if (res != 0) goto failed;
9638 Py_CLEAR(tmp);
9639 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009640 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9641 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009642 return 1;
9643 }
9644 if (tmp == NULL || tmp == Py_None) {
9645 Py_CLEAR(tmp);
9646 end_col_offset = 0;
9647 }
9648 else {
9649 int res;
9650 res = obj2ast_int(tmp, &end_col_offset, arena);
9651 if (res != 0) goto failed;
9652 Py_CLEAR(tmp);
9653 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009654 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9655 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009656 return 0;
9657failed:
9658 Py_XDECREF(tmp);
9659 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009660}
9661
9662int
9663obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9664{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009665 PyObject* tmp = NULL;
9666 identifier arg;
9667 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +01009668 int lineno;
9669 int col_offset;
9670 int end_lineno;
9671 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009672
Dino Viehlandac46eb42019-09-11 10:16:34 -07009673 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009674 return 1;
9675 }
9676 if (tmp == NULL || tmp == Py_None) {
9677 Py_CLEAR(tmp);
9678 arg = NULL;
9679 }
9680 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009681 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009682 res = obj2ast_identifier(tmp, &arg, arena);
9683 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009684 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009685 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009686 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009687 return 1;
9688 }
9689 if (tmp == NULL) {
9690 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9691 return 1;
9692 }
9693 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009694 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009695 res = obj2ast_expr(tmp, &value, arena);
9696 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009697 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009698 }
Pablo Galindo168660b2020-04-02 00:47:39 +01009699 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
9700 return 1;
9701 }
9702 if (tmp == NULL) {
9703 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
9704 return 1;
9705 }
9706 else {
9707 int res;
9708 res = obj2ast_int(tmp, &lineno, arena);
9709 if (res != 0) goto failed;
9710 Py_CLEAR(tmp);
9711 }
9712 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9713 {
9714 return 1;
9715 }
9716 if (tmp == NULL) {
9717 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
9718 return 1;
9719 }
9720 else {
9721 int res;
9722 res = obj2ast_int(tmp, &col_offset, arena);
9723 if (res != 0) goto failed;
9724 Py_CLEAR(tmp);
9725 }
9726 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9727 {
9728 return 1;
9729 }
9730 if (tmp == NULL || tmp == Py_None) {
9731 Py_CLEAR(tmp);
9732 end_lineno = 0;
9733 }
9734 else {
9735 int res;
9736 res = obj2ast_int(tmp, &end_lineno, arena);
9737 if (res != 0) goto failed;
9738 Py_CLEAR(tmp);
9739 }
9740 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9741 < 0) {
9742 return 1;
9743 }
9744 if (tmp == NULL || tmp == Py_None) {
9745 Py_CLEAR(tmp);
9746 end_col_offset = 0;
9747 }
9748 else {
9749 int res;
9750 res = obj2ast_int(tmp, &end_col_offset, arena);
9751 if (res != 0) goto failed;
9752 Py_CLEAR(tmp);
9753 }
9754 *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset,
9755 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009756 return 0;
9757failed:
9758 Py_XDECREF(tmp);
9759 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009760}
9761
9762int
9763obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9764{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009765 PyObject* tmp = NULL;
9766 identifier name;
9767 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009768
Dino Viehlandac46eb42019-09-11 10:16:34 -07009769 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009770 return 1;
9771 }
9772 if (tmp == NULL) {
9773 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9774 return 1;
9775 }
9776 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009777 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009778 res = obj2ast_identifier(tmp, &name, arena);
9779 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009780 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009781 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009782 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009783 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009784 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009785 if (tmp == NULL || tmp == Py_None) {
9786 Py_CLEAR(tmp);
9787 asname = NULL;
9788 }
9789 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009790 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009791 res = obj2ast_identifier(tmp, &asname, arena);
9792 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009793 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009794 }
9795 *out = alias(name, asname, arena);
9796 return 0;
9797failed:
9798 Py_XDECREF(tmp);
9799 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009800}
9801
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009802int
9803obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9804{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009805 PyObject* tmp = NULL;
9806 expr_ty context_expr;
9807 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009808
Dino Viehlandac46eb42019-09-11 10:16:34 -07009809 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9810 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009811 return 1;
9812 }
9813 if (tmp == NULL) {
9814 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9815 return 1;
9816 }
9817 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009818 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009819 res = obj2ast_expr(tmp, &context_expr, arena);
9820 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009821 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009822 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009823 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9824 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009825 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009826 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009827 if (tmp == NULL || tmp == Py_None) {
9828 Py_CLEAR(tmp);
9829 optional_vars = NULL;
9830 }
9831 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009832 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009833 res = obj2ast_expr(tmp, &optional_vars, arena);
9834 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009835 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009836 }
9837 *out = withitem(context_expr, optional_vars, arena);
9838 return 0;
9839failed:
9840 Py_XDECREF(tmp);
9841 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009842}
9843
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009844int
9845obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9846{
9847 int isinstance;
9848
9849 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009850 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009851
9852 if (obj == Py_None) {
9853 *out = NULL;
9854 return 0;
9855 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009856 tp = astmodulestate_global->TypeIgnore_type;
9857 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009858 if (isinstance == -1) {
9859 return 1;
9860 }
9861 if (isinstance) {
9862 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009863 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009864
Dino Viehlandac46eb42019-09-11 10:16:34 -07009865 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9866 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009867 return 1;
9868 }
9869 if (tmp == NULL) {
9870 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9871 return 1;
9872 }
9873 else {
9874 int res;
9875 res = obj2ast_int(tmp, &lineno, arena);
9876 if (res != 0) goto failed;
9877 Py_CLEAR(tmp);
9878 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009879 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009880 return 1;
9881 }
9882 if (tmp == NULL) {
9883 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9884 return 1;
9885 }
9886 else {
9887 int res;
9888 res = obj2ast_string(tmp, &tag, arena);
9889 if (res != 0) goto failed;
9890 Py_CLEAR(tmp);
9891 }
9892 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009893 if (*out == NULL) goto failed;
9894 return 0;
9895 }
9896
9897 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9898 failed:
9899 Py_XDECREF(tmp);
9900 return 1;
9901}
9902
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009903
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009904PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009905PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009906{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009907 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009908 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009909 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009910 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009911 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9912 goto error;
9913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009914 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009915 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9916 goto error;
9917 }
9918 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9919 goto error;
9920 }
9921 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9922 goto error;
9923 }
9924 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9925 goto error;
9926 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009927 Py_INCREF(astmodulestate(m)->mod_type);
9928 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009929 0) {
9930 goto error;
9931 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009932 Py_INCREF(astmodulestate(m)->Module_type);
9933 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009934 astmodulestate_global->Interactive_type) < 0) {
9935 goto error;
9936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009937 Py_INCREF(astmodulestate(m)->Interactive_type);
9938 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009939 astmodulestate_global->Expression_type) < 0) {
9940 goto error;
9941 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009942 Py_INCREF(astmodulestate(m)->Expression_type);
9943 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009944 astmodulestate_global->FunctionType_type) < 0) {
9945 goto error;
9946 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009947 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009948 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9949 goto error;
9950 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009951 Py_INCREF(astmodulestate(m)->stmt_type);
9952 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009953 astmodulestate_global->FunctionDef_type) < 0) {
9954 goto error;
9955 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009956 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9957 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009958 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9959 goto error;
9960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009961 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9962 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009963 < 0) {
9964 goto error;
9965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009966 Py_INCREF(astmodulestate(m)->ClassDef_type);
9967 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009968 0) {
9969 goto error;
9970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009971 Py_INCREF(astmodulestate(m)->Return_type);
9972 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009973 0) {
9974 goto error;
9975 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009976 Py_INCREF(astmodulestate(m)->Delete_type);
9977 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009978 0) {
9979 goto error;
9980 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009981 Py_INCREF(astmodulestate(m)->Assign_type);
9982 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009983 astmodulestate_global->AugAssign_type) < 0) {
9984 goto error;
9985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009986 Py_INCREF(astmodulestate(m)->AugAssign_type);
9987 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009988 astmodulestate_global->AnnAssign_type) < 0) {
9989 goto error;
9990 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009991 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009992 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9993 goto error;
9994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009995 Py_INCREF(astmodulestate(m)->For_type);
9996 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009997 < 0) {
9998 goto error;
9999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010000 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010001 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
10002 goto error;
10003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010004 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010005 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
10006 goto error;
10007 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010008 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010009 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
10010 goto error;
10011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010012 Py_INCREF(astmodulestate(m)->With_type);
10013 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010014 astmodulestate_global->AsyncWith_type) < 0) {
10015 goto error;
10016 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010017 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010018 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10019 goto error;
10020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010021 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010022 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10023 goto error;
10024 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010025 Py_INCREF(astmodulestate(m)->Try_type);
10026 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010027 0) {
10028 goto error;
10029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010030 Py_INCREF(astmodulestate(m)->Assert_type);
10031 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010032 0) {
10033 goto error;
10034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010035 Py_INCREF(astmodulestate(m)->Import_type);
10036 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010037 astmodulestate_global->ImportFrom_type) < 0) {
10038 goto error;
10039 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010040 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10041 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010042 0) {
10043 goto error;
10044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010045 Py_INCREF(astmodulestate(m)->Global_type);
10046 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010047 < 0) {
10048 goto error;
10049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010050 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010051 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10052 goto error;
10053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010054 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010055 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10056 goto error;
10057 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010058 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010059 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10060 goto error;
10061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010062 Py_INCREF(astmodulestate(m)->Break_type);
10063 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010064 < 0) {
10065 goto error;
10066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010067 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010068 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10069 goto error;
10070 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010071 Py_INCREF(astmodulestate(m)->expr_type);
10072 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010073 0) {
10074 goto error;
10075 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010076 Py_INCREF(astmodulestate(m)->BoolOp_type);
10077 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010078 astmodulestate_global->NamedExpr_type) < 0) {
10079 goto error;
10080 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010081 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010082 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10083 goto error;
10084 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010085 Py_INCREF(astmodulestate(m)->BinOp_type);
10086 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010087 0) {
10088 goto error;
10089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010090 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10091 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010092 0) {
10093 goto error;
10094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010095 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010096 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10097 goto error;
10098 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010099 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010100 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10101 goto error;
10102 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010103 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010104 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10105 goto error;
10106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010107 Py_INCREF(astmodulestate(m)->Set_type);
10108 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010109 < 0) {
10110 goto error;
10111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010112 Py_INCREF(astmodulestate(m)->ListComp_type);
10113 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010114 0) {
10115 goto error;
10116 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010117 Py_INCREF(astmodulestate(m)->SetComp_type);
10118 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010119 < 0) {
10120 goto error;
10121 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010122 Py_INCREF(astmodulestate(m)->DictComp_type);
10123 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010124 astmodulestate_global->GeneratorExp_type) < 0) {
10125 goto error;
10126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010127 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010128 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10129 goto error;
10130 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010131 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010132 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10133 goto error;
10134 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010135 Py_INCREF(astmodulestate(m)->Yield_type);
10136 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010137 astmodulestate_global->YieldFrom_type) < 0) {
10138 goto error;
10139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010140 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10141 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010142 0) {
10143 goto error;
10144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010145 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010146 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10147 goto error;
10148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010149 Py_INCREF(astmodulestate(m)->Call_type);
10150 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010151 astmodulestate_global->FormattedValue_type) < 0) {
10152 goto error;
10153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010154 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10155 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010156 astmodulestate_global->JoinedStr_type) < 0) {
10157 goto error;
10158 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010159 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10160 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010161 < 0) {
10162 goto error;
10163 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010164 Py_INCREF(astmodulestate(m)->Constant_type);
10165 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010166 astmodulestate_global->Attribute_type) < 0) {
10167 goto error;
10168 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010169 Py_INCREF(astmodulestate(m)->Attribute_type);
10170 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010171 astmodulestate_global->Subscript_type) < 0) {
10172 goto error;
10173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010174 Py_INCREF(astmodulestate(m)->Subscript_type);
10175 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010176 0) {
10177 goto error;
10178 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010179 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010180 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10181 goto error;
10182 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010183 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010184 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10185 goto error;
10186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010187 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010192 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10193 goto error;
10194 }
10195 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010197 astmodulestate_global->expr_context_type) < 0) {
10198 goto error;
10199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010200 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010201 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10202 goto error;
10203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010204 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010205 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10206 goto error;
10207 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010208 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010209 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10210 goto error;
10211 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010212 Py_INCREF(astmodulestate(m)->Del_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010213 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010214 0) {
10215 goto error;
10216 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010218 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10219 goto error;
10220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010221 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010222 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10223 goto error;
10224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010225 Py_INCREF(astmodulestate(m)->Or_type);
10226 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010227 < 0) {
10228 goto error;
10229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010230 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010231 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10232 goto error;
10233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010234 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010235 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10236 goto error;
10237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010238 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010239 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10240 goto error;
10241 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010242 Py_INCREF(astmodulestate(m)->Mult_type);
10243 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010244 0) {
10245 goto error;
10246 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010247 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010248 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10249 goto error;
10250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010251 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010252 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10253 goto error;
10254 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010255 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010256 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10257 goto error;
10258 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010259 Py_INCREF(astmodulestate(m)->Pow_type);
10260 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010261 0) {
10262 goto error;
10263 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010264 Py_INCREF(astmodulestate(m)->LShift_type);
10265 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010266 0) {
10267 goto error;
10268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010269 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010270 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10271 goto error;
10272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010273 Py_INCREF(astmodulestate(m)->BitOr_type);
10274 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010275 0) {
10276 goto error;
10277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010278 Py_INCREF(astmodulestate(m)->BitXor_type);
10279 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010280 0) {
10281 goto error;
10282 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010283 Py_INCREF(astmodulestate(m)->BitAnd_type);
10284 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010285 < 0) {
10286 goto error;
10287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010288 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10289 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010290 0) {
10291 goto error;
10292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010293 Py_INCREF(astmodulestate(m)->unaryop_type);
10294 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010295 0) {
10296 goto error;
10297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010298 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010299 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10300 goto error;
10301 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010302 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010303 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10304 goto error;
10305 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010306 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010307 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10308 goto error;
10309 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010310 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010311 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10312 goto error;
10313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010314 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010315 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10316 goto error;
10317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010318 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010319 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10320 goto error;
10321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010322 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010323 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10324 goto error;
10325 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010326 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010327 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10328 goto error;
10329 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010330 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010331 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10332 goto error;
10333 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010334 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010335 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10336 goto error;
10337 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010338 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010339 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10340 goto error;
10341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010342 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010343 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10344 goto error;
10345 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010346 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010347 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10348 goto error;
10349 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010350 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010351 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10352 goto error;
10353 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010354 Py_INCREF(astmodulestate(m)->NotIn_type);
10355 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010356 astmodulestate_global->comprehension_type) < 0) {
10357 goto error;
10358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010359 Py_INCREF(astmodulestate(m)->comprehension_type);
10360 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010361 astmodulestate_global->excepthandler_type) < 0) {
10362 goto error;
10363 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010364 Py_INCREF(astmodulestate(m)->excepthandler_type);
10365 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010366 astmodulestate_global->ExceptHandler_type) < 0) {
10367 goto error;
10368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010369 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10370 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010371 astmodulestate_global->arguments_type) < 0) {
10372 goto error;
10373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010374 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010375 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10376 goto error;
10377 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010378 Py_INCREF(astmodulestate(m)->arg_type);
10379 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010380 0) {
10381 goto error;
10382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010383 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010384 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10385 goto error;
10386 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010387 Py_INCREF(astmodulestate(m)->alias_type);
10388 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010389 < 0) {
10390 goto error;
10391 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010392 Py_INCREF(astmodulestate(m)->withitem_type);
10393 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010394 astmodulestate_global->type_ignore_type) < 0) {
10395 goto error;
10396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010397 Py_INCREF(astmodulestate(m)->type_ignore_type);
10398 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010399 astmodulestate_global->TypeIgnore_type) < 0) {
10400 goto error;
10401 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010402 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010403 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010404error:
10405 Py_DECREF(m);
10406 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010407}
10408
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010409
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010410PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010411{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010412 if (!init_types())
10413 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010414 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010415}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010416
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010417/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10418mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010419{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010420 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010421 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010422 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010423
Steve Dowerb82e17e2019-05-23 08:45:22 -070010424 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10425 return NULL;
10426 }
10427
Dino Viehlandac46eb42019-09-11 10:16:34 -070010428 req_type[0] = astmodulestate_global->Module_type;
10429 req_type[1] = astmodulestate_global->Expression_type;
10430 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010431
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010432 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010433
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010434 if (!init_types())
10435 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010436
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010437 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10438 if (isinstance == -1)
10439 return NULL;
10440 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010441 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010442 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010443 return NULL;
10444 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010445
10446 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010447 if (obj2ast_mod(ast, &res, arena) != 0)
10448 return NULL;
10449 else
10450 return res;
10451}
10452
10453int PyAST_Check(PyObject* obj)
10454{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010455 if (!init_types())
10456 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010457 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010458}
10459
Martin v. Löwis5b222132007-06-10 09:51:05 +000010460