blob: f58dd9c21787e2e5bf2de80161218574580b81eb [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07003#include <stddef.h>
4
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005#include "Python.h"
6#include "Python-ast.h"
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07007#include "structmember.h"
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008
Dino Viehlandac46eb42019-09-11 10:16:34 -07009typedef struct {
10 int initialized;
11 PyObject *AST_type;
12 PyObject *Add_singleton;
13 PyObject *Add_type;
14 PyObject *And_singleton;
15 PyObject *And_type;
16 PyObject *AnnAssign_type;
17 PyObject *Assert_type;
18 PyObject *Assign_type;
19 PyObject *AsyncFor_type;
20 PyObject *AsyncFunctionDef_type;
21 PyObject *AsyncWith_type;
22 PyObject *Attribute_type;
23 PyObject *AugAssign_type;
24 PyObject *AugLoad_singleton;
25 PyObject *AugLoad_type;
26 PyObject *AugStore_singleton;
27 PyObject *AugStore_type;
28 PyObject *Await_type;
29 PyObject *BinOp_type;
30 PyObject *BitAnd_singleton;
31 PyObject *BitAnd_type;
32 PyObject *BitOr_singleton;
33 PyObject *BitOr_type;
34 PyObject *BitXor_singleton;
35 PyObject *BitXor_type;
36 PyObject *BoolOp_type;
37 PyObject *Break_type;
38 PyObject *Call_type;
39 PyObject *ClassDef_type;
40 PyObject *Compare_type;
41 PyObject *Constant_type;
42 PyObject *Continue_type;
43 PyObject *Del_singleton;
44 PyObject *Del_type;
45 PyObject *Delete_type;
46 PyObject *DictComp_type;
47 PyObject *Dict_type;
48 PyObject *Div_singleton;
49 PyObject *Div_type;
50 PyObject *Eq_singleton;
51 PyObject *Eq_type;
52 PyObject *ExceptHandler_type;
53 PyObject *Expr_type;
54 PyObject *Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070055 PyObject *FloorDiv_singleton;
56 PyObject *FloorDiv_type;
57 PyObject *For_type;
58 PyObject *FormattedValue_type;
59 PyObject *FunctionDef_type;
60 PyObject *FunctionType_type;
61 PyObject *GeneratorExp_type;
62 PyObject *Global_type;
63 PyObject *GtE_singleton;
64 PyObject *GtE_type;
65 PyObject *Gt_singleton;
66 PyObject *Gt_type;
67 PyObject *IfExp_type;
68 PyObject *If_type;
69 PyObject *ImportFrom_type;
70 PyObject *Import_type;
71 PyObject *In_singleton;
72 PyObject *In_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070073 PyObject *Interactive_type;
74 PyObject *Invert_singleton;
75 PyObject *Invert_type;
76 PyObject *IsNot_singleton;
77 PyObject *IsNot_type;
78 PyObject *Is_singleton;
79 PyObject *Is_type;
80 PyObject *JoinedStr_type;
81 PyObject *LShift_singleton;
82 PyObject *LShift_type;
83 PyObject *Lambda_type;
84 PyObject *ListComp_type;
85 PyObject *List_type;
86 PyObject *Load_singleton;
87 PyObject *Load_type;
88 PyObject *LtE_singleton;
89 PyObject *LtE_type;
90 PyObject *Lt_singleton;
91 PyObject *Lt_type;
92 PyObject *MatMult_singleton;
93 PyObject *MatMult_type;
94 PyObject *Mod_singleton;
95 PyObject *Mod_type;
96 PyObject *Module_type;
97 PyObject *Mult_singleton;
98 PyObject *Mult_type;
99 PyObject *Name_type;
100 PyObject *NamedExpr_type;
101 PyObject *Nonlocal_type;
102 PyObject *NotEq_singleton;
103 PyObject *NotEq_type;
104 PyObject *NotIn_singleton;
105 PyObject *NotIn_type;
106 PyObject *Not_singleton;
107 PyObject *Not_type;
108 PyObject *Or_singleton;
109 PyObject *Or_type;
110 PyObject *Param_singleton;
111 PyObject *Param_type;
112 PyObject *Pass_type;
113 PyObject *Pow_singleton;
114 PyObject *Pow_type;
115 PyObject *RShift_singleton;
116 PyObject *RShift_type;
117 PyObject *Raise_type;
118 PyObject *Return_type;
119 PyObject *SetComp_type;
120 PyObject *Set_type;
121 PyObject *Slice_type;
122 PyObject *Starred_type;
123 PyObject *Store_singleton;
124 PyObject *Store_type;
125 PyObject *Sub_singleton;
126 PyObject *Sub_type;
127 PyObject *Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700128 PyObject *Try_type;
129 PyObject *Tuple_type;
130 PyObject *TypeIgnore_type;
131 PyObject *UAdd_singleton;
132 PyObject *UAdd_type;
133 PyObject *USub_singleton;
134 PyObject *USub_type;
135 PyObject *UnaryOp_type;
136 PyObject *While_type;
137 PyObject *With_type;
138 PyObject *YieldFrom_type;
139 PyObject *Yield_type;
140 PyObject *__dict__;
141 PyObject *__module__;
142 PyObject *_ast;
143 PyObject *_attributes;
144 PyObject *_fields;
145 PyObject *alias_type;
146 PyObject *annotation;
147 PyObject *arg;
148 PyObject *arg_type;
149 PyObject *args;
150 PyObject *argtypes;
151 PyObject *arguments_type;
152 PyObject *asname;
153 PyObject *attr;
154 PyObject *bases;
155 PyObject *body;
156 PyObject *boolop_type;
157 PyObject *cause;
158 PyObject *cmpop_type;
159 PyObject *col_offset;
160 PyObject *comparators;
161 PyObject *comprehension_type;
162 PyObject *context_expr;
163 PyObject *conversion;
164 PyObject *ctx;
165 PyObject *decorator_list;
166 PyObject *defaults;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700167 PyObject *elt;
168 PyObject *elts;
169 PyObject *end_col_offset;
170 PyObject *end_lineno;
171 PyObject *exc;
172 PyObject *excepthandler_type;
173 PyObject *expr_context_type;
174 PyObject *expr_type;
175 PyObject *finalbody;
176 PyObject *format_spec;
177 PyObject *func;
178 PyObject *generators;
179 PyObject *handlers;
180 PyObject *id;
181 PyObject *ifs;
182 PyObject *is_async;
183 PyObject *items;
184 PyObject *iter;
185 PyObject *key;
186 PyObject *keys;
187 PyObject *keyword_type;
188 PyObject *keywords;
189 PyObject *kind;
190 PyObject *kw_defaults;
191 PyObject *kwarg;
192 PyObject *kwonlyargs;
193 PyObject *left;
194 PyObject *level;
195 PyObject *lineno;
196 PyObject *lower;
197 PyObject *mod_type;
198 PyObject *module;
199 PyObject *msg;
200 PyObject *name;
201 PyObject *names;
202 PyObject *op;
203 PyObject *operand;
204 PyObject *operator_type;
205 PyObject *ops;
206 PyObject *optional_vars;
207 PyObject *orelse;
208 PyObject *posonlyargs;
209 PyObject *returns;
210 PyObject *right;
211 PyObject *simple;
212 PyObject *slice;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700213 PyObject *step;
214 PyObject *stmt_type;
215 PyObject *tag;
216 PyObject *target;
217 PyObject *targets;
218 PyObject *test;
219 PyObject *type;
220 PyObject *type_comment;
221 PyObject *type_ignore_type;
222 PyObject *type_ignores;
223 PyObject *unaryop_type;
224 PyObject *upper;
225 PyObject *value;
226 PyObject *values;
227 PyObject *vararg;
228 PyObject *withitem_type;
229} astmodulestate;
230
231
232#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
233
234static int astmodule_clear(PyObject *module)
235{
236 Py_CLEAR(astmodulestate(module)->AST_type);
237 Py_CLEAR(astmodulestate(module)->Add_singleton);
238 Py_CLEAR(astmodulestate(module)->Add_type);
239 Py_CLEAR(astmodulestate(module)->And_singleton);
240 Py_CLEAR(astmodulestate(module)->And_type);
241 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
242 Py_CLEAR(astmodulestate(module)->Assert_type);
243 Py_CLEAR(astmodulestate(module)->Assign_type);
244 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
245 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
246 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
247 Py_CLEAR(astmodulestate(module)->Attribute_type);
248 Py_CLEAR(astmodulestate(module)->AugAssign_type);
249 Py_CLEAR(astmodulestate(module)->AugLoad_singleton);
250 Py_CLEAR(astmodulestate(module)->AugLoad_type);
251 Py_CLEAR(astmodulestate(module)->AugStore_singleton);
252 Py_CLEAR(astmodulestate(module)->AugStore_type);
253 Py_CLEAR(astmodulestate(module)->Await_type);
254 Py_CLEAR(astmodulestate(module)->BinOp_type);
255 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
256 Py_CLEAR(astmodulestate(module)->BitAnd_type);
257 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
258 Py_CLEAR(astmodulestate(module)->BitOr_type);
259 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
260 Py_CLEAR(astmodulestate(module)->BitXor_type);
261 Py_CLEAR(astmodulestate(module)->BoolOp_type);
262 Py_CLEAR(astmodulestate(module)->Break_type);
263 Py_CLEAR(astmodulestate(module)->Call_type);
264 Py_CLEAR(astmodulestate(module)->ClassDef_type);
265 Py_CLEAR(astmodulestate(module)->Compare_type);
266 Py_CLEAR(astmodulestate(module)->Constant_type);
267 Py_CLEAR(astmodulestate(module)->Continue_type);
268 Py_CLEAR(astmodulestate(module)->Del_singleton);
269 Py_CLEAR(astmodulestate(module)->Del_type);
270 Py_CLEAR(astmodulestate(module)->Delete_type);
271 Py_CLEAR(astmodulestate(module)->DictComp_type);
272 Py_CLEAR(astmodulestate(module)->Dict_type);
273 Py_CLEAR(astmodulestate(module)->Div_singleton);
274 Py_CLEAR(astmodulestate(module)->Div_type);
275 Py_CLEAR(astmodulestate(module)->Eq_singleton);
276 Py_CLEAR(astmodulestate(module)->Eq_type);
277 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
278 Py_CLEAR(astmodulestate(module)->Expr_type);
279 Py_CLEAR(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700280 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
281 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
282 Py_CLEAR(astmodulestate(module)->For_type);
283 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
284 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
285 Py_CLEAR(astmodulestate(module)->FunctionType_type);
286 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
287 Py_CLEAR(astmodulestate(module)->Global_type);
288 Py_CLEAR(astmodulestate(module)->GtE_singleton);
289 Py_CLEAR(astmodulestate(module)->GtE_type);
290 Py_CLEAR(astmodulestate(module)->Gt_singleton);
291 Py_CLEAR(astmodulestate(module)->Gt_type);
292 Py_CLEAR(astmodulestate(module)->IfExp_type);
293 Py_CLEAR(astmodulestate(module)->If_type);
294 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
295 Py_CLEAR(astmodulestate(module)->Import_type);
296 Py_CLEAR(astmodulestate(module)->In_singleton);
297 Py_CLEAR(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700298 Py_CLEAR(astmodulestate(module)->Interactive_type);
299 Py_CLEAR(astmodulestate(module)->Invert_singleton);
300 Py_CLEAR(astmodulestate(module)->Invert_type);
301 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
302 Py_CLEAR(astmodulestate(module)->IsNot_type);
303 Py_CLEAR(astmodulestate(module)->Is_singleton);
304 Py_CLEAR(astmodulestate(module)->Is_type);
305 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
306 Py_CLEAR(astmodulestate(module)->LShift_singleton);
307 Py_CLEAR(astmodulestate(module)->LShift_type);
308 Py_CLEAR(astmodulestate(module)->Lambda_type);
309 Py_CLEAR(astmodulestate(module)->ListComp_type);
310 Py_CLEAR(astmodulestate(module)->List_type);
311 Py_CLEAR(astmodulestate(module)->Load_singleton);
312 Py_CLEAR(astmodulestate(module)->Load_type);
313 Py_CLEAR(astmodulestate(module)->LtE_singleton);
314 Py_CLEAR(astmodulestate(module)->LtE_type);
315 Py_CLEAR(astmodulestate(module)->Lt_singleton);
316 Py_CLEAR(astmodulestate(module)->Lt_type);
317 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
318 Py_CLEAR(astmodulestate(module)->MatMult_type);
319 Py_CLEAR(astmodulestate(module)->Mod_singleton);
320 Py_CLEAR(astmodulestate(module)->Mod_type);
321 Py_CLEAR(astmodulestate(module)->Module_type);
322 Py_CLEAR(astmodulestate(module)->Mult_singleton);
323 Py_CLEAR(astmodulestate(module)->Mult_type);
324 Py_CLEAR(astmodulestate(module)->Name_type);
325 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
326 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
327 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
328 Py_CLEAR(astmodulestate(module)->NotEq_type);
329 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
330 Py_CLEAR(astmodulestate(module)->NotIn_type);
331 Py_CLEAR(astmodulestate(module)->Not_singleton);
332 Py_CLEAR(astmodulestate(module)->Not_type);
333 Py_CLEAR(astmodulestate(module)->Or_singleton);
334 Py_CLEAR(astmodulestate(module)->Or_type);
335 Py_CLEAR(astmodulestate(module)->Param_singleton);
336 Py_CLEAR(astmodulestate(module)->Param_type);
337 Py_CLEAR(astmodulestate(module)->Pass_type);
338 Py_CLEAR(astmodulestate(module)->Pow_singleton);
339 Py_CLEAR(astmodulestate(module)->Pow_type);
340 Py_CLEAR(astmodulestate(module)->RShift_singleton);
341 Py_CLEAR(astmodulestate(module)->RShift_type);
342 Py_CLEAR(astmodulestate(module)->Raise_type);
343 Py_CLEAR(astmodulestate(module)->Return_type);
344 Py_CLEAR(astmodulestate(module)->SetComp_type);
345 Py_CLEAR(astmodulestate(module)->Set_type);
346 Py_CLEAR(astmodulestate(module)->Slice_type);
347 Py_CLEAR(astmodulestate(module)->Starred_type);
348 Py_CLEAR(astmodulestate(module)->Store_singleton);
349 Py_CLEAR(astmodulestate(module)->Store_type);
350 Py_CLEAR(astmodulestate(module)->Sub_singleton);
351 Py_CLEAR(astmodulestate(module)->Sub_type);
352 Py_CLEAR(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700353 Py_CLEAR(astmodulestate(module)->Try_type);
354 Py_CLEAR(astmodulestate(module)->Tuple_type);
355 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
356 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
357 Py_CLEAR(astmodulestate(module)->UAdd_type);
358 Py_CLEAR(astmodulestate(module)->USub_singleton);
359 Py_CLEAR(astmodulestate(module)->USub_type);
360 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
361 Py_CLEAR(astmodulestate(module)->While_type);
362 Py_CLEAR(astmodulestate(module)->With_type);
363 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
364 Py_CLEAR(astmodulestate(module)->Yield_type);
365 Py_CLEAR(astmodulestate(module)->__dict__);
366 Py_CLEAR(astmodulestate(module)->__module__);
367 Py_CLEAR(astmodulestate(module)->_ast);
368 Py_CLEAR(astmodulestate(module)->_attributes);
369 Py_CLEAR(astmodulestate(module)->_fields);
370 Py_CLEAR(astmodulestate(module)->alias_type);
371 Py_CLEAR(astmodulestate(module)->annotation);
372 Py_CLEAR(astmodulestate(module)->arg);
373 Py_CLEAR(astmodulestate(module)->arg_type);
374 Py_CLEAR(astmodulestate(module)->args);
375 Py_CLEAR(astmodulestate(module)->argtypes);
376 Py_CLEAR(astmodulestate(module)->arguments_type);
377 Py_CLEAR(astmodulestate(module)->asname);
378 Py_CLEAR(astmodulestate(module)->attr);
379 Py_CLEAR(astmodulestate(module)->bases);
380 Py_CLEAR(astmodulestate(module)->body);
381 Py_CLEAR(astmodulestate(module)->boolop_type);
382 Py_CLEAR(astmodulestate(module)->cause);
383 Py_CLEAR(astmodulestate(module)->cmpop_type);
384 Py_CLEAR(astmodulestate(module)->col_offset);
385 Py_CLEAR(astmodulestate(module)->comparators);
386 Py_CLEAR(astmodulestate(module)->comprehension_type);
387 Py_CLEAR(astmodulestate(module)->context_expr);
388 Py_CLEAR(astmodulestate(module)->conversion);
389 Py_CLEAR(astmodulestate(module)->ctx);
390 Py_CLEAR(astmodulestate(module)->decorator_list);
391 Py_CLEAR(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700392 Py_CLEAR(astmodulestate(module)->elt);
393 Py_CLEAR(astmodulestate(module)->elts);
394 Py_CLEAR(astmodulestate(module)->end_col_offset);
395 Py_CLEAR(astmodulestate(module)->end_lineno);
396 Py_CLEAR(astmodulestate(module)->exc);
397 Py_CLEAR(astmodulestate(module)->excepthandler_type);
398 Py_CLEAR(astmodulestate(module)->expr_context_type);
399 Py_CLEAR(astmodulestate(module)->expr_type);
400 Py_CLEAR(astmodulestate(module)->finalbody);
401 Py_CLEAR(astmodulestate(module)->format_spec);
402 Py_CLEAR(astmodulestate(module)->func);
403 Py_CLEAR(astmodulestate(module)->generators);
404 Py_CLEAR(astmodulestate(module)->handlers);
405 Py_CLEAR(astmodulestate(module)->id);
406 Py_CLEAR(astmodulestate(module)->ifs);
407 Py_CLEAR(astmodulestate(module)->is_async);
408 Py_CLEAR(astmodulestate(module)->items);
409 Py_CLEAR(astmodulestate(module)->iter);
410 Py_CLEAR(astmodulestate(module)->key);
411 Py_CLEAR(astmodulestate(module)->keys);
412 Py_CLEAR(astmodulestate(module)->keyword_type);
413 Py_CLEAR(astmodulestate(module)->keywords);
414 Py_CLEAR(astmodulestate(module)->kind);
415 Py_CLEAR(astmodulestate(module)->kw_defaults);
416 Py_CLEAR(astmodulestate(module)->kwarg);
417 Py_CLEAR(astmodulestate(module)->kwonlyargs);
418 Py_CLEAR(astmodulestate(module)->left);
419 Py_CLEAR(astmodulestate(module)->level);
420 Py_CLEAR(astmodulestate(module)->lineno);
421 Py_CLEAR(astmodulestate(module)->lower);
422 Py_CLEAR(astmodulestate(module)->mod_type);
423 Py_CLEAR(astmodulestate(module)->module);
424 Py_CLEAR(astmodulestate(module)->msg);
425 Py_CLEAR(astmodulestate(module)->name);
426 Py_CLEAR(astmodulestate(module)->names);
427 Py_CLEAR(astmodulestate(module)->op);
428 Py_CLEAR(astmodulestate(module)->operand);
429 Py_CLEAR(astmodulestate(module)->operator_type);
430 Py_CLEAR(astmodulestate(module)->ops);
431 Py_CLEAR(astmodulestate(module)->optional_vars);
432 Py_CLEAR(astmodulestate(module)->orelse);
433 Py_CLEAR(astmodulestate(module)->posonlyargs);
434 Py_CLEAR(astmodulestate(module)->returns);
435 Py_CLEAR(astmodulestate(module)->right);
436 Py_CLEAR(astmodulestate(module)->simple);
437 Py_CLEAR(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700438 Py_CLEAR(astmodulestate(module)->step);
439 Py_CLEAR(astmodulestate(module)->stmt_type);
440 Py_CLEAR(astmodulestate(module)->tag);
441 Py_CLEAR(astmodulestate(module)->target);
442 Py_CLEAR(astmodulestate(module)->targets);
443 Py_CLEAR(astmodulestate(module)->test);
444 Py_CLEAR(astmodulestate(module)->type);
445 Py_CLEAR(astmodulestate(module)->type_comment);
446 Py_CLEAR(astmodulestate(module)->type_ignore_type);
447 Py_CLEAR(astmodulestate(module)->type_ignores);
448 Py_CLEAR(astmodulestate(module)->unaryop_type);
449 Py_CLEAR(astmodulestate(module)->upper);
450 Py_CLEAR(astmodulestate(module)->value);
451 Py_CLEAR(astmodulestate(module)->values);
452 Py_CLEAR(astmodulestate(module)->vararg);
453 Py_CLEAR(astmodulestate(module)->withitem_type);
454
455 return 0;
456}
457
458static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
459{
460 Py_VISIT(astmodulestate(module)->AST_type);
461 Py_VISIT(astmodulestate(module)->Add_singleton);
462 Py_VISIT(astmodulestate(module)->Add_type);
463 Py_VISIT(astmodulestate(module)->And_singleton);
464 Py_VISIT(astmodulestate(module)->And_type);
465 Py_VISIT(astmodulestate(module)->AnnAssign_type);
466 Py_VISIT(astmodulestate(module)->Assert_type);
467 Py_VISIT(astmodulestate(module)->Assign_type);
468 Py_VISIT(astmodulestate(module)->AsyncFor_type);
469 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
470 Py_VISIT(astmodulestate(module)->AsyncWith_type);
471 Py_VISIT(astmodulestate(module)->Attribute_type);
472 Py_VISIT(astmodulestate(module)->AugAssign_type);
473 Py_VISIT(astmodulestate(module)->AugLoad_singleton);
474 Py_VISIT(astmodulestate(module)->AugLoad_type);
475 Py_VISIT(astmodulestate(module)->AugStore_singleton);
476 Py_VISIT(astmodulestate(module)->AugStore_type);
477 Py_VISIT(astmodulestate(module)->Await_type);
478 Py_VISIT(astmodulestate(module)->BinOp_type);
479 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
480 Py_VISIT(astmodulestate(module)->BitAnd_type);
481 Py_VISIT(astmodulestate(module)->BitOr_singleton);
482 Py_VISIT(astmodulestate(module)->BitOr_type);
483 Py_VISIT(astmodulestate(module)->BitXor_singleton);
484 Py_VISIT(astmodulestate(module)->BitXor_type);
485 Py_VISIT(astmodulestate(module)->BoolOp_type);
486 Py_VISIT(astmodulestate(module)->Break_type);
487 Py_VISIT(astmodulestate(module)->Call_type);
488 Py_VISIT(astmodulestate(module)->ClassDef_type);
489 Py_VISIT(astmodulestate(module)->Compare_type);
490 Py_VISIT(astmodulestate(module)->Constant_type);
491 Py_VISIT(astmodulestate(module)->Continue_type);
492 Py_VISIT(astmodulestate(module)->Del_singleton);
493 Py_VISIT(astmodulestate(module)->Del_type);
494 Py_VISIT(astmodulestate(module)->Delete_type);
495 Py_VISIT(astmodulestate(module)->DictComp_type);
496 Py_VISIT(astmodulestate(module)->Dict_type);
497 Py_VISIT(astmodulestate(module)->Div_singleton);
498 Py_VISIT(astmodulestate(module)->Div_type);
499 Py_VISIT(astmodulestate(module)->Eq_singleton);
500 Py_VISIT(astmodulestate(module)->Eq_type);
501 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
502 Py_VISIT(astmodulestate(module)->Expr_type);
503 Py_VISIT(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700504 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
505 Py_VISIT(astmodulestate(module)->FloorDiv_type);
506 Py_VISIT(astmodulestate(module)->For_type);
507 Py_VISIT(astmodulestate(module)->FormattedValue_type);
508 Py_VISIT(astmodulestate(module)->FunctionDef_type);
509 Py_VISIT(astmodulestate(module)->FunctionType_type);
510 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
511 Py_VISIT(astmodulestate(module)->Global_type);
512 Py_VISIT(astmodulestate(module)->GtE_singleton);
513 Py_VISIT(astmodulestate(module)->GtE_type);
514 Py_VISIT(astmodulestate(module)->Gt_singleton);
515 Py_VISIT(astmodulestate(module)->Gt_type);
516 Py_VISIT(astmodulestate(module)->IfExp_type);
517 Py_VISIT(astmodulestate(module)->If_type);
518 Py_VISIT(astmodulestate(module)->ImportFrom_type);
519 Py_VISIT(astmodulestate(module)->Import_type);
520 Py_VISIT(astmodulestate(module)->In_singleton);
521 Py_VISIT(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700522 Py_VISIT(astmodulestate(module)->Interactive_type);
523 Py_VISIT(astmodulestate(module)->Invert_singleton);
524 Py_VISIT(astmodulestate(module)->Invert_type);
525 Py_VISIT(astmodulestate(module)->IsNot_singleton);
526 Py_VISIT(astmodulestate(module)->IsNot_type);
527 Py_VISIT(astmodulestate(module)->Is_singleton);
528 Py_VISIT(astmodulestate(module)->Is_type);
529 Py_VISIT(astmodulestate(module)->JoinedStr_type);
530 Py_VISIT(astmodulestate(module)->LShift_singleton);
531 Py_VISIT(astmodulestate(module)->LShift_type);
532 Py_VISIT(astmodulestate(module)->Lambda_type);
533 Py_VISIT(astmodulestate(module)->ListComp_type);
534 Py_VISIT(astmodulestate(module)->List_type);
535 Py_VISIT(astmodulestate(module)->Load_singleton);
536 Py_VISIT(astmodulestate(module)->Load_type);
537 Py_VISIT(astmodulestate(module)->LtE_singleton);
538 Py_VISIT(astmodulestate(module)->LtE_type);
539 Py_VISIT(astmodulestate(module)->Lt_singleton);
540 Py_VISIT(astmodulestate(module)->Lt_type);
541 Py_VISIT(astmodulestate(module)->MatMult_singleton);
542 Py_VISIT(astmodulestate(module)->MatMult_type);
543 Py_VISIT(astmodulestate(module)->Mod_singleton);
544 Py_VISIT(astmodulestate(module)->Mod_type);
545 Py_VISIT(astmodulestate(module)->Module_type);
546 Py_VISIT(astmodulestate(module)->Mult_singleton);
547 Py_VISIT(astmodulestate(module)->Mult_type);
548 Py_VISIT(astmodulestate(module)->Name_type);
549 Py_VISIT(astmodulestate(module)->NamedExpr_type);
550 Py_VISIT(astmodulestate(module)->Nonlocal_type);
551 Py_VISIT(astmodulestate(module)->NotEq_singleton);
552 Py_VISIT(astmodulestate(module)->NotEq_type);
553 Py_VISIT(astmodulestate(module)->NotIn_singleton);
554 Py_VISIT(astmodulestate(module)->NotIn_type);
555 Py_VISIT(astmodulestate(module)->Not_singleton);
556 Py_VISIT(astmodulestate(module)->Not_type);
557 Py_VISIT(astmodulestate(module)->Or_singleton);
558 Py_VISIT(astmodulestate(module)->Or_type);
559 Py_VISIT(astmodulestate(module)->Param_singleton);
560 Py_VISIT(astmodulestate(module)->Param_type);
561 Py_VISIT(astmodulestate(module)->Pass_type);
562 Py_VISIT(astmodulestate(module)->Pow_singleton);
563 Py_VISIT(astmodulestate(module)->Pow_type);
564 Py_VISIT(astmodulestate(module)->RShift_singleton);
565 Py_VISIT(astmodulestate(module)->RShift_type);
566 Py_VISIT(astmodulestate(module)->Raise_type);
567 Py_VISIT(astmodulestate(module)->Return_type);
568 Py_VISIT(astmodulestate(module)->SetComp_type);
569 Py_VISIT(astmodulestate(module)->Set_type);
570 Py_VISIT(astmodulestate(module)->Slice_type);
571 Py_VISIT(astmodulestate(module)->Starred_type);
572 Py_VISIT(astmodulestate(module)->Store_singleton);
573 Py_VISIT(astmodulestate(module)->Store_type);
574 Py_VISIT(astmodulestate(module)->Sub_singleton);
575 Py_VISIT(astmodulestate(module)->Sub_type);
576 Py_VISIT(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700577 Py_VISIT(astmodulestate(module)->Try_type);
578 Py_VISIT(astmodulestate(module)->Tuple_type);
579 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
580 Py_VISIT(astmodulestate(module)->UAdd_singleton);
581 Py_VISIT(astmodulestate(module)->UAdd_type);
582 Py_VISIT(astmodulestate(module)->USub_singleton);
583 Py_VISIT(astmodulestate(module)->USub_type);
584 Py_VISIT(astmodulestate(module)->UnaryOp_type);
585 Py_VISIT(astmodulestate(module)->While_type);
586 Py_VISIT(astmodulestate(module)->With_type);
587 Py_VISIT(astmodulestate(module)->YieldFrom_type);
588 Py_VISIT(astmodulestate(module)->Yield_type);
589 Py_VISIT(astmodulestate(module)->__dict__);
590 Py_VISIT(astmodulestate(module)->__module__);
591 Py_VISIT(astmodulestate(module)->_ast);
592 Py_VISIT(astmodulestate(module)->_attributes);
593 Py_VISIT(astmodulestate(module)->_fields);
594 Py_VISIT(astmodulestate(module)->alias_type);
595 Py_VISIT(astmodulestate(module)->annotation);
596 Py_VISIT(astmodulestate(module)->arg);
597 Py_VISIT(astmodulestate(module)->arg_type);
598 Py_VISIT(astmodulestate(module)->args);
599 Py_VISIT(astmodulestate(module)->argtypes);
600 Py_VISIT(astmodulestate(module)->arguments_type);
601 Py_VISIT(astmodulestate(module)->asname);
602 Py_VISIT(astmodulestate(module)->attr);
603 Py_VISIT(astmodulestate(module)->bases);
604 Py_VISIT(astmodulestate(module)->body);
605 Py_VISIT(astmodulestate(module)->boolop_type);
606 Py_VISIT(astmodulestate(module)->cause);
607 Py_VISIT(astmodulestate(module)->cmpop_type);
608 Py_VISIT(astmodulestate(module)->col_offset);
609 Py_VISIT(astmodulestate(module)->comparators);
610 Py_VISIT(astmodulestate(module)->comprehension_type);
611 Py_VISIT(astmodulestate(module)->context_expr);
612 Py_VISIT(astmodulestate(module)->conversion);
613 Py_VISIT(astmodulestate(module)->ctx);
614 Py_VISIT(astmodulestate(module)->decorator_list);
615 Py_VISIT(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700616 Py_VISIT(astmodulestate(module)->elt);
617 Py_VISIT(astmodulestate(module)->elts);
618 Py_VISIT(astmodulestate(module)->end_col_offset);
619 Py_VISIT(astmodulestate(module)->end_lineno);
620 Py_VISIT(astmodulestate(module)->exc);
621 Py_VISIT(astmodulestate(module)->excepthandler_type);
622 Py_VISIT(astmodulestate(module)->expr_context_type);
623 Py_VISIT(astmodulestate(module)->expr_type);
624 Py_VISIT(astmodulestate(module)->finalbody);
625 Py_VISIT(astmodulestate(module)->format_spec);
626 Py_VISIT(astmodulestate(module)->func);
627 Py_VISIT(astmodulestate(module)->generators);
628 Py_VISIT(astmodulestate(module)->handlers);
629 Py_VISIT(astmodulestate(module)->id);
630 Py_VISIT(astmodulestate(module)->ifs);
631 Py_VISIT(astmodulestate(module)->is_async);
632 Py_VISIT(astmodulestate(module)->items);
633 Py_VISIT(astmodulestate(module)->iter);
634 Py_VISIT(astmodulestate(module)->key);
635 Py_VISIT(astmodulestate(module)->keys);
636 Py_VISIT(astmodulestate(module)->keyword_type);
637 Py_VISIT(astmodulestate(module)->keywords);
638 Py_VISIT(astmodulestate(module)->kind);
639 Py_VISIT(astmodulestate(module)->kw_defaults);
640 Py_VISIT(astmodulestate(module)->kwarg);
641 Py_VISIT(astmodulestate(module)->kwonlyargs);
642 Py_VISIT(astmodulestate(module)->left);
643 Py_VISIT(astmodulestate(module)->level);
644 Py_VISIT(astmodulestate(module)->lineno);
645 Py_VISIT(astmodulestate(module)->lower);
646 Py_VISIT(astmodulestate(module)->mod_type);
647 Py_VISIT(astmodulestate(module)->module);
648 Py_VISIT(astmodulestate(module)->msg);
649 Py_VISIT(astmodulestate(module)->name);
650 Py_VISIT(astmodulestate(module)->names);
651 Py_VISIT(astmodulestate(module)->op);
652 Py_VISIT(astmodulestate(module)->operand);
653 Py_VISIT(astmodulestate(module)->operator_type);
654 Py_VISIT(astmodulestate(module)->ops);
655 Py_VISIT(astmodulestate(module)->optional_vars);
656 Py_VISIT(astmodulestate(module)->orelse);
657 Py_VISIT(astmodulestate(module)->posonlyargs);
658 Py_VISIT(astmodulestate(module)->returns);
659 Py_VISIT(astmodulestate(module)->right);
660 Py_VISIT(astmodulestate(module)->simple);
661 Py_VISIT(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700662 Py_VISIT(astmodulestate(module)->step);
663 Py_VISIT(astmodulestate(module)->stmt_type);
664 Py_VISIT(astmodulestate(module)->tag);
665 Py_VISIT(astmodulestate(module)->target);
666 Py_VISIT(astmodulestate(module)->targets);
667 Py_VISIT(astmodulestate(module)->test);
668 Py_VISIT(astmodulestate(module)->type);
669 Py_VISIT(astmodulestate(module)->type_comment);
670 Py_VISIT(astmodulestate(module)->type_ignore_type);
671 Py_VISIT(astmodulestate(module)->type_ignores);
672 Py_VISIT(astmodulestate(module)->unaryop_type);
673 Py_VISIT(astmodulestate(module)->upper);
674 Py_VISIT(astmodulestate(module)->value);
675 Py_VISIT(astmodulestate(module)->values);
676 Py_VISIT(astmodulestate(module)->vararg);
677 Py_VISIT(astmodulestate(module)->withitem_type);
678
679 return 0;
680}
681
682static void astmodule_free(void* module) {
683 astmodule_clear((PyObject*)module);
684}
685
686static struct PyModuleDef _astmodule = {
687 PyModuleDef_HEAD_INIT,
688 "_ast",
689 NULL,
690 sizeof(astmodulestate),
691 NULL,
692 NULL,
693 astmodule_traverse,
694 astmodule_clear,
695 astmodule_free,
696};
697
698#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
699
700static int init_identifiers(void)
701{
702 astmodulestate *state = astmodulestate_global;
703 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
704 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
705 if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0;
706 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
707 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
708 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
709 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
710 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
711 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
712 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
713 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
714 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
715 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
716 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
717 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
718 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
719 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
720 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
721 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
722 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
723 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700724 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
725 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
726 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
727 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
728 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
729 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
730 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
731 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
732 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
733 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
734 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
735 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
736 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
737 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
738 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
739 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
740 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
741 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
742 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
743 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
744 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
745 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
746 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
747 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
748 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
749 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
750 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
751 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
752 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
753 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
754 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
755 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
756 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
757 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
758 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
759 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
760 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
761 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
762 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
763 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
764 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
765 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
766 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
767 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
768 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
769 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
770 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
771 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
772 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
773 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
774 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
775 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
776 return 1;
777};
778
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000779static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300780static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200781 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800782 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000783};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300784static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200785 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000786};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300787static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200788 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000789};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300790static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800791 "argtypes",
792 "returns",
793};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300794static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200795 "lineno",
796 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000797 "end_lineno",
798 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000799};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000800static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300801static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200802 "name",
803 "args",
804 "body",
805 "decorator_list",
806 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800807 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000808};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300809static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400810 "name",
811 "args",
812 "body",
813 "decorator_list",
814 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800815 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400816};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300817static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200818 "name",
819 "bases",
820 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200821 "body",
822 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000823};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300824static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200825 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000826};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300827static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200828 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000829};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300830static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200831 "targets",
832 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800833 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000834};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300835static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200836 "target",
837 "op",
838 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000839};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300840static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700841 "target",
842 "annotation",
843 "value",
844 "simple",
845};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300846static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200847 "target",
848 "iter",
849 "body",
850 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800851 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000852};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300853static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400854 "target",
855 "iter",
856 "body",
857 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800858 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400859};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300860static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200861 "test",
862 "body",
863 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000864};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300865static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200866 "test",
867 "body",
868 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000869};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300870static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200871 "items",
872 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800873 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000874};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300875static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400876 "items",
877 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800878 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400879};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300880static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200881 "exc",
882 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000883};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300884static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200885 "body",
886 "handlers",
887 "orelse",
888 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000889};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300890static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200891 "test",
892 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000893};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300894static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200895 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000896};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300897static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200898 "module",
899 "names",
900 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000901};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300902static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200903 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000904};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300905static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200906 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000907};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300908static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200909 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000910};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300911static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200912 "lineno",
913 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000914 "end_lineno",
915 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000916};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000917static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300918static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200919 "op",
920 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000921};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300922static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700923 "target",
924 "value",
925};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300926static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200927 "left",
928 "op",
929 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000930};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300931static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200932 "op",
933 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000934};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300935static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200936 "args",
937 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000938};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300939static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200940 "test",
941 "body",
942 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000943};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300944static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200945 "keys",
946 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000947};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300948static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200949 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000950};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300951static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200952 "elt",
953 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000954};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300955static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200956 "elt",
957 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000958};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300959static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200960 "key",
961 "value",
962 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000963};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300964static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200965 "elt",
966 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000967};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300968static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400969 "value",
970};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300971static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200972 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500973};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300974static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200975 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000976};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300977static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200978 "left",
979 "ops",
980 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000981};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300982static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200983 "func",
984 "args",
985 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000986};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300987static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400988 "value",
989 "conversion",
990 "format_spec",
991};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300992static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400993 "values",
994};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300995static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100996 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -0700997 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100998};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300999static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001000 "value",
1001 "attr",
1002 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001003};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001004static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001005 "value",
1006 "slice",
1007 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001008};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001009static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001010 "value",
1011 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +00001012};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001013static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001014 "id",
1015 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001016};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001017static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001018 "elts",
1019 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001020};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001021static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001022 "elts",
1023 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001024};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001025static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001026 "lower",
1027 "upper",
1028 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001029};
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001030static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001031static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001032static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001033static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001034static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001035static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001036static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001037 "target",
1038 "iter",
1039 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001040 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001041};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001042static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001043 "lineno",
1044 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001045 "end_lineno",
1046 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001047};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001048static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001049static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001050 "type",
1051 "name",
1052 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001053};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001054static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001055static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001056 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001057 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001058 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001059 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001060 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001061 "kwarg",
1062 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001063};
Neal Norwitzc1505362006-12-28 06:47:50 +00001064static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001065static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001066 "lineno",
1067 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001068 "end_lineno",
1069 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001070};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001071static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001072 "arg",
1073 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001074 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001075};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001076static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001077static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001078 "arg",
1079 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001080};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001081static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001082static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001083 "name",
1084 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001085};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001086static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001087static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001088 "context_expr",
1089 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001090};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001091static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001092static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001093 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001094 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001095};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001096
1097
INADA Naokifc489082017-01-25 22:33:43 +09001098
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001099typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001100 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001101 PyObject *dict;
1102} AST_object;
1103
Benjamin Peterson1767e022012-03-14 21:50:29 -05001104static void
1105ast_dealloc(AST_object *self)
1106{
INADA Naokia6296d32017-08-24 14:55:17 +09001107 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001108 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001109 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001110 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001111 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1112 assert(free_func != NULL);
1113 free_func(self);
1114 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001115}
1116
Neal Norwitz207c9f32008-03-31 04:42:11 +00001117static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001118ast_traverse(AST_object *self, visitproc visit, void *arg)
1119{
1120 Py_VISIT(self->dict);
1121 return 0;
1122}
1123
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001124static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001125ast_clear(AST_object *self)
1126{
1127 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001128 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001129}
1130
1131static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001132ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1133{
1134 Py_ssize_t i, numfields = 0;
1135 int res = -1;
1136 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001137 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001138 goto cleanup;
1139 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001140 if (fields) {
1141 numfields = PySequence_Size(fields);
1142 if (numfields == -1)
1143 goto cleanup;
1144 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001145
Neal Norwitz207c9f32008-03-31 04:42:11 +00001146 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001147 if (numfields < PyTuple_GET_SIZE(args)) {
1148 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1149 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001150 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001151 numfields, numfields == 1 ? "" : "s");
1152 res = -1;
1153 goto cleanup;
1154 }
1155 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1156 /* cannot be reached when fields is NULL */
1157 PyObject *name = PySequence_GetItem(fields, i);
1158 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001159 res = -1;
1160 goto cleanup;
1161 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001162 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1163 Py_DECREF(name);
1164 if (res < 0)
1165 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001166 }
1167 if (kw) {
1168 i = 0; /* needed by PyDict_Next */
1169 while (PyDict_Next(kw, &i, &key, &value)) {
1170 res = PyObject_SetAttr(self, key, value);
1171 if (res < 0)
1172 goto cleanup;
1173 }
1174 }
1175 cleanup:
1176 Py_XDECREF(fields);
1177 return res;
1178}
1179
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001180/* Pickling support */
1181static PyObject *
1182ast_type_reduce(PyObject *self, PyObject *unused)
1183{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001184 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001185 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001186 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001187 }
1188 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001189 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001190 }
1191 return Py_BuildValue("O()", Py_TYPE(self));
1192}
1193
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001194static PyMemberDef ast_type_members[] = {
1195 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1196 {NULL} /* Sentinel */
1197};
1198
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001199static PyMethodDef ast_type_methods[] = {
1200 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1201 {NULL}
1202};
1203
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001204static PyGetSetDef ast_type_getsets[] = {
1205 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1206 {NULL}
1207};
1208
Dino Viehlandac46eb42019-09-11 10:16:34 -07001209static PyType_Slot AST_type_slots[] = {
1210 {Py_tp_dealloc, ast_dealloc},
1211 {Py_tp_getattro, PyObject_GenericGetAttr},
1212 {Py_tp_setattro, PyObject_GenericSetAttr},
1213 {Py_tp_traverse, ast_traverse},
1214 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001215 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001216 {Py_tp_methods, ast_type_methods},
1217 {Py_tp_getset, ast_type_getsets},
1218 {Py_tp_init, ast_type_init},
1219 {Py_tp_alloc, PyType_GenericAlloc},
1220 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001221 {Py_tp_free, PyObject_GC_Del},
1222 {0, 0},
1223};
1224
1225static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001226 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001227 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001228 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001229 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1230 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001231};
1232
Dino Viehlandac46eb42019-09-11 10:16:34 -07001233static PyObject *
1234make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001235{
1236 PyObject *fnames, *result;
1237 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001238 fnames = PyTuple_New(num_fields);
1239 if (!fnames) return NULL;
1240 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001241 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001242 if (!field) {
1243 Py_DECREF(fnames);
1244 return NULL;
1245 }
1246 PyTuple_SET_ITEM(fnames, i, field);
1247 }
INADA Naokifc489082017-01-25 22:33:43 +09001248 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1249 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001250 astmodulestate_global->_fields, fnames,
1251 astmodulestate_global->__module__,
1252 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001253 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001254 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001255}
1256
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001257static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001258add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001259{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001260 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001261 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001262 if (!l)
1263 return 0;
1264 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001265 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001266 if (!s) {
1267 Py_DECREF(l);
1268 return 0;
1269 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001270 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001272 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001273 Py_DECREF(l);
1274 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001275}
1276
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001277/* Conversion AST -> Python */
1278
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001279static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1280{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001281 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001282 PyObject *result = PyList_New(n);
1283 PyObject *value;
1284 if (!result)
1285 return NULL;
1286 for (i = 0; i < n; i++) {
1287 value = func(asdl_seq_GET(seq, i));
1288 if (!value) {
1289 Py_DECREF(result);
1290 return NULL;
1291 }
1292 PyList_SET_ITEM(result, i, value);
1293 }
1294 return result;
1295}
1296
1297static PyObject* ast2obj_object(void *o)
1298{
1299 if (!o)
1300 o = Py_None;
1301 Py_INCREF((PyObject*)o);
1302 return (PyObject*)o;
1303}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001304#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001305#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001306#define ast2obj_identifier ast2obj_object
1307#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001308#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001309
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001310static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001311{
Christian Heimes217cfd12007-12-02 14:31:20 +00001312 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001313}
1314
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001315/* Conversion Python -> AST */
1316
1317static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1318{
1319 if (obj == Py_None)
1320 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001321 if (obj) {
1322 if (PyArena_AddPyObject(arena, obj) < 0) {
1323 *out = NULL;
1324 return -1;
1325 }
1326 Py_INCREF(obj);
1327 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001328 *out = obj;
1329 return 0;
1330}
1331
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001332static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1333{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001334 if (PyArena_AddPyObject(arena, obj) < 0) {
1335 *out = NULL;
1336 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001337 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001338 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001339 *out = obj;
1340 return 0;
1341}
1342
Benjamin Peterson180e6352011-07-22 11:09:07 -05001343static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001344{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001345 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1346 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001347 return 1;
1348 }
1349 return obj2ast_object(obj, out, arena);
1350}
1351
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001352static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1353{
1354 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1355 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1356 return 1;
1357 }
1358 return obj2ast_object(obj, out, arena);
1359}
1360
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001361static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1362{
1363 int i;
1364 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001365 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001366 return 1;
1367 }
1368
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001369 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001370 if (i == -1 && PyErr_Occurred())
1371 return 1;
1372 *out = i;
1373 return 0;
1374}
1375
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001376static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001377{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001378 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001379 empty_tuple = PyTuple_New(0);
1380 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001381 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1382 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001383 Py_XDECREF(empty_tuple);
1384 return -1;
1385 }
1386 Py_DECREF(empty_tuple);
1387 return 0;
1388}
1389
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001390
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001391static int init_types(void)
1392{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001393 PyObject *m;
1394 if (PyState_FindModule(&_astmodule) == NULL) {
1395 m = PyModule_Create(&_astmodule);
1396 if (!m) return 0;
1397 PyState_AddModule(m, &_astmodule);
1398 }
1399 astmodulestate *state = astmodulestate_global;
1400 if (state->initialized) return 1;
1401 if (init_identifiers() < 0) return 0;
1402 state->AST_type = PyType_FromSpec(&AST_type_spec);
1403 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001404 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001405 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1406 if (!state->mod_type) return 0;
1407 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1408 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1409 if (!state->Module_type) return 0;
1410 state->Interactive_type = make_type("Interactive", state->mod_type,
1411 Interactive_fields, 1);
1412 if (!state->Interactive_type) return 0;
1413 state->Expression_type = make_type("Expression", state->mod_type,
1414 Expression_fields, 1);
1415 if (!state->Expression_type) return 0;
1416 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1417 FunctionType_fields, 2);
1418 if (!state->FunctionType_type) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001419 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1420 if (!state->stmt_type) return 0;
1421 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001422 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1423 return 0;
1424 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1425 -1)
1426 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001427 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1428 FunctionDef_fields, 6);
1429 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001430 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1431 -1)
1432 return 0;
1433 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1434 == -1)
1435 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001436 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1437 state->stmt_type,
1438 AsyncFunctionDef_fields, 6);
1439 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001440 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1441 == -1)
1442 return 0;
1443 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1444 Py_None) == -1)
1445 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001446 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1447 ClassDef_fields, 5);
1448 if (!state->ClassDef_type) return 0;
1449 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1450 1);
1451 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001452 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1453 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001454 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1455 1);
1456 if (!state->Delete_type) return 0;
1457 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1458 3);
1459 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001460 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1461 -1)
1462 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001463 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1464 AugAssign_fields, 3);
1465 if (!state->AugAssign_type) return 0;
1466 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1467 AnnAssign_fields, 4);
1468 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001469 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1470 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001471 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1472 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001473 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1474 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001475 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1476 AsyncFor_fields, 5);
1477 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001478 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1479 -1)
1480 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001481 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1482 if (!state->While_type) return 0;
1483 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1484 if (!state->If_type) return 0;
1485 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1486 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001487 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1488 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001489 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1490 AsyncWith_fields, 3);
1491 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001492 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1493 == -1)
1494 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001495 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1496 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001497 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1498 return 0;
1499 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1500 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001501 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1502 if (!state->Try_type) return 0;
1503 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1504 2);
1505 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001506 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1507 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001508 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1509 1);
1510 if (!state->Import_type) return 0;
1511 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1512 ImportFrom_fields, 3);
1513 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001514 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1515 return 0;
1516 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1517 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001518 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1519 1);
1520 if (!state->Global_type) return 0;
1521 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1522 Nonlocal_fields, 1);
1523 if (!state->Nonlocal_type) return 0;
1524 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1525 if (!state->Expr_type) return 0;
1526 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1527 if (!state->Pass_type) return 0;
1528 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1529 if (!state->Break_type) return 0;
1530 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1531 if (!state->Continue_type) return 0;
1532 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1533 if (!state->expr_type) return 0;
1534 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001535 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1536 return 0;
1537 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1538 -1)
1539 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001540 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1541 2);
1542 if (!state->BoolOp_type) return 0;
1543 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1544 NamedExpr_fields, 2);
1545 if (!state->NamedExpr_type) return 0;
1546 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1547 if (!state->BinOp_type) return 0;
1548 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1549 UnaryOp_fields, 2);
1550 if (!state->UnaryOp_type) return 0;
1551 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1552 2);
1553 if (!state->Lambda_type) return 0;
1554 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1555 if (!state->IfExp_type) return 0;
1556 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1557 if (!state->Dict_type) return 0;
1558 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1559 if (!state->Set_type) return 0;
1560 state->ListComp_type = make_type("ListComp", state->expr_type,
1561 ListComp_fields, 2);
1562 if (!state->ListComp_type) return 0;
1563 state->SetComp_type = make_type("SetComp", state->expr_type,
1564 SetComp_fields, 2);
1565 if (!state->SetComp_type) return 0;
1566 state->DictComp_type = make_type("DictComp", state->expr_type,
1567 DictComp_fields, 3);
1568 if (!state->DictComp_type) return 0;
1569 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1570 GeneratorExp_fields, 2);
1571 if (!state->GeneratorExp_type) return 0;
1572 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1573 if (!state->Await_type) return 0;
1574 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1575 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001576 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1577 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001578 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1579 YieldFrom_fields, 1);
1580 if (!state->YieldFrom_type) return 0;
1581 state->Compare_type = make_type("Compare", state->expr_type,
1582 Compare_fields, 3);
1583 if (!state->Compare_type) return 0;
1584 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1585 if (!state->Call_type) return 0;
1586 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1587 FormattedValue_fields, 3);
1588 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001589 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1590 Py_None) == -1)
1591 return 0;
1592 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1593 Py_None) == -1)
1594 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001595 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1596 JoinedStr_fields, 1);
1597 if (!state->JoinedStr_type) return 0;
1598 state->Constant_type = make_type("Constant", state->expr_type,
1599 Constant_fields, 2);
1600 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001601 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1602 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001603 state->Attribute_type = make_type("Attribute", state->expr_type,
1604 Attribute_fields, 3);
1605 if (!state->Attribute_type) return 0;
1606 state->Subscript_type = make_type("Subscript", state->expr_type,
1607 Subscript_fields, 3);
1608 if (!state->Subscript_type) return 0;
1609 state->Starred_type = make_type("Starred", state->expr_type,
1610 Starred_fields, 2);
1611 if (!state->Starred_type) return 0;
1612 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1613 if (!state->Name_type) return 0;
1614 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1615 if (!state->List_type) return 0;
1616 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1617 if (!state->Tuple_type) return 0;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001618 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3);
1619 if (!state->Slice_type) return 0;
1620 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1621 return 0;
1622 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1623 return 0;
1624 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1625 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001626 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1627 0);
1628 if (!state->expr_context_type) return 0;
1629 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1630 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1631 if (!state->Load_type) return 0;
1632 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1633 NULL, NULL);
1634 if (!state->Load_singleton) return 0;
1635 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1636 if (!state->Store_type) return 0;
1637 state->Store_singleton = PyType_GenericNew((PyTypeObject
1638 *)state->Store_type, NULL, NULL);
1639 if (!state->Store_singleton) return 0;
1640 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1641 if (!state->Del_type) return 0;
1642 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1643 NULL, NULL);
1644 if (!state->Del_singleton) return 0;
1645 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1646 0);
1647 if (!state->AugLoad_type) return 0;
1648 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1649 *)state->AugLoad_type, NULL,
1650 NULL);
1651 if (!state->AugLoad_singleton) return 0;
1652 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1653 NULL, 0);
1654 if (!state->AugStore_type) return 0;
1655 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1656 *)state->AugStore_type, NULL,
1657 NULL);
1658 if (!state->AugStore_singleton) return 0;
1659 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1660 if (!state->Param_type) return 0;
1661 state->Param_singleton = PyType_GenericNew((PyTypeObject
1662 *)state->Param_type, NULL, NULL);
1663 if (!state->Param_singleton) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001664 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1665 if (!state->boolop_type) return 0;
1666 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1667 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1668 if (!state->And_type) return 0;
1669 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1670 NULL, NULL);
1671 if (!state->And_singleton) return 0;
1672 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1673 if (!state->Or_type) return 0;
1674 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1675 NULL, NULL);
1676 if (!state->Or_singleton) return 0;
1677 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1678 if (!state->operator_type) return 0;
1679 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1680 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1681 if (!state->Add_type) return 0;
1682 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1683 NULL, NULL);
1684 if (!state->Add_singleton) return 0;
1685 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1686 if (!state->Sub_type) return 0;
1687 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1688 NULL, NULL);
1689 if (!state->Sub_singleton) return 0;
1690 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1691 if (!state->Mult_type) return 0;
1692 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1693 NULL, NULL);
1694 if (!state->Mult_singleton) return 0;
1695 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1696 if (!state->MatMult_type) return 0;
1697 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1698 *)state->MatMult_type, NULL,
1699 NULL);
1700 if (!state->MatMult_singleton) return 0;
1701 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1702 if (!state->Div_type) return 0;
1703 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1704 NULL, NULL);
1705 if (!state->Div_singleton) return 0;
1706 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1707 if (!state->Mod_type) return 0;
1708 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1709 NULL, NULL);
1710 if (!state->Mod_singleton) return 0;
1711 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1712 if (!state->Pow_type) return 0;
1713 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1714 NULL, NULL);
1715 if (!state->Pow_singleton) return 0;
1716 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1717 if (!state->LShift_type) return 0;
1718 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1719 *)state->LShift_type, NULL,
1720 NULL);
1721 if (!state->LShift_singleton) return 0;
1722 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1723 if (!state->RShift_type) return 0;
1724 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1725 *)state->RShift_type, NULL,
1726 NULL);
1727 if (!state->RShift_singleton) return 0;
1728 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1729 if (!state->BitOr_type) return 0;
1730 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1731 *)state->BitOr_type, NULL, NULL);
1732 if (!state->BitOr_singleton) return 0;
1733 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1734 if (!state->BitXor_type) return 0;
1735 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1736 *)state->BitXor_type, NULL,
1737 NULL);
1738 if (!state->BitXor_singleton) return 0;
1739 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1740 if (!state->BitAnd_type) return 0;
1741 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1742 *)state->BitAnd_type, NULL,
1743 NULL);
1744 if (!state->BitAnd_singleton) return 0;
1745 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1746 if (!state->FloorDiv_type) return 0;
1747 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1748 *)state->FloorDiv_type, NULL,
1749 NULL);
1750 if (!state->FloorDiv_singleton) return 0;
1751 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1752 if (!state->unaryop_type) return 0;
1753 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1754 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1755 if (!state->Invert_type) return 0;
1756 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1757 *)state->Invert_type, NULL,
1758 NULL);
1759 if (!state->Invert_singleton) return 0;
1760 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1761 if (!state->Not_type) return 0;
1762 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1763 NULL, NULL);
1764 if (!state->Not_singleton) return 0;
1765 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1766 if (!state->UAdd_type) return 0;
1767 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1768 NULL, NULL);
1769 if (!state->UAdd_singleton) return 0;
1770 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1771 if (!state->USub_type) return 0;
1772 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1773 NULL, NULL);
1774 if (!state->USub_singleton) return 0;
1775 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1776 if (!state->cmpop_type) return 0;
1777 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1778 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1779 if (!state->Eq_type) return 0;
1780 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1781 NULL, NULL);
1782 if (!state->Eq_singleton) return 0;
1783 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1784 if (!state->NotEq_type) return 0;
1785 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1786 *)state->NotEq_type, NULL, NULL);
1787 if (!state->NotEq_singleton) return 0;
1788 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1789 if (!state->Lt_type) return 0;
1790 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1791 NULL, NULL);
1792 if (!state->Lt_singleton) return 0;
1793 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1794 if (!state->LtE_type) return 0;
1795 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1796 NULL, NULL);
1797 if (!state->LtE_singleton) return 0;
1798 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1799 if (!state->Gt_type) return 0;
1800 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1801 NULL, NULL);
1802 if (!state->Gt_singleton) return 0;
1803 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1804 if (!state->GtE_type) return 0;
1805 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1806 NULL, NULL);
1807 if (!state->GtE_singleton) return 0;
1808 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1809 if (!state->Is_type) return 0;
1810 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1811 NULL, NULL);
1812 if (!state->Is_singleton) return 0;
1813 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1814 if (!state->IsNot_type) return 0;
1815 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1816 *)state->IsNot_type, NULL, NULL);
1817 if (!state->IsNot_singleton) return 0;
1818 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1819 if (!state->In_type) return 0;
1820 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1821 NULL, NULL);
1822 if (!state->In_singleton) return 0;
1823 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1824 if (!state->NotIn_type) return 0;
1825 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1826 *)state->NotIn_type, NULL, NULL);
1827 if (!state->NotIn_singleton) return 0;
1828 state->comprehension_type = make_type("comprehension", state->AST_type,
1829 comprehension_fields, 4);
1830 if (!state->comprehension_type) return 0;
1831 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1832 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1833 NULL, 0);
1834 if (!state->excepthandler_type) return 0;
1835 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1836 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001837 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1838 == -1)
1839 return 0;
1840 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1841 Py_None) == -1)
1842 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001843 state->ExceptHandler_type = make_type("ExceptHandler",
1844 state->excepthandler_type,
1845 ExceptHandler_fields, 3);
1846 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001847 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1848 return 0;
1849 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1850 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001851 state->arguments_type = make_type("arguments", state->AST_type,
1852 arguments_fields, 7);
1853 if (!state->arguments_type) return 0;
1854 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001855 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1856 return 0;
1857 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1858 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001859 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1860 if (!state->arg_type) return 0;
1861 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001862 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1863 return 0;
1864 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1865 return 0;
1866 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1867 return 0;
1868 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1869 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001870 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1871 2);
1872 if (!state->keyword_type) return 0;
1873 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001874 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1875 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001876 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1877 if (!state->alias_type) return 0;
1878 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001879 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1880 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001881 state->withitem_type = make_type("withitem", state->AST_type,
1882 withitem_fields, 2);
1883 if (!state->withitem_type) return 0;
1884 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001885 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1886 == -1)
1887 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001888 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1889 0);
1890 if (!state->type_ignore_type) return 0;
1891 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1892 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1893 TypeIgnore_fields, 2);
1894 if (!state->TypeIgnore_type) return 0;
1895 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001896 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001897}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001898
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001899static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1900static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1901static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1902static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1903 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001904static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1905static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1906static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1907static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1908static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1909 arena);
1910static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1911 arena);
1912static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1913static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1914static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1915static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001916static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001917static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1918 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001919
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001920mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001921Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001922{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001923 mod_ty p;
1924 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1925 if (!p)
1926 return NULL;
1927 p->kind = Module_kind;
1928 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001929 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001930 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931}
1932
1933mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001934Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001935{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001936 mod_ty p;
1937 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1938 if (!p)
1939 return NULL;
1940 p->kind = Interactive_kind;
1941 p->v.Interactive.body = body;
1942 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001943}
1944
1945mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001946Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001948 mod_ty p;
1949 if (!body) {
1950 PyErr_SetString(PyExc_ValueError,
1951 "field body is required for Expression");
1952 return NULL;
1953 }
1954 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1955 if (!p)
1956 return NULL;
1957 p->kind = Expression_kind;
1958 p->v.Expression.body = body;
1959 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001960}
1961
1962mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001963FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1964{
1965 mod_ty p;
1966 if (!returns) {
1967 PyErr_SetString(PyExc_ValueError,
1968 "field returns is required for FunctionType");
1969 return NULL;
1970 }
1971 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1972 if (!p)
1973 return NULL;
1974 p->kind = FunctionType_kind;
1975 p->v.FunctionType.argtypes = argtypes;
1976 p->v.FunctionType.returns = returns;
1977 return p;
1978}
1979
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001980stmt_ty
1981FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001982 decorator_list, expr_ty returns, string type_comment, int lineno,
1983 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001985 stmt_ty p;
1986 if (!name) {
1987 PyErr_SetString(PyExc_ValueError,
1988 "field name is required for FunctionDef");
1989 return NULL;
1990 }
1991 if (!args) {
1992 PyErr_SetString(PyExc_ValueError,
1993 "field args is required for FunctionDef");
1994 return NULL;
1995 }
1996 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1997 if (!p)
1998 return NULL;
1999 p->kind = FunctionDef_kind;
2000 p->v.FunctionDef.name = name;
2001 p->v.FunctionDef.args = args;
2002 p->v.FunctionDef.body = body;
2003 p->v.FunctionDef.decorator_list = decorator_list;
2004 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002005 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002006 p->lineno = lineno;
2007 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002008 p->end_lineno = end_lineno;
2009 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002010 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002011}
2012
2013stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002014AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002015 * decorator_list, expr_ty returns, string type_comment, int
2016 lineno, int col_offset, int end_lineno, int end_col_offset,
2017 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002018{
2019 stmt_ty p;
2020 if (!name) {
2021 PyErr_SetString(PyExc_ValueError,
2022 "field name is required for AsyncFunctionDef");
2023 return NULL;
2024 }
2025 if (!args) {
2026 PyErr_SetString(PyExc_ValueError,
2027 "field args is required for AsyncFunctionDef");
2028 return NULL;
2029 }
2030 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2031 if (!p)
2032 return NULL;
2033 p->kind = AsyncFunctionDef_kind;
2034 p->v.AsyncFunctionDef.name = name;
2035 p->v.AsyncFunctionDef.args = args;
2036 p->v.AsyncFunctionDef.body = body;
2037 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2038 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002039 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002040 p->lineno = lineno;
2041 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002042 p->end_lineno = end_lineno;
2043 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002044 return p;
2045}
2046
2047stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002048ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002049 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2050 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002051{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002052 stmt_ty p;
2053 if (!name) {
2054 PyErr_SetString(PyExc_ValueError,
2055 "field name is required for ClassDef");
2056 return NULL;
2057 }
2058 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2059 if (!p)
2060 return NULL;
2061 p->kind = ClassDef_kind;
2062 p->v.ClassDef.name = name;
2063 p->v.ClassDef.bases = bases;
2064 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002065 p->v.ClassDef.body = body;
2066 p->v.ClassDef.decorator_list = decorator_list;
2067 p->lineno = lineno;
2068 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002069 p->end_lineno = end_lineno;
2070 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002071 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002072}
2073
2074stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002075Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2076 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002077{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002078 stmt_ty p;
2079 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2080 if (!p)
2081 return NULL;
2082 p->kind = Return_kind;
2083 p->v.Return.value = value;
2084 p->lineno = lineno;
2085 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002086 p->end_lineno = end_lineno;
2087 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002088 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002089}
2090
2091stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002092Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2093 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002094{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002095 stmt_ty p;
2096 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2097 if (!p)
2098 return NULL;
2099 p->kind = Delete_kind;
2100 p->v.Delete.targets = targets;
2101 p->lineno = lineno;
2102 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002103 p->end_lineno = end_lineno;
2104 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002105 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002106}
2107
2108stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002109Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2110 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002111{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002112 stmt_ty p;
2113 if (!value) {
2114 PyErr_SetString(PyExc_ValueError,
2115 "field value is required for Assign");
2116 return NULL;
2117 }
2118 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2119 if (!p)
2120 return NULL;
2121 p->kind = Assign_kind;
2122 p->v.Assign.targets = targets;
2123 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002124 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002125 p->lineno = lineno;
2126 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002127 p->end_lineno = end_lineno;
2128 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002129 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002130}
2131
2132stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002133AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002134 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002135{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002136 stmt_ty p;
2137 if (!target) {
2138 PyErr_SetString(PyExc_ValueError,
2139 "field target is required for AugAssign");
2140 return NULL;
2141 }
2142 if (!op) {
2143 PyErr_SetString(PyExc_ValueError,
2144 "field op is required for AugAssign");
2145 return NULL;
2146 }
2147 if (!value) {
2148 PyErr_SetString(PyExc_ValueError,
2149 "field value is required for AugAssign");
2150 return NULL;
2151 }
2152 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2153 if (!p)
2154 return NULL;
2155 p->kind = AugAssign_kind;
2156 p->v.AugAssign.target = target;
2157 p->v.AugAssign.op = op;
2158 p->v.AugAssign.value = value;
2159 p->lineno = lineno;
2160 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002161 p->end_lineno = end_lineno;
2162 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002163 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002164}
2165
2166stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002167AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002168 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2169 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002170{
2171 stmt_ty p;
2172 if (!target) {
2173 PyErr_SetString(PyExc_ValueError,
2174 "field target is required for AnnAssign");
2175 return NULL;
2176 }
2177 if (!annotation) {
2178 PyErr_SetString(PyExc_ValueError,
2179 "field annotation is required for AnnAssign");
2180 return NULL;
2181 }
2182 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2183 if (!p)
2184 return NULL;
2185 p->kind = AnnAssign_kind;
2186 p->v.AnnAssign.target = target;
2187 p->v.AnnAssign.annotation = annotation;
2188 p->v.AnnAssign.value = value;
2189 p->v.AnnAssign.simple = simple;
2190 p->lineno = lineno;
2191 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002192 p->end_lineno = end_lineno;
2193 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002194 return p;
2195}
2196
2197stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002198For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2199 type_comment, int lineno, int col_offset, int end_lineno, int
2200 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002201{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002202 stmt_ty p;
2203 if (!target) {
2204 PyErr_SetString(PyExc_ValueError,
2205 "field target is required for For");
2206 return NULL;
2207 }
2208 if (!iter) {
2209 PyErr_SetString(PyExc_ValueError,
2210 "field iter is required for For");
2211 return NULL;
2212 }
2213 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2214 if (!p)
2215 return NULL;
2216 p->kind = For_kind;
2217 p->v.For.target = target;
2218 p->v.For.iter = iter;
2219 p->v.For.body = body;
2220 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002221 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002222 p->lineno = lineno;
2223 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002224 p->end_lineno = end_lineno;
2225 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002226 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002227}
2228
2229stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002230AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2231 string type_comment, int lineno, int col_offset, int end_lineno, int
2232 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002233{
2234 stmt_ty p;
2235 if (!target) {
2236 PyErr_SetString(PyExc_ValueError,
2237 "field target is required for AsyncFor");
2238 return NULL;
2239 }
2240 if (!iter) {
2241 PyErr_SetString(PyExc_ValueError,
2242 "field iter is required for AsyncFor");
2243 return NULL;
2244 }
2245 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2246 if (!p)
2247 return NULL;
2248 p->kind = AsyncFor_kind;
2249 p->v.AsyncFor.target = target;
2250 p->v.AsyncFor.iter = iter;
2251 p->v.AsyncFor.body = body;
2252 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002253 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002254 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;
Yury Selivanov75445082015-05-11 22:57:16 -04002258 return p;
2259}
2260
2261stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002262While(expr_ty test, asdl_seq * body, asdl_seq * orelse, 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 (!test) {
2267 PyErr_SetString(PyExc_ValueError,
2268 "field test is required for While");
2269 return NULL;
2270 }
2271 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2272 if (!p)
2273 return NULL;
2274 p->kind = While_kind;
2275 p->v.While.test = test;
2276 p->v.While.body = body;
2277 p->v.While.orelse = orelse;
2278 p->lineno = lineno;
2279 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002280 p->end_lineno = end_lineno;
2281 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002282 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002283}
2284
2285stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002286If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002287 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002288{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002289 stmt_ty p;
2290 if (!test) {
2291 PyErr_SetString(PyExc_ValueError,
2292 "field test is required for If");
2293 return NULL;
2294 }
2295 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2296 if (!p)
2297 return NULL;
2298 p->kind = If_kind;
2299 p->v.If.test = test;
2300 p->v.If.body = body;
2301 p->v.If.orelse = orelse;
2302 p->lineno = lineno;
2303 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002304 p->end_lineno = end_lineno;
2305 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002306 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002307}
2308
2309stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002310With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2311 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002312{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002313 stmt_ty p;
2314 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2315 if (!p)
2316 return NULL;
2317 p->kind = With_kind;
2318 p->v.With.items = items;
2319 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002320 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002321 p->lineno = lineno;
2322 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002323 p->end_lineno = end_lineno;
2324 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002325 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002326}
2327
2328stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002329AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2330 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002331{
2332 stmt_ty p;
2333 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2334 if (!p)
2335 return NULL;
2336 p->kind = AsyncWith_kind;
2337 p->v.AsyncWith.items = items;
2338 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002339 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002340 p->lineno = lineno;
2341 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002342 p->end_lineno = end_lineno;
2343 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002344 return p;
2345}
2346
2347stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002348Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2349 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002350{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002351 stmt_ty p;
2352 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2353 if (!p)
2354 return NULL;
2355 p->kind = Raise_kind;
2356 p->v.Raise.exc = exc;
2357 p->v.Raise.cause = cause;
2358 p->lineno = lineno;
2359 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002360 p->end_lineno = end_lineno;
2361 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002362 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002363}
2364
2365stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002366Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002367 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2368 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002369{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002370 stmt_ty p;
2371 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2372 if (!p)
2373 return NULL;
2374 p->kind = Try_kind;
2375 p->v.Try.body = body;
2376 p->v.Try.handlers = handlers;
2377 p->v.Try.orelse = orelse;
2378 p->v.Try.finalbody = finalbody;
2379 p->lineno = lineno;
2380 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002381 p->end_lineno = end_lineno;
2382 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002383 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002384}
2385
2386stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002387Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2388 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002389{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002390 stmt_ty p;
2391 if (!test) {
2392 PyErr_SetString(PyExc_ValueError,
2393 "field test is required for Assert");
2394 return NULL;
2395 }
2396 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2397 if (!p)
2398 return NULL;
2399 p->kind = Assert_kind;
2400 p->v.Assert.test = test;
2401 p->v.Assert.msg = msg;
2402 p->lineno = lineno;
2403 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002404 p->end_lineno = end_lineno;
2405 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002406 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002407}
2408
2409stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002410Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2411 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002412{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002413 stmt_ty p;
2414 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2415 if (!p)
2416 return NULL;
2417 p->kind = Import_kind;
2418 p->v.Import.names = names;
2419 p->lineno = lineno;
2420 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002421 p->end_lineno = end_lineno;
2422 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002423 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002424}
2425
2426stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002427ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002428 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002429{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002430 stmt_ty p;
2431 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2432 if (!p)
2433 return NULL;
2434 p->kind = ImportFrom_kind;
2435 p->v.ImportFrom.module = module;
2436 p->v.ImportFrom.names = names;
2437 p->v.ImportFrom.level = level;
2438 p->lineno = lineno;
2439 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002440 p->end_lineno = end_lineno;
2441 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002442 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002443}
2444
2445stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002446Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2447 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002448{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002449 stmt_ty p;
2450 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2451 if (!p)
2452 return NULL;
2453 p->kind = Global_kind;
2454 p->v.Global.names = names;
2455 p->lineno = lineno;
2456 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002457 p->end_lineno = end_lineno;
2458 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002459 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002460}
2461
2462stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002463Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2464 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002465{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002466 stmt_ty p;
2467 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2468 if (!p)
2469 return NULL;
2470 p->kind = Nonlocal_kind;
2471 p->v.Nonlocal.names = names;
2472 p->lineno = lineno;
2473 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002474 p->end_lineno = end_lineno;
2475 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002476 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002477}
2478
2479stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002480Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2481 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002482{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002483 stmt_ty p;
2484 if (!value) {
2485 PyErr_SetString(PyExc_ValueError,
2486 "field value is required for Expr");
2487 return NULL;
2488 }
2489 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2490 if (!p)
2491 return NULL;
2492 p->kind = Expr_kind;
2493 p->v.Expr.value = value;
2494 p->lineno = lineno;
2495 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002496 p->end_lineno = end_lineno;
2497 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002498 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002499}
2500
2501stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002502Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2503 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002504{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002505 stmt_ty p;
2506 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2507 if (!p)
2508 return NULL;
2509 p->kind = Pass_kind;
2510 p->lineno = lineno;
2511 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002512 p->end_lineno = end_lineno;
2513 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002514 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002515}
2516
2517stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002518Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2519 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002520{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002521 stmt_ty p;
2522 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2523 if (!p)
2524 return NULL;
2525 p->kind = Break_kind;
2526 p->lineno = lineno;
2527 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002528 p->end_lineno = end_lineno;
2529 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002530 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002531}
2532
2533stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002534Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2535 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002536{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002537 stmt_ty p;
2538 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2539 if (!p)
2540 return NULL;
2541 p->kind = Continue_kind;
2542 p->lineno = lineno;
2543 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002544 p->end_lineno = end_lineno;
2545 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002546 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002547}
2548
2549expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002550BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2551 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002552{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002553 expr_ty p;
2554 if (!op) {
2555 PyErr_SetString(PyExc_ValueError,
2556 "field op is required for BoolOp");
2557 return NULL;
2558 }
2559 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2560 if (!p)
2561 return NULL;
2562 p->kind = BoolOp_kind;
2563 p->v.BoolOp.op = op;
2564 p->v.BoolOp.values = values;
2565 p->lineno = lineno;
2566 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002567 p->end_lineno = end_lineno;
2568 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002569 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002570}
2571
2572expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002573NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2574 end_lineno, int end_col_offset, PyArena *arena)
2575{
2576 expr_ty p;
2577 if (!target) {
2578 PyErr_SetString(PyExc_ValueError,
2579 "field target is required for NamedExpr");
2580 return NULL;
2581 }
2582 if (!value) {
2583 PyErr_SetString(PyExc_ValueError,
2584 "field value is required for NamedExpr");
2585 return NULL;
2586 }
2587 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2588 if (!p)
2589 return NULL;
2590 p->kind = NamedExpr_kind;
2591 p->v.NamedExpr.target = target;
2592 p->v.NamedExpr.value = value;
2593 p->lineno = lineno;
2594 p->col_offset = col_offset;
2595 p->end_lineno = end_lineno;
2596 p->end_col_offset = end_col_offset;
2597 return p;
2598}
2599
2600expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002601BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002602 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002603{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002604 expr_ty p;
2605 if (!left) {
2606 PyErr_SetString(PyExc_ValueError,
2607 "field left is required for BinOp");
2608 return NULL;
2609 }
2610 if (!op) {
2611 PyErr_SetString(PyExc_ValueError,
2612 "field op is required for BinOp");
2613 return NULL;
2614 }
2615 if (!right) {
2616 PyErr_SetString(PyExc_ValueError,
2617 "field right is required for BinOp");
2618 return NULL;
2619 }
2620 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2621 if (!p)
2622 return NULL;
2623 p->kind = BinOp_kind;
2624 p->v.BinOp.left = left;
2625 p->v.BinOp.op = op;
2626 p->v.BinOp.right = right;
2627 p->lineno = lineno;
2628 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002629 p->end_lineno = end_lineno;
2630 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002631 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632}
2633
2634expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002635UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2636 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002637{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002638 expr_ty p;
2639 if (!op) {
2640 PyErr_SetString(PyExc_ValueError,
2641 "field op is required for UnaryOp");
2642 return NULL;
2643 }
2644 if (!operand) {
2645 PyErr_SetString(PyExc_ValueError,
2646 "field operand is required for UnaryOp");
2647 return NULL;
2648 }
2649 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2650 if (!p)
2651 return NULL;
2652 p->kind = UnaryOp_kind;
2653 p->v.UnaryOp.op = op;
2654 p->v.UnaryOp.operand = operand;
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
2662expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002663Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2664 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002666 expr_ty p;
2667 if (!args) {
2668 PyErr_SetString(PyExc_ValueError,
2669 "field args is required for Lambda");
2670 return NULL;
2671 }
2672 if (!body) {
2673 PyErr_SetString(PyExc_ValueError,
2674 "field body is required for Lambda");
2675 return NULL;
2676 }
2677 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2678 if (!p)
2679 return NULL;
2680 p->kind = Lambda_kind;
2681 p->v.Lambda.args = args;
2682 p->v.Lambda.body = body;
2683 p->lineno = lineno;
2684 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002685 p->end_lineno = end_lineno;
2686 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002687 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688}
2689
2690expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002691IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002692 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002693{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002694 expr_ty p;
2695 if (!test) {
2696 PyErr_SetString(PyExc_ValueError,
2697 "field test is required for IfExp");
2698 return NULL;
2699 }
2700 if (!body) {
2701 PyErr_SetString(PyExc_ValueError,
2702 "field body is required for IfExp");
2703 return NULL;
2704 }
2705 if (!orelse) {
2706 PyErr_SetString(PyExc_ValueError,
2707 "field orelse is required for IfExp");
2708 return NULL;
2709 }
2710 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2711 if (!p)
2712 return NULL;
2713 p->kind = IfExp_kind;
2714 p->v.IfExp.test = test;
2715 p->v.IfExp.body = body;
2716 p->v.IfExp.orelse = orelse;
2717 p->lineno = lineno;
2718 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002719 p->end_lineno = end_lineno;
2720 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002721 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002722}
2723
2724expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002725Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2726 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002727{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002728 expr_ty p;
2729 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2730 if (!p)
2731 return NULL;
2732 p->kind = Dict_kind;
2733 p->v.Dict.keys = keys;
2734 p->v.Dict.values = values;
2735 p->lineno = lineno;
2736 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002737 p->end_lineno = end_lineno;
2738 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002739 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002740}
2741
2742expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002743Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2744 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002745{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002746 expr_ty p;
2747 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2748 if (!p)
2749 return NULL;
2750 p->kind = Set_kind;
2751 p->v.Set.elts = elts;
2752 p->lineno = lineno;
2753 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002754 p->end_lineno = end_lineno;
2755 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002756 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002757}
2758
2759expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002760ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2761 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002762{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002763 expr_ty p;
2764 if (!elt) {
2765 PyErr_SetString(PyExc_ValueError,
2766 "field elt is required for ListComp");
2767 return NULL;
2768 }
2769 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2770 if (!p)
2771 return NULL;
2772 p->kind = ListComp_kind;
2773 p->v.ListComp.elt = elt;
2774 p->v.ListComp.generators = generators;
2775 p->lineno = lineno;
2776 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002777 p->end_lineno = end_lineno;
2778 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002779 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002780}
2781
2782expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002783SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2784 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002785{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002786 expr_ty p;
2787 if (!elt) {
2788 PyErr_SetString(PyExc_ValueError,
2789 "field elt is required for SetComp");
2790 return NULL;
2791 }
2792 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2793 if (!p)
2794 return NULL;
2795 p->kind = SetComp_kind;
2796 p->v.SetComp.elt = elt;
2797 p->v.SetComp.generators = generators;
2798 p->lineno = lineno;
2799 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002800 p->end_lineno = end_lineno;
2801 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002802 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002803}
2804
2805expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002806DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002807 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002808{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002809 expr_ty p;
2810 if (!key) {
2811 PyErr_SetString(PyExc_ValueError,
2812 "field key is required for DictComp");
2813 return NULL;
2814 }
2815 if (!value) {
2816 PyErr_SetString(PyExc_ValueError,
2817 "field value is required for DictComp");
2818 return NULL;
2819 }
2820 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2821 if (!p)
2822 return NULL;
2823 p->kind = DictComp_kind;
2824 p->v.DictComp.key = key;
2825 p->v.DictComp.value = value;
2826 p->v.DictComp.generators = generators;
2827 p->lineno = lineno;
2828 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002829 p->end_lineno = end_lineno;
2830 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002831 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002832}
2833
2834expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002835GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002836 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002837{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002838 expr_ty p;
2839 if (!elt) {
2840 PyErr_SetString(PyExc_ValueError,
2841 "field elt is required for GeneratorExp");
2842 return NULL;
2843 }
2844 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2845 if (!p)
2846 return NULL;
2847 p->kind = GeneratorExp_kind;
2848 p->v.GeneratorExp.elt = elt;
2849 p->v.GeneratorExp.generators = generators;
2850 p->lineno = lineno;
2851 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002852 p->end_lineno = end_lineno;
2853 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002854 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002855}
2856
2857expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002858Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2859 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002860{
2861 expr_ty p;
2862 if (!value) {
2863 PyErr_SetString(PyExc_ValueError,
2864 "field value is required for Await");
2865 return NULL;
2866 }
2867 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2868 if (!p)
2869 return NULL;
2870 p->kind = Await_kind;
2871 p->v.Await.value = value;
2872 p->lineno = lineno;
2873 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002874 p->end_lineno = end_lineno;
2875 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002876 return p;
2877}
2878
2879expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002880Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2881 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002882{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002883 expr_ty p;
2884 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2885 if (!p)
2886 return NULL;
2887 p->kind = Yield_kind;
2888 p->v.Yield.value = value;
2889 p->lineno = lineno;
2890 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002891 p->end_lineno = end_lineno;
2892 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002893 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002894}
2895
2896expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002897YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2898 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002899{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002900 expr_ty p;
2901 if (!value) {
2902 PyErr_SetString(PyExc_ValueError,
2903 "field value is required for YieldFrom");
2904 return NULL;
2905 }
2906 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2907 if (!p)
2908 return NULL;
2909 p->kind = YieldFrom_kind;
2910 p->v.YieldFrom.value = value;
2911 p->lineno = lineno;
2912 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002913 p->end_lineno = end_lineno;
2914 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002915 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002916}
2917
2918expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002919Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002920 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002921{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002922 expr_ty p;
2923 if (!left) {
2924 PyErr_SetString(PyExc_ValueError,
2925 "field left is required for Compare");
2926 return NULL;
2927 }
2928 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2929 if (!p)
2930 return NULL;
2931 p->kind = Compare_kind;
2932 p->v.Compare.left = left;
2933 p->v.Compare.ops = ops;
2934 p->v.Compare.comparators = comparators;
2935 p->lineno = lineno;
2936 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002937 p->end_lineno = end_lineno;
2938 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002939 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002940}
2941
2942expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002943Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002944 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002945{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002946 expr_ty p;
2947 if (!func) {
2948 PyErr_SetString(PyExc_ValueError,
2949 "field func is required for Call");
2950 return NULL;
2951 }
2952 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2953 if (!p)
2954 return NULL;
2955 p->kind = Call_kind;
2956 p->v.Call.func = func;
2957 p->v.Call.args = args;
2958 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002959 p->lineno = lineno;
2960 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002961 p->end_lineno = end_lineno;
2962 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002963 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002964}
2965
2966expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002967FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2968 int col_offset, int end_lineno, int end_col_offset, PyArena
2969 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002970{
2971 expr_ty p;
2972 if (!value) {
2973 PyErr_SetString(PyExc_ValueError,
2974 "field value is required for FormattedValue");
2975 return NULL;
2976 }
2977 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2978 if (!p)
2979 return NULL;
2980 p->kind = FormattedValue_kind;
2981 p->v.FormattedValue.value = value;
2982 p->v.FormattedValue.conversion = conversion;
2983 p->v.FormattedValue.format_spec = format_spec;
2984 p->lineno = lineno;
2985 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002986 p->end_lineno = end_lineno;
2987 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002988 return p;
2989}
2990
2991expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002992JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2993 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002994{
2995 expr_ty p;
2996 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2997 if (!p)
2998 return NULL;
2999 p->kind = JoinedStr_kind;
3000 p->v.JoinedStr.values = values;
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;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003005 return p;
3006}
3007
3008expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003009Constant(constant value, string kind, int lineno, int col_offset, int
3010 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003011{
3012 expr_ty p;
3013 if (!value) {
3014 PyErr_SetString(PyExc_ValueError,
3015 "field value is required for Constant");
3016 return NULL;
3017 }
3018 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3019 if (!p)
3020 return NULL;
3021 p->kind = Constant_kind;
3022 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003023 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003024 p->lineno = lineno;
3025 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003026 p->end_lineno = end_lineno;
3027 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003028 return p;
3029}
3030
3031expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003032Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003033 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003034{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003035 expr_ty p;
3036 if (!value) {
3037 PyErr_SetString(PyExc_ValueError,
3038 "field value is required for Attribute");
3039 return NULL;
3040 }
3041 if (!attr) {
3042 PyErr_SetString(PyExc_ValueError,
3043 "field attr is required for Attribute");
3044 return NULL;
3045 }
3046 if (!ctx) {
3047 PyErr_SetString(PyExc_ValueError,
3048 "field ctx is required for Attribute");
3049 return NULL;
3050 }
3051 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3052 if (!p)
3053 return NULL;
3054 p->kind = Attribute_kind;
3055 p->v.Attribute.value = value;
3056 p->v.Attribute.attr = attr;
3057 p->v.Attribute.ctx = ctx;
3058 p->lineno = lineno;
3059 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003060 p->end_lineno = end_lineno;
3061 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003062 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003063}
3064
3065expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003066Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003067 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003068{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003069 expr_ty p;
3070 if (!value) {
3071 PyErr_SetString(PyExc_ValueError,
3072 "field value is required for Subscript");
3073 return NULL;
3074 }
3075 if (!slice) {
3076 PyErr_SetString(PyExc_ValueError,
3077 "field slice is required for Subscript");
3078 return NULL;
3079 }
3080 if (!ctx) {
3081 PyErr_SetString(PyExc_ValueError,
3082 "field ctx is required for Subscript");
3083 return NULL;
3084 }
3085 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3086 if (!p)
3087 return NULL;
3088 p->kind = Subscript_kind;
3089 p->v.Subscript.value = value;
3090 p->v.Subscript.slice = slice;
3091 p->v.Subscript.ctx = ctx;
3092 p->lineno = lineno;
3093 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003094 p->end_lineno = end_lineno;
3095 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003096 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003097}
3098
3099expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003100Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3101 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003102{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003103 expr_ty p;
3104 if (!value) {
3105 PyErr_SetString(PyExc_ValueError,
3106 "field value is required for Starred");
3107 return NULL;
3108 }
3109 if (!ctx) {
3110 PyErr_SetString(PyExc_ValueError,
3111 "field ctx is required for Starred");
3112 return NULL;
3113 }
3114 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3115 if (!p)
3116 return NULL;
3117 p->kind = Starred_kind;
3118 p->v.Starred.value = value;
3119 p->v.Starred.ctx = ctx;
3120 p->lineno = lineno;
3121 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003122 p->end_lineno = end_lineno;
3123 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003124 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003125}
3126
3127expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003128Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3129 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003130{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003131 expr_ty p;
3132 if (!id) {
3133 PyErr_SetString(PyExc_ValueError,
3134 "field id is required for Name");
3135 return NULL;
3136 }
3137 if (!ctx) {
3138 PyErr_SetString(PyExc_ValueError,
3139 "field ctx is required for Name");
3140 return NULL;
3141 }
3142 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3143 if (!p)
3144 return NULL;
3145 p->kind = Name_kind;
3146 p->v.Name.id = id;
3147 p->v.Name.ctx = ctx;
3148 p->lineno = lineno;
3149 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003150 p->end_lineno = end_lineno;
3151 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003152 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003153}
3154
3155expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003156List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3157 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003158{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003159 expr_ty p;
3160 if (!ctx) {
3161 PyErr_SetString(PyExc_ValueError,
3162 "field ctx is required for List");
3163 return NULL;
3164 }
3165 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3166 if (!p)
3167 return NULL;
3168 p->kind = List_kind;
3169 p->v.List.elts = elts;
3170 p->v.List.ctx = ctx;
3171 p->lineno = lineno;
3172 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003173 p->end_lineno = end_lineno;
3174 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003175 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003176}
3177
3178expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003179Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3180 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003181{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003182 expr_ty p;
3183 if (!ctx) {
3184 PyErr_SetString(PyExc_ValueError,
3185 "field ctx is required for Tuple");
3186 return NULL;
3187 }
3188 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3189 if (!p)
3190 return NULL;
3191 p->kind = Tuple_kind;
3192 p->v.Tuple.elts = elts;
3193 p->v.Tuple.ctx = ctx;
3194 p->lineno = lineno;
3195 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003196 p->end_lineno = end_lineno;
3197 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003198 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003199}
3200
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003201expr_ty
3202Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3203 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003204{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003205 expr_ty p;
3206 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003207 if (!p)
3208 return NULL;
3209 p->kind = Slice_kind;
3210 p->v.Slice.lower = lower;
3211 p->v.Slice.upper = upper;
3212 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003213 p->lineno = lineno;
3214 p->col_offset = col_offset;
3215 p->end_lineno = end_lineno;
3216 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003217 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003218}
3219
3220comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003221comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3222 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003223{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003224 comprehension_ty p;
3225 if (!target) {
3226 PyErr_SetString(PyExc_ValueError,
3227 "field target is required for comprehension");
3228 return NULL;
3229 }
3230 if (!iter) {
3231 PyErr_SetString(PyExc_ValueError,
3232 "field iter is required for comprehension");
3233 return NULL;
3234 }
3235 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3236 if (!p)
3237 return NULL;
3238 p->target = target;
3239 p->iter = iter;
3240 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003241 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003242 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003243}
3244
3245excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003246ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003247 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003248{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003249 excepthandler_ty p;
3250 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3251 if (!p)
3252 return NULL;
3253 p->kind = ExceptHandler_kind;
3254 p->v.ExceptHandler.type = type;
3255 p->v.ExceptHandler.name = name;
3256 p->v.ExceptHandler.body = body;
3257 p->lineno = lineno;
3258 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003259 p->end_lineno = end_lineno;
3260 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003261 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003262}
3263
3264arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003265arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003266 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3267 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003268{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003269 arguments_ty p;
3270 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3271 if (!p)
3272 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003273 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003274 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003275 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003276 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003277 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003278 p->kwarg = kwarg;
3279 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003280 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003281}
3282
Neal Norwitzc1505362006-12-28 06:47:50 +00003283arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003284arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3285 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003286{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003287 arg_ty p;
3288 if (!arg) {
3289 PyErr_SetString(PyExc_ValueError,
3290 "field arg is required for arg");
3291 return NULL;
3292 }
3293 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3294 if (!p)
3295 return NULL;
3296 p->arg = arg;
3297 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003298 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003299 p->lineno = lineno;
3300 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003301 p->end_lineno = end_lineno;
3302 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003303 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003304}
3305
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003306keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003307keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003308{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003309 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003310 if (!value) {
3311 PyErr_SetString(PyExc_ValueError,
3312 "field value is required for keyword");
3313 return NULL;
3314 }
3315 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3316 if (!p)
3317 return NULL;
3318 p->arg = arg;
3319 p->value = value;
3320 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003321}
3322
3323alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003324alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003325{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003326 alias_ty p;
3327 if (!name) {
3328 PyErr_SetString(PyExc_ValueError,
3329 "field name is required for alias");
3330 return NULL;
3331 }
3332 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3333 if (!p)
3334 return NULL;
3335 p->name = name;
3336 p->asname = asname;
3337 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003338}
3339
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003340withitem_ty
3341withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3342{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003343 withitem_ty p;
3344 if (!context_expr) {
3345 PyErr_SetString(PyExc_ValueError,
3346 "field context_expr is required for withitem");
3347 return NULL;
3348 }
3349 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3350 if (!p)
3351 return NULL;
3352 p->context_expr = context_expr;
3353 p->optional_vars = optional_vars;
3354 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003355}
3356
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003357type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003358TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003359{
3360 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003361 if (!tag) {
3362 PyErr_SetString(PyExc_ValueError,
3363 "field tag is required for TypeIgnore");
3364 return NULL;
3365 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003366 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3367 if (!p)
3368 return NULL;
3369 p->kind = TypeIgnore_kind;
3370 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003371 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003372 return p;
3373}
3374
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003375
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003376PyObject*
3377ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003378{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003379 mod_ty o = (mod_ty)_o;
3380 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003381 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003382 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003383 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003384 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003385
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003386 switch (o->kind) {
3387 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003388 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3389 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003390 if (!result) goto failed;
3391 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3392 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003393 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003394 goto failed;
3395 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003396 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3397 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003398 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3399 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003400 goto failed;
3401 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003402 break;
3403 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003404 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3405 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003406 if (!result) goto failed;
3407 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3408 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003409 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003410 goto failed;
3411 Py_DECREF(value);
3412 break;
3413 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003414 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3415 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003416 if (!result) goto failed;
3417 value = ast2obj_expr(o->v.Expression.body);
3418 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003419 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003420 goto failed;
3421 Py_DECREF(value);
3422 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003423 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003424 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3425 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003426 if (!result) goto failed;
3427 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3428 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003429 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3430 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003431 goto failed;
3432 Py_DECREF(value);
3433 value = ast2obj_expr(o->v.FunctionType.returns);
3434 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003435 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3436 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003437 goto failed;
3438 Py_DECREF(value);
3439 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003440 }
3441 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003442failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003443 Py_XDECREF(value);
3444 Py_XDECREF(result);
3445 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003446}
3447
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003448PyObject*
3449ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003450{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003451 stmt_ty o = (stmt_ty)_o;
3452 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003453 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003454 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003455 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003456 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003457
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003458 switch (o->kind) {
3459 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003460 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3461 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003462 if (!result) goto failed;
3463 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003464 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003465 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003466 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003467 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003468 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003469 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003470 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003471 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003472 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003473 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3474 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003475 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003476 goto failed;
3477 Py_DECREF(value);
3478 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3479 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003480 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3481 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003482 goto failed;
3483 Py_DECREF(value);
3484 value = ast2obj_expr(o->v.FunctionDef.returns);
3485 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003486 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3487 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003488 goto failed;
3489 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003490 value = ast2obj_string(o->v.FunctionDef.type_comment);
3491 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003492 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3493 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003494 goto failed;
3495 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003496 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003497 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003498 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3499 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003500 if (!result) goto failed;
3501 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3502 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003503 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003504 goto failed;
3505 Py_DECREF(value);
3506 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3507 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003508 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003509 goto failed;
3510 Py_DECREF(value);
3511 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3512 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003513 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003514 goto failed;
3515 Py_DECREF(value);
3516 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3517 ast2obj_expr);
3518 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003519 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3520 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003521 goto failed;
3522 Py_DECREF(value);
3523 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3524 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003525 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3526 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003527 goto failed;
3528 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003529 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3530 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003531 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3532 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003533 goto failed;
3534 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003535 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003536 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003537 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3538 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003539 if (!result) goto failed;
3540 value = ast2obj_identifier(o->v.ClassDef.name);
3541 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003542 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003543 goto failed;
3544 Py_DECREF(value);
3545 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3546 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003547 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003548 goto failed;
3549 Py_DECREF(value);
3550 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3551 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003552 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3553 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003554 goto failed;
3555 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3557 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003558 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003559 goto failed;
3560 Py_DECREF(value);
3561 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3562 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003563 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3564 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003565 goto failed;
3566 Py_DECREF(value);
3567 break;
3568 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003569 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3570 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003571 if (!result) goto failed;
3572 value = ast2obj_expr(o->v.Return.value);
3573 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003574 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003575 goto failed;
3576 Py_DECREF(value);
3577 break;
3578 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003579 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3580 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003581 if (!result) goto failed;
3582 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3583 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003584 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3585 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 goto failed;
3587 Py_DECREF(value);
3588 break;
3589 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003590 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3591 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003592 if (!result) goto failed;
3593 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3594 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003595 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3596 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003597 goto failed;
3598 Py_DECREF(value);
3599 value = ast2obj_expr(o->v.Assign.value);
3600 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003601 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003602 goto failed;
3603 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003604 value = ast2obj_string(o->v.Assign.type_comment);
3605 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003606 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3607 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003608 goto failed;
3609 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003610 break;
3611 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003612 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3613 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 if (!result) goto failed;
3615 value = ast2obj_expr(o->v.AugAssign.target);
3616 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003617 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3618 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003619 goto failed;
3620 Py_DECREF(value);
3621 value = ast2obj_operator(o->v.AugAssign.op);
3622 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003623 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003624 goto failed;
3625 Py_DECREF(value);
3626 value = ast2obj_expr(o->v.AugAssign.value);
3627 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003628 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003629 goto failed;
3630 Py_DECREF(value);
3631 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003632 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003633 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3634 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003635 if (!result) goto failed;
3636 value = ast2obj_expr(o->v.AnnAssign.target);
3637 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003638 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3639 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003640 goto failed;
3641 Py_DECREF(value);
3642 value = ast2obj_expr(o->v.AnnAssign.annotation);
3643 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003644 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3645 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003646 goto failed;
3647 Py_DECREF(value);
3648 value = ast2obj_expr(o->v.AnnAssign.value);
3649 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003650 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003651 goto failed;
3652 Py_DECREF(value);
3653 value = ast2obj_int(o->v.AnnAssign.simple);
3654 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003655 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3656 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003657 goto failed;
3658 Py_DECREF(value);
3659 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003660 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003661 tp = (PyTypeObject *)astmodulestate_global->For_type;
3662 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003663 if (!result) goto failed;
3664 value = ast2obj_expr(o->v.For.target);
3665 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003666 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3667 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003668 goto failed;
3669 Py_DECREF(value);
3670 value = ast2obj_expr(o->v.For.iter);
3671 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003672 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003673 goto failed;
3674 Py_DECREF(value);
3675 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3676 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003677 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003678 goto failed;
3679 Py_DECREF(value);
3680 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3681 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003682 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3683 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003684 goto failed;
3685 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003686 value = ast2obj_string(o->v.For.type_comment);
3687 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003688 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3689 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003690 goto failed;
3691 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003692 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003693 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003694 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3695 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003696 if (!result) goto failed;
3697 value = ast2obj_expr(o->v.AsyncFor.target);
3698 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003699 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3700 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003701 goto failed;
3702 Py_DECREF(value);
3703 value = ast2obj_expr(o->v.AsyncFor.iter);
3704 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003705 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003706 goto failed;
3707 Py_DECREF(value);
3708 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3709 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003710 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003711 goto failed;
3712 Py_DECREF(value);
3713 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3714 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003715 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3716 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003717 goto failed;
3718 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003719 value = ast2obj_string(o->v.AsyncFor.type_comment);
3720 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003721 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3722 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003723 goto failed;
3724 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003725 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003726 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 tp = (PyTypeObject *)astmodulestate_global->While_type;
3728 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003729 if (!result) goto failed;
3730 value = ast2obj_expr(o->v.While.test);
3731 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003732 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003733 goto failed;
3734 Py_DECREF(value);
3735 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3736 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003737 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003738 goto failed;
3739 Py_DECREF(value);
3740 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3741 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003742 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3743 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003744 goto failed;
3745 Py_DECREF(value);
3746 break;
3747 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003748 tp = (PyTypeObject *)astmodulestate_global->If_type;
3749 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003750 if (!result) goto failed;
3751 value = ast2obj_expr(o->v.If.test);
3752 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003753 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003754 goto failed;
3755 Py_DECREF(value);
3756 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3757 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003758 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003759 goto failed;
3760 Py_DECREF(value);
3761 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003763 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3764 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003765 goto failed;
3766 Py_DECREF(value);
3767 break;
3768 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003769 tp = (PyTypeObject *)astmodulestate_global->With_type;
3770 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003771 if (!result) goto failed;
3772 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003774 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003775 goto failed;
3776 Py_DECREF(value);
3777 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3778 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003779 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003780 goto failed;
3781 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003782 value = ast2obj_string(o->v.With.type_comment);
3783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003784 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3785 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003786 goto failed;
3787 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003788 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003789 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003790 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3791 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003792 if (!result) goto failed;
3793 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003796 goto failed;
3797 Py_DECREF(value);
3798 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3799 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003800 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003801 goto failed;
3802 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003803 value = ast2obj_string(o->v.AsyncWith.type_comment);
3804 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003805 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3806 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003807 goto failed;
3808 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003809 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003810 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003811 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3812 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 if (!result) goto failed;
3814 value = ast2obj_expr(o->v.Raise.exc);
3815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003816 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003817 goto failed;
3818 Py_DECREF(value);
3819 value = ast2obj_expr(o->v.Raise.cause);
3820 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003821 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003822 goto failed;
3823 Py_DECREF(value);
3824 break;
3825 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003826 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3827 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003828 if (!result) goto failed;
3829 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3830 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003831 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003832 goto failed;
3833 Py_DECREF(value);
3834 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3835 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003836 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3837 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003838 goto failed;
3839 Py_DECREF(value);
3840 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3841 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003842 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3843 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003844 goto failed;
3845 Py_DECREF(value);
3846 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3847 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003848 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3849 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003850 goto failed;
3851 Py_DECREF(value);
3852 break;
3853 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003854 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3855 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 if (!result) goto failed;
3857 value = ast2obj_expr(o->v.Assert.test);
3858 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003860 goto failed;
3861 Py_DECREF(value);
3862 value = ast2obj_expr(o->v.Assert.msg);
3863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003865 goto failed;
3866 Py_DECREF(value);
3867 break;
3868 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3870 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003871 if (!result) goto failed;
3872 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 goto failed;
3876 Py_DECREF(value);
3877 break;
3878 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003879 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3880 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003881 if (!result) goto failed;
3882 value = ast2obj_identifier(o->v.ImportFrom.module);
3883 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003884 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3885 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003886 goto failed;
3887 Py_DECREF(value);
3888 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3889 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003890 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 goto failed;
3892 Py_DECREF(value);
3893 value = ast2obj_int(o->v.ImportFrom.level);
3894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003895 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003896 goto failed;
3897 Py_DECREF(value);
3898 break;
3899 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003900 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3901 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003902 if (!result) goto failed;
3903 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3904 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003905 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003906 goto failed;
3907 Py_DECREF(value);
3908 break;
3909 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003910 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3911 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003912 if (!result) goto failed;
3913 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3914 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003915 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003916 goto failed;
3917 Py_DECREF(value);
3918 break;
3919 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003920 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3921 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003922 if (!result) goto failed;
3923 value = ast2obj_expr(o->v.Expr.value);
3924 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003925 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003926 goto failed;
3927 Py_DECREF(value);
3928 break;
3929 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003930 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3931 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003932 if (!result) goto failed;
3933 break;
3934 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003935 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3936 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003937 if (!result) goto failed;
3938 break;
3939 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003940 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3941 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003942 if (!result) goto failed;
3943 break;
3944 }
3945 value = ast2obj_int(o->lineno);
3946 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003947 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003948 goto failed;
3949 Py_DECREF(value);
3950 value = ast2obj_int(o->col_offset);
3951 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003952 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003953 goto failed;
3954 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003955 value = ast2obj_int(o->end_lineno);
3956 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003957 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003958 goto failed;
3959 Py_DECREF(value);
3960 value = ast2obj_int(o->end_col_offset);
3961 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003962 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3963 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003964 goto failed;
3965 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003966 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003967failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 Py_XDECREF(value);
3969 Py_XDECREF(result);
3970 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003971}
3972
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003973PyObject*
3974ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003975{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003976 expr_ty o = (expr_ty)_o;
3977 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003978 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003979 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003980 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003981 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003982
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003983 switch (o->kind) {
3984 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003985 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3986 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003987 if (!result) goto failed;
3988 value = ast2obj_boolop(o->v.BoolOp.op);
3989 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003990 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003991 goto failed;
3992 Py_DECREF(value);
3993 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3994 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003995 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3996 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003997 goto failed;
3998 Py_DECREF(value);
3999 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004000 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004001 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4002 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004003 if (!result) goto failed;
4004 value = ast2obj_expr(o->v.NamedExpr.target);
4005 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004006 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4007 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004008 goto failed;
4009 Py_DECREF(value);
4010 value = ast2obj_expr(o->v.NamedExpr.value);
4011 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004013 goto failed;
4014 Py_DECREF(value);
4015 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004016 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004017 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4018 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004019 if (!result) goto failed;
4020 value = ast2obj_expr(o->v.BinOp.left);
4021 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004023 goto failed;
4024 Py_DECREF(value);
4025 value = ast2obj_operator(o->v.BinOp.op);
4026 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 goto failed;
4029 Py_DECREF(value);
4030 value = ast2obj_expr(o->v.BinOp.right);
4031 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004033 goto failed;
4034 Py_DECREF(value);
4035 break;
4036 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004037 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4038 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004039 if (!result) goto failed;
4040 value = ast2obj_unaryop(o->v.UnaryOp.op);
4041 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004042 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004043 goto failed;
4044 Py_DECREF(value);
4045 value = ast2obj_expr(o->v.UnaryOp.operand);
4046 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004047 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4048 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004049 goto failed;
4050 Py_DECREF(value);
4051 break;
4052 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4054 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 if (!result) goto failed;
4056 value = ast2obj_arguments(o->v.Lambda.args);
4057 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 goto failed;
4060 Py_DECREF(value);
4061 value = ast2obj_expr(o->v.Lambda.body);
4062 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004063 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004064 goto failed;
4065 Py_DECREF(value);
4066 break;
4067 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004068 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4069 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 if (!result) goto failed;
4071 value = ast2obj_expr(o->v.IfExp.test);
4072 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004073 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004074 goto failed;
4075 Py_DECREF(value);
4076 value = ast2obj_expr(o->v.IfExp.body);
4077 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004078 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004079 goto failed;
4080 Py_DECREF(value);
4081 value = ast2obj_expr(o->v.IfExp.orelse);
4082 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004083 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4084 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004085 goto failed;
4086 Py_DECREF(value);
4087 break;
4088 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004089 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4090 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004091 if (!result) goto failed;
4092 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4093 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004094 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004095 goto failed;
4096 Py_DECREF(value);
4097 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4098 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004099 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4100 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004101 goto failed;
4102 Py_DECREF(value);
4103 break;
4104 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004105 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4106 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004107 if (!result) goto failed;
4108 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4109 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004110 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004111 goto failed;
4112 Py_DECREF(value);
4113 break;
4114 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004115 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4116 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004117 if (!result) goto failed;
4118 value = ast2obj_expr(o->v.ListComp.elt);
4119 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004120 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004121 goto failed;
4122 Py_DECREF(value);
4123 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4124 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004125 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4126 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004127 goto failed;
4128 Py_DECREF(value);
4129 break;
4130 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004131 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4132 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 if (!result) goto failed;
4134 value = ast2obj_expr(o->v.SetComp.elt);
4135 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004136 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004137 goto failed;
4138 Py_DECREF(value);
4139 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4140 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004141 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4142 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004143 goto failed;
4144 Py_DECREF(value);
4145 break;
4146 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004147 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4148 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004149 if (!result) goto failed;
4150 value = ast2obj_expr(o->v.DictComp.key);
4151 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004152 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004153 goto failed;
4154 Py_DECREF(value);
4155 value = ast2obj_expr(o->v.DictComp.value);
4156 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004157 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004158 goto failed;
4159 Py_DECREF(value);
4160 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4161 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004162 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4163 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004164 goto failed;
4165 Py_DECREF(value);
4166 break;
4167 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004168 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4169 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004170 if (!result) goto failed;
4171 value = ast2obj_expr(o->v.GeneratorExp.elt);
4172 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004173 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004174 goto failed;
4175 Py_DECREF(value);
4176 value = ast2obj_list(o->v.GeneratorExp.generators,
4177 ast2obj_comprehension);
4178 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004179 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4180 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004181 goto failed;
4182 Py_DECREF(value);
4183 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004184 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004185 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4186 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004187 if (!result) goto failed;
4188 value = ast2obj_expr(o->v.Await.value);
4189 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004191 goto failed;
4192 Py_DECREF(value);
4193 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004194 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4196 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 if (!result) goto failed;
4198 value = ast2obj_expr(o->v.Yield.value);
4199 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004201 goto failed;
4202 Py_DECREF(value);
4203 break;
4204 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004205 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4206 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004207 if (!result) goto failed;
4208 value = ast2obj_expr(o->v.YieldFrom.value);
4209 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004210 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004211 goto failed;
4212 Py_DECREF(value);
4213 break;
4214 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004215 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4216 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 if (!result) goto failed;
4218 value = ast2obj_expr(o->v.Compare.left);
4219 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004220 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004221 goto failed;
4222 Py_DECREF(value);
4223 {
4224 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4225 value = PyList_New(n);
4226 if (!value) goto failed;
4227 for(i = 0; i < n; i++)
4228 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004229 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004230 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004231 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004232 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004233 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004234 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004235 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004236 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4237 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004238 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004239 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004240 break;
4241 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004242 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4243 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004244 if (!result) goto failed;
4245 value = ast2obj_expr(o->v.Call.func);
4246 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004247 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004248 goto failed;
4249 Py_DECREF(value);
4250 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4251 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004252 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004253 goto failed;
4254 Py_DECREF(value);
4255 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4256 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004257 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4258 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004259 goto failed;
4260 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004261 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004262 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004263 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4264 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004265 if (!result) goto failed;
4266 value = ast2obj_expr(o->v.FormattedValue.value);
4267 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004268 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004269 goto failed;
4270 Py_DECREF(value);
4271 value = ast2obj_int(o->v.FormattedValue.conversion);
4272 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004273 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4274 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004275 goto failed;
4276 Py_DECREF(value);
4277 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4278 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004279 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4280 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004281 goto failed;
4282 Py_DECREF(value);
4283 break;
4284 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004285 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4286 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004287 if (!result) goto failed;
4288 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4289 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004290 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4291 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004292 goto failed;
4293 Py_DECREF(value);
4294 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004295 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004296 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4297 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004298 if (!result) goto failed;
4299 value = ast2obj_constant(o->v.Constant.value);
4300 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004301 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004302 goto failed;
4303 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004304 value = ast2obj_string(o->v.Constant.kind);
4305 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004306 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004307 goto failed;
4308 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004309 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004310 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004311 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4312 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004313 if (!result) goto failed;
4314 value = ast2obj_expr(o->v.Attribute.value);
4315 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004316 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004317 goto failed;
4318 Py_DECREF(value);
4319 value = ast2obj_identifier(o->v.Attribute.attr);
4320 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004321 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004322 goto failed;
4323 Py_DECREF(value);
4324 value = ast2obj_expr_context(o->v.Attribute.ctx);
4325 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004326 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 goto failed;
4328 Py_DECREF(value);
4329 break;
4330 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004331 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4332 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004333 if (!result) goto failed;
4334 value = ast2obj_expr(o->v.Subscript.value);
4335 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004336 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004337 goto failed;
4338 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004339 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004340 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004341 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004342 goto failed;
4343 Py_DECREF(value);
4344 value = ast2obj_expr_context(o->v.Subscript.ctx);
4345 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004346 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 goto failed;
4348 Py_DECREF(value);
4349 break;
4350 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004351 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4352 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004353 if (!result) goto failed;
4354 value = ast2obj_expr(o->v.Starred.value);
4355 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004356 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 goto failed;
4358 Py_DECREF(value);
4359 value = ast2obj_expr_context(o->v.Starred.ctx);
4360 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004361 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004362 goto failed;
4363 Py_DECREF(value);
4364 break;
4365 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004366 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4367 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004368 if (!result) goto failed;
4369 value = ast2obj_identifier(o->v.Name.id);
4370 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004371 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004372 goto failed;
4373 Py_DECREF(value);
4374 value = ast2obj_expr_context(o->v.Name.ctx);
4375 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004376 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004377 goto failed;
4378 Py_DECREF(value);
4379 break;
4380 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 tp = (PyTypeObject *)astmodulestate_global->List_type;
4382 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004383 if (!result) goto failed;
4384 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4385 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004386 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004387 goto failed;
4388 Py_DECREF(value);
4389 value = ast2obj_expr_context(o->v.List.ctx);
4390 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004392 goto failed;
4393 Py_DECREF(value);
4394 break;
4395 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004396 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4397 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004398 if (!result) goto failed;
4399 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4400 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004401 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004402 goto failed;
4403 Py_DECREF(value);
4404 value = ast2obj_expr_context(o->v.Tuple.ctx);
4405 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004406 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004407 goto failed;
4408 Py_DECREF(value);
4409 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004410 case Slice_kind:
4411 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4412 result = PyType_GenericNew(tp, NULL, NULL);
4413 if (!result) goto failed;
4414 value = ast2obj_expr(o->v.Slice.lower);
4415 if (!value) goto failed;
4416 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4417 goto failed;
4418 Py_DECREF(value);
4419 value = ast2obj_expr(o->v.Slice.upper);
4420 if (!value) goto failed;
4421 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4422 goto failed;
4423 Py_DECREF(value);
4424 value = ast2obj_expr(o->v.Slice.step);
4425 if (!value) goto failed;
4426 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4427 goto failed;
4428 Py_DECREF(value);
4429 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004430 }
4431 value = ast2obj_int(o->lineno);
4432 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004433 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004434 goto failed;
4435 Py_DECREF(value);
4436 value = ast2obj_int(o->col_offset);
4437 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004438 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004439 goto failed;
4440 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004441 value = ast2obj_int(o->end_lineno);
4442 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004443 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004444 goto failed;
4445 Py_DECREF(value);
4446 value = ast2obj_int(o->end_col_offset);
4447 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004448 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4449 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004450 goto failed;
4451 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004452 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004453failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004454 Py_XDECREF(value);
4455 Py_XDECREF(result);
4456 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004457}
4458
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004459PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004460{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 switch(o) {
4462 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004463 Py_INCREF(astmodulestate_global->Load_singleton);
4464 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004466 Py_INCREF(astmodulestate_global->Store_singleton);
4467 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004468 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004469 Py_INCREF(astmodulestate_global->Del_singleton);
4470 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004471 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004472 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4473 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004474 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004475 Py_INCREF(astmodulestate_global->AugStore_singleton);
4476 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004477 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004478 Py_INCREF(astmodulestate_global->Param_singleton);
4479 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004480 default:
4481 /* should never happen, but just in case ... */
4482 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4483 return NULL;
4484 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004485}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004486PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004487{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004488 switch(o) {
4489 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004490 Py_INCREF(astmodulestate_global->And_singleton);
4491 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004492 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004493 Py_INCREF(astmodulestate_global->Or_singleton);
4494 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 default:
4496 /* should never happen, but just in case ... */
4497 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4498 return NULL;
4499 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004500}
4501PyObject* ast2obj_operator(operator_ty o)
4502{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 switch(o) {
4504 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004505 Py_INCREF(astmodulestate_global->Add_singleton);
4506 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004507 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004508 Py_INCREF(astmodulestate_global->Sub_singleton);
4509 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004511 Py_INCREF(astmodulestate_global->Mult_singleton);
4512 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004513 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004514 Py_INCREF(astmodulestate_global->MatMult_singleton);
4515 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004516 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004517 Py_INCREF(astmodulestate_global->Div_singleton);
4518 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004519 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004520 Py_INCREF(astmodulestate_global->Mod_singleton);
4521 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004522 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004523 Py_INCREF(astmodulestate_global->Pow_singleton);
4524 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004525 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004526 Py_INCREF(astmodulestate_global->LShift_singleton);
4527 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004528 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004529 Py_INCREF(astmodulestate_global->RShift_singleton);
4530 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004531 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004532 Py_INCREF(astmodulestate_global->BitOr_singleton);
4533 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004534 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004535 Py_INCREF(astmodulestate_global->BitXor_singleton);
4536 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004537 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004538 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4539 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004540 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004541 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4542 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004543 default:
4544 /* should never happen, but just in case ... */
4545 PyErr_Format(PyExc_SystemError, "unknown operator found");
4546 return NULL;
4547 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004548}
4549PyObject* ast2obj_unaryop(unaryop_ty o)
4550{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004551 switch(o) {
4552 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004553 Py_INCREF(astmodulestate_global->Invert_singleton);
4554 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004555 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004556 Py_INCREF(astmodulestate_global->Not_singleton);
4557 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004558 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004559 Py_INCREF(astmodulestate_global->UAdd_singleton);
4560 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004561 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004562 Py_INCREF(astmodulestate_global->USub_singleton);
4563 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004564 default:
4565 /* should never happen, but just in case ... */
4566 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4567 return NULL;
4568 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004569}
4570PyObject* ast2obj_cmpop(cmpop_ty o)
4571{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004572 switch(o) {
4573 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004574 Py_INCREF(astmodulestate_global->Eq_singleton);
4575 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004576 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004577 Py_INCREF(astmodulestate_global->NotEq_singleton);
4578 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004579 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004580 Py_INCREF(astmodulestate_global->Lt_singleton);
4581 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004582 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004583 Py_INCREF(astmodulestate_global->LtE_singleton);
4584 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004585 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004586 Py_INCREF(astmodulestate_global->Gt_singleton);
4587 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004588 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004589 Py_INCREF(astmodulestate_global->GtE_singleton);
4590 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004591 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004592 Py_INCREF(astmodulestate_global->Is_singleton);
4593 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004594 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004595 Py_INCREF(astmodulestate_global->IsNot_singleton);
4596 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004597 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004598 Py_INCREF(astmodulestate_global->In_singleton);
4599 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004601 Py_INCREF(astmodulestate_global->NotIn_singleton);
4602 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004603 default:
4604 /* should never happen, but just in case ... */
4605 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4606 return NULL;
4607 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004608}
4609PyObject*
4610ast2obj_comprehension(void* _o)
4611{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004612 comprehension_ty o = (comprehension_ty)_o;
4613 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004614 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004615 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004616 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004618
Dino Viehlandac46eb42019-09-11 10:16:34 -07004619 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4620 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004621 if (!result) return NULL;
4622 value = ast2obj_expr(o->target);
4623 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004624 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004625 goto failed;
4626 Py_DECREF(value);
4627 value = ast2obj_expr(o->iter);
4628 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004629 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004630 goto failed;
4631 Py_DECREF(value);
4632 value = ast2obj_list(o->ifs, ast2obj_expr);
4633 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004634 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004635 goto failed;
4636 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004637 value = ast2obj_int(o->is_async);
4638 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004639 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004640 goto failed;
4641 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004642 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004643failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004644 Py_XDECREF(value);
4645 Py_XDECREF(result);
4646 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004647}
4648
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004649PyObject*
4650ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004651{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004652 excepthandler_ty o = (excepthandler_ty)_o;
4653 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004654 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004655 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004656 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004658
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004659 switch (o->kind) {
4660 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004661 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4662 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004663 if (!result) goto failed;
4664 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004665 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004666 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004667 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004668 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004669 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004670 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004671 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004673 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004674 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4675 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004676 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004677 goto failed;
4678 Py_DECREF(value);
4679 break;
4680 }
4681 value = ast2obj_int(o->lineno);
4682 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004683 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004684 goto failed;
4685 Py_DECREF(value);
4686 value = ast2obj_int(o->col_offset);
4687 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004688 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004689 goto failed;
4690 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004691 value = ast2obj_int(o->end_lineno);
4692 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004693 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004694 goto failed;
4695 Py_DECREF(value);
4696 value = ast2obj_int(o->end_col_offset);
4697 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004698 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4699 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004700 goto failed;
4701 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004703failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 Py_XDECREF(value);
4705 Py_XDECREF(result);
4706 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004707}
4708
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004709PyObject*
4710ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004711{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004712 arguments_ty o = (arguments_ty)_o;
4713 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004714 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004715 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004716 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004718
Dino Viehlandac46eb42019-09-11 10:16:34 -07004719 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4720 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004721 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004722 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4723 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004724 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4725 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004726 goto failed;
4727 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004728 value = ast2obj_list(o->args, ast2obj_arg);
4729 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004730 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004731 goto failed;
4732 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004733 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004734 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004735 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004736 goto failed;
4737 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004738 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4739 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004740 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4741 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004742 goto failed;
4743 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004744 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004745 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004746 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4747 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004748 goto failed;
4749 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004750 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004751 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004752 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004753 goto failed;
4754 Py_DECREF(value);
4755 value = ast2obj_list(o->defaults, ast2obj_expr);
4756 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004757 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004758 goto failed;
4759 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004761failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 Py_XDECREF(value);
4763 Py_XDECREF(result);
4764 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004765}
4766
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004767PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004768ast2obj_arg(void* _o)
4769{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004770 arg_ty o = (arg_ty)_o;
4771 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004772 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004774 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004775 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004776
Dino Viehlandac46eb42019-09-11 10:16:34 -07004777 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4778 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004779 if (!result) return NULL;
4780 value = ast2obj_identifier(o->arg);
4781 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004782 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004783 goto failed;
4784 Py_DECREF(value);
4785 value = ast2obj_expr(o->annotation);
4786 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004787 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4788 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004789 goto failed;
4790 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004791 value = ast2obj_string(o->type_comment);
4792 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004793 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4794 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004795 goto failed;
4796 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004797 value = ast2obj_int(o->lineno);
4798 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004799 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004800 goto failed;
4801 Py_DECREF(value);
4802 value = ast2obj_int(o->col_offset);
4803 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004804 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004805 goto failed;
4806 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004807 value = ast2obj_int(o->end_lineno);
4808 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004809 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004810 goto failed;
4811 Py_DECREF(value);
4812 value = ast2obj_int(o->end_col_offset);
4813 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004814 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4815 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004816 goto failed;
4817 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004818 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004819failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004820 Py_XDECREF(value);
4821 Py_XDECREF(result);
4822 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004823}
4824
4825PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004826ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004827{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004828 keyword_ty o = (keyword_ty)_o;
4829 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004830 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004831 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004832 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004833 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004834
Dino Viehlandac46eb42019-09-11 10:16:34 -07004835 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4836 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004837 if (!result) return NULL;
4838 value = ast2obj_identifier(o->arg);
4839 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004840 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004841 goto failed;
4842 Py_DECREF(value);
4843 value = ast2obj_expr(o->value);
4844 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004845 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 goto failed;
4847 Py_DECREF(value);
4848 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004849failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004850 Py_XDECREF(value);
4851 Py_XDECREF(result);
4852 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004853}
4854
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004855PyObject*
4856ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004857{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004858 alias_ty o = (alias_ty)_o;
4859 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004860 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004862 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004863 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004864
Dino Viehlandac46eb42019-09-11 10:16:34 -07004865 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4866 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 if (!result) return NULL;
4868 value = ast2obj_identifier(o->name);
4869 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004870 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004871 goto failed;
4872 Py_DECREF(value);
4873 value = ast2obj_identifier(o->asname);
4874 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004875 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004876 goto failed;
4877 Py_DECREF(value);
4878 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004879failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004880 Py_XDECREF(value);
4881 Py_XDECREF(result);
4882 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004883}
4884
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004885PyObject*
4886ast2obj_withitem(void* _o)
4887{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004888 withitem_ty o = (withitem_ty)_o;
4889 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004890 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004892 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004893 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004894
Dino Viehlandac46eb42019-09-11 10:16:34 -07004895 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4896 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004897 if (!result) return NULL;
4898 value = ast2obj_expr(o->context_expr);
4899 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004900 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4901 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004902 goto failed;
4903 Py_DECREF(value);
4904 value = ast2obj_expr(o->optional_vars);
4905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004906 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4907 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 goto failed;
4909 Py_DECREF(value);
4910 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004911failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004912 Py_XDECREF(value);
4913 Py_XDECREF(result);
4914 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004915}
4916
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004917PyObject*
4918ast2obj_type_ignore(void* _o)
4919{
4920 type_ignore_ty o = (type_ignore_ty)_o;
4921 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004922 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004923 if (!o) {
4924 Py_RETURN_NONE;
4925 }
4926
4927 switch (o->kind) {
4928 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004929 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4930 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004931 if (!result) goto failed;
4932 value = ast2obj_int(o->v.TypeIgnore.lineno);
4933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004934 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4935 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004936 goto failed;
4937 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004938 value = ast2obj_string(o->v.TypeIgnore.tag);
4939 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004940 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004941 goto failed;
4942 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004943 break;
4944 }
4945 return result;
4946failed:
4947 Py_XDECREF(value);
4948 Py_XDECREF(result);
4949 return NULL;
4950}
4951
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004952
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004953int
4954obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4955{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004956 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004957
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004958 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004959 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004960
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004961 if (obj == Py_None) {
4962 *out = NULL;
4963 return 0;
4964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004965 tp = astmodulestate_global->Module_type;
4966 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004967 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004968 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004969 }
4970 if (isinstance) {
4971 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004972 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004973
Dino Viehlandac46eb42019-09-11 10:16:34 -07004974 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02004975 return 1;
4976 }
4977 if (tmp == NULL) {
4978 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
4979 return 1;
4980 }
4981 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004982 int res;
4983 Py_ssize_t len;
4984 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004985 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07004986 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 +02004987 goto failed;
4988 }
4989 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004990 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004991 if (body == NULL) goto failed;
4992 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07004993 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03004994 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
4995 Py_INCREF(tmp2);
4996 res = obj2ast_stmt(tmp2, &val, arena);
4997 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004998 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004999 if (len != PyList_GET_SIZE(tmp)) {
5000 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5001 goto failed;
5002 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005003 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005004 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005005 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005006 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005007 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5008 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005009 return 1;
5010 }
5011 if (tmp == NULL) {
5012 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5013 return 1;
5014 }
5015 else {
5016 int res;
5017 Py_ssize_t len;
5018 Py_ssize_t i;
5019 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005020 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 -08005021 goto failed;
5022 }
5023 len = PyList_GET_SIZE(tmp);
5024 type_ignores = _Py_asdl_seq_new(len, arena);
5025 if (type_ignores == NULL) goto failed;
5026 for (i = 0; i < len; i++) {
5027 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005028 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5029 Py_INCREF(tmp2);
5030 res = obj2ast_type_ignore(tmp2, &val, arena);
5031 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005032 if (res != 0) goto failed;
5033 if (len != PyList_GET_SIZE(tmp)) {
5034 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5035 goto failed;
5036 }
5037 asdl_seq_SET(type_ignores, i, val);
5038 }
5039 Py_CLEAR(tmp);
5040 }
5041 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005042 if (*out == NULL) goto failed;
5043 return 0;
5044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005045 tp = astmodulestate_global->Interactive_type;
5046 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005047 if (isinstance == -1) {
5048 return 1;
5049 }
5050 if (isinstance) {
5051 asdl_seq* body;
5052
Dino Viehlandac46eb42019-09-11 10:16:34 -07005053 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005054 return 1;
5055 }
5056 if (tmp == NULL) {
5057 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5058 return 1;
5059 }
5060 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005061 int res;
5062 Py_ssize_t len;
5063 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005064 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005065 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 +02005066 goto failed;
5067 }
5068 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005069 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005070 if (body == NULL) goto failed;
5071 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005072 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005073 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5074 Py_INCREF(tmp2);
5075 res = obj2ast_stmt(tmp2, &val, arena);
5076 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005077 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005078 if (len != PyList_GET_SIZE(tmp)) {
5079 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5080 goto failed;
5081 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005082 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005083 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005084 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005085 }
5086 *out = Interactive(body, arena);
5087 if (*out == NULL) goto failed;
5088 return 0;
5089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005090 tp = astmodulestate_global->Expression_type;
5091 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005092 if (isinstance == -1) {
5093 return 1;
5094 }
5095 if (isinstance) {
5096 expr_ty body;
5097
Dino Viehlandac46eb42019-09-11 10:16:34 -07005098 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005099 return 1;
5100 }
5101 if (tmp == NULL) {
5102 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5103 return 1;
5104 }
5105 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005106 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005107 res = obj2ast_expr(tmp, &body, arena);
5108 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005109 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005110 }
5111 *out = Expression(body, arena);
5112 if (*out == NULL) goto failed;
5113 return 0;
5114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005115 tp = astmodulestate_global->FunctionType_type;
5116 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005117 if (isinstance == -1) {
5118 return 1;
5119 }
5120 if (isinstance) {
5121 asdl_seq* argtypes;
5122 expr_ty returns;
5123
Dino Viehlandac46eb42019-09-11 10:16:34 -07005124 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5125 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005126 return 1;
5127 }
5128 if (tmp == NULL) {
5129 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5130 return 1;
5131 }
5132 else {
5133 int res;
5134 Py_ssize_t len;
5135 Py_ssize_t i;
5136 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005137 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 -08005138 goto failed;
5139 }
5140 len = PyList_GET_SIZE(tmp);
5141 argtypes = _Py_asdl_seq_new(len, arena);
5142 if (argtypes == NULL) goto failed;
5143 for (i = 0; i < len; i++) {
5144 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005145 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5146 Py_INCREF(tmp2);
5147 res = obj2ast_expr(tmp2, &val, arena);
5148 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005149 if (res != 0) goto failed;
5150 if (len != PyList_GET_SIZE(tmp)) {
5151 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5152 goto failed;
5153 }
5154 asdl_seq_SET(argtypes, i, val);
5155 }
5156 Py_CLEAR(tmp);
5157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005158 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5159 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005160 return 1;
5161 }
5162 if (tmp == NULL) {
5163 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5164 return 1;
5165 }
5166 else {
5167 int res;
5168 res = obj2ast_expr(tmp, &returns, arena);
5169 if (res != 0) goto failed;
5170 Py_CLEAR(tmp);
5171 }
5172 *out = FunctionType(argtypes, returns, arena);
5173 if (*out == NULL) goto failed;
5174 return 0;
5175 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005176
5177 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5178 failed:
5179 Py_XDECREF(tmp);
5180 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005181}
5182
5183int
5184obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5185{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005186 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005187
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005188 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005189 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005190 int lineno;
5191 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005192 int end_lineno;
5193 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005194
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005195 if (obj == Py_None) {
5196 *out = NULL;
5197 return 0;
5198 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005199 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005200 return 1;
5201 }
5202 if (tmp == NULL) {
5203 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5204 return 1;
5205 }
5206 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005207 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005208 res = obj2ast_int(tmp, &lineno, arena);
5209 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005210 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005211 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005212 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5213 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005214 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005215 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005216 if (tmp == NULL) {
5217 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5218 return 1;
5219 }
5220 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005221 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005222 res = obj2ast_int(tmp, &col_offset, arena);
5223 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005224 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005225 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005226 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5227 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005228 return 1;
5229 }
5230 if (tmp == NULL || tmp == Py_None) {
5231 Py_CLEAR(tmp);
5232 end_lineno = 0;
5233 }
5234 else {
5235 int res;
5236 res = obj2ast_int(tmp, &end_lineno, arena);
5237 if (res != 0) goto failed;
5238 Py_CLEAR(tmp);
5239 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005240 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5241 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005242 return 1;
5243 }
5244 if (tmp == NULL || tmp == Py_None) {
5245 Py_CLEAR(tmp);
5246 end_col_offset = 0;
5247 }
5248 else {
5249 int res;
5250 res = obj2ast_int(tmp, &end_col_offset, arena);
5251 if (res != 0) goto failed;
5252 Py_CLEAR(tmp);
5253 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005254 tp = astmodulestate_global->FunctionDef_type;
5255 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005256 if (isinstance == -1) {
5257 return 1;
5258 }
5259 if (isinstance) {
5260 identifier name;
5261 arguments_ty args;
5262 asdl_seq* body;
5263 asdl_seq* decorator_list;
5264 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005265 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005266
Dino Viehlandac46eb42019-09-11 10:16:34 -07005267 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005268 return 1;
5269 }
5270 if (tmp == NULL) {
5271 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5272 return 1;
5273 }
5274 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005275 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005276 res = obj2ast_identifier(tmp, &name, arena);
5277 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005278 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005280 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005281 return 1;
5282 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005283 if (tmp == NULL) {
5284 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5285 return 1;
5286 }
5287 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005288 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005289 res = obj2ast_arguments(tmp, &args, arena);
5290 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005291 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005293 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005294 return 1;
5295 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005296 if (tmp == NULL) {
5297 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5298 return 1;
5299 }
5300 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005301 int res;
5302 Py_ssize_t len;
5303 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005304 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005305 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 +02005306 goto failed;
5307 }
5308 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005309 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005310 if (body == NULL) goto failed;
5311 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005312 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005313 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5314 Py_INCREF(tmp2);
5315 res = obj2ast_stmt(tmp2, &val, arena);
5316 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005317 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005318 if (len != PyList_GET_SIZE(tmp)) {
5319 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5320 goto failed;
5321 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005322 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005323 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005324 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005325 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005326 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5327 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005328 return 1;
5329 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005330 if (tmp == NULL) {
5331 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5332 return 1;
5333 }
5334 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005335 int res;
5336 Py_ssize_t len;
5337 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005338 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005339 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 +02005340 goto failed;
5341 }
5342 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005343 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005344 if (decorator_list == NULL) goto failed;
5345 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005346 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005347 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5348 Py_INCREF(tmp2);
5349 res = obj2ast_expr(tmp2, &val, arena);
5350 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005351 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005352 if (len != PyList_GET_SIZE(tmp)) {
5353 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5354 goto failed;
5355 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005356 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005357 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005358 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005360 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5361 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005362 return 1;
5363 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005364 if (tmp == NULL || tmp == Py_None) {
5365 Py_CLEAR(tmp);
5366 returns = NULL;
5367 }
5368 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005369 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005370 res = obj2ast_expr(tmp, &returns, arena);
5371 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005372 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005374 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5375 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005376 return 1;
5377 }
5378 if (tmp == NULL || tmp == Py_None) {
5379 Py_CLEAR(tmp);
5380 type_comment = NULL;
5381 }
5382 else {
5383 int res;
5384 res = obj2ast_string(tmp, &type_comment, arena);
5385 if (res != 0) goto failed;
5386 Py_CLEAR(tmp);
5387 }
5388 *out = FunctionDef(name, args, body, decorator_list, returns,
5389 type_comment, lineno, col_offset, end_lineno,
5390 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005391 if (*out == NULL) goto failed;
5392 return 0;
5393 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005394 tp = astmodulestate_global->AsyncFunctionDef_type;
5395 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005396 if (isinstance == -1) {
5397 return 1;
5398 }
5399 if (isinstance) {
5400 identifier name;
5401 arguments_ty args;
5402 asdl_seq* body;
5403 asdl_seq* decorator_list;
5404 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005405 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005406
Dino Viehlandac46eb42019-09-11 10:16:34 -07005407 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005408 return 1;
5409 }
5410 if (tmp == NULL) {
5411 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5412 return 1;
5413 }
5414 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005415 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005416 res = obj2ast_identifier(tmp, &name, arena);
5417 if (res != 0) goto failed;
5418 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005419 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005420 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005421 return 1;
5422 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005423 if (tmp == NULL) {
5424 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5425 return 1;
5426 }
5427 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005428 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005429 res = obj2ast_arguments(tmp, &args, arena);
5430 if (res != 0) goto failed;
5431 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005432 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005433 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005434 return 1;
5435 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005436 if (tmp == NULL) {
5437 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5438 return 1;
5439 }
5440 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005441 int res;
5442 Py_ssize_t len;
5443 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005444 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005445 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 -04005446 goto failed;
5447 }
5448 len = PyList_GET_SIZE(tmp);
5449 body = _Py_asdl_seq_new(len, arena);
5450 if (body == NULL) goto failed;
5451 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005452 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005453 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5454 Py_INCREF(tmp2);
5455 res = obj2ast_stmt(tmp2, &val, arena);
5456 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005457 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005458 if (len != PyList_GET_SIZE(tmp)) {
5459 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5460 goto failed;
5461 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005462 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005463 }
5464 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005465 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005466 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5467 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005468 return 1;
5469 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005470 if (tmp == NULL) {
5471 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5472 return 1;
5473 }
5474 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005475 int res;
5476 Py_ssize_t len;
5477 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005478 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005479 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 -04005480 goto failed;
5481 }
5482 len = PyList_GET_SIZE(tmp);
5483 decorator_list = _Py_asdl_seq_new(len, arena);
5484 if (decorator_list == NULL) goto failed;
5485 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005486 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005487 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5488 Py_INCREF(tmp2);
5489 res = obj2ast_expr(tmp2, &val, arena);
5490 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005491 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005492 if (len != PyList_GET_SIZE(tmp)) {
5493 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5494 goto failed;
5495 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005496 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005497 }
5498 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005499 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005500 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5501 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005502 return 1;
5503 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005504 if (tmp == NULL || tmp == Py_None) {
5505 Py_CLEAR(tmp);
5506 returns = NULL;
5507 }
5508 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005509 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005510 res = obj2ast_expr(tmp, &returns, arena);
5511 if (res != 0) goto failed;
5512 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005513 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005514 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5515 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005516 return 1;
5517 }
5518 if (tmp == NULL || tmp == Py_None) {
5519 Py_CLEAR(tmp);
5520 type_comment = NULL;
5521 }
5522 else {
5523 int res;
5524 res = obj2ast_string(tmp, &type_comment, arena);
5525 if (res != 0) goto failed;
5526 Py_CLEAR(tmp);
5527 }
Yury Selivanov75445082015-05-11 22:57:16 -04005528 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005529 type_comment, lineno, col_offset, end_lineno,
5530 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005531 if (*out == NULL) goto failed;
5532 return 0;
5533 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005534 tp = astmodulestate_global->ClassDef_type;
5535 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005536 if (isinstance == -1) {
5537 return 1;
5538 }
5539 if (isinstance) {
5540 identifier name;
5541 asdl_seq* bases;
5542 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005543 asdl_seq* body;
5544 asdl_seq* decorator_list;
5545
Dino Viehlandac46eb42019-09-11 10:16:34 -07005546 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005547 return 1;
5548 }
5549 if (tmp == NULL) {
5550 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5551 return 1;
5552 }
5553 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005554 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005555 res = obj2ast_identifier(tmp, &name, arena);
5556 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005557 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005558 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005559 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005560 return 1;
5561 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005562 if (tmp == NULL) {
5563 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5564 return 1;
5565 }
5566 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005567 int res;
5568 Py_ssize_t len;
5569 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005570 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005571 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 +02005572 goto failed;
5573 }
5574 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005575 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005576 if (bases == NULL) goto failed;
5577 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005578 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005579 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5580 Py_INCREF(tmp2);
5581 res = obj2ast_expr(tmp2, &val, arena);
5582 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005583 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005584 if (len != PyList_GET_SIZE(tmp)) {
5585 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5586 goto failed;
5587 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005588 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005589 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005590 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005591 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005592 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5593 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005594 return 1;
5595 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005596 if (tmp == NULL) {
5597 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5598 return 1;
5599 }
5600 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005601 int res;
5602 Py_ssize_t len;
5603 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005604 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005605 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 +02005606 goto failed;
5607 }
5608 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005609 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005610 if (keywords == NULL) goto failed;
5611 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005612 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005613 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5614 Py_INCREF(tmp2);
5615 res = obj2ast_keyword(tmp2, &val, arena);
5616 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005617 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005618 if (len != PyList_GET_SIZE(tmp)) {
5619 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5620 goto failed;
5621 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005622 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005623 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005624 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005626 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005627 return 1;
5628 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005629 if (tmp == NULL) {
5630 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5631 return 1;
5632 }
5633 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005634 int res;
5635 Py_ssize_t len;
5636 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005637 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005638 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 +02005639 goto failed;
5640 }
5641 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005642 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005643 if (body == NULL) goto failed;
5644 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005645 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005646 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5647 Py_INCREF(tmp2);
5648 res = obj2ast_stmt(tmp2, &val, arena);
5649 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005650 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005651 if (len != PyList_GET_SIZE(tmp)) {
5652 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5653 goto failed;
5654 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005655 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005656 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005657 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005658 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005659 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5660 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005661 return 1;
5662 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005663 if (tmp == NULL) {
5664 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5665 return 1;
5666 }
5667 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005668 int res;
5669 Py_ssize_t len;
5670 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005671 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005672 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 +02005673 goto failed;
5674 }
5675 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005676 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005677 if (decorator_list == NULL) goto failed;
5678 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005679 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005680 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5681 Py_INCREF(tmp2);
5682 res = obj2ast_expr(tmp2, &val, arena);
5683 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005684 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005685 if (len != PyList_GET_SIZE(tmp)) {
5686 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5687 goto failed;
5688 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005689 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005690 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005691 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005692 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005693 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005694 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005695 if (*out == NULL) goto failed;
5696 return 0;
5697 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005698 tp = astmodulestate_global->Return_type;
5699 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005700 if (isinstance == -1) {
5701 return 1;
5702 }
5703 if (isinstance) {
5704 expr_ty value;
5705
Dino Viehlandac46eb42019-09-11 10:16:34 -07005706 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005707 return 1;
5708 }
5709 if (tmp == NULL || tmp == Py_None) {
5710 Py_CLEAR(tmp);
5711 value = NULL;
5712 }
5713 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005714 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005715 res = obj2ast_expr(tmp, &value, arena);
5716 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005717 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005718 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005719 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5720 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005721 if (*out == NULL) goto failed;
5722 return 0;
5723 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005724 tp = astmodulestate_global->Delete_type;
5725 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005726 if (isinstance == -1) {
5727 return 1;
5728 }
5729 if (isinstance) {
5730 asdl_seq* targets;
5731
Dino Viehlandac46eb42019-09-11 10:16:34 -07005732 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5733 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005734 return 1;
5735 }
5736 if (tmp == NULL) {
5737 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5738 return 1;
5739 }
5740 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005741 int res;
5742 Py_ssize_t len;
5743 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005744 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005745 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 +02005746 goto failed;
5747 }
5748 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005749 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005750 if (targets == NULL) goto failed;
5751 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005752 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005753 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5754 Py_INCREF(tmp2);
5755 res = obj2ast_expr(tmp2, &val, arena);
5756 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005757 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005758 if (len != PyList_GET_SIZE(tmp)) {
5759 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5760 goto failed;
5761 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005762 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005764 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005765 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005766 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5767 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005768 if (*out == NULL) goto failed;
5769 return 0;
5770 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005771 tp = astmodulestate_global->Assign_type;
5772 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005773 if (isinstance == -1) {
5774 return 1;
5775 }
5776 if (isinstance) {
5777 asdl_seq* targets;
5778 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005779 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005780
Dino Viehlandac46eb42019-09-11 10:16:34 -07005781 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5782 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005783 return 1;
5784 }
5785 if (tmp == NULL) {
5786 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5787 return 1;
5788 }
5789 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005790 int res;
5791 Py_ssize_t len;
5792 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005793 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005794 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 +02005795 goto failed;
5796 }
5797 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005798 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005799 if (targets == NULL) goto failed;
5800 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005801 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005802 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5803 Py_INCREF(tmp2);
5804 res = obj2ast_expr(tmp2, &val, arena);
5805 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005807 if (len != PyList_GET_SIZE(tmp)) {
5808 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5809 goto failed;
5810 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005811 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005812 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005813 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005814 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005815 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005816 return 1;
5817 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005818 if (tmp == NULL) {
5819 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5820 return 1;
5821 }
5822 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005823 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005824 res = obj2ast_expr(tmp, &value, arena);
5825 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005826 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005827 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005828 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5829 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005830 return 1;
5831 }
5832 if (tmp == NULL || tmp == Py_None) {
5833 Py_CLEAR(tmp);
5834 type_comment = NULL;
5835 }
5836 else {
5837 int res;
5838 res = obj2ast_string(tmp, &type_comment, arena);
5839 if (res != 0) goto failed;
5840 Py_CLEAR(tmp);
5841 }
5842 *out = Assign(targets, value, type_comment, lineno, col_offset,
5843 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005844 if (*out == NULL) goto failed;
5845 return 0;
5846 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005847 tp = astmodulestate_global->AugAssign_type;
5848 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005849 if (isinstance == -1) {
5850 return 1;
5851 }
5852 if (isinstance) {
5853 expr_ty target;
5854 operator_ty op;
5855 expr_ty value;
5856
Dino Viehlandac46eb42019-09-11 10:16:34 -07005857 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5858 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005859 return 1;
5860 }
5861 if (tmp == NULL) {
5862 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5863 return 1;
5864 }
5865 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005866 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005867 res = obj2ast_expr(tmp, &target, arena);
5868 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005869 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005870 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005871 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872 return 1;
5873 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005874 if (tmp == NULL) {
5875 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5876 return 1;
5877 }
5878 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005879 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005880 res = obj2ast_operator(tmp, &op, arena);
5881 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005882 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005884 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005885 return 1;
5886 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005887 if (tmp == NULL) {
5888 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5889 return 1;
5890 }
5891 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005892 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005893 res = obj2ast_expr(tmp, &value, arena);
5894 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005895 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005896 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005897 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5898 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005899 if (*out == NULL) goto failed;
5900 return 0;
5901 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005902 tp = astmodulestate_global->AnnAssign_type;
5903 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005904 if (isinstance == -1) {
5905 return 1;
5906 }
5907 if (isinstance) {
5908 expr_ty target;
5909 expr_ty annotation;
5910 expr_ty value;
5911 int simple;
5912
Dino Viehlandac46eb42019-09-11 10:16:34 -07005913 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5914 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005915 return 1;
5916 }
5917 if (tmp == NULL) {
5918 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5919 return 1;
5920 }
5921 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005922 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005923 res = obj2ast_expr(tmp, &target, arena);
5924 if (res != 0) goto failed;
5925 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005926 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005927 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
5928 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005929 return 1;
5930 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005931 if (tmp == NULL) {
5932 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
5933 return 1;
5934 }
5935 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005936 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005937 res = obj2ast_expr(tmp, &annotation, arena);
5938 if (res != 0) goto failed;
5939 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005940 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005941 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005942 return 1;
5943 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005944 if (tmp == NULL || tmp == Py_None) {
5945 Py_CLEAR(tmp);
5946 value = NULL;
5947 }
5948 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005949 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005950 res = obj2ast_expr(tmp, &value, arena);
5951 if (res != 0) goto failed;
5952 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005954 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
5955 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005956 return 1;
5957 }
5958 if (tmp == NULL) {
5959 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
5960 return 1;
5961 }
5962 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005963 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005964 res = obj2ast_int(tmp, &simple, arena);
5965 if (res != 0) goto failed;
5966 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005967 }
5968 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005969 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005970 if (*out == NULL) goto failed;
5971 return 0;
5972 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005973 tp = astmodulestate_global->For_type;
5974 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005975 if (isinstance == -1) {
5976 return 1;
5977 }
5978 if (isinstance) {
5979 expr_ty target;
5980 expr_ty iter;
5981 asdl_seq* body;
5982 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005983 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005984
Dino Viehlandac46eb42019-09-11 10:16:34 -07005985 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5986 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005987 return 1;
5988 }
5989 if (tmp == NULL) {
5990 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
5991 return 1;
5992 }
5993 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005994 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005995 res = obj2ast_expr(tmp, &target, arena);
5996 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005997 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005998 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005999 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006000 return 1;
6001 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006002 if (tmp == NULL) {
6003 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6004 return 1;
6005 }
6006 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006007 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006008 res = obj2ast_expr(tmp, &iter, arena);
6009 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006010 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006012 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006013 return 1;
6014 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006015 if (tmp == NULL) {
6016 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6017 return 1;
6018 }
6019 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006020 int res;
6021 Py_ssize_t len;
6022 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006023 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006024 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 +02006025 goto failed;
6026 }
6027 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006028 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006029 if (body == NULL) goto failed;
6030 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006031 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006032 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6033 Py_INCREF(tmp2);
6034 res = obj2ast_stmt(tmp2, &val, arena);
6035 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006036 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006037 if (len != PyList_GET_SIZE(tmp)) {
6038 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6039 goto failed;
6040 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006041 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006042 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006043 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006045 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6046 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006047 return 1;
6048 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006049 if (tmp == NULL) {
6050 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6051 return 1;
6052 }
6053 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006054 int res;
6055 Py_ssize_t len;
6056 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006057 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006058 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 +02006059 goto failed;
6060 }
6061 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006062 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006063 if (orelse == NULL) goto failed;
6064 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006065 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006066 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6067 Py_INCREF(tmp2);
6068 res = obj2ast_stmt(tmp2, &val, arena);
6069 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006070 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006071 if (len != PyList_GET_SIZE(tmp)) {
6072 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6073 goto failed;
6074 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006075 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006076 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006077 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006078 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006079 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6080 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006081 return 1;
6082 }
6083 if (tmp == NULL || tmp == Py_None) {
6084 Py_CLEAR(tmp);
6085 type_comment = NULL;
6086 }
6087 else {
6088 int res;
6089 res = obj2ast_string(tmp, &type_comment, arena);
6090 if (res != 0) goto failed;
6091 Py_CLEAR(tmp);
6092 }
6093 *out = For(target, iter, body, orelse, type_comment, lineno,
6094 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006095 if (*out == NULL) goto failed;
6096 return 0;
6097 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006098 tp = astmodulestate_global->AsyncFor_type;
6099 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006100 if (isinstance == -1) {
6101 return 1;
6102 }
6103 if (isinstance) {
6104 expr_ty target;
6105 expr_ty iter;
6106 asdl_seq* body;
6107 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006108 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006109
Dino Viehlandac46eb42019-09-11 10:16:34 -07006110 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6111 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006112 return 1;
6113 }
6114 if (tmp == NULL) {
6115 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6116 return 1;
6117 }
6118 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006119 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006120 res = obj2ast_expr(tmp, &target, arena);
6121 if (res != 0) goto failed;
6122 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006123 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006124 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006125 return 1;
6126 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006127 if (tmp == NULL) {
6128 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6129 return 1;
6130 }
6131 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006132 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006133 res = obj2ast_expr(tmp, &iter, arena);
6134 if (res != 0) goto failed;
6135 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006137 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006138 return 1;
6139 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006140 if (tmp == NULL) {
6141 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6142 return 1;
6143 }
6144 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006145 int res;
6146 Py_ssize_t len;
6147 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006148 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006149 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 -04006150 goto failed;
6151 }
6152 len = PyList_GET_SIZE(tmp);
6153 body = _Py_asdl_seq_new(len, arena);
6154 if (body == NULL) goto failed;
6155 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006156 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006157 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6158 Py_INCREF(tmp2);
6159 res = obj2ast_stmt(tmp2, &val, arena);
6160 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006161 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006162 if (len != PyList_GET_SIZE(tmp)) {
6163 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6164 goto failed;
6165 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006166 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006167 }
6168 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006170 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6171 {
Yury Selivanov75445082015-05-11 22:57:16 -04006172 return 1;
6173 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006174 if (tmp == NULL) {
6175 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6176 return 1;
6177 }
6178 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006179 int res;
6180 Py_ssize_t len;
6181 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006182 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006183 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 -04006184 goto failed;
6185 }
6186 len = PyList_GET_SIZE(tmp);
6187 orelse = _Py_asdl_seq_new(len, arena);
6188 if (orelse == NULL) goto failed;
6189 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006190 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006191 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6192 Py_INCREF(tmp2);
6193 res = obj2ast_stmt(tmp2, &val, arena);
6194 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006195 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006196 if (len != PyList_GET_SIZE(tmp)) {
6197 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6198 goto failed;
6199 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006200 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006201 }
6202 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006204 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6205 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006206 return 1;
6207 }
6208 if (tmp == NULL || tmp == Py_None) {
6209 Py_CLEAR(tmp);
6210 type_comment = NULL;
6211 }
6212 else {
6213 int res;
6214 res = obj2ast_string(tmp, &type_comment, arena);
6215 if (res != 0) goto failed;
6216 Py_CLEAR(tmp);
6217 }
6218 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6219 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006220 if (*out == NULL) goto failed;
6221 return 0;
6222 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006223 tp = astmodulestate_global->While_type;
6224 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006225 if (isinstance == -1) {
6226 return 1;
6227 }
6228 if (isinstance) {
6229 expr_ty test;
6230 asdl_seq* body;
6231 asdl_seq* orelse;
6232
Dino Viehlandac46eb42019-09-11 10:16:34 -07006233 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006234 return 1;
6235 }
6236 if (tmp == NULL) {
6237 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6238 return 1;
6239 }
6240 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006241 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006242 res = obj2ast_expr(tmp, &test, arena);
6243 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006244 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006246 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006247 return 1;
6248 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006249 if (tmp == NULL) {
6250 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6251 return 1;
6252 }
6253 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006254 int res;
6255 Py_ssize_t len;
6256 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006257 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006258 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 +02006259 goto failed;
6260 }
6261 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006262 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006263 if (body == NULL) goto failed;
6264 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006265 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006266 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6267 Py_INCREF(tmp2);
6268 res = obj2ast_stmt(tmp2, &val, arena);
6269 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006270 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006271 if (len != PyList_GET_SIZE(tmp)) {
6272 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6273 goto failed;
6274 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006275 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006276 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006277 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006279 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6280 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006281 return 1;
6282 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006283 if (tmp == NULL) {
6284 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6285 return 1;
6286 }
6287 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006288 int res;
6289 Py_ssize_t len;
6290 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006291 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006292 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 +02006293 goto failed;
6294 }
6295 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006296 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006297 if (orelse == NULL) goto failed;
6298 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006299 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006300 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6301 Py_INCREF(tmp2);
6302 res = obj2ast_stmt(tmp2, &val, arena);
6303 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006304 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006305 if (len != PyList_GET_SIZE(tmp)) {
6306 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6307 goto failed;
6308 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006309 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006310 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006311 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006312 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006313 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6314 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006315 if (*out == NULL) goto failed;
6316 return 0;
6317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006318 tp = astmodulestate_global->If_type;
6319 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006320 if (isinstance == -1) {
6321 return 1;
6322 }
6323 if (isinstance) {
6324 expr_ty test;
6325 asdl_seq* body;
6326 asdl_seq* orelse;
6327
Dino Viehlandac46eb42019-09-11 10:16:34 -07006328 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006329 return 1;
6330 }
6331 if (tmp == NULL) {
6332 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6333 return 1;
6334 }
6335 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006336 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006337 res = obj2ast_expr(tmp, &test, arena);
6338 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006339 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006340 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006341 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006342 return 1;
6343 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006344 if (tmp == NULL) {
6345 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6346 return 1;
6347 }
6348 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006349 int res;
6350 Py_ssize_t len;
6351 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006352 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006353 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 +02006354 goto failed;
6355 }
6356 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006357 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006358 if (body == NULL) goto failed;
6359 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006360 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006361 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6362 Py_INCREF(tmp2);
6363 res = obj2ast_stmt(tmp2, &val, arena);
6364 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006365 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006366 if (len != PyList_GET_SIZE(tmp)) {
6367 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6368 goto failed;
6369 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006370 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006371 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006372 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006374 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6375 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006376 return 1;
6377 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006378 if (tmp == NULL) {
6379 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6380 return 1;
6381 }
6382 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006383 int res;
6384 Py_ssize_t len;
6385 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006386 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006387 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006388 goto failed;
6389 }
6390 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006391 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006392 if (orelse == NULL) goto failed;
6393 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006394 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006395 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6396 Py_INCREF(tmp2);
6397 res = obj2ast_stmt(tmp2, &val, arena);
6398 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006399 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006400 if (len != PyList_GET_SIZE(tmp)) {
6401 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6402 goto failed;
6403 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006404 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006405 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006406 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006407 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006408 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6409 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006410 if (*out == NULL) goto failed;
6411 return 0;
6412 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006413 tp = astmodulestate_global->With_type;
6414 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006415 if (isinstance == -1) {
6416 return 1;
6417 }
6418 if (isinstance) {
6419 asdl_seq* items;
6420 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006421 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006422
Dino Viehlandac46eb42019-09-11 10:16:34 -07006423 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006424 return 1;
6425 }
6426 if (tmp == NULL) {
6427 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6428 return 1;
6429 }
6430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006431 int res;
6432 Py_ssize_t len;
6433 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006434 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006435 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 +02006436 goto failed;
6437 }
6438 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006439 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006440 if (items == NULL) goto failed;
6441 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006442 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006443 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6444 Py_INCREF(tmp2);
6445 res = obj2ast_withitem(tmp2, &val, arena);
6446 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006447 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006448 if (len != PyList_GET_SIZE(tmp)) {
6449 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6450 goto failed;
6451 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006452 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006453 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006454 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006455 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006456 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006457 return 1;
6458 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006459 if (tmp == NULL) {
6460 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6461 return 1;
6462 }
6463 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006464 int res;
6465 Py_ssize_t len;
6466 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006467 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006468 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 +02006469 goto failed;
6470 }
6471 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006472 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006473 if (body == NULL) goto failed;
6474 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006475 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006476 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6477 Py_INCREF(tmp2);
6478 res = obj2ast_stmt(tmp2, &val, arena);
6479 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006480 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006481 if (len != PyList_GET_SIZE(tmp)) {
6482 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6483 goto failed;
6484 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006485 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006486 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006487 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006488 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006489 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6490 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006491 return 1;
6492 }
6493 if (tmp == NULL || tmp == Py_None) {
6494 Py_CLEAR(tmp);
6495 type_comment = NULL;
6496 }
6497 else {
6498 int res;
6499 res = obj2ast_string(tmp, &type_comment, arena);
6500 if (res != 0) goto failed;
6501 Py_CLEAR(tmp);
6502 }
6503 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006504 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006505 if (*out == NULL) goto failed;
6506 return 0;
6507 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006508 tp = astmodulestate_global->AsyncWith_type;
6509 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006510 if (isinstance == -1) {
6511 return 1;
6512 }
6513 if (isinstance) {
6514 asdl_seq* items;
6515 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006516 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006517
Dino Viehlandac46eb42019-09-11 10:16:34 -07006518 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006519 return 1;
6520 }
6521 if (tmp == NULL) {
6522 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6523 return 1;
6524 }
6525 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006526 int res;
6527 Py_ssize_t len;
6528 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006529 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006530 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 -04006531 goto failed;
6532 }
6533 len = PyList_GET_SIZE(tmp);
6534 items = _Py_asdl_seq_new(len, arena);
6535 if (items == NULL) goto failed;
6536 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006537 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006538 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6539 Py_INCREF(tmp2);
6540 res = obj2ast_withitem(tmp2, &val, arena);
6541 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006542 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006543 if (len != PyList_GET_SIZE(tmp)) {
6544 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6545 goto failed;
6546 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006547 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006548 }
6549 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006550 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006551 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006552 return 1;
6553 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006554 if (tmp == NULL) {
6555 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6556 return 1;
6557 }
6558 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006559 int res;
6560 Py_ssize_t len;
6561 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006562 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006563 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 -04006564 goto failed;
6565 }
6566 len = PyList_GET_SIZE(tmp);
6567 body = _Py_asdl_seq_new(len, arena);
6568 if (body == NULL) goto failed;
6569 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006570 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006571 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6572 Py_INCREF(tmp2);
6573 res = obj2ast_stmt(tmp2, &val, arena);
6574 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006575 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006576 if (len != PyList_GET_SIZE(tmp)) {
6577 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6578 goto failed;
6579 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006580 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006581 }
6582 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006583 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006584 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6585 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006586 return 1;
6587 }
6588 if (tmp == NULL || tmp == Py_None) {
6589 Py_CLEAR(tmp);
6590 type_comment = NULL;
6591 }
6592 else {
6593 int res;
6594 res = obj2ast_string(tmp, &type_comment, arena);
6595 if (res != 0) goto failed;
6596 Py_CLEAR(tmp);
6597 }
6598 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6599 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006600 if (*out == NULL) goto failed;
6601 return 0;
6602 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006603 tp = astmodulestate_global->Raise_type;
6604 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006605 if (isinstance == -1) {
6606 return 1;
6607 }
6608 if (isinstance) {
6609 expr_ty exc;
6610 expr_ty cause;
6611
Dino Viehlandac46eb42019-09-11 10:16:34 -07006612 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006613 return 1;
6614 }
6615 if (tmp == NULL || tmp == Py_None) {
6616 Py_CLEAR(tmp);
6617 exc = NULL;
6618 }
6619 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006620 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006621 res = obj2ast_expr(tmp, &exc, arena);
6622 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006623 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006624 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006625 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006626 return 1;
6627 }
6628 if (tmp == NULL || tmp == Py_None) {
6629 Py_CLEAR(tmp);
6630 cause = NULL;
6631 }
6632 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006633 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006634 res = obj2ast_expr(tmp, &cause, arena);
6635 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006636 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006637 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006638 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6639 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006640 if (*out == NULL) goto failed;
6641 return 0;
6642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006643 tp = astmodulestate_global->Try_type;
6644 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006645 if (isinstance == -1) {
6646 return 1;
6647 }
6648 if (isinstance) {
6649 asdl_seq* body;
6650 asdl_seq* handlers;
6651 asdl_seq* orelse;
6652 asdl_seq* finalbody;
6653
Dino Viehlandac46eb42019-09-11 10:16:34 -07006654 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006655 return 1;
6656 }
6657 if (tmp == NULL) {
6658 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6659 return 1;
6660 }
6661 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006662 int res;
6663 Py_ssize_t len;
6664 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006665 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006666 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 +02006667 goto failed;
6668 }
6669 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006670 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006671 if (body == NULL) goto failed;
6672 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006673 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006674 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6675 Py_INCREF(tmp2);
6676 res = obj2ast_stmt(tmp2, &val, arena);
6677 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006678 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006679 if (len != PyList_GET_SIZE(tmp)) {
6680 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6681 goto failed;
6682 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006683 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006684 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006685 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006686 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006687 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6688 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006689 return 1;
6690 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006691 if (tmp == NULL) {
6692 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6693 return 1;
6694 }
6695 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006696 int res;
6697 Py_ssize_t len;
6698 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006699 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006700 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 +02006701 goto failed;
6702 }
6703 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006704 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006705 if (handlers == NULL) goto failed;
6706 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006707 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006708 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6709 Py_INCREF(tmp2);
6710 res = obj2ast_excepthandler(tmp2, &val, arena);
6711 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006712 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006713 if (len != PyList_GET_SIZE(tmp)) {
6714 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6715 goto failed;
6716 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006717 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006718 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006719 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006720 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006721 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6722 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006723 return 1;
6724 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006725 if (tmp == NULL) {
6726 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6727 return 1;
6728 }
6729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006730 int res;
6731 Py_ssize_t len;
6732 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006733 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006734 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 +02006735 goto failed;
6736 }
6737 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006738 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006739 if (orelse == NULL) goto failed;
6740 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006741 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006742 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6743 Py_INCREF(tmp2);
6744 res = obj2ast_stmt(tmp2, &val, arena);
6745 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006746 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006747 if (len != PyList_GET_SIZE(tmp)) {
6748 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6749 goto failed;
6750 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006751 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006752 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006753 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006754 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006755 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6756 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006757 return 1;
6758 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006759 if (tmp == NULL) {
6760 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6761 return 1;
6762 }
6763 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006764 int res;
6765 Py_ssize_t len;
6766 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006767 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006768 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 +02006769 goto failed;
6770 }
6771 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006772 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006773 if (finalbody == NULL) goto failed;
6774 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006775 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006776 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6777 Py_INCREF(tmp2);
6778 res = obj2ast_stmt(tmp2, &val, arena);
6779 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006780 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006781 if (len != PyList_GET_SIZE(tmp)) {
6782 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6783 goto failed;
6784 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006785 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006786 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006787 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006788 }
6789 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006790 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 if (*out == NULL) goto failed;
6792 return 0;
6793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006794 tp = astmodulestate_global->Assert_type;
6795 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006796 if (isinstance == -1) {
6797 return 1;
6798 }
6799 if (isinstance) {
6800 expr_ty test;
6801 expr_ty msg;
6802
Dino Viehlandac46eb42019-09-11 10:16:34 -07006803 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006804 return 1;
6805 }
6806 if (tmp == NULL) {
6807 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6808 return 1;
6809 }
6810 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006811 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006812 res = obj2ast_expr(tmp, &test, arena);
6813 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006814 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006816 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006817 return 1;
6818 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006819 if (tmp == NULL || tmp == Py_None) {
6820 Py_CLEAR(tmp);
6821 msg = NULL;
6822 }
6823 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006824 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006825 res = obj2ast_expr(tmp, &msg, arena);
6826 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006827 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006828 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006829 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6830 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006831 if (*out == NULL) goto failed;
6832 return 0;
6833 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006834 tp = astmodulestate_global->Import_type;
6835 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006836 if (isinstance == -1) {
6837 return 1;
6838 }
6839 if (isinstance) {
6840 asdl_seq* names;
6841
Dino Viehlandac46eb42019-09-11 10:16:34 -07006842 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006843 return 1;
6844 }
6845 if (tmp == NULL) {
6846 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6847 return 1;
6848 }
6849 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006850 int res;
6851 Py_ssize_t len;
6852 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006853 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006854 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 +02006855 goto failed;
6856 }
6857 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006858 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006859 if (names == NULL) goto failed;
6860 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006861 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006862 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6863 Py_INCREF(tmp2);
6864 res = obj2ast_alias(tmp2, &val, arena);
6865 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006866 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006867 if (len != PyList_GET_SIZE(tmp)) {
6868 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6869 goto failed;
6870 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006871 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006872 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006873 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006874 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006875 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6876 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006877 if (*out == NULL) goto failed;
6878 return 0;
6879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006880 tp = astmodulestate_global->ImportFrom_type;
6881 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006882 if (isinstance == -1) {
6883 return 1;
6884 }
6885 if (isinstance) {
6886 identifier module;
6887 asdl_seq* names;
6888 int level;
6889
Dino Viehlandac46eb42019-09-11 10:16:34 -07006890 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6891 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006892 return 1;
6893 }
6894 if (tmp == NULL || tmp == Py_None) {
6895 Py_CLEAR(tmp);
6896 module = NULL;
6897 }
6898 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006899 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 res = obj2ast_identifier(tmp, &module, arena);
6901 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006902 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006903 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006904 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006905 return 1;
6906 }
6907 if (tmp == NULL) {
6908 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6909 return 1;
6910 }
6911 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006912 int res;
6913 Py_ssize_t len;
6914 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006915 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006916 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 +02006917 goto failed;
6918 }
6919 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006920 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006921 if (names == NULL) goto failed;
6922 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006923 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006924 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6925 Py_INCREF(tmp2);
6926 res = obj2ast_alias(tmp2, &val, arena);
6927 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006928 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006929 if (len != PyList_GET_SIZE(tmp)) {
6930 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
6931 goto failed;
6932 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006933 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006934 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006935 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006937 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006938 return 1;
6939 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006940 if (tmp == NULL || tmp == Py_None) {
6941 Py_CLEAR(tmp);
6942 level = 0;
6943 }
6944 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006945 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006946 res = obj2ast_int(tmp, &level, arena);
6947 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006948 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006949 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006950 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
6951 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006952 if (*out == NULL) goto failed;
6953 return 0;
6954 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006955 tp = astmodulestate_global->Global_type;
6956 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006957 if (isinstance == -1) {
6958 return 1;
6959 }
6960 if (isinstance) {
6961 asdl_seq* names;
6962
Dino Viehlandac46eb42019-09-11 10:16:34 -07006963 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006964 return 1;
6965 }
6966 if (tmp == NULL) {
6967 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
6968 return 1;
6969 }
6970 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006971 int res;
6972 Py_ssize_t len;
6973 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006975 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 +02006976 goto failed;
6977 }
6978 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006979 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006980 if (names == NULL) goto failed;
6981 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006982 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006983 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6984 Py_INCREF(tmp2);
6985 res = obj2ast_identifier(tmp2, &val, arena);
6986 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006987 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006988 if (len != PyList_GET_SIZE(tmp)) {
6989 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
6990 goto failed;
6991 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006992 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006993 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006994 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006995 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006996 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
6997 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006998 if (*out == NULL) goto failed;
6999 return 0;
7000 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007001 tp = astmodulestate_global->Nonlocal_type;
7002 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 if (isinstance == -1) {
7004 return 1;
7005 }
7006 if (isinstance) {
7007 asdl_seq* names;
7008
Dino Viehlandac46eb42019-09-11 10:16:34 -07007009 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007010 return 1;
7011 }
7012 if (tmp == NULL) {
7013 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7014 return 1;
7015 }
7016 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007017 int res;
7018 Py_ssize_t len;
7019 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007020 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007021 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 +02007022 goto failed;
7023 }
7024 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007025 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007026 if (names == NULL) goto failed;
7027 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007028 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007029 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7030 Py_INCREF(tmp2);
7031 res = obj2ast_identifier(tmp2, &val, arena);
7032 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007033 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007034 if (len != PyList_GET_SIZE(tmp)) {
7035 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7036 goto failed;
7037 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007038 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007039 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007040 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007041 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007042 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7043 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007044 if (*out == NULL) goto failed;
7045 return 0;
7046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007047 tp = astmodulestate_global->Expr_type;
7048 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 if (isinstance == -1) {
7050 return 1;
7051 }
7052 if (isinstance) {
7053 expr_ty value;
7054
Dino Viehlandac46eb42019-09-11 10:16:34 -07007055 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007056 return 1;
7057 }
7058 if (tmp == NULL) {
7059 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7060 return 1;
7061 }
7062 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007064 res = obj2ast_expr(tmp, &value, arena);
7065 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007066 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007067 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007068 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7069 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007070 if (*out == NULL) goto failed;
7071 return 0;
7072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007073 tp = astmodulestate_global->Pass_type;
7074 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007075 if (isinstance == -1) {
7076 return 1;
7077 }
7078 if (isinstance) {
7079
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007080 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007081 if (*out == NULL) goto failed;
7082 return 0;
7083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007084 tp = astmodulestate_global->Break_type;
7085 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007086 if (isinstance == -1) {
7087 return 1;
7088 }
7089 if (isinstance) {
7090
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007091 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007092 if (*out == NULL) goto failed;
7093 return 0;
7094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007095 tp = astmodulestate_global->Continue_type;
7096 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007097 if (isinstance == -1) {
7098 return 1;
7099 }
7100 if (isinstance) {
7101
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007102 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007103 if (*out == NULL) goto failed;
7104 return 0;
7105 }
7106
7107 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7108 failed:
7109 Py_XDECREF(tmp);
7110 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007111}
7112
7113int
7114obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7115{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007116 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007117
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007118 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007119 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007120 int lineno;
7121 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007122 int end_lineno;
7123 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007124
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007125 if (obj == Py_None) {
7126 *out = NULL;
7127 return 0;
7128 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007129 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007130 return 1;
7131 }
7132 if (tmp == NULL) {
7133 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7134 return 1;
7135 }
7136 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007137 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007138 res = obj2ast_int(tmp, &lineno, arena);
7139 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007140 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007142 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7143 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007144 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007145 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007146 if (tmp == NULL) {
7147 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7148 return 1;
7149 }
7150 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007151 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007152 res = obj2ast_int(tmp, &col_offset, arena);
7153 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007154 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007155 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007156 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7157 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007158 return 1;
7159 }
7160 if (tmp == NULL || tmp == Py_None) {
7161 Py_CLEAR(tmp);
7162 end_lineno = 0;
7163 }
7164 else {
7165 int res;
7166 res = obj2ast_int(tmp, &end_lineno, arena);
7167 if (res != 0) goto failed;
7168 Py_CLEAR(tmp);
7169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007170 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7171 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007172 return 1;
7173 }
7174 if (tmp == NULL || tmp == Py_None) {
7175 Py_CLEAR(tmp);
7176 end_col_offset = 0;
7177 }
7178 else {
7179 int res;
7180 res = obj2ast_int(tmp, &end_col_offset, arena);
7181 if (res != 0) goto failed;
7182 Py_CLEAR(tmp);
7183 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007184 tp = astmodulestate_global->BoolOp_type;
7185 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007186 if (isinstance == -1) {
7187 return 1;
7188 }
7189 if (isinstance) {
7190 boolop_ty op;
7191 asdl_seq* values;
7192
Dino Viehlandac46eb42019-09-11 10:16:34 -07007193 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007194 return 1;
7195 }
7196 if (tmp == NULL) {
7197 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7198 return 1;
7199 }
7200 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007201 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007202 res = obj2ast_boolop(tmp, &op, arena);
7203 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007204 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007206 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7207 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007208 return 1;
7209 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007210 if (tmp == NULL) {
7211 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7212 return 1;
7213 }
7214 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007215 int res;
7216 Py_ssize_t len;
7217 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007218 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007219 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 +02007220 goto failed;
7221 }
7222 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007223 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007224 if (values == NULL) goto failed;
7225 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007226 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007227 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7228 Py_INCREF(tmp2);
7229 res = obj2ast_expr(tmp2, &val, arena);
7230 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007231 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007232 if (len != PyList_GET_SIZE(tmp)) {
7233 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7234 goto failed;
7235 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007236 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007237 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007238 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007239 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007240 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7241 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007242 if (*out == NULL) goto failed;
7243 return 0;
7244 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007245 tp = astmodulestate_global->NamedExpr_type;
7246 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007247 if (isinstance == -1) {
7248 return 1;
7249 }
7250 if (isinstance) {
7251 expr_ty target;
7252 expr_ty value;
7253
Dino Viehlandac46eb42019-09-11 10:16:34 -07007254 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7255 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007256 return 1;
7257 }
7258 if (tmp == NULL) {
7259 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7260 return 1;
7261 }
7262 else {
7263 int res;
7264 res = obj2ast_expr(tmp, &target, arena);
7265 if (res != 0) goto failed;
7266 Py_CLEAR(tmp);
7267 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007268 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007269 return 1;
7270 }
7271 if (tmp == NULL) {
7272 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7273 return 1;
7274 }
7275 else {
7276 int res;
7277 res = obj2ast_expr(tmp, &value, arena);
7278 if (res != 0) goto failed;
7279 Py_CLEAR(tmp);
7280 }
7281 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7282 end_col_offset, arena);
7283 if (*out == NULL) goto failed;
7284 return 0;
7285 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007286 tp = astmodulestate_global->BinOp_type;
7287 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 if (isinstance == -1) {
7289 return 1;
7290 }
7291 if (isinstance) {
7292 expr_ty left;
7293 operator_ty op;
7294 expr_ty right;
7295
Dino Viehlandac46eb42019-09-11 10:16:34 -07007296 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007297 return 1;
7298 }
7299 if (tmp == NULL) {
7300 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7301 return 1;
7302 }
7303 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007304 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007305 res = obj2ast_expr(tmp, &left, arena);
7306 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007307 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007309 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 return 1;
7311 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007312 if (tmp == NULL) {
7313 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7314 return 1;
7315 }
7316 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007317 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007318 res = obj2ast_operator(tmp, &op, arena);
7319 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007320 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007322 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007323 return 1;
7324 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007325 if (tmp == NULL) {
7326 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7327 return 1;
7328 }
7329 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007330 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007331 res = obj2ast_expr(tmp, &right, arena);
7332 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007333 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007334 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007335 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7336 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007337 if (*out == NULL) goto failed;
7338 return 0;
7339 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007340 tp = astmodulestate_global->UnaryOp_type;
7341 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007342 if (isinstance == -1) {
7343 return 1;
7344 }
7345 if (isinstance) {
7346 unaryop_ty op;
7347 expr_ty operand;
7348
Dino Viehlandac46eb42019-09-11 10:16:34 -07007349 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007350 return 1;
7351 }
7352 if (tmp == NULL) {
7353 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7354 return 1;
7355 }
7356 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007357 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007358 res = obj2ast_unaryop(tmp, &op, arena);
7359 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007360 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007361 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007362 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7363 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007364 return 1;
7365 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007366 if (tmp == NULL) {
7367 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7368 return 1;
7369 }
7370 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007371 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007372 res = obj2ast_expr(tmp, &operand, arena);
7373 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007374 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007375 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007376 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7377 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007378 if (*out == NULL) goto failed;
7379 return 0;
7380 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007381 tp = astmodulestate_global->Lambda_type;
7382 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007383 if (isinstance == -1) {
7384 return 1;
7385 }
7386 if (isinstance) {
7387 arguments_ty args;
7388 expr_ty body;
7389
Dino Viehlandac46eb42019-09-11 10:16:34 -07007390 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007391 return 1;
7392 }
7393 if (tmp == NULL) {
7394 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7395 return 1;
7396 }
7397 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007398 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007399 res = obj2ast_arguments(tmp, &args, arena);
7400 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007401 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007402 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007403 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007404 return 1;
7405 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007406 if (tmp == NULL) {
7407 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7408 return 1;
7409 }
7410 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007411 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007412 res = obj2ast_expr(tmp, &body, arena);
7413 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007414 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007415 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007416 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7417 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007418 if (*out == NULL) goto failed;
7419 return 0;
7420 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007421 tp = astmodulestate_global->IfExp_type;
7422 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007423 if (isinstance == -1) {
7424 return 1;
7425 }
7426 if (isinstance) {
7427 expr_ty test;
7428 expr_ty body;
7429 expr_ty orelse;
7430
Dino Viehlandac46eb42019-09-11 10:16:34 -07007431 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007432 return 1;
7433 }
7434 if (tmp == NULL) {
7435 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7436 return 1;
7437 }
7438 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007439 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007440 res = obj2ast_expr(tmp, &test, arena);
7441 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007442 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007443 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007444 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007445 return 1;
7446 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007447 if (tmp == NULL) {
7448 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7449 return 1;
7450 }
7451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007452 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007453 res = obj2ast_expr(tmp, &body, arena);
7454 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007455 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007456 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007457 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7458 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007459 return 1;
7460 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007461 if (tmp == NULL) {
7462 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7463 return 1;
7464 }
7465 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007466 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007467 res = obj2ast_expr(tmp, &orelse, arena);
7468 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007469 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007470 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007471 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7472 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 if (*out == NULL) goto failed;
7474 return 0;
7475 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007476 tp = astmodulestate_global->Dict_type;
7477 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007478 if (isinstance == -1) {
7479 return 1;
7480 }
7481 if (isinstance) {
7482 asdl_seq* keys;
7483 asdl_seq* values;
7484
Dino Viehlandac46eb42019-09-11 10:16:34 -07007485 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007486 return 1;
7487 }
7488 if (tmp == NULL) {
7489 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7490 return 1;
7491 }
7492 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007493 int res;
7494 Py_ssize_t len;
7495 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007496 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007497 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 +02007498 goto failed;
7499 }
7500 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007501 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007502 if (keys == NULL) goto failed;
7503 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007504 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007505 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7506 Py_INCREF(tmp2);
7507 res = obj2ast_expr(tmp2, &val, arena);
7508 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007509 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007510 if (len != PyList_GET_SIZE(tmp)) {
7511 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7512 goto failed;
7513 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007514 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007515 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007516 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007517 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007518 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7519 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007520 return 1;
7521 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007522 if (tmp == NULL) {
7523 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7524 return 1;
7525 }
7526 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007527 int res;
7528 Py_ssize_t len;
7529 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007530 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007531 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 +02007532 goto failed;
7533 }
7534 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007535 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007536 if (values == NULL) goto failed;
7537 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007538 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007539 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7540 Py_INCREF(tmp2);
7541 res = obj2ast_expr(tmp2, &val, arena);
7542 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007543 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007544 if (len != PyList_GET_SIZE(tmp)) {
7545 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7546 goto failed;
7547 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007548 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007550 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007551 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007552 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7553 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007554 if (*out == NULL) goto failed;
7555 return 0;
7556 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007557 tp = astmodulestate_global->Set_type;
7558 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007559 if (isinstance == -1) {
7560 return 1;
7561 }
7562 if (isinstance) {
7563 asdl_seq* elts;
7564
Dino Viehlandac46eb42019-09-11 10:16:34 -07007565 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007566 return 1;
7567 }
7568 if (tmp == NULL) {
7569 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7570 return 1;
7571 }
7572 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007573 int res;
7574 Py_ssize_t len;
7575 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007576 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007577 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 +02007578 goto failed;
7579 }
7580 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007581 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007582 if (elts == NULL) goto failed;
7583 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007584 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007585 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7586 Py_INCREF(tmp2);
7587 res = obj2ast_expr(tmp2, &val, arena);
7588 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007589 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007590 if (len != PyList_GET_SIZE(tmp)) {
7591 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7592 goto failed;
7593 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007594 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007596 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007597 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007598 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007599 if (*out == NULL) goto failed;
7600 return 0;
7601 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007602 tp = astmodulestate_global->ListComp_type;
7603 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007604 if (isinstance == -1) {
7605 return 1;
7606 }
7607 if (isinstance) {
7608 expr_ty elt;
7609 asdl_seq* generators;
7610
Dino Viehlandac46eb42019-09-11 10:16:34 -07007611 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007612 return 1;
7613 }
7614 if (tmp == NULL) {
7615 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7616 return 1;
7617 }
7618 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007619 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007620 res = obj2ast_expr(tmp, &elt, arena);
7621 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007622 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007623 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007624 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7625 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007626 return 1;
7627 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007628 if (tmp == NULL) {
7629 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7630 return 1;
7631 }
7632 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007633 int res;
7634 Py_ssize_t len;
7635 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007636 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007637 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 +02007638 goto failed;
7639 }
7640 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007641 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007642 if (generators == NULL) goto failed;
7643 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007644 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007645 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7646 Py_INCREF(tmp2);
7647 res = obj2ast_comprehension(tmp2, &val, arena);
7648 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007649 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007650 if (len != PyList_GET_SIZE(tmp)) {
7651 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7652 goto failed;
7653 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007654 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007655 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007656 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007657 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007658 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7659 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007660 if (*out == NULL) goto failed;
7661 return 0;
7662 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007663 tp = astmodulestate_global->SetComp_type;
7664 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007665 if (isinstance == -1) {
7666 return 1;
7667 }
7668 if (isinstance) {
7669 expr_ty elt;
7670 asdl_seq* generators;
7671
Dino Viehlandac46eb42019-09-11 10:16:34 -07007672 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007673 return 1;
7674 }
7675 if (tmp == NULL) {
7676 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7677 return 1;
7678 }
7679 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007680 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007681 res = obj2ast_expr(tmp, &elt, arena);
7682 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007683 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007684 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007685 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7686 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007687 return 1;
7688 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007689 if (tmp == NULL) {
7690 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7691 return 1;
7692 }
7693 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007694 int res;
7695 Py_ssize_t len;
7696 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007697 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007698 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 +02007699 goto failed;
7700 }
7701 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007702 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007703 if (generators == NULL) goto failed;
7704 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007705 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007706 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7707 Py_INCREF(tmp2);
7708 res = obj2ast_comprehension(tmp2, &val, arena);
7709 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007710 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007711 if (len != PyList_GET_SIZE(tmp)) {
7712 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7713 goto failed;
7714 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007715 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007716 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007717 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007718 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007719 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7720 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007721 if (*out == NULL) goto failed;
7722 return 0;
7723 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007724 tp = astmodulestate_global->DictComp_type;
7725 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007726 if (isinstance == -1) {
7727 return 1;
7728 }
7729 if (isinstance) {
7730 expr_ty key;
7731 expr_ty value;
7732 asdl_seq* generators;
7733
Dino Viehlandac46eb42019-09-11 10:16:34 -07007734 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007735 return 1;
7736 }
7737 if (tmp == NULL) {
7738 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7739 return 1;
7740 }
7741 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007742 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007743 res = obj2ast_expr(tmp, &key, arena);
7744 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007745 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007746 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007747 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007748 return 1;
7749 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007750 if (tmp == NULL) {
7751 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7752 return 1;
7753 }
7754 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007756 res = obj2ast_expr(tmp, &value, arena);
7757 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007758 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007759 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007760 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7761 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007762 return 1;
7763 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007764 if (tmp == NULL) {
7765 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7766 return 1;
7767 }
7768 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007769 int res;
7770 Py_ssize_t len;
7771 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007772 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007773 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 +02007774 goto failed;
7775 }
7776 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007777 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007778 if (generators == NULL) goto failed;
7779 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007780 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007781 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7782 Py_INCREF(tmp2);
7783 res = obj2ast_comprehension(tmp2, &val, arena);
7784 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007785 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007786 if (len != PyList_GET_SIZE(tmp)) {
7787 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7788 goto failed;
7789 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007790 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007792 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007793 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007794 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7795 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007796 if (*out == NULL) goto failed;
7797 return 0;
7798 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007799 tp = astmodulestate_global->GeneratorExp_type;
7800 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007801 if (isinstance == -1) {
7802 return 1;
7803 }
7804 if (isinstance) {
7805 expr_ty elt;
7806 asdl_seq* generators;
7807
Dino Viehlandac46eb42019-09-11 10:16:34 -07007808 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007809 return 1;
7810 }
7811 if (tmp == NULL) {
7812 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7813 return 1;
7814 }
7815 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007817 res = obj2ast_expr(tmp, &elt, arena);
7818 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007819 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007820 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007821 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7822 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007823 return 1;
7824 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007825 if (tmp == NULL) {
7826 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7827 return 1;
7828 }
7829 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007830 int res;
7831 Py_ssize_t len;
7832 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007833 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007834 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 +02007835 goto failed;
7836 }
7837 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007838 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007839 if (generators == NULL) goto failed;
7840 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007841 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007842 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7843 Py_INCREF(tmp2);
7844 res = obj2ast_comprehension(tmp2, &val, arena);
7845 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007846 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007847 if (len != PyList_GET_SIZE(tmp)) {
7848 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7849 goto failed;
7850 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007851 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007852 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007853 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007854 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007855 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7856 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007857 if (*out == NULL) goto failed;
7858 return 0;
7859 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007860 tp = astmodulestate_global->Await_type;
7861 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007862 if (isinstance == -1) {
7863 return 1;
7864 }
7865 if (isinstance) {
7866 expr_ty value;
7867
Dino Viehlandac46eb42019-09-11 10:16:34 -07007868 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007869 return 1;
7870 }
7871 if (tmp == NULL) {
7872 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7873 return 1;
7874 }
7875 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007876 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007877 res = obj2ast_expr(tmp, &value, arena);
7878 if (res != 0) goto failed;
7879 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007880 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007881 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7882 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007883 if (*out == NULL) goto failed;
7884 return 0;
7885 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007886 tp = astmodulestate_global->Yield_type;
7887 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007888 if (isinstance == -1) {
7889 return 1;
7890 }
7891 if (isinstance) {
7892 expr_ty value;
7893
Dino Viehlandac46eb42019-09-11 10:16:34 -07007894 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007895 return 1;
7896 }
7897 if (tmp == NULL || tmp == Py_None) {
7898 Py_CLEAR(tmp);
7899 value = NULL;
7900 }
7901 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007902 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007903 res = obj2ast_expr(tmp, &value, arena);
7904 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007905 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007906 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007907 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7908 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007909 if (*out == NULL) goto failed;
7910 return 0;
7911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007912 tp = astmodulestate_global->YieldFrom_type;
7913 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007914 if (isinstance == -1) {
7915 return 1;
7916 }
7917 if (isinstance) {
7918 expr_ty value;
7919
Dino Viehlandac46eb42019-09-11 10:16:34 -07007920 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007921 return 1;
7922 }
7923 if (tmp == NULL) {
7924 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7925 return 1;
7926 }
7927 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007928 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007929 res = obj2ast_expr(tmp, &value, arena);
7930 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007931 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007932 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007933 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
7934 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007935 if (*out == NULL) goto failed;
7936 return 0;
7937 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007938 tp = astmodulestate_global->Compare_type;
7939 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007940 if (isinstance == -1) {
7941 return 1;
7942 }
7943 if (isinstance) {
7944 expr_ty left;
7945 asdl_int_seq* ops;
7946 asdl_seq* comparators;
7947
Dino Viehlandac46eb42019-09-11 10:16:34 -07007948 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007949 return 1;
7950 }
7951 if (tmp == NULL) {
7952 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
7953 return 1;
7954 }
7955 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007956 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007957 res = obj2ast_expr(tmp, &left, arena);
7958 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007959 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007961 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007962 return 1;
7963 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007964 if (tmp == NULL) {
7965 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
7966 return 1;
7967 }
7968 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007969 int res;
7970 Py_ssize_t len;
7971 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007972 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007973 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 +02007974 goto failed;
7975 }
7976 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007977 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007978 if (ops == NULL) goto failed;
7979 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007980 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007981 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7982 Py_INCREF(tmp2);
7983 res = obj2ast_cmpop(tmp2, &val, arena);
7984 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007985 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007986 if (len != PyList_GET_SIZE(tmp)) {
7987 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
7988 goto failed;
7989 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007990 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007991 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007992 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007994 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
7995 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007996 return 1;
7997 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007998 if (tmp == NULL) {
7999 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8000 return 1;
8001 }
8002 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008003 int res;
8004 Py_ssize_t len;
8005 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008006 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008007 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 +02008008 goto failed;
8009 }
8010 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008011 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008012 if (comparators == NULL) goto failed;
8013 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008014 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008015 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8016 Py_INCREF(tmp2);
8017 res = obj2ast_expr(tmp2, &val, arena);
8018 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008019 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008020 if (len != PyList_GET_SIZE(tmp)) {
8021 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8022 goto failed;
8023 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008024 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008025 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008026 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008027 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008028 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8029 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008030 if (*out == NULL) goto failed;
8031 return 0;
8032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008033 tp = astmodulestate_global->Call_type;
8034 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008035 if (isinstance == -1) {
8036 return 1;
8037 }
8038 if (isinstance) {
8039 expr_ty func;
8040 asdl_seq* args;
8041 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008042
Dino Viehlandac46eb42019-09-11 10:16:34 -07008043 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008044 return 1;
8045 }
8046 if (tmp == NULL) {
8047 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8048 return 1;
8049 }
8050 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008051 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008052 res = obj2ast_expr(tmp, &func, arena);
8053 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008054 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008055 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008056 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008057 return 1;
8058 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008059 if (tmp == NULL) {
8060 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8061 return 1;
8062 }
8063 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008064 int res;
8065 Py_ssize_t len;
8066 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008067 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008068 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 +02008069 goto failed;
8070 }
8071 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008072 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008073 if (args == NULL) goto failed;
8074 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008075 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008076 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8077 Py_INCREF(tmp2);
8078 res = obj2ast_expr(tmp2, &val, arena);
8079 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008080 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008081 if (len != PyList_GET_SIZE(tmp)) {
8082 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8083 goto failed;
8084 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008085 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008086 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008087 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008088 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008089 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8090 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008091 return 1;
8092 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008093 if (tmp == NULL) {
8094 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8095 return 1;
8096 }
8097 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 int res;
8099 Py_ssize_t len;
8100 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008101 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008102 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008103 goto failed;
8104 }
8105 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008106 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008107 if (keywords == NULL) goto failed;
8108 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008109 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008110 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8111 Py_INCREF(tmp2);
8112 res = obj2ast_keyword(tmp2, &val, arena);
8113 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008114 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008115 if (len != PyList_GET_SIZE(tmp)) {
8116 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8117 goto failed;
8118 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008119 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008120 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008121 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008122 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008123 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8124 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008125 if (*out == NULL) goto failed;
8126 return 0;
8127 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008128 tp = astmodulestate_global->FormattedValue_type;
8129 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008130 if (isinstance == -1) {
8131 return 1;
8132 }
8133 if (isinstance) {
8134 expr_ty value;
8135 int conversion;
8136 expr_ty format_spec;
8137
Dino Viehlandac46eb42019-09-11 10:16:34 -07008138 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008139 return 1;
8140 }
8141 if (tmp == NULL) {
8142 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8143 return 1;
8144 }
8145 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008146 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008147 res = obj2ast_expr(tmp, &value, arena);
8148 if (res != 0) goto failed;
8149 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008150 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008151 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8152 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008153 return 1;
8154 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008155 if (tmp == NULL || tmp == Py_None) {
8156 Py_CLEAR(tmp);
8157 conversion = 0;
8158 }
8159 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008160 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008161 res = obj2ast_int(tmp, &conversion, arena);
8162 if (res != 0) goto failed;
8163 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008165 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8166 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008167 return 1;
8168 }
8169 if (tmp == NULL || tmp == Py_None) {
8170 Py_CLEAR(tmp);
8171 format_spec = NULL;
8172 }
8173 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008174 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008175 res = obj2ast_expr(tmp, &format_spec, arena);
8176 if (res != 0) goto failed;
8177 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008178 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008179 *out = FormattedValue(value, conversion, format_spec, lineno,
8180 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008181 if (*out == NULL) goto failed;
8182 return 0;
8183 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008184 tp = astmodulestate_global->JoinedStr_type;
8185 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008186 if (isinstance == -1) {
8187 return 1;
8188 }
8189 if (isinstance) {
8190 asdl_seq* values;
8191
Dino Viehlandac46eb42019-09-11 10:16:34 -07008192 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8193 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008194 return 1;
8195 }
8196 if (tmp == NULL) {
8197 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8198 return 1;
8199 }
8200 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008201 int res;
8202 Py_ssize_t len;
8203 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008204 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008205 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 -04008206 goto failed;
8207 }
8208 len = PyList_GET_SIZE(tmp);
8209 values = _Py_asdl_seq_new(len, arena);
8210 if (values == NULL) goto failed;
8211 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008212 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008213 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8214 Py_INCREF(tmp2);
8215 res = obj2ast_expr(tmp2, &val, arena);
8216 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008217 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008218 if (len != PyList_GET_SIZE(tmp)) {
8219 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8220 goto failed;
8221 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008222 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008223 }
8224 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008225 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008226 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8227 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008228 if (*out == NULL) goto failed;
8229 return 0;
8230 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008231 tp = astmodulestate_global->Constant_type;
8232 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008233 if (isinstance == -1) {
8234 return 1;
8235 }
8236 if (isinstance) {
8237 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008238 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008239
Dino Viehlandac46eb42019-09-11 10:16:34 -07008240 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008241 return 1;
8242 }
8243 if (tmp == NULL) {
8244 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8245 return 1;
8246 }
8247 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008248 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008249 res = obj2ast_constant(tmp, &value, arena);
8250 if (res != 0) goto failed;
8251 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008253 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008254 return 1;
8255 }
8256 if (tmp == NULL || tmp == Py_None) {
8257 Py_CLEAR(tmp);
8258 kind = NULL;
8259 }
8260 else {
8261 int res;
8262 res = obj2ast_string(tmp, &kind, arena);
8263 if (res != 0) goto failed;
8264 Py_CLEAR(tmp);
8265 }
8266 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8267 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008268 if (*out == NULL) goto failed;
8269 return 0;
8270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008271 tp = astmodulestate_global->Attribute_type;
8272 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008273 if (isinstance == -1) {
8274 return 1;
8275 }
8276 if (isinstance) {
8277 expr_ty value;
8278 identifier attr;
8279 expr_context_ty ctx;
8280
Dino Viehlandac46eb42019-09-11 10:16:34 -07008281 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008282 return 1;
8283 }
8284 if (tmp == NULL) {
8285 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8286 return 1;
8287 }
8288 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008289 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008290 res = obj2ast_expr(tmp, &value, arena);
8291 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008292 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008293 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008294 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008295 return 1;
8296 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008297 if (tmp == NULL) {
8298 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8299 return 1;
8300 }
8301 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008302 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008303 res = obj2ast_identifier(tmp, &attr, arena);
8304 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008305 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008306 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008307 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008308 return 1;
8309 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008310 if (tmp == NULL) {
8311 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8312 return 1;
8313 }
8314 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008315 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008316 res = obj2ast_expr_context(tmp, &ctx, arena);
8317 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008318 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008319 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008320 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8321 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008322 if (*out == NULL) goto failed;
8323 return 0;
8324 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008325 tp = astmodulestate_global->Subscript_type;
8326 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008327 if (isinstance == -1) {
8328 return 1;
8329 }
8330 if (isinstance) {
8331 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008332 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008333 expr_context_ty ctx;
8334
Dino Viehlandac46eb42019-09-11 10:16:34 -07008335 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008336 return 1;
8337 }
8338 if (tmp == NULL) {
8339 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8340 return 1;
8341 }
8342 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008343 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008344 res = obj2ast_expr(tmp, &value, arena);
8345 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008346 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008347 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008348 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008349 return 1;
8350 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008351 if (tmp == NULL) {
8352 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8353 return 1;
8354 }
8355 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008356 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008357 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008358 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008359 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008360 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008361 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008362 return 1;
8363 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008364 if (tmp == NULL) {
8365 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8366 return 1;
8367 }
8368 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008369 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008370 res = obj2ast_expr_context(tmp, &ctx, arena);
8371 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008372 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008373 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008374 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8375 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008376 if (*out == NULL) goto failed;
8377 return 0;
8378 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008379 tp = astmodulestate_global->Starred_type;
8380 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008381 if (isinstance == -1) {
8382 return 1;
8383 }
8384 if (isinstance) {
8385 expr_ty value;
8386 expr_context_ty ctx;
8387
Dino Viehlandac46eb42019-09-11 10:16:34 -07008388 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008389 return 1;
8390 }
8391 if (tmp == NULL) {
8392 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8393 return 1;
8394 }
8395 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008396 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008397 res = obj2ast_expr(tmp, &value, arena);
8398 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008399 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008400 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008401 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008402 return 1;
8403 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008404 if (tmp == NULL) {
8405 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8406 return 1;
8407 }
8408 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008409 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008410 res = obj2ast_expr_context(tmp, &ctx, arena);
8411 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008412 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008413 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008414 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8415 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008416 if (*out == NULL) goto failed;
8417 return 0;
8418 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008419 tp = astmodulestate_global->Name_type;
8420 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008421 if (isinstance == -1) {
8422 return 1;
8423 }
8424 if (isinstance) {
8425 identifier id;
8426 expr_context_ty ctx;
8427
Dino Viehlandac46eb42019-09-11 10:16:34 -07008428 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008429 return 1;
8430 }
8431 if (tmp == NULL) {
8432 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8433 return 1;
8434 }
8435 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008436 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008437 res = obj2ast_identifier(tmp, &id, arena);
8438 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008439 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008440 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008441 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008442 return 1;
8443 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008444 if (tmp == NULL) {
8445 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8446 return 1;
8447 }
8448 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008449 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008450 res = obj2ast_expr_context(tmp, &ctx, arena);
8451 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008452 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008453 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008454 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8455 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008456 if (*out == NULL) goto failed;
8457 return 0;
8458 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008459 tp = astmodulestate_global->List_type;
8460 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008461 if (isinstance == -1) {
8462 return 1;
8463 }
8464 if (isinstance) {
8465 asdl_seq* elts;
8466 expr_context_ty ctx;
8467
Dino Viehlandac46eb42019-09-11 10:16:34 -07008468 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008469 return 1;
8470 }
8471 if (tmp == NULL) {
8472 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8473 return 1;
8474 }
8475 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008476 int res;
8477 Py_ssize_t len;
8478 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008479 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008480 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 +02008481 goto failed;
8482 }
8483 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008484 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008485 if (elts == NULL) goto failed;
8486 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008487 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008488 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8489 Py_INCREF(tmp2);
8490 res = obj2ast_expr(tmp2, &val, arena);
8491 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008492 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008493 if (len != PyList_GET_SIZE(tmp)) {
8494 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8495 goto failed;
8496 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008497 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008498 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008499 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008500 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008501 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008502 return 1;
8503 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008504 if (tmp == NULL) {
8505 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8506 return 1;
8507 }
8508 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008509 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008510 res = obj2ast_expr_context(tmp, &ctx, arena);
8511 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008512 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008513 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008514 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8515 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008516 if (*out == NULL) goto failed;
8517 return 0;
8518 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008519 tp = astmodulestate_global->Tuple_type;
8520 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008521 if (isinstance == -1) {
8522 return 1;
8523 }
8524 if (isinstance) {
8525 asdl_seq* elts;
8526 expr_context_ty ctx;
8527
Dino Viehlandac46eb42019-09-11 10:16:34 -07008528 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008529 return 1;
8530 }
8531 if (tmp == NULL) {
8532 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8533 return 1;
8534 }
8535 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008536 int res;
8537 Py_ssize_t len;
8538 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008539 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008540 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 +02008541 goto failed;
8542 }
8543 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008544 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 if (elts == NULL) goto failed;
8546 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008547 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008548 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8549 Py_INCREF(tmp2);
8550 res = obj2ast_expr(tmp2, &val, arena);
8551 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008552 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008553 if (len != PyList_GET_SIZE(tmp)) {
8554 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8555 goto failed;
8556 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008557 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008558 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008559 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008560 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008561 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008562 return 1;
8563 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008564 if (tmp == NULL) {
8565 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8566 return 1;
8567 }
8568 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008569 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008570 res = obj2ast_expr_context(tmp, &ctx, arena);
8571 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008572 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008573 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008574 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8575 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008576 if (*out == NULL) goto failed;
8577 return 0;
8578 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008579 tp = astmodulestate_global->Slice_type;
8580 isinstance = PyObject_IsInstance(obj, tp);
8581 if (isinstance == -1) {
8582 return 1;
8583 }
8584 if (isinstance) {
8585 expr_ty lower;
8586 expr_ty upper;
8587 expr_ty step;
8588
8589 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8590 return 1;
8591 }
8592 if (tmp == NULL || tmp == Py_None) {
8593 Py_CLEAR(tmp);
8594 lower = NULL;
8595 }
8596 else {
8597 int res;
8598 res = obj2ast_expr(tmp, &lower, arena);
8599 if (res != 0) goto failed;
8600 Py_CLEAR(tmp);
8601 }
8602 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8603 return 1;
8604 }
8605 if (tmp == NULL || tmp == Py_None) {
8606 Py_CLEAR(tmp);
8607 upper = NULL;
8608 }
8609 else {
8610 int res;
8611 res = obj2ast_expr(tmp, &upper, arena);
8612 if (res != 0) goto failed;
8613 Py_CLEAR(tmp);
8614 }
8615 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8616 return 1;
8617 }
8618 if (tmp == NULL || tmp == Py_None) {
8619 Py_CLEAR(tmp);
8620 step = NULL;
8621 }
8622 else {
8623 int res;
8624 res = obj2ast_expr(tmp, &step, arena);
8625 if (res != 0) goto failed;
8626 Py_CLEAR(tmp);
8627 }
8628 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8629 end_col_offset, arena);
8630 if (*out == NULL) goto failed;
8631 return 0;
8632 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008633
8634 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8635 failed:
8636 Py_XDECREF(tmp);
8637 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008638}
8639
8640int
8641obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8642{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008643 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008644
Dino Viehlandac46eb42019-09-11 10:16:34 -07008645 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008646 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008647 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008648 }
8649 if (isinstance) {
8650 *out = Load;
8651 return 0;
8652 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008653 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008654 if (isinstance == -1) {
8655 return 1;
8656 }
8657 if (isinstance) {
8658 *out = Store;
8659 return 0;
8660 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008661 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008662 if (isinstance == -1) {
8663 return 1;
8664 }
8665 if (isinstance) {
8666 *out = Del;
8667 return 0;
8668 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008669 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008670 if (isinstance == -1) {
8671 return 1;
8672 }
8673 if (isinstance) {
8674 *out = AugLoad;
8675 return 0;
8676 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008677 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008678 if (isinstance == -1) {
8679 return 1;
8680 }
8681 if (isinstance) {
8682 *out = AugStore;
8683 return 0;
8684 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008685 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008686 if (isinstance == -1) {
8687 return 1;
8688 }
8689 if (isinstance) {
8690 *out = Param;
8691 return 0;
8692 }
8693
8694 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8695 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008696}
8697
8698int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008699obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8700{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008701 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008702
Dino Viehlandac46eb42019-09-11 10:16:34 -07008703 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008704 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008705 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008706 }
8707 if (isinstance) {
8708 *out = And;
8709 return 0;
8710 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008711 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008712 if (isinstance == -1) {
8713 return 1;
8714 }
8715 if (isinstance) {
8716 *out = Or;
8717 return 0;
8718 }
8719
8720 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8721 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008722}
8723
8724int
8725obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8726{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008727 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008728
Dino Viehlandac46eb42019-09-11 10:16:34 -07008729 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008730 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008731 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008732 }
8733 if (isinstance) {
8734 *out = Add;
8735 return 0;
8736 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008737 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008738 if (isinstance == -1) {
8739 return 1;
8740 }
8741 if (isinstance) {
8742 *out = Sub;
8743 return 0;
8744 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008745 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008746 if (isinstance == -1) {
8747 return 1;
8748 }
8749 if (isinstance) {
8750 *out = Mult;
8751 return 0;
8752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008753 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008754 if (isinstance == -1) {
8755 return 1;
8756 }
8757 if (isinstance) {
8758 *out = MatMult;
8759 return 0;
8760 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008761 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008762 if (isinstance == -1) {
8763 return 1;
8764 }
8765 if (isinstance) {
8766 *out = Div;
8767 return 0;
8768 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008769 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008770 if (isinstance == -1) {
8771 return 1;
8772 }
8773 if (isinstance) {
8774 *out = Mod;
8775 return 0;
8776 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008777 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008778 if (isinstance == -1) {
8779 return 1;
8780 }
8781 if (isinstance) {
8782 *out = Pow;
8783 return 0;
8784 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008785 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008786 if (isinstance == -1) {
8787 return 1;
8788 }
8789 if (isinstance) {
8790 *out = LShift;
8791 return 0;
8792 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008793 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008794 if (isinstance == -1) {
8795 return 1;
8796 }
8797 if (isinstance) {
8798 *out = RShift;
8799 return 0;
8800 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008801 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008802 if (isinstance == -1) {
8803 return 1;
8804 }
8805 if (isinstance) {
8806 *out = BitOr;
8807 return 0;
8808 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008809 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008810 if (isinstance == -1) {
8811 return 1;
8812 }
8813 if (isinstance) {
8814 *out = BitXor;
8815 return 0;
8816 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008817 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008818 if (isinstance == -1) {
8819 return 1;
8820 }
8821 if (isinstance) {
8822 *out = BitAnd;
8823 return 0;
8824 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008825 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008826 if (isinstance == -1) {
8827 return 1;
8828 }
8829 if (isinstance) {
8830 *out = FloorDiv;
8831 return 0;
8832 }
8833
8834 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8835 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008836}
8837
8838int
8839obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8840{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008841 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008842
Dino Viehlandac46eb42019-09-11 10:16:34 -07008843 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008844 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008845 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008846 }
8847 if (isinstance) {
8848 *out = Invert;
8849 return 0;
8850 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008851 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008852 if (isinstance == -1) {
8853 return 1;
8854 }
8855 if (isinstance) {
8856 *out = Not;
8857 return 0;
8858 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008859 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008860 if (isinstance == -1) {
8861 return 1;
8862 }
8863 if (isinstance) {
8864 *out = UAdd;
8865 return 0;
8866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008867 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008868 if (isinstance == -1) {
8869 return 1;
8870 }
8871 if (isinstance) {
8872 *out = USub;
8873 return 0;
8874 }
8875
8876 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
8877 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008878}
8879
8880int
8881obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
8882{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008883 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008884
Dino Viehlandac46eb42019-09-11 10:16:34 -07008885 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008886 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008887 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008888 }
8889 if (isinstance) {
8890 *out = Eq;
8891 return 0;
8892 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008893 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008894 if (isinstance == -1) {
8895 return 1;
8896 }
8897 if (isinstance) {
8898 *out = NotEq;
8899 return 0;
8900 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008901 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008902 if (isinstance == -1) {
8903 return 1;
8904 }
8905 if (isinstance) {
8906 *out = Lt;
8907 return 0;
8908 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008909 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008910 if (isinstance == -1) {
8911 return 1;
8912 }
8913 if (isinstance) {
8914 *out = LtE;
8915 return 0;
8916 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008917 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008918 if (isinstance == -1) {
8919 return 1;
8920 }
8921 if (isinstance) {
8922 *out = Gt;
8923 return 0;
8924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008925 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008926 if (isinstance == -1) {
8927 return 1;
8928 }
8929 if (isinstance) {
8930 *out = GtE;
8931 return 0;
8932 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008933 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008934 if (isinstance == -1) {
8935 return 1;
8936 }
8937 if (isinstance) {
8938 *out = Is;
8939 return 0;
8940 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008941 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008942 if (isinstance == -1) {
8943 return 1;
8944 }
8945 if (isinstance) {
8946 *out = IsNot;
8947 return 0;
8948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008949 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008950 if (isinstance == -1) {
8951 return 1;
8952 }
8953 if (isinstance) {
8954 *out = In;
8955 return 0;
8956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008957 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008958 if (isinstance == -1) {
8959 return 1;
8960 }
8961 if (isinstance) {
8962 *out = NotIn;
8963 return 0;
8964 }
8965
8966 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
8967 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008968}
8969
8970int
8971obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
8972{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008973 PyObject* tmp = NULL;
8974 expr_ty target;
8975 expr_ty iter;
8976 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07008977 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008978
Dino Viehlandac46eb42019-09-11 10:16:34 -07008979 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008980 return 1;
8981 }
8982 if (tmp == NULL) {
8983 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
8984 return 1;
8985 }
8986 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008988 res = obj2ast_expr(tmp, &target, arena);
8989 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008990 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008991 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008992 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008993 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008994 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008995 if (tmp == NULL) {
8996 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
8997 return 1;
8998 }
8999 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009000 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009001 res = obj2ast_expr(tmp, &iter, arena);
9002 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009003 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009004 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009005 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009006 return 1;
9007 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009008 if (tmp == NULL) {
9009 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9010 return 1;
9011 }
9012 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009013 int res;
9014 Py_ssize_t len;
9015 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009016 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009017 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 +02009018 goto failed;
9019 }
9020 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009021 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009022 if (ifs == NULL) goto failed;
9023 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009024 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009025 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9026 Py_INCREF(tmp2);
9027 res = obj2ast_expr(tmp2, &val, arena);
9028 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009029 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009030 if (len != PyList_GET_SIZE(tmp)) {
9031 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9032 goto failed;
9033 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009034 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009035 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009036 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009038 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009039 return 1;
9040 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009041 if (tmp == NULL) {
9042 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9043 return 1;
9044 }
9045 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009046 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009047 res = obj2ast_int(tmp, &is_async, arena);
9048 if (res != 0) goto failed;
9049 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009050 }
9051 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009052 return 0;
9053failed:
9054 Py_XDECREF(tmp);
9055 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009056}
9057
9058int
9059obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9060{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009061 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009062
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009063 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009064 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009065 int lineno;
9066 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009067 int end_lineno;
9068 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009069
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009070 if (obj == Py_None) {
9071 *out = NULL;
9072 return 0;
9073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009074 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009075 return 1;
9076 }
9077 if (tmp == NULL) {
9078 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9079 return 1;
9080 }
9081 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009082 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009083 res = obj2ast_int(tmp, &lineno, arena);
9084 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009085 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009087 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9088 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009089 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009090 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009091 if (tmp == NULL) {
9092 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9093 return 1;
9094 }
9095 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009096 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009097 res = obj2ast_int(tmp, &col_offset, arena);
9098 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009099 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009100 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009101 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9102 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009103 return 1;
9104 }
9105 if (tmp == NULL || tmp == Py_None) {
9106 Py_CLEAR(tmp);
9107 end_lineno = 0;
9108 }
9109 else {
9110 int res;
9111 res = obj2ast_int(tmp, &end_lineno, arena);
9112 if (res != 0) goto failed;
9113 Py_CLEAR(tmp);
9114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009115 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9116 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009117 return 1;
9118 }
9119 if (tmp == NULL || tmp == Py_None) {
9120 Py_CLEAR(tmp);
9121 end_col_offset = 0;
9122 }
9123 else {
9124 int res;
9125 res = obj2ast_int(tmp, &end_col_offset, arena);
9126 if (res != 0) goto failed;
9127 Py_CLEAR(tmp);
9128 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009129 tp = astmodulestate_global->ExceptHandler_type;
9130 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009131 if (isinstance == -1) {
9132 return 1;
9133 }
9134 if (isinstance) {
9135 expr_ty type;
9136 identifier name;
9137 asdl_seq* body;
9138
Dino Viehlandac46eb42019-09-11 10:16:34 -07009139 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009140 return 1;
9141 }
9142 if (tmp == NULL || tmp == Py_None) {
9143 Py_CLEAR(tmp);
9144 type = NULL;
9145 }
9146 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009147 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009148 res = obj2ast_expr(tmp, &type, arena);
9149 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009150 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009152 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009153 return 1;
9154 }
9155 if (tmp == NULL || tmp == Py_None) {
9156 Py_CLEAR(tmp);
9157 name = NULL;
9158 }
9159 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009160 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009161 res = obj2ast_identifier(tmp, &name, arena);
9162 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009163 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009165 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009166 return 1;
9167 }
9168 if (tmp == NULL) {
9169 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9170 return 1;
9171 }
9172 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009173 int res;
9174 Py_ssize_t len;
9175 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009176 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009177 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 +02009178 goto failed;
9179 }
9180 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009181 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009182 if (body == NULL) goto failed;
9183 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009184 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009185 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9186 Py_INCREF(tmp2);
9187 res = obj2ast_stmt(tmp2, &val, arena);
9188 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009189 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009190 if (len != PyList_GET_SIZE(tmp)) {
9191 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9192 goto failed;
9193 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009194 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009195 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009196 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009197 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009198 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9199 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009200 if (*out == NULL) goto failed;
9201 return 0;
9202 }
9203
9204 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9205 failed:
9206 Py_XDECREF(tmp);
9207 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009208}
9209
9210int
9211obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9212{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009213 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009214 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009215 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009216 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009217 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009219 arg_ty kwarg;
9220 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009221
Dino Viehlandac46eb42019-09-11 10:16:34 -07009222 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9223 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009224 return 1;
9225 }
9226 if (tmp == NULL) {
9227 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9228 return 1;
9229 }
9230 else {
9231 int res;
9232 Py_ssize_t len;
9233 Py_ssize_t i;
9234 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009235 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 +01009236 goto failed;
9237 }
9238 len = PyList_GET_SIZE(tmp);
9239 posonlyargs = _Py_asdl_seq_new(len, arena);
9240 if (posonlyargs == NULL) goto failed;
9241 for (i = 0; i < len; i++) {
9242 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009243 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9244 Py_INCREF(tmp2);
9245 res = obj2ast_arg(tmp2, &val, arena);
9246 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009247 if (res != 0) goto failed;
9248 if (len != PyList_GET_SIZE(tmp)) {
9249 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9250 goto failed;
9251 }
9252 asdl_seq_SET(posonlyargs, i, val);
9253 }
9254 Py_CLEAR(tmp);
9255 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009256 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009257 return 1;
9258 }
9259 if (tmp == NULL) {
9260 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9261 return 1;
9262 }
9263 else {
9264 int res;
9265 Py_ssize_t len;
9266 Py_ssize_t i;
9267 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009268 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 +02009269 goto failed;
9270 }
9271 len = PyList_GET_SIZE(tmp);
9272 args = _Py_asdl_seq_new(len, arena);
9273 if (args == NULL) goto failed;
9274 for (i = 0; i < len; i++) {
9275 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009276 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9277 Py_INCREF(tmp2);
9278 res = obj2ast_arg(tmp2, &val, arena);
9279 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009280 if (res != 0) goto failed;
9281 if (len != PyList_GET_SIZE(tmp)) {
9282 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9283 goto failed;
9284 }
9285 asdl_seq_SET(args, i, val);
9286 }
9287 Py_CLEAR(tmp);
9288 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009289 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009290 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009291 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009292 if (tmp == NULL || tmp == Py_None) {
9293 Py_CLEAR(tmp);
9294 vararg = NULL;
9295 }
9296 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009297 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009298 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009299 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009300 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009301 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009302 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9303 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009304 return 1;
9305 }
9306 if (tmp == NULL) {
9307 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9308 return 1;
9309 }
9310 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009311 int res;
9312 Py_ssize_t len;
9313 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009314 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009315 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 +02009316 goto failed;
9317 }
9318 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009319 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009320 if (kwonlyargs == NULL) goto failed;
9321 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009322 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009323 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9324 Py_INCREF(tmp2);
9325 res = obj2ast_arg(tmp2, &val, arena);
9326 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009327 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009328 if (len != PyList_GET_SIZE(tmp)) {
9329 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9330 goto failed;
9331 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009332 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009333 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009334 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009335 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009336 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9337 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009338 return 1;
9339 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009340 if (tmp == NULL) {
9341 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9342 return 1;
9343 }
9344 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009345 int res;
9346 Py_ssize_t len;
9347 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009348 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009349 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 +02009350 goto failed;
9351 }
9352 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009353 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009354 if (kw_defaults == NULL) goto failed;
9355 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009356 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009357 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9358 Py_INCREF(tmp2);
9359 res = obj2ast_expr(tmp2, &val, arena);
9360 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009361 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009362 if (len != PyList_GET_SIZE(tmp)) {
9363 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9364 goto failed;
9365 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009366 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009367 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009368 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009369 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009370 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009371 return 1;
9372 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009373 if (tmp == NULL || tmp == Py_None) {
9374 Py_CLEAR(tmp);
9375 kwarg = NULL;
9376 }
9377 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009378 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009379 res = obj2ast_arg(tmp, &kwarg, arena);
9380 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009381 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009383 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009384 return 1;
9385 }
9386 if (tmp == NULL) {
9387 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9388 return 1;
9389 }
9390 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009391 int res;
9392 Py_ssize_t len;
9393 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009394 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009395 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 +02009396 goto failed;
9397 }
9398 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009399 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009400 if (defaults == NULL) goto failed;
9401 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009402 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009403 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9404 Py_INCREF(tmp2);
9405 res = obj2ast_expr(tmp2, &val, arena);
9406 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009407 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009408 if (len != PyList_GET_SIZE(tmp)) {
9409 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9410 goto failed;
9411 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009412 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009413 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009414 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009415 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009416 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009417 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009418 return 0;
9419failed:
9420 Py_XDECREF(tmp);
9421 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009422}
9423
9424int
9425obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9426{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009427 PyObject* tmp = NULL;
9428 identifier arg;
9429 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009430 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009431 int lineno;
9432 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009433 int end_lineno;
9434 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009435
Dino Viehlandac46eb42019-09-11 10:16:34 -07009436 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009437 return 1;
9438 }
9439 if (tmp == NULL) {
9440 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9441 return 1;
9442 }
9443 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009444 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009445 res = obj2ast_identifier(tmp, &arg, arena);
9446 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009447 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009448 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009449 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9450 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009451 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009452 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009453 if (tmp == NULL || tmp == Py_None) {
9454 Py_CLEAR(tmp);
9455 annotation = NULL;
9456 }
9457 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009458 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009459 res = obj2ast_expr(tmp, &annotation, arena);
9460 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009461 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009462 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009463 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9464 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009465 return 1;
9466 }
9467 if (tmp == NULL || tmp == Py_None) {
9468 Py_CLEAR(tmp);
9469 type_comment = NULL;
9470 }
9471 else {
9472 int res;
9473 res = obj2ast_string(tmp, &type_comment, arena);
9474 if (res != 0) goto failed;
9475 Py_CLEAR(tmp);
9476 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009477 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009478 return 1;
9479 }
9480 if (tmp == NULL) {
9481 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9482 return 1;
9483 }
9484 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009485 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009486 res = obj2ast_int(tmp, &lineno, arena);
9487 if (res != 0) goto failed;
9488 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009489 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009490 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9491 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009492 return 1;
9493 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009494 if (tmp == NULL) {
9495 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9496 return 1;
9497 }
9498 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009499 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009500 res = obj2ast_int(tmp, &col_offset, arena);
9501 if (res != 0) goto failed;
9502 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009503 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009504 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9505 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009506 return 1;
9507 }
9508 if (tmp == NULL || tmp == Py_None) {
9509 Py_CLEAR(tmp);
9510 end_lineno = 0;
9511 }
9512 else {
9513 int res;
9514 res = obj2ast_int(tmp, &end_lineno, arena);
9515 if (res != 0) goto failed;
9516 Py_CLEAR(tmp);
9517 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009518 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9519 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009520 return 1;
9521 }
9522 if (tmp == NULL || tmp == Py_None) {
9523 Py_CLEAR(tmp);
9524 end_col_offset = 0;
9525 }
9526 else {
9527 int res;
9528 res = obj2ast_int(tmp, &end_col_offset, arena);
9529 if (res != 0) goto failed;
9530 Py_CLEAR(tmp);
9531 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009532 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9533 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009534 return 0;
9535failed:
9536 Py_XDECREF(tmp);
9537 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009538}
9539
9540int
9541obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9542{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009543 PyObject* tmp = NULL;
9544 identifier arg;
9545 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009546
Dino Viehlandac46eb42019-09-11 10:16:34 -07009547 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009548 return 1;
9549 }
9550 if (tmp == NULL || tmp == Py_None) {
9551 Py_CLEAR(tmp);
9552 arg = NULL;
9553 }
9554 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009555 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009556 res = obj2ast_identifier(tmp, &arg, arena);
9557 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009558 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009559 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009560 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009561 return 1;
9562 }
9563 if (tmp == NULL) {
9564 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9565 return 1;
9566 }
9567 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009568 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009569 res = obj2ast_expr(tmp, &value, arena);
9570 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009571 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009572 }
9573 *out = keyword(arg, value, arena);
9574 return 0;
9575failed:
9576 Py_XDECREF(tmp);
9577 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009578}
9579
9580int
9581obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9582{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009583 PyObject* tmp = NULL;
9584 identifier name;
9585 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009586
Dino Viehlandac46eb42019-09-11 10:16:34 -07009587 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009588 return 1;
9589 }
9590 if (tmp == NULL) {
9591 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9592 return 1;
9593 }
9594 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009595 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009596 res = obj2ast_identifier(tmp, &name, arena);
9597 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009598 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009599 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009600 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009601 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009602 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009603 if (tmp == NULL || tmp == Py_None) {
9604 Py_CLEAR(tmp);
9605 asname = NULL;
9606 }
9607 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009608 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009609 res = obj2ast_identifier(tmp, &asname, arena);
9610 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009611 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009612 }
9613 *out = alias(name, asname, arena);
9614 return 0;
9615failed:
9616 Py_XDECREF(tmp);
9617 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009618}
9619
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009620int
9621obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9622{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009623 PyObject* tmp = NULL;
9624 expr_ty context_expr;
9625 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009626
Dino Viehlandac46eb42019-09-11 10:16:34 -07009627 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9628 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009629 return 1;
9630 }
9631 if (tmp == NULL) {
9632 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9633 return 1;
9634 }
9635 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009636 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009637 res = obj2ast_expr(tmp, &context_expr, arena);
9638 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009639 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009640 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009641 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9642 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009643 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009644 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009645 if (tmp == NULL || tmp == Py_None) {
9646 Py_CLEAR(tmp);
9647 optional_vars = NULL;
9648 }
9649 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009650 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009651 res = obj2ast_expr(tmp, &optional_vars, arena);
9652 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009653 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009654 }
9655 *out = withitem(context_expr, optional_vars, arena);
9656 return 0;
9657failed:
9658 Py_XDECREF(tmp);
9659 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009660}
9661
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009662int
9663obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9664{
9665 int isinstance;
9666
9667 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009668 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009669
9670 if (obj == Py_None) {
9671 *out = NULL;
9672 return 0;
9673 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009674 tp = astmodulestate_global->TypeIgnore_type;
9675 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009676 if (isinstance == -1) {
9677 return 1;
9678 }
9679 if (isinstance) {
9680 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009681 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009682
Dino Viehlandac46eb42019-09-11 10:16:34 -07009683 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9684 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009685 return 1;
9686 }
9687 if (tmp == NULL) {
9688 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9689 return 1;
9690 }
9691 else {
9692 int res;
9693 res = obj2ast_int(tmp, &lineno, arena);
9694 if (res != 0) goto failed;
9695 Py_CLEAR(tmp);
9696 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009697 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009698 return 1;
9699 }
9700 if (tmp == NULL) {
9701 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9702 return 1;
9703 }
9704 else {
9705 int res;
9706 res = obj2ast_string(tmp, &tag, arena);
9707 if (res != 0) goto failed;
9708 Py_CLEAR(tmp);
9709 }
9710 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009711 if (*out == NULL) goto failed;
9712 return 0;
9713 }
9714
9715 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9716 failed:
9717 Py_XDECREF(tmp);
9718 return 1;
9719}
9720
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009721
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009722PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009723PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009724{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009725 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009726 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009727 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009728 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009729 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9730 goto error;
9731 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009732 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009733 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9734 goto error;
9735 }
9736 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9737 goto error;
9738 }
9739 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9740 goto error;
9741 }
9742 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9743 goto error;
9744 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009745 Py_INCREF(astmodulestate(m)->mod_type);
9746 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009747 0) {
9748 goto error;
9749 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009750 Py_INCREF(astmodulestate(m)->Module_type);
9751 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009752 astmodulestate_global->Interactive_type) < 0) {
9753 goto error;
9754 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009755 Py_INCREF(astmodulestate(m)->Interactive_type);
9756 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009757 astmodulestate_global->Expression_type) < 0) {
9758 goto error;
9759 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009760 Py_INCREF(astmodulestate(m)->Expression_type);
9761 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009762 astmodulestate_global->FunctionType_type) < 0) {
9763 goto error;
9764 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009765 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009766 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9767 goto error;
9768 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009769 Py_INCREF(astmodulestate(m)->stmt_type);
9770 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009771 astmodulestate_global->FunctionDef_type) < 0) {
9772 goto error;
9773 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009774 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9775 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009776 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9777 goto error;
9778 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009779 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9780 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009781 < 0) {
9782 goto error;
9783 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009784 Py_INCREF(astmodulestate(m)->ClassDef_type);
9785 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009786 0) {
9787 goto error;
9788 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009789 Py_INCREF(astmodulestate(m)->Return_type);
9790 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009791 0) {
9792 goto error;
9793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009794 Py_INCREF(astmodulestate(m)->Delete_type);
9795 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009796 0) {
9797 goto error;
9798 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009799 Py_INCREF(astmodulestate(m)->Assign_type);
9800 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009801 astmodulestate_global->AugAssign_type) < 0) {
9802 goto error;
9803 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009804 Py_INCREF(astmodulestate(m)->AugAssign_type);
9805 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009806 astmodulestate_global->AnnAssign_type) < 0) {
9807 goto error;
9808 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009809 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009810 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9811 goto error;
9812 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009813 Py_INCREF(astmodulestate(m)->For_type);
9814 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009815 < 0) {
9816 goto error;
9817 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009818 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009819 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9820 goto error;
9821 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009822 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009823 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9824 goto error;
9825 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009826 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009827 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9828 goto error;
9829 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009830 Py_INCREF(astmodulestate(m)->With_type);
9831 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009832 astmodulestate_global->AsyncWith_type) < 0) {
9833 goto error;
9834 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009835 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009836 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
9837 goto error;
9838 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009839 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009840 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
9841 goto error;
9842 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009843 Py_INCREF(astmodulestate(m)->Try_type);
9844 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009845 0) {
9846 goto error;
9847 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009848 Py_INCREF(astmodulestate(m)->Assert_type);
9849 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009850 0) {
9851 goto error;
9852 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009853 Py_INCREF(astmodulestate(m)->Import_type);
9854 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009855 astmodulestate_global->ImportFrom_type) < 0) {
9856 goto error;
9857 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009858 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9859 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009860 0) {
9861 goto error;
9862 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009863 Py_INCREF(astmodulestate(m)->Global_type);
9864 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009865 < 0) {
9866 goto error;
9867 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009868 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009869 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
9870 goto error;
9871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009872 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009873 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
9874 goto error;
9875 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009876 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009877 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
9878 goto error;
9879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009880 Py_INCREF(astmodulestate(m)->Break_type);
9881 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009882 < 0) {
9883 goto error;
9884 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009885 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009886 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
9887 goto error;
9888 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009889 Py_INCREF(astmodulestate(m)->expr_type);
9890 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009891 0) {
9892 goto error;
9893 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009894 Py_INCREF(astmodulestate(m)->BoolOp_type);
9895 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009896 astmodulestate_global->NamedExpr_type) < 0) {
9897 goto error;
9898 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009899 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009900 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
9901 goto error;
9902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009903 Py_INCREF(astmodulestate(m)->BinOp_type);
9904 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009905 0) {
9906 goto error;
9907 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009908 Py_INCREF(astmodulestate(m)->UnaryOp_type);
9909 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009910 0) {
9911 goto error;
9912 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009913 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009914 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
9915 goto error;
9916 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009917 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009918 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
9919 goto error;
9920 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009921 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009922 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
9923 goto error;
9924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009925 Py_INCREF(astmodulestate(m)->Set_type);
9926 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009927 < 0) {
9928 goto error;
9929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009930 Py_INCREF(astmodulestate(m)->ListComp_type);
9931 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009932 0) {
9933 goto error;
9934 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009935 Py_INCREF(astmodulestate(m)->SetComp_type);
9936 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009937 < 0) {
9938 goto error;
9939 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009940 Py_INCREF(astmodulestate(m)->DictComp_type);
9941 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009942 astmodulestate_global->GeneratorExp_type) < 0) {
9943 goto error;
9944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009945 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009946 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
9947 goto error;
9948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009949 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009950 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
9951 goto error;
9952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009953 Py_INCREF(astmodulestate(m)->Yield_type);
9954 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009955 astmodulestate_global->YieldFrom_type) < 0) {
9956 goto error;
9957 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009958 Py_INCREF(astmodulestate(m)->YieldFrom_type);
9959 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009960 0) {
9961 goto error;
9962 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009963 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009964 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
9965 goto error;
9966 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009967 Py_INCREF(astmodulestate(m)->Call_type);
9968 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009969 astmodulestate_global->FormattedValue_type) < 0) {
9970 goto error;
9971 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009972 Py_INCREF(astmodulestate(m)->FormattedValue_type);
9973 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009974 astmodulestate_global->JoinedStr_type) < 0) {
9975 goto error;
9976 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009977 Py_INCREF(astmodulestate(m)->JoinedStr_type);
9978 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009979 < 0) {
9980 goto error;
9981 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009982 Py_INCREF(astmodulestate(m)->Constant_type);
9983 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009984 astmodulestate_global->Attribute_type) < 0) {
9985 goto error;
9986 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009987 Py_INCREF(astmodulestate(m)->Attribute_type);
9988 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009989 astmodulestate_global->Subscript_type) < 0) {
9990 goto error;
9991 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009992 Py_INCREF(astmodulestate(m)->Subscript_type);
9993 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009994 0) {
9995 goto error;
9996 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009997 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009998 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
9999 goto error;
10000 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010001 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010002 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10003 goto error;
10004 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010005 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010006 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10007 goto error;
10008 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010009 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010010 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10011 goto error;
10012 }
10013 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010014 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010015 astmodulestate_global->expr_context_type) < 0) {
10016 goto error;
10017 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010018 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010019 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10020 goto error;
10021 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010022 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010023 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10024 goto error;
10025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010026 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010027 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10028 goto error;
10029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010030 Py_INCREF(astmodulestate(m)->Del_type);
10031 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_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)->AugLoad_type);
10036 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010037 < 0) {
10038 goto error;
10039 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010040 Py_INCREF(astmodulestate(m)->AugStore_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010041 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) {
10042 goto error;
10043 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010044 Py_INCREF(astmodulestate(m)->Param_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010045 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010046 0) {
10047 goto error;
10048 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010049 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010050 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10051 goto error;
10052 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010053 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010054 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10055 goto error;
10056 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010057 Py_INCREF(astmodulestate(m)->Or_type);
10058 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010059 < 0) {
10060 goto error;
10061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010062 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010063 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10064 goto error;
10065 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010066 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010067 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10068 goto error;
10069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010070 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010071 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10072 goto error;
10073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010074 Py_INCREF(astmodulestate(m)->Mult_type);
10075 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010076 0) {
10077 goto error;
10078 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010079 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010080 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10081 goto error;
10082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010083 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010084 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10085 goto error;
10086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010087 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010088 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10089 goto error;
10090 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010091 Py_INCREF(astmodulestate(m)->Pow_type);
10092 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010093 0) {
10094 goto error;
10095 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010096 Py_INCREF(astmodulestate(m)->LShift_type);
10097 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010098 0) {
10099 goto error;
10100 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010101 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010102 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10103 goto error;
10104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010105 Py_INCREF(astmodulestate(m)->BitOr_type);
10106 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010107 0) {
10108 goto error;
10109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010110 Py_INCREF(astmodulestate(m)->BitXor_type);
10111 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010112 0) {
10113 goto error;
10114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010115 Py_INCREF(astmodulestate(m)->BitAnd_type);
10116 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010117 < 0) {
10118 goto error;
10119 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010120 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10121 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010122 0) {
10123 goto error;
10124 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010125 Py_INCREF(astmodulestate(m)->unaryop_type);
10126 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010127 0) {
10128 goto error;
10129 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010130 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010131 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10132 goto error;
10133 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010134 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010135 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10136 goto error;
10137 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010138 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010139 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10140 goto error;
10141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010142 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010143 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10144 goto error;
10145 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010146 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010147 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10148 goto error;
10149 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010150 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010151 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10152 goto error;
10153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010154 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010155 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10156 goto error;
10157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010158 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010159 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10160 goto error;
10161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010162 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010163 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10164 goto error;
10165 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010166 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010167 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10168 goto error;
10169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010170 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010171 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10172 goto error;
10173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010174 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010175 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10176 goto error;
10177 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010178 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010179 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10180 goto error;
10181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010182 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010183 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10184 goto error;
10185 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010186 Py_INCREF(astmodulestate(m)->NotIn_type);
10187 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 astmodulestate_global->comprehension_type) < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->comprehension_type);
10192 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010193 astmodulestate_global->excepthandler_type) < 0) {
10194 goto error;
10195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 Py_INCREF(astmodulestate(m)->excepthandler_type);
10197 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010198 astmodulestate_global->ExceptHandler_type) < 0) {
10199 goto error;
10200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010201 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10202 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010203 astmodulestate_global->arguments_type) < 0) {
10204 goto error;
10205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010206 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010207 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10208 goto error;
10209 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010210 Py_INCREF(astmodulestate(m)->arg_type);
10211 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010212 0) {
10213 goto error;
10214 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010215 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010216 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10217 goto error;
10218 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010219 Py_INCREF(astmodulestate(m)->alias_type);
10220 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010221 < 0) {
10222 goto error;
10223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010224 Py_INCREF(astmodulestate(m)->withitem_type);
10225 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010226 astmodulestate_global->type_ignore_type) < 0) {
10227 goto error;
10228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010229 Py_INCREF(astmodulestate(m)->type_ignore_type);
10230 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010231 astmodulestate_global->TypeIgnore_type) < 0) {
10232 goto error;
10233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010234 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010235 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010236error:
10237 Py_DECREF(m);
10238 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010239}
10240
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010241
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010242PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010243{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010244 if (!init_types())
10245 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010246 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010247}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010248
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010249/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10250mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010251{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010252 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010253 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010254 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010255
Steve Dowerb82e17e2019-05-23 08:45:22 -070010256 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10257 return NULL;
10258 }
10259
Dino Viehlandac46eb42019-09-11 10:16:34 -070010260 req_type[0] = astmodulestate_global->Module_type;
10261 req_type[1] = astmodulestate_global->Expression_type;
10262 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010263
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010264 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010265
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010266 if (!init_types())
10267 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010268
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010269 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10270 if (isinstance == -1)
10271 return NULL;
10272 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010273 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010274 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010275 return NULL;
10276 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010277
10278 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010279 if (obj2ast_mod(ast, &res, arena) != 0)
10280 return NULL;
10281 else
10282 return res;
10283}
10284
10285int PyAST_Check(PyObject* obj)
10286{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010287 if (!init_types())
10288 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010289 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010290}
10291
Martin v. Löwis5b222132007-06-10 09:51:05 +000010292