1 // File automatically generated by Parser/asdl_c.py.
2
3 #include "Python.h"
4 #include "pycore_ast.h"
5 #include "pycore_ast_state.h" // struct ast_state
6 #include "pycore_ceval.h" // _Py_EnterRecursiveCall
7 #include "pycore_interp.h" // _PyInterpreterState.ast
8 #include "pycore_pystate.h" // _PyInterpreterState_GET()
9 #include "structmember.h"
10 #include <stddef.h>
11
12 // Forward declaration
13 static int init_types(struct ast_state *state);
14
15 static struct ast_state*
get_ast_state(void)16 get_ast_state(void)
17 {
18 PyInterpreterState *interp = _PyInterpreterState_GET();
19 struct ast_state *state = &interp->ast;
20 if (!init_types(state)) {
21 return NULL;
22 }
23 return state;
24 }
25
_PyAST_Fini(PyInterpreterState * interp)26 void _PyAST_Fini(PyInterpreterState *interp)
27 {
28 struct ast_state *state = &interp->ast;
29
30 Py_CLEAR(state->AST_type);
31 Py_CLEAR(state->Add_singleton);
32 Py_CLEAR(state->Add_type);
33 Py_CLEAR(state->And_singleton);
34 Py_CLEAR(state->And_type);
35 Py_CLEAR(state->AnnAssign_type);
36 Py_CLEAR(state->Assert_type);
37 Py_CLEAR(state->Assign_type);
38 Py_CLEAR(state->AsyncFor_type);
39 Py_CLEAR(state->AsyncFunctionDef_type);
40 Py_CLEAR(state->AsyncWith_type);
41 Py_CLEAR(state->Attribute_type);
42 Py_CLEAR(state->AugAssign_type);
43 Py_CLEAR(state->Await_type);
44 Py_CLEAR(state->BinOp_type);
45 Py_CLEAR(state->BitAnd_singleton);
46 Py_CLEAR(state->BitAnd_type);
47 Py_CLEAR(state->BitOr_singleton);
48 Py_CLEAR(state->BitOr_type);
49 Py_CLEAR(state->BitXor_singleton);
50 Py_CLEAR(state->BitXor_type);
51 Py_CLEAR(state->BoolOp_type);
52 Py_CLEAR(state->Break_type);
53 Py_CLEAR(state->Call_type);
54 Py_CLEAR(state->ClassDef_type);
55 Py_CLEAR(state->Compare_type);
56 Py_CLEAR(state->Constant_type);
57 Py_CLEAR(state->Continue_type);
58 Py_CLEAR(state->Del_singleton);
59 Py_CLEAR(state->Del_type);
60 Py_CLEAR(state->Delete_type);
61 Py_CLEAR(state->DictComp_type);
62 Py_CLEAR(state->Dict_type);
63 Py_CLEAR(state->Div_singleton);
64 Py_CLEAR(state->Div_type);
65 Py_CLEAR(state->Eq_singleton);
66 Py_CLEAR(state->Eq_type);
67 Py_CLEAR(state->ExceptHandler_type);
68 Py_CLEAR(state->Expr_type);
69 Py_CLEAR(state->Expression_type);
70 Py_CLEAR(state->FloorDiv_singleton);
71 Py_CLEAR(state->FloorDiv_type);
72 Py_CLEAR(state->For_type);
73 Py_CLEAR(state->FormattedValue_type);
74 Py_CLEAR(state->FunctionDef_type);
75 Py_CLEAR(state->FunctionType_type);
76 Py_CLEAR(state->GeneratorExp_type);
77 Py_CLEAR(state->Global_type);
78 Py_CLEAR(state->GtE_singleton);
79 Py_CLEAR(state->GtE_type);
80 Py_CLEAR(state->Gt_singleton);
81 Py_CLEAR(state->Gt_type);
82 Py_CLEAR(state->IfExp_type);
83 Py_CLEAR(state->If_type);
84 Py_CLEAR(state->ImportFrom_type);
85 Py_CLEAR(state->Import_type);
86 Py_CLEAR(state->In_singleton);
87 Py_CLEAR(state->In_type);
88 Py_CLEAR(state->Interactive_type);
89 Py_CLEAR(state->Invert_singleton);
90 Py_CLEAR(state->Invert_type);
91 Py_CLEAR(state->IsNot_singleton);
92 Py_CLEAR(state->IsNot_type);
93 Py_CLEAR(state->Is_singleton);
94 Py_CLEAR(state->Is_type);
95 Py_CLEAR(state->JoinedStr_type);
96 Py_CLEAR(state->LShift_singleton);
97 Py_CLEAR(state->LShift_type);
98 Py_CLEAR(state->Lambda_type);
99 Py_CLEAR(state->ListComp_type);
100 Py_CLEAR(state->List_type);
101 Py_CLEAR(state->Load_singleton);
102 Py_CLEAR(state->Load_type);
103 Py_CLEAR(state->LtE_singleton);
104 Py_CLEAR(state->LtE_type);
105 Py_CLEAR(state->Lt_singleton);
106 Py_CLEAR(state->Lt_type);
107 Py_CLEAR(state->MatMult_singleton);
108 Py_CLEAR(state->MatMult_type);
109 Py_CLEAR(state->MatchAs_type);
110 Py_CLEAR(state->MatchClass_type);
111 Py_CLEAR(state->MatchMapping_type);
112 Py_CLEAR(state->MatchOr_type);
113 Py_CLEAR(state->MatchSequence_type);
114 Py_CLEAR(state->MatchSingleton_type);
115 Py_CLEAR(state->MatchStar_type);
116 Py_CLEAR(state->MatchValue_type);
117 Py_CLEAR(state->Match_type);
118 Py_CLEAR(state->Mod_singleton);
119 Py_CLEAR(state->Mod_type);
120 Py_CLEAR(state->Module_type);
121 Py_CLEAR(state->Mult_singleton);
122 Py_CLEAR(state->Mult_type);
123 Py_CLEAR(state->Name_type);
124 Py_CLEAR(state->NamedExpr_type);
125 Py_CLEAR(state->Nonlocal_type);
126 Py_CLEAR(state->NotEq_singleton);
127 Py_CLEAR(state->NotEq_type);
128 Py_CLEAR(state->NotIn_singleton);
129 Py_CLEAR(state->NotIn_type);
130 Py_CLEAR(state->Not_singleton);
131 Py_CLEAR(state->Not_type);
132 Py_CLEAR(state->Or_singleton);
133 Py_CLEAR(state->Or_type);
134 Py_CLEAR(state->Pass_type);
135 Py_CLEAR(state->Pow_singleton);
136 Py_CLEAR(state->Pow_type);
137 Py_CLEAR(state->RShift_singleton);
138 Py_CLEAR(state->RShift_type);
139 Py_CLEAR(state->Raise_type);
140 Py_CLEAR(state->Return_type);
141 Py_CLEAR(state->SetComp_type);
142 Py_CLEAR(state->Set_type);
143 Py_CLEAR(state->Slice_type);
144 Py_CLEAR(state->Starred_type);
145 Py_CLEAR(state->Store_singleton);
146 Py_CLEAR(state->Store_type);
147 Py_CLEAR(state->Sub_singleton);
148 Py_CLEAR(state->Sub_type);
149 Py_CLEAR(state->Subscript_type);
150 Py_CLEAR(state->TryStar_type);
151 Py_CLEAR(state->Try_type);
152 Py_CLEAR(state->Tuple_type);
153 Py_CLEAR(state->TypeIgnore_type);
154 Py_CLEAR(state->UAdd_singleton);
155 Py_CLEAR(state->UAdd_type);
156 Py_CLEAR(state->USub_singleton);
157 Py_CLEAR(state->USub_type);
158 Py_CLEAR(state->UnaryOp_type);
159 Py_CLEAR(state->While_type);
160 Py_CLEAR(state->With_type);
161 Py_CLEAR(state->YieldFrom_type);
162 Py_CLEAR(state->Yield_type);
163 Py_CLEAR(state->__dict__);
164 Py_CLEAR(state->__doc__);
165 Py_CLEAR(state->__match_args__);
166 Py_CLEAR(state->__module__);
167 Py_CLEAR(state->_attributes);
168 Py_CLEAR(state->_fields);
169 Py_CLEAR(state->alias_type);
170 Py_CLEAR(state->annotation);
171 Py_CLEAR(state->arg);
172 Py_CLEAR(state->arg_type);
173 Py_CLEAR(state->args);
174 Py_CLEAR(state->argtypes);
175 Py_CLEAR(state->arguments_type);
176 Py_CLEAR(state->asname);
177 Py_CLEAR(state->ast);
178 Py_CLEAR(state->attr);
179 Py_CLEAR(state->bases);
180 Py_CLEAR(state->body);
181 Py_CLEAR(state->boolop_type);
182 Py_CLEAR(state->cases);
183 Py_CLEAR(state->cause);
184 Py_CLEAR(state->cls);
185 Py_CLEAR(state->cmpop_type);
186 Py_CLEAR(state->col_offset);
187 Py_CLEAR(state->comparators);
188 Py_CLEAR(state->comprehension_type);
189 Py_CLEAR(state->context_expr);
190 Py_CLEAR(state->conversion);
191 Py_CLEAR(state->ctx);
192 Py_CLEAR(state->decorator_list);
193 Py_CLEAR(state->defaults);
194 Py_CLEAR(state->elt);
195 Py_CLEAR(state->elts);
196 Py_CLEAR(state->end_col_offset);
197 Py_CLEAR(state->end_lineno);
198 Py_CLEAR(state->exc);
199 Py_CLEAR(state->excepthandler_type);
200 Py_CLEAR(state->expr_context_type);
201 Py_CLEAR(state->expr_type);
202 Py_CLEAR(state->finalbody);
203 Py_CLEAR(state->format_spec);
204 Py_CLEAR(state->func);
205 Py_CLEAR(state->generators);
206 Py_CLEAR(state->guard);
207 Py_CLEAR(state->handlers);
208 Py_CLEAR(state->id);
209 Py_CLEAR(state->ifs);
210 Py_CLEAR(state->is_async);
211 Py_CLEAR(state->items);
212 Py_CLEAR(state->iter);
213 Py_CLEAR(state->key);
214 Py_CLEAR(state->keys);
215 Py_CLEAR(state->keyword_type);
216 Py_CLEAR(state->keywords);
217 Py_CLEAR(state->kind);
218 Py_CLEAR(state->kw_defaults);
219 Py_CLEAR(state->kwarg);
220 Py_CLEAR(state->kwd_attrs);
221 Py_CLEAR(state->kwd_patterns);
222 Py_CLEAR(state->kwonlyargs);
223 Py_CLEAR(state->left);
224 Py_CLEAR(state->level);
225 Py_CLEAR(state->lineno);
226 Py_CLEAR(state->lower);
227 Py_CLEAR(state->match_case_type);
228 Py_CLEAR(state->mod_type);
229 Py_CLEAR(state->module);
230 Py_CLEAR(state->msg);
231 Py_CLEAR(state->name);
232 Py_CLEAR(state->names);
233 Py_CLEAR(state->op);
234 Py_CLEAR(state->operand);
235 Py_CLEAR(state->operator_type);
236 Py_CLEAR(state->ops);
237 Py_CLEAR(state->optional_vars);
238 Py_CLEAR(state->orelse);
239 Py_CLEAR(state->pattern);
240 Py_CLEAR(state->pattern_type);
241 Py_CLEAR(state->patterns);
242 Py_CLEAR(state->posonlyargs);
243 Py_CLEAR(state->rest);
244 Py_CLEAR(state->returns);
245 Py_CLEAR(state->right);
246 Py_CLEAR(state->simple);
247 Py_CLEAR(state->slice);
248 Py_CLEAR(state->step);
249 Py_CLEAR(state->stmt_type);
250 Py_CLEAR(state->subject);
251 Py_CLEAR(state->tag);
252 Py_CLEAR(state->target);
253 Py_CLEAR(state->targets);
254 Py_CLEAR(state->test);
255 Py_CLEAR(state->type);
256 Py_CLEAR(state->type_comment);
257 Py_CLEAR(state->type_ignore_type);
258 Py_CLEAR(state->type_ignores);
259 Py_CLEAR(state->unaryop_type);
260 Py_CLEAR(state->upper);
261 Py_CLEAR(state->value);
262 Py_CLEAR(state->values);
263 Py_CLEAR(state->vararg);
264 Py_CLEAR(state->withitem_type);
265
266 #if !defined(NDEBUG)
267 state->initialized = -1;
268 #else
269 state->initialized = 0;
270 #endif
271 }
272
init_identifiers(struct ast_state * state)273 static int init_identifiers(struct ast_state *state)
274 {
275 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
276 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
277 if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return 0;
278 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
279 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
280 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
281 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
282 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
283 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
284 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
285 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
286 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
287 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
288 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
289 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
290 if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return 0;
291 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
292 if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return 0;
293 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
294 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
295 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
296 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
297 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
298 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
299 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
300 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
301 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
302 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
303 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
304 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
305 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
306 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
307 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
308 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
309 if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return 0;
310 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
311 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
312 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
313 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
314 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
315 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
316 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
317 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
318 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
319 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
320 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
321 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
322 if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return 0;
323 if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return 0;
324 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
325 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
326 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
327 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
328 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
329 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
330 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
331 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
332 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
333 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
334 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
335 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
336 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
337 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
338 if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return 0;
339 if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return 0;
340 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
341 if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return 0;
342 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
343 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
344 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
345 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
346 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
347 if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return 0;
348 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
349 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
350 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
351 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
352 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
353 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
354 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
355 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
356 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
357 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
358 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
359 return 1;
360 };
361
362 GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
363 GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
364 GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
365 GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
366 GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
367 GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
368 GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
369 GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
370 GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
371 GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
372 GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
373 GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
374 GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
375
376 static PyObject* ast2obj_mod(struct ast_state *state, void*);
377 static const char * const Module_fields[]={
378 "body",
379 "type_ignores",
380 };
381 static const char * const Interactive_fields[]={
382 "body",
383 };
384 static const char * const Expression_fields[]={
385 "body",
386 };
387 static const char * const FunctionType_fields[]={
388 "argtypes",
389 "returns",
390 };
391 static const char * const stmt_attributes[] = {
392 "lineno",
393 "col_offset",
394 "end_lineno",
395 "end_col_offset",
396 };
397 static PyObject* ast2obj_stmt(struct ast_state *state, void*);
398 static const char * const FunctionDef_fields[]={
399 "name",
400 "args",
401 "body",
402 "decorator_list",
403 "returns",
404 "type_comment",
405 };
406 static const char * const AsyncFunctionDef_fields[]={
407 "name",
408 "args",
409 "body",
410 "decorator_list",
411 "returns",
412 "type_comment",
413 };
414 static const char * const ClassDef_fields[]={
415 "name",
416 "bases",
417 "keywords",
418 "body",
419 "decorator_list",
420 };
421 static const char * const Return_fields[]={
422 "value",
423 };
424 static const char * const Delete_fields[]={
425 "targets",
426 };
427 static const char * const Assign_fields[]={
428 "targets",
429 "value",
430 "type_comment",
431 };
432 static const char * const AugAssign_fields[]={
433 "target",
434 "op",
435 "value",
436 };
437 static const char * const AnnAssign_fields[]={
438 "target",
439 "annotation",
440 "value",
441 "simple",
442 };
443 static const char * const For_fields[]={
444 "target",
445 "iter",
446 "body",
447 "orelse",
448 "type_comment",
449 };
450 static const char * const AsyncFor_fields[]={
451 "target",
452 "iter",
453 "body",
454 "orelse",
455 "type_comment",
456 };
457 static const char * const While_fields[]={
458 "test",
459 "body",
460 "orelse",
461 };
462 static const char * const If_fields[]={
463 "test",
464 "body",
465 "orelse",
466 };
467 static const char * const With_fields[]={
468 "items",
469 "body",
470 "type_comment",
471 };
472 static const char * const AsyncWith_fields[]={
473 "items",
474 "body",
475 "type_comment",
476 };
477 static const char * const Match_fields[]={
478 "subject",
479 "cases",
480 };
481 static const char * const Raise_fields[]={
482 "exc",
483 "cause",
484 };
485 static const char * const Try_fields[]={
486 "body",
487 "handlers",
488 "orelse",
489 "finalbody",
490 };
491 static const char * const TryStar_fields[]={
492 "body",
493 "handlers",
494 "orelse",
495 "finalbody",
496 };
497 static const char * const Assert_fields[]={
498 "test",
499 "msg",
500 };
501 static const char * const Import_fields[]={
502 "names",
503 };
504 static const char * const ImportFrom_fields[]={
505 "module",
506 "names",
507 "level",
508 };
509 static const char * const Global_fields[]={
510 "names",
511 };
512 static const char * const Nonlocal_fields[]={
513 "names",
514 };
515 static const char * const Expr_fields[]={
516 "value",
517 };
518 static const char * const expr_attributes[] = {
519 "lineno",
520 "col_offset",
521 "end_lineno",
522 "end_col_offset",
523 };
524 static PyObject* ast2obj_expr(struct ast_state *state, void*);
525 static const char * const BoolOp_fields[]={
526 "op",
527 "values",
528 };
529 static const char * const NamedExpr_fields[]={
530 "target",
531 "value",
532 };
533 static const char * const BinOp_fields[]={
534 "left",
535 "op",
536 "right",
537 };
538 static const char * const UnaryOp_fields[]={
539 "op",
540 "operand",
541 };
542 static const char * const Lambda_fields[]={
543 "args",
544 "body",
545 };
546 static const char * const IfExp_fields[]={
547 "test",
548 "body",
549 "orelse",
550 };
551 static const char * const Dict_fields[]={
552 "keys",
553 "values",
554 };
555 static const char * const Set_fields[]={
556 "elts",
557 };
558 static const char * const ListComp_fields[]={
559 "elt",
560 "generators",
561 };
562 static const char * const SetComp_fields[]={
563 "elt",
564 "generators",
565 };
566 static const char * const DictComp_fields[]={
567 "key",
568 "value",
569 "generators",
570 };
571 static const char * const GeneratorExp_fields[]={
572 "elt",
573 "generators",
574 };
575 static const char * const Await_fields[]={
576 "value",
577 };
578 static const char * const Yield_fields[]={
579 "value",
580 };
581 static const char * const YieldFrom_fields[]={
582 "value",
583 };
584 static const char * const Compare_fields[]={
585 "left",
586 "ops",
587 "comparators",
588 };
589 static const char * const Call_fields[]={
590 "func",
591 "args",
592 "keywords",
593 };
594 static const char * const FormattedValue_fields[]={
595 "value",
596 "conversion",
597 "format_spec",
598 };
599 static const char * const JoinedStr_fields[]={
600 "values",
601 };
602 static const char * const Constant_fields[]={
603 "value",
604 "kind",
605 };
606 static const char * const Attribute_fields[]={
607 "value",
608 "attr",
609 "ctx",
610 };
611 static const char * const Subscript_fields[]={
612 "value",
613 "slice",
614 "ctx",
615 };
616 static const char * const Starred_fields[]={
617 "value",
618 "ctx",
619 };
620 static const char * const Name_fields[]={
621 "id",
622 "ctx",
623 };
624 static const char * const List_fields[]={
625 "elts",
626 "ctx",
627 };
628 static const char * const Tuple_fields[]={
629 "elts",
630 "ctx",
631 };
632 static const char * const Slice_fields[]={
633 "lower",
634 "upper",
635 "step",
636 };
637 static PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty);
638 static PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty);
639 static PyObject* ast2obj_operator(struct ast_state *state, operator_ty);
640 static PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty);
641 static PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty);
642 static PyObject* ast2obj_comprehension(struct ast_state *state, void*);
643 static const char * const comprehension_fields[]={
644 "target",
645 "iter",
646 "ifs",
647 "is_async",
648 };
649 static const char * const excepthandler_attributes[] = {
650 "lineno",
651 "col_offset",
652 "end_lineno",
653 "end_col_offset",
654 };
655 static PyObject* ast2obj_excepthandler(struct ast_state *state, void*);
656 static const char * const ExceptHandler_fields[]={
657 "type",
658 "name",
659 "body",
660 };
661 static PyObject* ast2obj_arguments(struct ast_state *state, void*);
662 static const char * const arguments_fields[]={
663 "posonlyargs",
664 "args",
665 "vararg",
666 "kwonlyargs",
667 "kw_defaults",
668 "kwarg",
669 "defaults",
670 };
671 static PyObject* ast2obj_arg(struct ast_state *state, void*);
672 static const char * const arg_attributes[] = {
673 "lineno",
674 "col_offset",
675 "end_lineno",
676 "end_col_offset",
677 };
678 static const char * const arg_fields[]={
679 "arg",
680 "annotation",
681 "type_comment",
682 };
683 static PyObject* ast2obj_keyword(struct ast_state *state, void*);
684 static const char * const keyword_attributes[] = {
685 "lineno",
686 "col_offset",
687 "end_lineno",
688 "end_col_offset",
689 };
690 static const char * const keyword_fields[]={
691 "arg",
692 "value",
693 };
694 static PyObject* ast2obj_alias(struct ast_state *state, void*);
695 static const char * const alias_attributes[] = {
696 "lineno",
697 "col_offset",
698 "end_lineno",
699 "end_col_offset",
700 };
701 static const char * const alias_fields[]={
702 "name",
703 "asname",
704 };
705 static PyObject* ast2obj_withitem(struct ast_state *state, void*);
706 static const char * const withitem_fields[]={
707 "context_expr",
708 "optional_vars",
709 };
710 static PyObject* ast2obj_match_case(struct ast_state *state, void*);
711 static const char * const match_case_fields[]={
712 "pattern",
713 "guard",
714 "body",
715 };
716 static const char * const pattern_attributes[] = {
717 "lineno",
718 "col_offset",
719 "end_lineno",
720 "end_col_offset",
721 };
722 static PyObject* ast2obj_pattern(struct ast_state *state, void*);
723 static const char * const MatchValue_fields[]={
724 "value",
725 };
726 static const char * const MatchSingleton_fields[]={
727 "value",
728 };
729 static const char * const MatchSequence_fields[]={
730 "patterns",
731 };
732 static const char * const MatchMapping_fields[]={
733 "keys",
734 "patterns",
735 "rest",
736 };
737 static const char * const MatchClass_fields[]={
738 "cls",
739 "patterns",
740 "kwd_attrs",
741 "kwd_patterns",
742 };
743 static const char * const MatchStar_fields[]={
744 "name",
745 };
746 static const char * const MatchAs_fields[]={
747 "pattern",
748 "name",
749 };
750 static const char * const MatchOr_fields[]={
751 "patterns",
752 };
753 static PyObject* ast2obj_type_ignore(struct ast_state *state, void*);
754 static const char * const TypeIgnore_fields[]={
755 "lineno",
756 "tag",
757 };
758
759
760
761 typedef struct {
762 PyObject_HEAD
763 PyObject *dict;
764 } AST_object;
765
766 static void
ast_dealloc(AST_object * self)767 ast_dealloc(AST_object *self)
768 {
769 /* bpo-31095: UnTrack is needed before calling any callbacks */
770 PyTypeObject *tp = Py_TYPE(self);
771 PyObject_GC_UnTrack(self);
772 Py_CLEAR(self->dict);
773 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
774 assert(free_func != NULL);
775 free_func(self);
776 Py_DECREF(tp);
777 }
778
779 static int
ast_traverse(AST_object * self,visitproc visit,void * arg)780 ast_traverse(AST_object *self, visitproc visit, void *arg)
781 {
782 Py_VISIT(Py_TYPE(self));
783 Py_VISIT(self->dict);
784 return 0;
785 }
786
787 static int
ast_clear(AST_object * self)788 ast_clear(AST_object *self)
789 {
790 Py_CLEAR(self->dict);
791 return 0;
792 }
793
794 static int
ast_type_init(PyObject * self,PyObject * args,PyObject * kw)795 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
796 {
797 struct ast_state *state = get_ast_state();
798 if (state == NULL) {
799 return -1;
800 }
801
802 Py_ssize_t i, numfields = 0;
803 int res = -1;
804 PyObject *key, *value, *fields;
805 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
806 goto cleanup;
807 }
808 if (fields) {
809 numfields = PySequence_Size(fields);
810 if (numfields == -1) {
811 goto cleanup;
812 }
813 }
814
815 res = 0; /* if no error occurs, this stays 0 to the end */
816 if (numfields < PyTuple_GET_SIZE(args)) {
817 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
818 "%zd positional argument%s",
819 _PyType_Name(Py_TYPE(self)),
820 numfields, numfields == 1 ? "" : "s");
821 res = -1;
822 goto cleanup;
823 }
824 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
825 /* cannot be reached when fields is NULL */
826 PyObject *name = PySequence_GetItem(fields, i);
827 if (!name) {
828 res = -1;
829 goto cleanup;
830 }
831 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
832 Py_DECREF(name);
833 if (res < 0) {
834 goto cleanup;
835 }
836 }
837 if (kw) {
838 i = 0; /* needed by PyDict_Next */
839 while (PyDict_Next(kw, &i, &key, &value)) {
840 int contains = PySequence_Contains(fields, key);
841 if (contains == -1) {
842 res = -1;
843 goto cleanup;
844 } else if (contains == 1) {
845 Py_ssize_t p = PySequence_Index(fields, key);
846 if (p == -1) {
847 res = -1;
848 goto cleanup;
849 }
850 if (p < PyTuple_GET_SIZE(args)) {
851 PyErr_Format(PyExc_TypeError,
852 "%.400s got multiple values for argument '%U'",
853 Py_TYPE(self)->tp_name, key);
854 res = -1;
855 goto cleanup;
856 }
857 }
858 res = PyObject_SetAttr(self, key, value);
859 if (res < 0) {
860 goto cleanup;
861 }
862 }
863 }
864 cleanup:
865 Py_XDECREF(fields);
866 return res;
867 }
868
869 /* Pickling support */
870 static PyObject *
ast_type_reduce(PyObject * self,PyObject * unused)871 ast_type_reduce(PyObject *self, PyObject *unused)
872 {
873 struct ast_state *state = get_ast_state();
874 if (state == NULL) {
875 return NULL;
876 }
877
878 PyObject *dict;
879 if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
880 return NULL;
881 }
882 if (dict) {
883 return Py_BuildValue("O()N", Py_TYPE(self), dict);
884 }
885 return Py_BuildValue("O()", Py_TYPE(self));
886 }
887
888 static PyMemberDef ast_type_members[] = {
889 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
890 {NULL} /* Sentinel */
891 };
892
893 static PyMethodDef ast_type_methods[] = {
894 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
895 {NULL}
896 };
897
898 static PyGetSetDef ast_type_getsets[] = {
899 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
900 {NULL}
901 };
902
903 static PyType_Slot AST_type_slots[] = {
904 {Py_tp_dealloc, ast_dealloc},
905 {Py_tp_getattro, PyObject_GenericGetAttr},
906 {Py_tp_setattro, PyObject_GenericSetAttr},
907 {Py_tp_traverse, ast_traverse},
908 {Py_tp_clear, ast_clear},
909 {Py_tp_members, ast_type_members},
910 {Py_tp_methods, ast_type_methods},
911 {Py_tp_getset, ast_type_getsets},
912 {Py_tp_init, ast_type_init},
913 {Py_tp_alloc, PyType_GenericAlloc},
914 {Py_tp_new, PyType_GenericNew},
915 {Py_tp_free, PyObject_GC_Del},
916 {0, 0},
917 };
918
919 static PyType_Spec AST_type_spec = {
920 "ast.AST",
921 sizeof(AST_object),
922 0,
923 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
924 AST_type_slots
925 };
926
927 static PyObject *
make_type(struct ast_state * state,const char * type,PyObject * base,const char * const * fields,int num_fields,const char * doc)928 make_type(struct ast_state *state, const char *type, PyObject* base,
929 const char* const* fields, int num_fields, const char *doc)
930 {
931 PyObject *fnames, *result;
932 int i;
933 fnames = PyTuple_New(num_fields);
934 if (!fnames) return NULL;
935 for (i = 0; i < num_fields; i++) {
936 PyObject *field = PyUnicode_InternFromString(fields[i]);
937 if (!field) {
938 Py_DECREF(fnames);
939 return NULL;
940 }
941 PyTuple_SET_ITEM(fnames, i, field);
942 }
943 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
944 type, base,
945 state->_fields, fnames,
946 state->__match_args__, fnames,
947 state->__module__,
948 state->ast,
949 state->__doc__, doc);
950 Py_DECREF(fnames);
951 return result;
952 }
953
954 static int
add_attributes(struct ast_state * state,PyObject * type,const char * const * attrs,int num_fields)955 add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
956 {
957 int i, result;
958 PyObject *s, *l = PyTuple_New(num_fields);
959 if (!l)
960 return 0;
961 for (i = 0; i < num_fields; i++) {
962 s = PyUnicode_InternFromString(attrs[i]);
963 if (!s) {
964 Py_DECREF(l);
965 return 0;
966 }
967 PyTuple_SET_ITEM(l, i, s);
968 }
969 result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
970 Py_DECREF(l);
971 return result;
972 }
973
974 /* Conversion AST -> Python */
975
ast2obj_list(struct ast_state * state,asdl_seq * seq,PyObject * (* func)(struct ast_state * state,void *))976 static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq, PyObject* (*func)(struct ast_state *state, void*))
977 {
978 Py_ssize_t i, n = asdl_seq_LEN(seq);
979 PyObject *result = PyList_New(n);
980 PyObject *value;
981 if (!result)
982 return NULL;
983 for (i = 0; i < n; i++) {
984 value = func(state, asdl_seq_GET_UNTYPED(seq, i));
985 if (!value) {
986 Py_DECREF(result);
987 return NULL;
988 }
989 PyList_SET_ITEM(result, i, value);
990 }
991 return result;
992 }
993
ast2obj_object(struct ast_state * Py_UNUSED (state),void * o)994 static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
995 {
996 if (!o)
997 o = Py_None;
998 Py_INCREF((PyObject*)o);
999 return (PyObject*)o;
1000 }
1001 #define ast2obj_constant ast2obj_object
1002 #define ast2obj_identifier ast2obj_object
1003 #define ast2obj_string ast2obj_object
1004
ast2obj_int(struct ast_state * Py_UNUSED (state),long b)1005 static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
1006 {
1007 return PyLong_FromLong(b);
1008 }
1009
1010 /* Conversion Python -> AST */
1011
obj2ast_object(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)1012 static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1013 {
1014 if (obj == Py_None)
1015 obj = NULL;
1016 if (obj) {
1017 if (_PyArena_AddPyObject(arena, obj) < 0) {
1018 *out = NULL;
1019 return -1;
1020 }
1021 Py_INCREF(obj);
1022 }
1023 *out = obj;
1024 return 0;
1025 }
1026
obj2ast_constant(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)1027 static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1028 {
1029 if (_PyArena_AddPyObject(arena, obj) < 0) {
1030 *out = NULL;
1031 return -1;
1032 }
1033 Py_INCREF(obj);
1034 *out = obj;
1035 return 0;
1036 }
1037
obj2ast_identifier(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)1038 static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1039 {
1040 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1041 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
1042 return 1;
1043 }
1044 return obj2ast_object(state, obj, out, arena);
1045 }
1046
obj2ast_string(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)1047 static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1048 {
1049 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1050 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1051 return 1;
1052 }
1053 return obj2ast_object(state, obj, out, arena);
1054 }
1055
obj2ast_int(struct ast_state * Py_UNUSED (state),PyObject * obj,int * out,PyArena * arena)1056 static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
1057 {
1058 int i;
1059 if (!PyLong_Check(obj)) {
1060 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
1061 return 1;
1062 }
1063
1064 i = _PyLong_AsInt(obj);
1065 if (i == -1 && PyErr_Occurred())
1066 return 1;
1067 *out = i;
1068 return 0;
1069 }
1070
add_ast_fields(struct ast_state * state)1071 static int add_ast_fields(struct ast_state *state)
1072 {
1073 PyObject *empty_tuple;
1074 empty_tuple = PyTuple_New(0);
1075 if (!empty_tuple ||
1076 PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
1077 PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
1078 PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
1079 Py_XDECREF(empty_tuple);
1080 return -1;
1081 }
1082 Py_DECREF(empty_tuple);
1083 return 0;
1084 }
1085
1086
1087
1088 static int
init_types(struct ast_state * state)1089 init_types(struct ast_state *state)
1090 {
1091 // init_types() must not be called after _PyAST_Fini()
1092 // has been called
1093 assert(state->initialized >= 0);
1094
1095 if (state->initialized) {
1096 return 1;
1097 }
1098 if (init_identifiers(state) < 0) {
1099 return 0;
1100 }
1101 state->AST_type = PyType_FromSpec(&AST_type_spec);
1102 if (!state->AST_type) {
1103 return 0;
1104 }
1105 if (add_ast_fields(state) < 0) {
1106 return 0;
1107 }
1108 state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
1109 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1110 " | Interactive(stmt* body)\n"
1111 " | Expression(expr body)\n"
1112 " | FunctionType(expr* argtypes, expr returns)");
1113 if (!state->mod_type) return 0;
1114 if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
1115 state->Module_type = make_type(state, "Module", state->mod_type,
1116 Module_fields, 2,
1117 "Module(stmt* body, type_ignore* type_ignores)");
1118 if (!state->Module_type) return 0;
1119 state->Interactive_type = make_type(state, "Interactive", state->mod_type,
1120 Interactive_fields, 1,
1121 "Interactive(stmt* body)");
1122 if (!state->Interactive_type) return 0;
1123 state->Expression_type = make_type(state, "Expression", state->mod_type,
1124 Expression_fields, 1,
1125 "Expression(expr body)");
1126 if (!state->Expression_type) return 0;
1127 state->FunctionType_type = make_type(state, "FunctionType",
1128 state->mod_type, FunctionType_fields,
1129 2,
1130 "FunctionType(expr* argtypes, expr returns)");
1131 if (!state->FunctionType_type) return 0;
1132 state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
1133 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1134 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1135 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1136 " | Return(expr? value)\n"
1137 " | Delete(expr* targets)\n"
1138 " | Assign(expr* targets, expr value, string? type_comment)\n"
1139 " | AugAssign(expr target, operator op, expr value)\n"
1140 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1141 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1142 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1143 " | While(expr test, stmt* body, stmt* orelse)\n"
1144 " | If(expr test, stmt* body, stmt* orelse)\n"
1145 " | With(withitem* items, stmt* body, string? type_comment)\n"
1146 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1147 " | Match(expr subject, match_case* cases)\n"
1148 " | Raise(expr? exc, expr? cause)\n"
1149 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1150 " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1151 " | Assert(expr test, expr? msg)\n"
1152 " | Import(alias* names)\n"
1153 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1154 " | Global(identifier* names)\n"
1155 " | Nonlocal(identifier* names)\n"
1156 " | Expr(expr value)\n"
1157 " | Pass\n"
1158 " | Break\n"
1159 " | Continue");
1160 if (!state->stmt_type) return 0;
1161 if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
1162 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1163 return 0;
1164 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1165 -1)
1166 return 0;
1167 state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
1168 FunctionDef_fields, 6,
1169 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
1170 if (!state->FunctionDef_type) return 0;
1171 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1172 -1)
1173 return 0;
1174 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1175 == -1)
1176 return 0;
1177 state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
1178 state->stmt_type,
1179 AsyncFunctionDef_fields, 6,
1180 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
1181 if (!state->AsyncFunctionDef_type) return 0;
1182 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1183 == -1)
1184 return 0;
1185 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1186 Py_None) == -1)
1187 return 0;
1188 state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
1189 ClassDef_fields, 5,
1190 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
1191 if (!state->ClassDef_type) return 0;
1192 state->Return_type = make_type(state, "Return", state->stmt_type,
1193 Return_fields, 1,
1194 "Return(expr? value)");
1195 if (!state->Return_type) return 0;
1196 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1197 return 0;
1198 state->Delete_type = make_type(state, "Delete", state->stmt_type,
1199 Delete_fields, 1,
1200 "Delete(expr* targets)");
1201 if (!state->Delete_type) return 0;
1202 state->Assign_type = make_type(state, "Assign", state->stmt_type,
1203 Assign_fields, 3,
1204 "Assign(expr* targets, expr value, string? type_comment)");
1205 if (!state->Assign_type) return 0;
1206 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1207 -1)
1208 return 0;
1209 state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
1210 AugAssign_fields, 3,
1211 "AugAssign(expr target, operator op, expr value)");
1212 if (!state->AugAssign_type) return 0;
1213 state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
1214 AnnAssign_fields, 4,
1215 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
1216 if (!state->AnnAssign_type) return 0;
1217 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1218 return 0;
1219 state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
1220 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1221 if (!state->For_type) return 0;
1222 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1223 return 0;
1224 state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
1225 AsyncFor_fields, 5,
1226 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1227 if (!state->AsyncFor_type) return 0;
1228 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1229 -1)
1230 return 0;
1231 state->While_type = make_type(state, "While", state->stmt_type,
1232 While_fields, 3,
1233 "While(expr test, stmt* body, stmt* orelse)");
1234 if (!state->While_type) return 0;
1235 state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
1236 "If(expr test, stmt* body, stmt* orelse)");
1237 if (!state->If_type) return 0;
1238 state->With_type = make_type(state, "With", state->stmt_type, With_fields,
1239 3,
1240 "With(withitem* items, stmt* body, string? type_comment)");
1241 if (!state->With_type) return 0;
1242 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1243 return 0;
1244 state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
1245 AsyncWith_fields, 3,
1246 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
1247 if (!state->AsyncWith_type) return 0;
1248 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1249 == -1)
1250 return 0;
1251 state->Match_type = make_type(state, "Match", state->stmt_type,
1252 Match_fields, 2,
1253 "Match(expr subject, match_case* cases)");
1254 if (!state->Match_type) return 0;
1255 state->Raise_type = make_type(state, "Raise", state->stmt_type,
1256 Raise_fields, 2,
1257 "Raise(expr? exc, expr? cause)");
1258 if (!state->Raise_type) return 0;
1259 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1260 return 0;
1261 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1262 return 0;
1263 state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
1264 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
1265 if (!state->Try_type) return 0;
1266 state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
1267 TryStar_fields, 4,
1268 "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
1269 if (!state->TryStar_type) return 0;
1270 state->Assert_type = make_type(state, "Assert", state->stmt_type,
1271 Assert_fields, 2,
1272 "Assert(expr test, expr? msg)");
1273 if (!state->Assert_type) return 0;
1274 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1275 return 0;
1276 state->Import_type = make_type(state, "Import", state->stmt_type,
1277 Import_fields, 1,
1278 "Import(alias* names)");
1279 if (!state->Import_type) return 0;
1280 state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
1281 ImportFrom_fields, 3,
1282 "ImportFrom(identifier? module, alias* names, int? level)");
1283 if (!state->ImportFrom_type) return 0;
1284 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1285 return 0;
1286 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1287 return 0;
1288 state->Global_type = make_type(state, "Global", state->stmt_type,
1289 Global_fields, 1,
1290 "Global(identifier* names)");
1291 if (!state->Global_type) return 0;
1292 state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
1293 Nonlocal_fields, 1,
1294 "Nonlocal(identifier* names)");
1295 if (!state->Nonlocal_type) return 0;
1296 state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
1297 1,
1298 "Expr(expr value)");
1299 if (!state->Expr_type) return 0;
1300 state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
1301 "Pass");
1302 if (!state->Pass_type) return 0;
1303 state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
1304 "Break");
1305 if (!state->Break_type) return 0;
1306 state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
1307 0,
1308 "Continue");
1309 if (!state->Continue_type) return 0;
1310 state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
1311 "expr = BoolOp(boolop op, expr* values)\n"
1312 " | NamedExpr(expr target, expr value)\n"
1313 " | BinOp(expr left, operator op, expr right)\n"
1314 " | UnaryOp(unaryop op, expr operand)\n"
1315 " | Lambda(arguments args, expr body)\n"
1316 " | IfExp(expr test, expr body, expr orelse)\n"
1317 " | Dict(expr* keys, expr* values)\n"
1318 " | Set(expr* elts)\n"
1319 " | ListComp(expr elt, comprehension* generators)\n"
1320 " | SetComp(expr elt, comprehension* generators)\n"
1321 " | DictComp(expr key, expr value, comprehension* generators)\n"
1322 " | GeneratorExp(expr elt, comprehension* generators)\n"
1323 " | Await(expr value)\n"
1324 " | Yield(expr? value)\n"
1325 " | YieldFrom(expr value)\n"
1326 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1327 " | Call(expr func, expr* args, keyword* keywords)\n"
1328 " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
1329 " | JoinedStr(expr* values)\n"
1330 " | Constant(constant value, string? kind)\n"
1331 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1332 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1333 " | Starred(expr value, expr_context ctx)\n"
1334 " | Name(identifier id, expr_context ctx)\n"
1335 " | List(expr* elts, expr_context ctx)\n"
1336 " | Tuple(expr* elts, expr_context ctx)\n"
1337 " | Slice(expr? lower, expr? upper, expr? step)");
1338 if (!state->expr_type) return 0;
1339 if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
1340 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1341 return 0;
1342 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1343 -1)
1344 return 0;
1345 state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
1346 BoolOp_fields, 2,
1347 "BoolOp(boolop op, expr* values)");
1348 if (!state->BoolOp_type) return 0;
1349 state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
1350 NamedExpr_fields, 2,
1351 "NamedExpr(expr target, expr value)");
1352 if (!state->NamedExpr_type) return 0;
1353 state->BinOp_type = make_type(state, "BinOp", state->expr_type,
1354 BinOp_fields, 3,
1355 "BinOp(expr left, operator op, expr right)");
1356 if (!state->BinOp_type) return 0;
1357 state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
1358 UnaryOp_fields, 2,
1359 "UnaryOp(unaryop op, expr operand)");
1360 if (!state->UnaryOp_type) return 0;
1361 state->Lambda_type = make_type(state, "Lambda", state->expr_type,
1362 Lambda_fields, 2,
1363 "Lambda(arguments args, expr body)");
1364 if (!state->Lambda_type) return 0;
1365 state->IfExp_type = make_type(state, "IfExp", state->expr_type,
1366 IfExp_fields, 3,
1367 "IfExp(expr test, expr body, expr orelse)");
1368 if (!state->IfExp_type) return 0;
1369 state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
1370 2,
1371 "Dict(expr* keys, expr* values)");
1372 if (!state->Dict_type) return 0;
1373 state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
1374 "Set(expr* elts)");
1375 if (!state->Set_type) return 0;
1376 state->ListComp_type = make_type(state, "ListComp", state->expr_type,
1377 ListComp_fields, 2,
1378 "ListComp(expr elt, comprehension* generators)");
1379 if (!state->ListComp_type) return 0;
1380 state->SetComp_type = make_type(state, "SetComp", state->expr_type,
1381 SetComp_fields, 2,
1382 "SetComp(expr elt, comprehension* generators)");
1383 if (!state->SetComp_type) return 0;
1384 state->DictComp_type = make_type(state, "DictComp", state->expr_type,
1385 DictComp_fields, 3,
1386 "DictComp(expr key, expr value, comprehension* generators)");
1387 if (!state->DictComp_type) return 0;
1388 state->GeneratorExp_type = make_type(state, "GeneratorExp",
1389 state->expr_type, GeneratorExp_fields,
1390 2,
1391 "GeneratorExp(expr elt, comprehension* generators)");
1392 if (!state->GeneratorExp_type) return 0;
1393 state->Await_type = make_type(state, "Await", state->expr_type,
1394 Await_fields, 1,
1395 "Await(expr value)");
1396 if (!state->Await_type) return 0;
1397 state->Yield_type = make_type(state, "Yield", state->expr_type,
1398 Yield_fields, 1,
1399 "Yield(expr? value)");
1400 if (!state->Yield_type) return 0;
1401 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1402 return 0;
1403 state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
1404 YieldFrom_fields, 1,
1405 "YieldFrom(expr value)");
1406 if (!state->YieldFrom_type) return 0;
1407 state->Compare_type = make_type(state, "Compare", state->expr_type,
1408 Compare_fields, 3,
1409 "Compare(expr left, cmpop* ops, expr* comparators)");
1410 if (!state->Compare_type) return 0;
1411 state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
1412 3,
1413 "Call(expr func, expr* args, keyword* keywords)");
1414 if (!state->Call_type) return 0;
1415 state->FormattedValue_type = make_type(state, "FormattedValue",
1416 state->expr_type,
1417 FormattedValue_fields, 3,
1418 "FormattedValue(expr value, int conversion, expr? format_spec)");
1419 if (!state->FormattedValue_type) return 0;
1420 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1421 Py_None) == -1)
1422 return 0;
1423 state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
1424 JoinedStr_fields, 1,
1425 "JoinedStr(expr* values)");
1426 if (!state->JoinedStr_type) return 0;
1427 state->Constant_type = make_type(state, "Constant", state->expr_type,
1428 Constant_fields, 2,
1429 "Constant(constant value, string? kind)");
1430 if (!state->Constant_type) return 0;
1431 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1432 return 0;
1433 state->Attribute_type = make_type(state, "Attribute", state->expr_type,
1434 Attribute_fields, 3,
1435 "Attribute(expr value, identifier attr, expr_context ctx)");
1436 if (!state->Attribute_type) return 0;
1437 state->Subscript_type = make_type(state, "Subscript", state->expr_type,
1438 Subscript_fields, 3,
1439 "Subscript(expr value, expr slice, expr_context ctx)");
1440 if (!state->Subscript_type) return 0;
1441 state->Starred_type = make_type(state, "Starred", state->expr_type,
1442 Starred_fields, 2,
1443 "Starred(expr value, expr_context ctx)");
1444 if (!state->Starred_type) return 0;
1445 state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
1446 2,
1447 "Name(identifier id, expr_context ctx)");
1448 if (!state->Name_type) return 0;
1449 state->List_type = make_type(state, "List", state->expr_type, List_fields,
1450 2,
1451 "List(expr* elts, expr_context ctx)");
1452 if (!state->List_type) return 0;
1453 state->Tuple_type = make_type(state, "Tuple", state->expr_type,
1454 Tuple_fields, 2,
1455 "Tuple(expr* elts, expr_context ctx)");
1456 if (!state->Tuple_type) return 0;
1457 state->Slice_type = make_type(state, "Slice", state->expr_type,
1458 Slice_fields, 3,
1459 "Slice(expr? lower, expr? upper, expr? step)");
1460 if (!state->Slice_type) return 0;
1461 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1462 return 0;
1463 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1464 return 0;
1465 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1466 return 0;
1467 state->expr_context_type = make_type(state, "expr_context",
1468 state->AST_type, NULL, 0,
1469 "expr_context = Load | Store | Del");
1470 if (!state->expr_context_type) return 0;
1471 if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
1472 state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
1473 0,
1474 "Load");
1475 if (!state->Load_type) return 0;
1476 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1477 NULL, NULL);
1478 if (!state->Load_singleton) return 0;
1479 state->Store_type = make_type(state, "Store", state->expr_context_type,
1480 NULL, 0,
1481 "Store");
1482 if (!state->Store_type) return 0;
1483 state->Store_singleton = PyType_GenericNew((PyTypeObject
1484 *)state->Store_type, NULL, NULL);
1485 if (!state->Store_singleton) return 0;
1486 state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
1487 "Del");
1488 if (!state->Del_type) return 0;
1489 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1490 NULL, NULL);
1491 if (!state->Del_singleton) return 0;
1492 state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
1493 "boolop = And | Or");
1494 if (!state->boolop_type) return 0;
1495 if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
1496 state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
1497 "And");
1498 if (!state->And_type) return 0;
1499 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1500 NULL, NULL);
1501 if (!state->And_singleton) return 0;
1502 state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
1503 "Or");
1504 if (!state->Or_type) return 0;
1505 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1506 NULL, NULL);
1507 if (!state->Or_singleton) return 0;
1508 state->operator_type = make_type(state, "operator", state->AST_type, NULL,
1509 0,
1510 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
1511 if (!state->operator_type) return 0;
1512 if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
1513 state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
1514 "Add");
1515 if (!state->Add_type) return 0;
1516 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1517 NULL, NULL);
1518 if (!state->Add_singleton) return 0;
1519 state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
1520 "Sub");
1521 if (!state->Sub_type) return 0;
1522 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1523 NULL, NULL);
1524 if (!state->Sub_singleton) return 0;
1525 state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
1526 "Mult");
1527 if (!state->Mult_type) return 0;
1528 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1529 NULL, NULL);
1530 if (!state->Mult_singleton) return 0;
1531 state->MatMult_type = make_type(state, "MatMult", state->operator_type,
1532 NULL, 0,
1533 "MatMult");
1534 if (!state->MatMult_type) return 0;
1535 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1536 *)state->MatMult_type, NULL,
1537 NULL);
1538 if (!state->MatMult_singleton) return 0;
1539 state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
1540 "Div");
1541 if (!state->Div_type) return 0;
1542 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1543 NULL, NULL);
1544 if (!state->Div_singleton) return 0;
1545 state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
1546 "Mod");
1547 if (!state->Mod_type) return 0;
1548 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1549 NULL, NULL);
1550 if (!state->Mod_singleton) return 0;
1551 state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
1552 "Pow");
1553 if (!state->Pow_type) return 0;
1554 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1555 NULL, NULL);
1556 if (!state->Pow_singleton) return 0;
1557 state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
1558 0,
1559 "LShift");
1560 if (!state->LShift_type) return 0;
1561 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1562 *)state->LShift_type, NULL,
1563 NULL);
1564 if (!state->LShift_singleton) return 0;
1565 state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
1566 0,
1567 "RShift");
1568 if (!state->RShift_type) return 0;
1569 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1570 *)state->RShift_type, NULL,
1571 NULL);
1572 if (!state->RShift_singleton) return 0;
1573 state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
1574 "BitOr");
1575 if (!state->BitOr_type) return 0;
1576 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1577 *)state->BitOr_type, NULL, NULL);
1578 if (!state->BitOr_singleton) return 0;
1579 state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
1580 0,
1581 "BitXor");
1582 if (!state->BitXor_type) return 0;
1583 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1584 *)state->BitXor_type, NULL,
1585 NULL);
1586 if (!state->BitXor_singleton) return 0;
1587 state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
1588 0,
1589 "BitAnd");
1590 if (!state->BitAnd_type) return 0;
1591 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1592 *)state->BitAnd_type, NULL,
1593 NULL);
1594 if (!state->BitAnd_singleton) return 0;
1595 state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
1596 NULL, 0,
1597 "FloorDiv");
1598 if (!state->FloorDiv_type) return 0;
1599 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1600 *)state->FloorDiv_type, NULL,
1601 NULL);
1602 if (!state->FloorDiv_singleton) return 0;
1603 state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
1604 "unaryop = Invert | Not | UAdd | USub");
1605 if (!state->unaryop_type) return 0;
1606 if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
1607 state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
1608 0,
1609 "Invert");
1610 if (!state->Invert_type) return 0;
1611 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1612 *)state->Invert_type, NULL,
1613 NULL);
1614 if (!state->Invert_singleton) return 0;
1615 state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
1616 "Not");
1617 if (!state->Not_type) return 0;
1618 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1619 NULL, NULL);
1620 if (!state->Not_singleton) return 0;
1621 state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
1622 "UAdd");
1623 if (!state->UAdd_type) return 0;
1624 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1625 NULL, NULL);
1626 if (!state->UAdd_singleton) return 0;
1627 state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
1628 "USub");
1629 if (!state->USub_type) return 0;
1630 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1631 NULL, NULL);
1632 if (!state->USub_singleton) return 0;
1633 state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
1634 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
1635 if (!state->cmpop_type) return 0;
1636 if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
1637 state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
1638 "Eq");
1639 if (!state->Eq_type) return 0;
1640 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1641 NULL, NULL);
1642 if (!state->Eq_singleton) return 0;
1643 state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
1644 "NotEq");
1645 if (!state->NotEq_type) return 0;
1646 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1647 *)state->NotEq_type, NULL, NULL);
1648 if (!state->NotEq_singleton) return 0;
1649 state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
1650 "Lt");
1651 if (!state->Lt_type) return 0;
1652 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1653 NULL, NULL);
1654 if (!state->Lt_singleton) return 0;
1655 state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
1656 "LtE");
1657 if (!state->LtE_type) return 0;
1658 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1659 NULL, NULL);
1660 if (!state->LtE_singleton) return 0;
1661 state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
1662 "Gt");
1663 if (!state->Gt_type) return 0;
1664 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1665 NULL, NULL);
1666 if (!state->Gt_singleton) return 0;
1667 state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
1668 "GtE");
1669 if (!state->GtE_type) return 0;
1670 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1671 NULL, NULL);
1672 if (!state->GtE_singleton) return 0;
1673 state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
1674 "Is");
1675 if (!state->Is_type) return 0;
1676 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1677 NULL, NULL);
1678 if (!state->Is_singleton) return 0;
1679 state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
1680 "IsNot");
1681 if (!state->IsNot_type) return 0;
1682 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1683 *)state->IsNot_type, NULL, NULL);
1684 if (!state->IsNot_singleton) return 0;
1685 state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
1686 "In");
1687 if (!state->In_type) return 0;
1688 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1689 NULL, NULL);
1690 if (!state->In_singleton) return 0;
1691 state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
1692 "NotIn");
1693 if (!state->NotIn_type) return 0;
1694 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1695 *)state->NotIn_type, NULL, NULL);
1696 if (!state->NotIn_singleton) return 0;
1697 state->comprehension_type = make_type(state, "comprehension",
1698 state->AST_type,
1699 comprehension_fields, 4,
1700 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
1701 if (!state->comprehension_type) return 0;
1702 if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
1703 state->excepthandler_type = make_type(state, "excepthandler",
1704 state->AST_type, NULL, 0,
1705 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
1706 if (!state->excepthandler_type) return 0;
1707 if (!add_attributes(state, state->excepthandler_type,
1708 excepthandler_attributes, 4)) return 0;
1709 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1710 == -1)
1711 return 0;
1712 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1713 Py_None) == -1)
1714 return 0;
1715 state->ExceptHandler_type = make_type(state, "ExceptHandler",
1716 state->excepthandler_type,
1717 ExceptHandler_fields, 3,
1718 "ExceptHandler(expr? type, identifier? name, stmt* body)");
1719 if (!state->ExceptHandler_type) return 0;
1720 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1721 return 0;
1722 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1723 return 0;
1724 state->arguments_type = make_type(state, "arguments", state->AST_type,
1725 arguments_fields, 7,
1726 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
1727 if (!state->arguments_type) return 0;
1728 if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
1729 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1730 return 0;
1731 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1732 return 0;
1733 state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
1734 "arg(identifier arg, expr? annotation, string? type_comment)");
1735 if (!state->arg_type) return 0;
1736 if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
1737 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1738 return 0;
1739 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1740 return 0;
1741 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1742 return 0;
1743 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1744 return 0;
1745 state->keyword_type = make_type(state, "keyword", state->AST_type,
1746 keyword_fields, 2,
1747 "keyword(identifier? arg, expr value)");
1748 if (!state->keyword_type) return 0;
1749 if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
1750 return 0;
1751 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1752 return 0;
1753 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1754 return 0;
1755 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1756 == -1)
1757 return 0;
1758 state->alias_type = make_type(state, "alias", state->AST_type,
1759 alias_fields, 2,
1760 "alias(identifier name, identifier? asname)");
1761 if (!state->alias_type) return 0;
1762 if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
1763 0;
1764 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1765 return 0;
1766 if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
1767 return 0;
1768 if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
1769 -1)
1770 return 0;
1771 state->withitem_type = make_type(state, "withitem", state->AST_type,
1772 withitem_fields, 2,
1773 "withitem(expr context_expr, expr? optional_vars)");
1774 if (!state->withitem_type) return 0;
1775 if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
1776 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1777 == -1)
1778 return 0;
1779 state->match_case_type = make_type(state, "match_case", state->AST_type,
1780 match_case_fields, 3,
1781 "match_case(pattern pattern, expr? guard, stmt* body)");
1782 if (!state->match_case_type) return 0;
1783 if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
1784 if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
1785 return 0;
1786 state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
1787 "pattern = MatchValue(expr value)\n"
1788 " | MatchSingleton(constant value)\n"
1789 " | MatchSequence(pattern* patterns)\n"
1790 " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
1791 " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
1792 " | MatchStar(identifier? name)\n"
1793 " | MatchAs(pattern? pattern, identifier? name)\n"
1794 " | MatchOr(pattern* patterns)");
1795 if (!state->pattern_type) return 0;
1796 if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
1797 return 0;
1798 state->MatchValue_type = make_type(state, "MatchValue",
1799 state->pattern_type, MatchValue_fields,
1800 1,
1801 "MatchValue(expr value)");
1802 if (!state->MatchValue_type) return 0;
1803 state->MatchSingleton_type = make_type(state, "MatchSingleton",
1804 state->pattern_type,
1805 MatchSingleton_fields, 1,
1806 "MatchSingleton(constant value)");
1807 if (!state->MatchSingleton_type) return 0;
1808 state->MatchSequence_type = make_type(state, "MatchSequence",
1809 state->pattern_type,
1810 MatchSequence_fields, 1,
1811 "MatchSequence(pattern* patterns)");
1812 if (!state->MatchSequence_type) return 0;
1813 state->MatchMapping_type = make_type(state, "MatchMapping",
1814 state->pattern_type,
1815 MatchMapping_fields, 3,
1816 "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
1817 if (!state->MatchMapping_type) return 0;
1818 if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
1819 return 0;
1820 state->MatchClass_type = make_type(state, "MatchClass",
1821 state->pattern_type, MatchClass_fields,
1822 4,
1823 "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
1824 if (!state->MatchClass_type) return 0;
1825 state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
1826 MatchStar_fields, 1,
1827 "MatchStar(identifier? name)");
1828 if (!state->MatchStar_type) return 0;
1829 if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
1830 return 0;
1831 state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
1832 MatchAs_fields, 2,
1833 "MatchAs(pattern? pattern, identifier? name)");
1834 if (!state->MatchAs_type) return 0;
1835 if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
1836 return 0;
1837 if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
1838 return 0;
1839 state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
1840 MatchOr_fields, 1,
1841 "MatchOr(pattern* patterns)");
1842 if (!state->MatchOr_type) return 0;
1843 state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
1844 NULL, 0,
1845 "type_ignore = TypeIgnore(int lineno, string tag)");
1846 if (!state->type_ignore_type) return 0;
1847 if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
1848 state->TypeIgnore_type = make_type(state, "TypeIgnore",
1849 state->type_ignore_type,
1850 TypeIgnore_fields, 2,
1851 "TypeIgnore(int lineno, string tag)");
1852 if (!state->TypeIgnore_type) return 0;
1853
1854 state->recursion_depth = 0;
1855 state->recursion_limit = 0;
1856 state->initialized = 1;
1857 return 1;
1858 }
1859
1860 static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
1861 PyArena* arena);
1862 static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
1863 PyArena* arena);
1864 static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
1865 PyArena* arena);
1866 static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
1867 expr_context_ty* out, PyArena* arena);
1868 static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
1869 out, PyArena* arena);
1870 static int obj2ast_operator(struct ast_state *state, PyObject* obj,
1871 operator_ty* out, PyArena* arena);
1872 static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
1873 out, PyArena* arena);
1874 static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
1875 PyArena* arena);
1876 static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
1877 comprehension_ty* out, PyArena* arena);
1878 static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
1879 excepthandler_ty* out, PyArena* arena);
1880 static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
1881 arguments_ty* out, PyArena* arena);
1882 static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
1883 PyArena* arena);
1884 static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
1885 out, PyArena* arena);
1886 static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
1887 PyArena* arena);
1888 static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
1889 withitem_ty* out, PyArena* arena);
1890 static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
1891 match_case_ty* out, PyArena* arena);
1892 static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
1893 out, PyArena* arena);
1894 static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
1895 type_ignore_ty* out, PyArena* arena);
1896
1897 mod_ty
_PyAST_Module(asdl_stmt_seq * body,asdl_type_ignore_seq * type_ignores,PyArena * arena)1898 _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
1899 PyArena *arena)
1900 {
1901 mod_ty p;
1902 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1903 if (!p)
1904 return NULL;
1905 p->kind = Module_kind;
1906 p->v.Module.body = body;
1907 p->v.Module.type_ignores = type_ignores;
1908 return p;
1909 }
1910
1911 mod_ty
_PyAST_Interactive(asdl_stmt_seq * body,PyArena * arena)1912 _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
1913 {
1914 mod_ty p;
1915 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1916 if (!p)
1917 return NULL;
1918 p->kind = Interactive_kind;
1919 p->v.Interactive.body = body;
1920 return p;
1921 }
1922
1923 mod_ty
_PyAST_Expression(expr_ty body,PyArena * arena)1924 _PyAST_Expression(expr_ty body, PyArena *arena)
1925 {
1926 mod_ty p;
1927 if (!body) {
1928 PyErr_SetString(PyExc_ValueError,
1929 "field 'body' is required for Expression");
1930 return NULL;
1931 }
1932 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1933 if (!p)
1934 return NULL;
1935 p->kind = Expression_kind;
1936 p->v.Expression.body = body;
1937 return p;
1938 }
1939
1940 mod_ty
_PyAST_FunctionType(asdl_expr_seq * argtypes,expr_ty returns,PyArena * arena)1941 _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
1942 {
1943 mod_ty p;
1944 if (!returns) {
1945 PyErr_SetString(PyExc_ValueError,
1946 "field 'returns' is required for FunctionType");
1947 return NULL;
1948 }
1949 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1950 if (!p)
1951 return NULL;
1952 p->kind = FunctionType_kind;
1953 p->v.FunctionType.argtypes = argtypes;
1954 p->v.FunctionType.returns = returns;
1955 return p;
1956 }
1957
1958 stmt_ty
_PyAST_FunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1959 _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
1960 asdl_expr_seq * decorator_list, expr_ty returns, string
1961 type_comment, int lineno, int col_offset, int end_lineno,
1962 int end_col_offset, PyArena *arena)
1963 {
1964 stmt_ty p;
1965 if (!name) {
1966 PyErr_SetString(PyExc_ValueError,
1967 "field 'name' is required for FunctionDef");
1968 return NULL;
1969 }
1970 if (!args) {
1971 PyErr_SetString(PyExc_ValueError,
1972 "field 'args' is required for FunctionDef");
1973 return NULL;
1974 }
1975 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
1976 if (!p)
1977 return NULL;
1978 p->kind = FunctionDef_kind;
1979 p->v.FunctionDef.name = name;
1980 p->v.FunctionDef.args = args;
1981 p->v.FunctionDef.body = body;
1982 p->v.FunctionDef.decorator_list = decorator_list;
1983 p->v.FunctionDef.returns = returns;
1984 p->v.FunctionDef.type_comment = type_comment;
1985 p->lineno = lineno;
1986 p->col_offset = col_offset;
1987 p->end_lineno = end_lineno;
1988 p->end_col_offset = end_col_offset;
1989 return p;
1990 }
1991
1992 stmt_ty
_PyAST_AsyncFunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1993 _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
1994 body, asdl_expr_seq * decorator_list, expr_ty returns,
1995 string type_comment, int lineno, int col_offset, int
1996 end_lineno, int end_col_offset, PyArena *arena)
1997 {
1998 stmt_ty p;
1999 if (!name) {
2000 PyErr_SetString(PyExc_ValueError,
2001 "field 'name' is required for AsyncFunctionDef");
2002 return NULL;
2003 }
2004 if (!args) {
2005 PyErr_SetString(PyExc_ValueError,
2006 "field 'args' is required for AsyncFunctionDef");
2007 return NULL;
2008 }
2009 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2010 if (!p)
2011 return NULL;
2012 p->kind = AsyncFunctionDef_kind;
2013 p->v.AsyncFunctionDef.name = name;
2014 p->v.AsyncFunctionDef.args = args;
2015 p->v.AsyncFunctionDef.body = body;
2016 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2017 p->v.AsyncFunctionDef.returns = returns;
2018 p->v.AsyncFunctionDef.type_comment = type_comment;
2019 p->lineno = lineno;
2020 p->col_offset = col_offset;
2021 p->end_lineno = end_lineno;
2022 p->end_col_offset = end_col_offset;
2023 return p;
2024 }
2025
2026 stmt_ty
_PyAST_ClassDef(identifier name,asdl_expr_seq * bases,asdl_keyword_seq * keywords,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2027 _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
2028 keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
2029 int lineno, int col_offset, int end_lineno, int end_col_offset,
2030 PyArena *arena)
2031 {
2032 stmt_ty p;
2033 if (!name) {
2034 PyErr_SetString(PyExc_ValueError,
2035 "field 'name' is required for ClassDef");
2036 return NULL;
2037 }
2038 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2039 if (!p)
2040 return NULL;
2041 p->kind = ClassDef_kind;
2042 p->v.ClassDef.name = name;
2043 p->v.ClassDef.bases = bases;
2044 p->v.ClassDef.keywords = keywords;
2045 p->v.ClassDef.body = body;
2046 p->v.ClassDef.decorator_list = decorator_list;
2047 p->lineno = lineno;
2048 p->col_offset = col_offset;
2049 p->end_lineno = end_lineno;
2050 p->end_col_offset = end_col_offset;
2051 return p;
2052 }
2053
2054 stmt_ty
_PyAST_Return(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2055 _PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2056 end_col_offset, PyArena *arena)
2057 {
2058 stmt_ty p;
2059 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2060 if (!p)
2061 return NULL;
2062 p->kind = Return_kind;
2063 p->v.Return.value = value;
2064 p->lineno = lineno;
2065 p->col_offset = col_offset;
2066 p->end_lineno = end_lineno;
2067 p->end_col_offset = end_col_offset;
2068 return p;
2069 }
2070
2071 stmt_ty
_PyAST_Delete(asdl_expr_seq * targets,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2072 _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
2073 end_lineno, int end_col_offset, PyArena *arena)
2074 {
2075 stmt_ty p;
2076 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2077 if (!p)
2078 return NULL;
2079 p->kind = Delete_kind;
2080 p->v.Delete.targets = targets;
2081 p->lineno = lineno;
2082 p->col_offset = col_offset;
2083 p->end_lineno = end_lineno;
2084 p->end_col_offset = end_col_offset;
2085 return p;
2086 }
2087
2088 stmt_ty
_PyAST_Assign(asdl_expr_seq * targets,expr_ty value,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2089 _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
2090 lineno, int col_offset, int end_lineno, int end_col_offset,
2091 PyArena *arena)
2092 {
2093 stmt_ty p;
2094 if (!value) {
2095 PyErr_SetString(PyExc_ValueError,
2096 "field 'value' is required for Assign");
2097 return NULL;
2098 }
2099 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2100 if (!p)
2101 return NULL;
2102 p->kind = Assign_kind;
2103 p->v.Assign.targets = targets;
2104 p->v.Assign.value = value;
2105 p->v.Assign.type_comment = type_comment;
2106 p->lineno = lineno;
2107 p->col_offset = col_offset;
2108 p->end_lineno = end_lineno;
2109 p->end_col_offset = end_col_offset;
2110 return p;
2111 }
2112
2113 stmt_ty
_PyAST_AugAssign(expr_ty target,operator_ty op,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2114 _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
2115 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2116 {
2117 stmt_ty p;
2118 if (!target) {
2119 PyErr_SetString(PyExc_ValueError,
2120 "field 'target' is required for AugAssign");
2121 return NULL;
2122 }
2123 if (!op) {
2124 PyErr_SetString(PyExc_ValueError,
2125 "field 'op' is required for AugAssign");
2126 return NULL;
2127 }
2128 if (!value) {
2129 PyErr_SetString(PyExc_ValueError,
2130 "field 'value' is required for AugAssign");
2131 return NULL;
2132 }
2133 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2134 if (!p)
2135 return NULL;
2136 p->kind = AugAssign_kind;
2137 p->v.AugAssign.target = target;
2138 p->v.AugAssign.op = op;
2139 p->v.AugAssign.value = value;
2140 p->lineno = lineno;
2141 p->col_offset = col_offset;
2142 p->end_lineno = end_lineno;
2143 p->end_col_offset = end_col_offset;
2144 return p;
2145 }
2146
2147 stmt_ty
_PyAST_AnnAssign(expr_ty target,expr_ty annotation,expr_ty value,int simple,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2148 _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
2149 int lineno, int col_offset, int end_lineno, int
2150 end_col_offset, PyArena *arena)
2151 {
2152 stmt_ty p;
2153 if (!target) {
2154 PyErr_SetString(PyExc_ValueError,
2155 "field 'target' is required for AnnAssign");
2156 return NULL;
2157 }
2158 if (!annotation) {
2159 PyErr_SetString(PyExc_ValueError,
2160 "field 'annotation' is required for AnnAssign");
2161 return NULL;
2162 }
2163 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2164 if (!p)
2165 return NULL;
2166 p->kind = AnnAssign_kind;
2167 p->v.AnnAssign.target = target;
2168 p->v.AnnAssign.annotation = annotation;
2169 p->v.AnnAssign.value = value;
2170 p->v.AnnAssign.simple = simple;
2171 p->lineno = lineno;
2172 p->col_offset = col_offset;
2173 p->end_lineno = end_lineno;
2174 p->end_col_offset = end_col_offset;
2175 return p;
2176 }
2177
2178 stmt_ty
_PyAST_For(expr_ty target,expr_ty iter,asdl_stmt_seq * body,asdl_stmt_seq * orelse,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2179 _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
2180 orelse, string type_comment, int lineno, int col_offset, int
2181 end_lineno, int end_col_offset, PyArena *arena)
2182 {
2183 stmt_ty p;
2184 if (!target) {
2185 PyErr_SetString(PyExc_ValueError,
2186 "field 'target' is required for For");
2187 return NULL;
2188 }
2189 if (!iter) {
2190 PyErr_SetString(PyExc_ValueError,
2191 "field 'iter' is required for For");
2192 return NULL;
2193 }
2194 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2195 if (!p)
2196 return NULL;
2197 p->kind = For_kind;
2198 p->v.For.target = target;
2199 p->v.For.iter = iter;
2200 p->v.For.body = body;
2201 p->v.For.orelse = orelse;
2202 p->v.For.type_comment = type_comment;
2203 p->lineno = lineno;
2204 p->col_offset = col_offset;
2205 p->end_lineno = end_lineno;
2206 p->end_col_offset = end_col_offset;
2207 return p;
2208 }
2209
2210 stmt_ty
_PyAST_AsyncFor(expr_ty target,expr_ty iter,asdl_stmt_seq * body,asdl_stmt_seq * orelse,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2211 _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
2212 asdl_stmt_seq * orelse, string type_comment, int lineno, int
2213 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2214 {
2215 stmt_ty p;
2216 if (!target) {
2217 PyErr_SetString(PyExc_ValueError,
2218 "field 'target' is required for AsyncFor");
2219 return NULL;
2220 }
2221 if (!iter) {
2222 PyErr_SetString(PyExc_ValueError,
2223 "field 'iter' is required for AsyncFor");
2224 return NULL;
2225 }
2226 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2227 if (!p)
2228 return NULL;
2229 p->kind = AsyncFor_kind;
2230 p->v.AsyncFor.target = target;
2231 p->v.AsyncFor.iter = iter;
2232 p->v.AsyncFor.body = body;
2233 p->v.AsyncFor.orelse = orelse;
2234 p->v.AsyncFor.type_comment = type_comment;
2235 p->lineno = lineno;
2236 p->col_offset = col_offset;
2237 p->end_lineno = end_lineno;
2238 p->end_col_offset = end_col_offset;
2239 return p;
2240 }
2241
2242 stmt_ty
_PyAST_While(expr_ty test,asdl_stmt_seq * body,asdl_stmt_seq * orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2243 _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2244 lineno, int col_offset, int end_lineno, int end_col_offset,
2245 PyArena *arena)
2246 {
2247 stmt_ty p;
2248 if (!test) {
2249 PyErr_SetString(PyExc_ValueError,
2250 "field 'test' is required for While");
2251 return NULL;
2252 }
2253 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2254 if (!p)
2255 return NULL;
2256 p->kind = While_kind;
2257 p->v.While.test = test;
2258 p->v.While.body = body;
2259 p->v.While.orelse = orelse;
2260 p->lineno = lineno;
2261 p->col_offset = col_offset;
2262 p->end_lineno = end_lineno;
2263 p->end_col_offset = end_col_offset;
2264 return p;
2265 }
2266
2267 stmt_ty
_PyAST_If(expr_ty test,asdl_stmt_seq * body,asdl_stmt_seq * orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2268 _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2269 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2270 *arena)
2271 {
2272 stmt_ty p;
2273 if (!test) {
2274 PyErr_SetString(PyExc_ValueError,
2275 "field 'test' is required for If");
2276 return NULL;
2277 }
2278 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2279 if (!p)
2280 return NULL;
2281 p->kind = If_kind;
2282 p->v.If.test = test;
2283 p->v.If.body = body;
2284 p->v.If.orelse = orelse;
2285 p->lineno = lineno;
2286 p->col_offset = col_offset;
2287 p->end_lineno = end_lineno;
2288 p->end_col_offset = end_col_offset;
2289 return p;
2290 }
2291
2292 stmt_ty
_PyAST_With(asdl_withitem_seq * items,asdl_stmt_seq * body,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2293 _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2294 type_comment, int lineno, int col_offset, int end_lineno, int
2295 end_col_offset, PyArena *arena)
2296 {
2297 stmt_ty p;
2298 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2299 if (!p)
2300 return NULL;
2301 p->kind = With_kind;
2302 p->v.With.items = items;
2303 p->v.With.body = body;
2304 p->v.With.type_comment = type_comment;
2305 p->lineno = lineno;
2306 p->col_offset = col_offset;
2307 p->end_lineno = end_lineno;
2308 p->end_col_offset = end_col_offset;
2309 return p;
2310 }
2311
2312 stmt_ty
_PyAST_AsyncWith(asdl_withitem_seq * items,asdl_stmt_seq * body,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2313 _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2314 type_comment, int lineno, int col_offset, int end_lineno, int
2315 end_col_offset, PyArena *arena)
2316 {
2317 stmt_ty p;
2318 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2319 if (!p)
2320 return NULL;
2321 p->kind = AsyncWith_kind;
2322 p->v.AsyncWith.items = items;
2323 p->v.AsyncWith.body = body;
2324 p->v.AsyncWith.type_comment = type_comment;
2325 p->lineno = lineno;
2326 p->col_offset = col_offset;
2327 p->end_lineno = end_lineno;
2328 p->end_col_offset = end_col_offset;
2329 return p;
2330 }
2331
2332 stmt_ty
_PyAST_Match(expr_ty subject,asdl_match_case_seq * cases,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2333 _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
2334 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2335 {
2336 stmt_ty p;
2337 if (!subject) {
2338 PyErr_SetString(PyExc_ValueError,
2339 "field 'subject' is required for Match");
2340 return NULL;
2341 }
2342 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2343 if (!p)
2344 return NULL;
2345 p->kind = Match_kind;
2346 p->v.Match.subject = subject;
2347 p->v.Match.cases = cases;
2348 p->lineno = lineno;
2349 p->col_offset = col_offset;
2350 p->end_lineno = end_lineno;
2351 p->end_col_offset = end_col_offset;
2352 return p;
2353 }
2354
2355 stmt_ty
_PyAST_Raise(expr_ty exc,expr_ty cause,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2356 _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
2357 end_lineno, int end_col_offset, PyArena *arena)
2358 {
2359 stmt_ty p;
2360 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2361 if (!p)
2362 return NULL;
2363 p->kind = Raise_kind;
2364 p->v.Raise.exc = exc;
2365 p->v.Raise.cause = cause;
2366 p->lineno = lineno;
2367 p->col_offset = col_offset;
2368 p->end_lineno = end_lineno;
2369 p->end_col_offset = end_col_offset;
2370 return p;
2371 }
2372
2373 stmt_ty
_PyAST_Try(asdl_stmt_seq * body,asdl_excepthandler_seq * handlers,asdl_stmt_seq * orelse,asdl_stmt_seq * finalbody,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2374 _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2375 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
2376 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2377 {
2378 stmt_ty p;
2379 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2380 if (!p)
2381 return NULL;
2382 p->kind = Try_kind;
2383 p->v.Try.body = body;
2384 p->v.Try.handlers = handlers;
2385 p->v.Try.orelse = orelse;
2386 p->v.Try.finalbody = finalbody;
2387 p->lineno = lineno;
2388 p->col_offset = col_offset;
2389 p->end_lineno = end_lineno;
2390 p->end_col_offset = end_col_offset;
2391 return p;
2392 }
2393
2394 stmt_ty
_PyAST_TryStar(asdl_stmt_seq * body,asdl_excepthandler_seq * handlers,asdl_stmt_seq * orelse,asdl_stmt_seq * finalbody,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2395 _PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2396 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
2397 int col_offset, int end_lineno, int end_col_offset, PyArena
2398 *arena)
2399 {
2400 stmt_ty p;
2401 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2402 if (!p)
2403 return NULL;
2404 p->kind = TryStar_kind;
2405 p->v.TryStar.body = body;
2406 p->v.TryStar.handlers = handlers;
2407 p->v.TryStar.orelse = orelse;
2408 p->v.TryStar.finalbody = finalbody;
2409 p->lineno = lineno;
2410 p->col_offset = col_offset;
2411 p->end_lineno = end_lineno;
2412 p->end_col_offset = end_col_offset;
2413 return p;
2414 }
2415
2416 stmt_ty
_PyAST_Assert(expr_ty test,expr_ty msg,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2417 _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
2418 end_lineno, int end_col_offset, PyArena *arena)
2419 {
2420 stmt_ty p;
2421 if (!test) {
2422 PyErr_SetString(PyExc_ValueError,
2423 "field 'test' is required for Assert");
2424 return NULL;
2425 }
2426 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2427 if (!p)
2428 return NULL;
2429 p->kind = Assert_kind;
2430 p->v.Assert.test = test;
2431 p->v.Assert.msg = msg;
2432 p->lineno = lineno;
2433 p->col_offset = col_offset;
2434 p->end_lineno = end_lineno;
2435 p->end_col_offset = end_col_offset;
2436 return p;
2437 }
2438
2439 stmt_ty
_PyAST_Import(asdl_alias_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2440 _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
2441 end_lineno, int end_col_offset, PyArena *arena)
2442 {
2443 stmt_ty p;
2444 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2445 if (!p)
2446 return NULL;
2447 p->kind = Import_kind;
2448 p->v.Import.names = names;
2449 p->lineno = lineno;
2450 p->col_offset = col_offset;
2451 p->end_lineno = end_lineno;
2452 p->end_col_offset = end_col_offset;
2453 return p;
2454 }
2455
2456 stmt_ty
_PyAST_ImportFrom(identifier module,asdl_alias_seq * names,int level,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2457 _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
2458 lineno, int col_offset, int end_lineno, int end_col_offset,
2459 PyArena *arena)
2460 {
2461 stmt_ty p;
2462 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2463 if (!p)
2464 return NULL;
2465 p->kind = ImportFrom_kind;
2466 p->v.ImportFrom.module = module;
2467 p->v.ImportFrom.names = names;
2468 p->v.ImportFrom.level = level;
2469 p->lineno = lineno;
2470 p->col_offset = col_offset;
2471 p->end_lineno = end_lineno;
2472 p->end_col_offset = end_col_offset;
2473 return p;
2474 }
2475
2476 stmt_ty
_PyAST_Global(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2477 _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
2478 end_lineno, int end_col_offset, PyArena *arena)
2479 {
2480 stmt_ty p;
2481 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2482 if (!p)
2483 return NULL;
2484 p->kind = Global_kind;
2485 p->v.Global.names = names;
2486 p->lineno = lineno;
2487 p->col_offset = col_offset;
2488 p->end_lineno = end_lineno;
2489 p->end_col_offset = end_col_offset;
2490 return p;
2491 }
2492
2493 stmt_ty
_PyAST_Nonlocal(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2494 _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
2495 end_lineno, int end_col_offset, PyArena *arena)
2496 {
2497 stmt_ty p;
2498 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2499 if (!p)
2500 return NULL;
2501 p->kind = Nonlocal_kind;
2502 p->v.Nonlocal.names = names;
2503 p->lineno = lineno;
2504 p->col_offset = col_offset;
2505 p->end_lineno = end_lineno;
2506 p->end_col_offset = end_col_offset;
2507 return p;
2508 }
2509
2510 stmt_ty
_PyAST_Expr(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2511 _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2512 end_col_offset, PyArena *arena)
2513 {
2514 stmt_ty p;
2515 if (!value) {
2516 PyErr_SetString(PyExc_ValueError,
2517 "field 'value' is required for Expr");
2518 return NULL;
2519 }
2520 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2521 if (!p)
2522 return NULL;
2523 p->kind = Expr_kind;
2524 p->v.Expr.value = value;
2525 p->lineno = lineno;
2526 p->col_offset = col_offset;
2527 p->end_lineno = end_lineno;
2528 p->end_col_offset = end_col_offset;
2529 return p;
2530 }
2531
2532 stmt_ty
_PyAST_Pass(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2533 _PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
2534 PyArena *arena)
2535 {
2536 stmt_ty p;
2537 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2538 if (!p)
2539 return NULL;
2540 p->kind = Pass_kind;
2541 p->lineno = lineno;
2542 p->col_offset = col_offset;
2543 p->end_lineno = end_lineno;
2544 p->end_col_offset = end_col_offset;
2545 return p;
2546 }
2547
2548 stmt_ty
_PyAST_Break(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2549 _PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
2550 PyArena *arena)
2551 {
2552 stmt_ty p;
2553 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2554 if (!p)
2555 return NULL;
2556 p->kind = Break_kind;
2557 p->lineno = lineno;
2558 p->col_offset = col_offset;
2559 p->end_lineno = end_lineno;
2560 p->end_col_offset = end_col_offset;
2561 return p;
2562 }
2563
2564 stmt_ty
_PyAST_Continue(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2565 _PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2566 PyArena *arena)
2567 {
2568 stmt_ty p;
2569 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2570 if (!p)
2571 return NULL;
2572 p->kind = Continue_kind;
2573 p->lineno = lineno;
2574 p->col_offset = col_offset;
2575 p->end_lineno = end_lineno;
2576 p->end_col_offset = end_col_offset;
2577 return p;
2578 }
2579
2580 expr_ty
_PyAST_BoolOp(boolop_ty op,asdl_expr_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2581 _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
2582 int end_lineno, int end_col_offset, PyArena *arena)
2583 {
2584 expr_ty p;
2585 if (!op) {
2586 PyErr_SetString(PyExc_ValueError,
2587 "field 'op' is required for BoolOp");
2588 return NULL;
2589 }
2590 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2591 if (!p)
2592 return NULL;
2593 p->kind = BoolOp_kind;
2594 p->v.BoolOp.op = op;
2595 p->v.BoolOp.values = values;
2596 p->lineno = lineno;
2597 p->col_offset = col_offset;
2598 p->end_lineno = end_lineno;
2599 p->end_col_offset = end_col_offset;
2600 return p;
2601 }
2602
2603 expr_ty
_PyAST_NamedExpr(expr_ty target,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2604 _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2605 end_lineno, int end_col_offset, PyArena *arena)
2606 {
2607 expr_ty p;
2608 if (!target) {
2609 PyErr_SetString(PyExc_ValueError,
2610 "field 'target' is required for NamedExpr");
2611 return NULL;
2612 }
2613 if (!value) {
2614 PyErr_SetString(PyExc_ValueError,
2615 "field 'value' is required for NamedExpr");
2616 return NULL;
2617 }
2618 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2619 if (!p)
2620 return NULL;
2621 p->kind = NamedExpr_kind;
2622 p->v.NamedExpr.target = target;
2623 p->v.NamedExpr.value = value;
2624 p->lineno = lineno;
2625 p->col_offset = col_offset;
2626 p->end_lineno = end_lineno;
2627 p->end_col_offset = end_col_offset;
2628 return p;
2629 }
2630
2631 expr_ty
_PyAST_BinOp(expr_ty left,operator_ty op,expr_ty right,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2632 _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
2633 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2634 {
2635 expr_ty p;
2636 if (!left) {
2637 PyErr_SetString(PyExc_ValueError,
2638 "field 'left' is required for BinOp");
2639 return NULL;
2640 }
2641 if (!op) {
2642 PyErr_SetString(PyExc_ValueError,
2643 "field 'op' is required for BinOp");
2644 return NULL;
2645 }
2646 if (!right) {
2647 PyErr_SetString(PyExc_ValueError,
2648 "field 'right' is required for BinOp");
2649 return NULL;
2650 }
2651 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2652 if (!p)
2653 return NULL;
2654 p->kind = BinOp_kind;
2655 p->v.BinOp.left = left;
2656 p->v.BinOp.op = op;
2657 p->v.BinOp.right = right;
2658 p->lineno = lineno;
2659 p->col_offset = col_offset;
2660 p->end_lineno = end_lineno;
2661 p->end_col_offset = end_col_offset;
2662 return p;
2663 }
2664
2665 expr_ty
_PyAST_UnaryOp(unaryop_ty op,expr_ty operand,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2666 _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2667 end_lineno, int end_col_offset, PyArena *arena)
2668 {
2669 expr_ty p;
2670 if (!op) {
2671 PyErr_SetString(PyExc_ValueError,
2672 "field 'op' is required for UnaryOp");
2673 return NULL;
2674 }
2675 if (!operand) {
2676 PyErr_SetString(PyExc_ValueError,
2677 "field 'operand' is required for UnaryOp");
2678 return NULL;
2679 }
2680 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2681 if (!p)
2682 return NULL;
2683 p->kind = UnaryOp_kind;
2684 p->v.UnaryOp.op = op;
2685 p->v.UnaryOp.operand = operand;
2686 p->lineno = lineno;
2687 p->col_offset = col_offset;
2688 p->end_lineno = end_lineno;
2689 p->end_col_offset = end_col_offset;
2690 return p;
2691 }
2692
2693 expr_ty
_PyAST_Lambda(arguments_ty args,expr_ty body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2694 _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2695 end_lineno, int end_col_offset, PyArena *arena)
2696 {
2697 expr_ty p;
2698 if (!args) {
2699 PyErr_SetString(PyExc_ValueError,
2700 "field 'args' is required for Lambda");
2701 return NULL;
2702 }
2703 if (!body) {
2704 PyErr_SetString(PyExc_ValueError,
2705 "field 'body' is required for Lambda");
2706 return NULL;
2707 }
2708 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2709 if (!p)
2710 return NULL;
2711 p->kind = Lambda_kind;
2712 p->v.Lambda.args = args;
2713 p->v.Lambda.body = body;
2714 p->lineno = lineno;
2715 p->col_offset = col_offset;
2716 p->end_lineno = end_lineno;
2717 p->end_col_offset = end_col_offset;
2718 return p;
2719 }
2720
2721 expr_ty
_PyAST_IfExp(expr_ty test,expr_ty body,expr_ty orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2722 _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
2723 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2724 {
2725 expr_ty p;
2726 if (!test) {
2727 PyErr_SetString(PyExc_ValueError,
2728 "field 'test' is required for IfExp");
2729 return NULL;
2730 }
2731 if (!body) {
2732 PyErr_SetString(PyExc_ValueError,
2733 "field 'body' is required for IfExp");
2734 return NULL;
2735 }
2736 if (!orelse) {
2737 PyErr_SetString(PyExc_ValueError,
2738 "field 'orelse' is required for IfExp");
2739 return NULL;
2740 }
2741 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2742 if (!p)
2743 return NULL;
2744 p->kind = IfExp_kind;
2745 p->v.IfExp.test = test;
2746 p->v.IfExp.body = body;
2747 p->v.IfExp.orelse = orelse;
2748 p->lineno = lineno;
2749 p->col_offset = col_offset;
2750 p->end_lineno = end_lineno;
2751 p->end_col_offset = end_col_offset;
2752 return p;
2753 }
2754
2755 expr_ty
_PyAST_Dict(asdl_expr_seq * keys,asdl_expr_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2756 _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
2757 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2758 {
2759 expr_ty p;
2760 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2761 if (!p)
2762 return NULL;
2763 p->kind = Dict_kind;
2764 p->v.Dict.keys = keys;
2765 p->v.Dict.values = values;
2766 p->lineno = lineno;
2767 p->col_offset = col_offset;
2768 p->end_lineno = end_lineno;
2769 p->end_col_offset = end_col_offset;
2770 return p;
2771 }
2772
2773 expr_ty
_PyAST_Set(asdl_expr_seq * elts,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2774 _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
2775 int end_col_offset, PyArena *arena)
2776 {
2777 expr_ty p;
2778 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2779 if (!p)
2780 return NULL;
2781 p->kind = Set_kind;
2782 p->v.Set.elts = elts;
2783 p->lineno = lineno;
2784 p->col_offset = col_offset;
2785 p->end_lineno = end_lineno;
2786 p->end_col_offset = end_col_offset;
2787 return p;
2788 }
2789
2790 expr_ty
_PyAST_ListComp(expr_ty elt,asdl_comprehension_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2791 _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2792 int col_offset, int end_lineno, int end_col_offset, PyArena
2793 *arena)
2794 {
2795 expr_ty p;
2796 if (!elt) {
2797 PyErr_SetString(PyExc_ValueError,
2798 "field 'elt' is required for ListComp");
2799 return NULL;
2800 }
2801 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2802 if (!p)
2803 return NULL;
2804 p->kind = ListComp_kind;
2805 p->v.ListComp.elt = elt;
2806 p->v.ListComp.generators = generators;
2807 p->lineno = lineno;
2808 p->col_offset = col_offset;
2809 p->end_lineno = end_lineno;
2810 p->end_col_offset = end_col_offset;
2811 return p;
2812 }
2813
2814 expr_ty
_PyAST_SetComp(expr_ty elt,asdl_comprehension_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2815 _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2816 int col_offset, int end_lineno, int end_col_offset, PyArena
2817 *arena)
2818 {
2819 expr_ty p;
2820 if (!elt) {
2821 PyErr_SetString(PyExc_ValueError,
2822 "field 'elt' is required for SetComp");
2823 return NULL;
2824 }
2825 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2826 if (!p)
2827 return NULL;
2828 p->kind = SetComp_kind;
2829 p->v.SetComp.elt = elt;
2830 p->v.SetComp.generators = generators;
2831 p->lineno = lineno;
2832 p->col_offset = col_offset;
2833 p->end_lineno = end_lineno;
2834 p->end_col_offset = end_col_offset;
2835 return p;
2836 }
2837
2838 expr_ty
_PyAST_DictComp(expr_ty key,expr_ty value,asdl_comprehension_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2839 _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
2840 generators, int lineno, int col_offset, int end_lineno, int
2841 end_col_offset, PyArena *arena)
2842 {
2843 expr_ty p;
2844 if (!key) {
2845 PyErr_SetString(PyExc_ValueError,
2846 "field 'key' is required for DictComp");
2847 return NULL;
2848 }
2849 if (!value) {
2850 PyErr_SetString(PyExc_ValueError,
2851 "field 'value' is required for DictComp");
2852 return NULL;
2853 }
2854 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2855 if (!p)
2856 return NULL;
2857 p->kind = DictComp_kind;
2858 p->v.DictComp.key = key;
2859 p->v.DictComp.value = value;
2860 p->v.DictComp.generators = generators;
2861 p->lineno = lineno;
2862 p->col_offset = col_offset;
2863 p->end_lineno = end_lineno;
2864 p->end_col_offset = end_col_offset;
2865 return p;
2866 }
2867
2868 expr_ty
_PyAST_GeneratorExp(expr_ty elt,asdl_comprehension_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2869 _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
2870 lineno, int col_offset, int end_lineno, int end_col_offset,
2871 PyArena *arena)
2872 {
2873 expr_ty p;
2874 if (!elt) {
2875 PyErr_SetString(PyExc_ValueError,
2876 "field 'elt' is required for GeneratorExp");
2877 return NULL;
2878 }
2879 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2880 if (!p)
2881 return NULL;
2882 p->kind = GeneratorExp_kind;
2883 p->v.GeneratorExp.elt = elt;
2884 p->v.GeneratorExp.generators = generators;
2885 p->lineno = lineno;
2886 p->col_offset = col_offset;
2887 p->end_lineno = end_lineno;
2888 p->end_col_offset = end_col_offset;
2889 return p;
2890 }
2891
2892 expr_ty
_PyAST_Await(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2893 _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2894 end_col_offset, PyArena *arena)
2895 {
2896 expr_ty p;
2897 if (!value) {
2898 PyErr_SetString(PyExc_ValueError,
2899 "field 'value' is required for Await");
2900 return NULL;
2901 }
2902 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2903 if (!p)
2904 return NULL;
2905 p->kind = Await_kind;
2906 p->v.Await.value = value;
2907 p->lineno = lineno;
2908 p->col_offset = col_offset;
2909 p->end_lineno = end_lineno;
2910 p->end_col_offset = end_col_offset;
2911 return p;
2912 }
2913
2914 expr_ty
_PyAST_Yield(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2915 _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2916 end_col_offset, PyArena *arena)
2917 {
2918 expr_ty p;
2919 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2920 if (!p)
2921 return NULL;
2922 p->kind = Yield_kind;
2923 p->v.Yield.value = value;
2924 p->lineno = lineno;
2925 p->col_offset = col_offset;
2926 p->end_lineno = end_lineno;
2927 p->end_col_offset = end_col_offset;
2928 return p;
2929 }
2930
2931 expr_ty
_PyAST_YieldFrom(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2932 _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2933 end_col_offset, PyArena *arena)
2934 {
2935 expr_ty p;
2936 if (!value) {
2937 PyErr_SetString(PyExc_ValueError,
2938 "field 'value' is required for YieldFrom");
2939 return NULL;
2940 }
2941 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2942 if (!p)
2943 return NULL;
2944 p->kind = YieldFrom_kind;
2945 p->v.YieldFrom.value = value;
2946 p->lineno = lineno;
2947 p->col_offset = col_offset;
2948 p->end_lineno = end_lineno;
2949 p->end_col_offset = end_col_offset;
2950 return p;
2951 }
2952
2953 expr_ty
_PyAST_Compare(expr_ty left,asdl_int_seq * ops,asdl_expr_seq * comparators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2954 _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
2955 int lineno, int col_offset, int end_lineno, int end_col_offset,
2956 PyArena *arena)
2957 {
2958 expr_ty p;
2959 if (!left) {
2960 PyErr_SetString(PyExc_ValueError,
2961 "field 'left' is required for Compare");
2962 return NULL;
2963 }
2964 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2965 if (!p)
2966 return NULL;
2967 p->kind = Compare_kind;
2968 p->v.Compare.left = left;
2969 p->v.Compare.ops = ops;
2970 p->v.Compare.comparators = comparators;
2971 p->lineno = lineno;
2972 p->col_offset = col_offset;
2973 p->end_lineno = end_lineno;
2974 p->end_col_offset = end_col_offset;
2975 return p;
2976 }
2977
2978 expr_ty
_PyAST_Call(expr_ty func,asdl_expr_seq * args,asdl_keyword_seq * keywords,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2979 _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
2980 int lineno, int col_offset, int end_lineno, int end_col_offset,
2981 PyArena *arena)
2982 {
2983 expr_ty p;
2984 if (!func) {
2985 PyErr_SetString(PyExc_ValueError,
2986 "field 'func' is required for Call");
2987 return NULL;
2988 }
2989 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2990 if (!p)
2991 return NULL;
2992 p->kind = Call_kind;
2993 p->v.Call.func = func;
2994 p->v.Call.args = args;
2995 p->v.Call.keywords = keywords;
2996 p->lineno = lineno;
2997 p->col_offset = col_offset;
2998 p->end_lineno = end_lineno;
2999 p->end_col_offset = end_col_offset;
3000 return p;
3001 }
3002
3003 expr_ty
_PyAST_FormattedValue(expr_ty value,int conversion,expr_ty format_spec,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3004 _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
3005 lineno, int col_offset, int end_lineno, int
3006 end_col_offset, PyArena *arena)
3007 {
3008 expr_ty p;
3009 if (!value) {
3010 PyErr_SetString(PyExc_ValueError,
3011 "field 'value' is required for FormattedValue");
3012 return NULL;
3013 }
3014 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3015 if (!p)
3016 return NULL;
3017 p->kind = FormattedValue_kind;
3018 p->v.FormattedValue.value = value;
3019 p->v.FormattedValue.conversion = conversion;
3020 p->v.FormattedValue.format_spec = format_spec;
3021 p->lineno = lineno;
3022 p->col_offset = col_offset;
3023 p->end_lineno = end_lineno;
3024 p->end_col_offset = end_col_offset;
3025 return p;
3026 }
3027
3028 expr_ty
_PyAST_JoinedStr(asdl_expr_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3029 _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
3030 end_lineno, int end_col_offset, PyArena *arena)
3031 {
3032 expr_ty p;
3033 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3034 if (!p)
3035 return NULL;
3036 p->kind = JoinedStr_kind;
3037 p->v.JoinedStr.values = values;
3038 p->lineno = lineno;
3039 p->col_offset = col_offset;
3040 p->end_lineno = end_lineno;
3041 p->end_col_offset = end_col_offset;
3042 return p;
3043 }
3044
3045 expr_ty
_PyAST_Constant(constant value,string kind,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3046 _PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
3047 end_lineno, int end_col_offset, PyArena *arena)
3048 {
3049 expr_ty p;
3050 if (!value) {
3051 PyErr_SetString(PyExc_ValueError,
3052 "field 'value' is required for Constant");
3053 return NULL;
3054 }
3055 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3056 if (!p)
3057 return NULL;
3058 p->kind = Constant_kind;
3059 p->v.Constant.value = value;
3060 p->v.Constant.kind = kind;
3061 p->lineno = lineno;
3062 p->col_offset = col_offset;
3063 p->end_lineno = end_lineno;
3064 p->end_col_offset = end_col_offset;
3065 return p;
3066 }
3067
3068 expr_ty
_PyAST_Attribute(expr_ty value,identifier attr,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3069 _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
3070 lineno, int col_offset, int end_lineno, int end_col_offset,
3071 PyArena *arena)
3072 {
3073 expr_ty p;
3074 if (!value) {
3075 PyErr_SetString(PyExc_ValueError,
3076 "field 'value' is required for Attribute");
3077 return NULL;
3078 }
3079 if (!attr) {
3080 PyErr_SetString(PyExc_ValueError,
3081 "field 'attr' is required for Attribute");
3082 return NULL;
3083 }
3084 if (!ctx) {
3085 PyErr_SetString(PyExc_ValueError,
3086 "field 'ctx' is required for Attribute");
3087 return NULL;
3088 }
3089 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3090 if (!p)
3091 return NULL;
3092 p->kind = Attribute_kind;
3093 p->v.Attribute.value = value;
3094 p->v.Attribute.attr = attr;
3095 p->v.Attribute.ctx = ctx;
3096 p->lineno = lineno;
3097 p->col_offset = col_offset;
3098 p->end_lineno = end_lineno;
3099 p->end_col_offset = end_col_offset;
3100 return p;
3101 }
3102
3103 expr_ty
_PyAST_Subscript(expr_ty value,expr_ty slice,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3104 _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
3105 int col_offset, int end_lineno, int end_col_offset, PyArena
3106 *arena)
3107 {
3108 expr_ty p;
3109 if (!value) {
3110 PyErr_SetString(PyExc_ValueError,
3111 "field 'value' is required for Subscript");
3112 return NULL;
3113 }
3114 if (!slice) {
3115 PyErr_SetString(PyExc_ValueError,
3116 "field 'slice' is required for Subscript");
3117 return NULL;
3118 }
3119 if (!ctx) {
3120 PyErr_SetString(PyExc_ValueError,
3121 "field 'ctx' is required for Subscript");
3122 return NULL;
3123 }
3124 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3125 if (!p)
3126 return NULL;
3127 p->kind = Subscript_kind;
3128 p->v.Subscript.value = value;
3129 p->v.Subscript.slice = slice;
3130 p->v.Subscript.ctx = ctx;
3131 p->lineno = lineno;
3132 p->col_offset = col_offset;
3133 p->end_lineno = end_lineno;
3134 p->end_col_offset = end_col_offset;
3135 return p;
3136 }
3137
3138 expr_ty
_PyAST_Starred(expr_ty value,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3139 _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
3140 int end_lineno, int end_col_offset, PyArena *arena)
3141 {
3142 expr_ty p;
3143 if (!value) {
3144 PyErr_SetString(PyExc_ValueError,
3145 "field 'value' is required for Starred");
3146 return NULL;
3147 }
3148 if (!ctx) {
3149 PyErr_SetString(PyExc_ValueError,
3150 "field 'ctx' is required for Starred");
3151 return NULL;
3152 }
3153 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3154 if (!p)
3155 return NULL;
3156 p->kind = Starred_kind;
3157 p->v.Starred.value = value;
3158 p->v.Starred.ctx = ctx;
3159 p->lineno = lineno;
3160 p->col_offset = col_offset;
3161 p->end_lineno = end_lineno;
3162 p->end_col_offset = end_col_offset;
3163 return p;
3164 }
3165
3166 expr_ty
_PyAST_Name(identifier id,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3167 _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3168 end_lineno, int end_col_offset, PyArena *arena)
3169 {
3170 expr_ty p;
3171 if (!id) {
3172 PyErr_SetString(PyExc_ValueError,
3173 "field 'id' is required for Name");
3174 return NULL;
3175 }
3176 if (!ctx) {
3177 PyErr_SetString(PyExc_ValueError,
3178 "field 'ctx' is required for Name");
3179 return NULL;
3180 }
3181 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3182 if (!p)
3183 return NULL;
3184 p->kind = Name_kind;
3185 p->v.Name.id = id;
3186 p->v.Name.ctx = ctx;
3187 p->lineno = lineno;
3188 p->col_offset = col_offset;
3189 p->end_lineno = end_lineno;
3190 p->end_col_offset = end_col_offset;
3191 return p;
3192 }
3193
3194 expr_ty
_PyAST_List(asdl_expr_seq * elts,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3195 _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3196 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3197 {
3198 expr_ty p;
3199 if (!ctx) {
3200 PyErr_SetString(PyExc_ValueError,
3201 "field 'ctx' is required for List");
3202 return NULL;
3203 }
3204 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3205 if (!p)
3206 return NULL;
3207 p->kind = List_kind;
3208 p->v.List.elts = elts;
3209 p->v.List.ctx = ctx;
3210 p->lineno = lineno;
3211 p->col_offset = col_offset;
3212 p->end_lineno = end_lineno;
3213 p->end_col_offset = end_col_offset;
3214 return p;
3215 }
3216
3217 expr_ty
_PyAST_Tuple(asdl_expr_seq * elts,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3218 _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3219 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3220 {
3221 expr_ty p;
3222 if (!ctx) {
3223 PyErr_SetString(PyExc_ValueError,
3224 "field 'ctx' is required for Tuple");
3225 return NULL;
3226 }
3227 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3228 if (!p)
3229 return NULL;
3230 p->kind = Tuple_kind;
3231 p->v.Tuple.elts = elts;
3232 p->v.Tuple.ctx = ctx;
3233 p->lineno = lineno;
3234 p->col_offset = col_offset;
3235 p->end_lineno = end_lineno;
3236 p->end_col_offset = end_col_offset;
3237 return p;
3238 }
3239
3240 expr_ty
_PyAST_Slice(expr_ty lower,expr_ty upper,expr_ty step,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3241 _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
3242 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3243 {
3244 expr_ty p;
3245 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3246 if (!p)
3247 return NULL;
3248 p->kind = Slice_kind;
3249 p->v.Slice.lower = lower;
3250 p->v.Slice.upper = upper;
3251 p->v.Slice.step = step;
3252 p->lineno = lineno;
3253 p->col_offset = col_offset;
3254 p->end_lineno = end_lineno;
3255 p->end_col_offset = end_col_offset;
3256 return p;
3257 }
3258
3259 comprehension_ty
_PyAST_comprehension(expr_ty target,expr_ty iter,asdl_expr_seq * ifs,int is_async,PyArena * arena)3260 _PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
3261 is_async, PyArena *arena)
3262 {
3263 comprehension_ty p;
3264 if (!target) {
3265 PyErr_SetString(PyExc_ValueError,
3266 "field 'target' is required for comprehension");
3267 return NULL;
3268 }
3269 if (!iter) {
3270 PyErr_SetString(PyExc_ValueError,
3271 "field 'iter' is required for comprehension");
3272 return NULL;
3273 }
3274 p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
3275 if (!p)
3276 return NULL;
3277 p->target = target;
3278 p->iter = iter;
3279 p->ifs = ifs;
3280 p->is_async = is_async;
3281 return p;
3282 }
3283
3284 excepthandler_ty
_PyAST_ExceptHandler(expr_ty type,identifier name,asdl_stmt_seq * body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3285 _PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
3286 lineno, int col_offset, int end_lineno, int
3287 end_col_offset, PyArena *arena)
3288 {
3289 excepthandler_ty p;
3290 p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
3291 if (!p)
3292 return NULL;
3293 p->kind = ExceptHandler_kind;
3294 p->v.ExceptHandler.type = type;
3295 p->v.ExceptHandler.name = name;
3296 p->v.ExceptHandler.body = body;
3297 p->lineno = lineno;
3298 p->col_offset = col_offset;
3299 p->end_lineno = end_lineno;
3300 p->end_col_offset = end_col_offset;
3301 return p;
3302 }
3303
3304 arguments_ty
_PyAST_arguments(asdl_arg_seq * posonlyargs,asdl_arg_seq * args,arg_ty vararg,asdl_arg_seq * kwonlyargs,asdl_expr_seq * kw_defaults,arg_ty kwarg,asdl_expr_seq * defaults,PyArena * arena)3305 _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
3306 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
3307 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
3308 *arena)
3309 {
3310 arguments_ty p;
3311 p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
3312 if (!p)
3313 return NULL;
3314 p->posonlyargs = posonlyargs;
3315 p->args = args;
3316 p->vararg = vararg;
3317 p->kwonlyargs = kwonlyargs;
3318 p->kw_defaults = kw_defaults;
3319 p->kwarg = kwarg;
3320 p->defaults = defaults;
3321 return p;
3322 }
3323
3324 arg_ty
_PyAST_arg(identifier arg,expr_ty annotation,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3325 _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
3326 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3327 {
3328 arg_ty p;
3329 if (!arg) {
3330 PyErr_SetString(PyExc_ValueError,
3331 "field 'arg' is required for arg");
3332 return NULL;
3333 }
3334 p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
3335 if (!p)
3336 return NULL;
3337 p->arg = arg;
3338 p->annotation = annotation;
3339 p->type_comment = type_comment;
3340 p->lineno = lineno;
3341 p->col_offset = col_offset;
3342 p->end_lineno = end_lineno;
3343 p->end_col_offset = end_col_offset;
3344 return p;
3345 }
3346
3347 keyword_ty
_PyAST_keyword(identifier arg,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3348 _PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3349 end_lineno, int end_col_offset, PyArena *arena)
3350 {
3351 keyword_ty p;
3352 if (!value) {
3353 PyErr_SetString(PyExc_ValueError,
3354 "field 'value' is required for keyword");
3355 return NULL;
3356 }
3357 p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
3358 if (!p)
3359 return NULL;
3360 p->arg = arg;
3361 p->value = value;
3362 p->lineno = lineno;
3363 p->col_offset = col_offset;
3364 p->end_lineno = end_lineno;
3365 p->end_col_offset = end_col_offset;
3366 return p;
3367 }
3368
3369 alias_ty
_PyAST_alias(identifier name,identifier asname,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3370 _PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
3371 int end_lineno, int end_col_offset, PyArena *arena)
3372 {
3373 alias_ty p;
3374 if (!name) {
3375 PyErr_SetString(PyExc_ValueError,
3376 "field 'name' is required for alias");
3377 return NULL;
3378 }
3379 p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
3380 if (!p)
3381 return NULL;
3382 p->name = name;
3383 p->asname = asname;
3384 p->lineno = lineno;
3385 p->col_offset = col_offset;
3386 p->end_lineno = end_lineno;
3387 p->end_col_offset = end_col_offset;
3388 return p;
3389 }
3390
3391 withitem_ty
_PyAST_withitem(expr_ty context_expr,expr_ty optional_vars,PyArena * arena)3392 _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3393 {
3394 withitem_ty p;
3395 if (!context_expr) {
3396 PyErr_SetString(PyExc_ValueError,
3397 "field 'context_expr' is required for withitem");
3398 return NULL;
3399 }
3400 p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
3401 if (!p)
3402 return NULL;
3403 p->context_expr = context_expr;
3404 p->optional_vars = optional_vars;
3405 return p;
3406 }
3407
3408 match_case_ty
_PyAST_match_case(pattern_ty pattern,expr_ty guard,asdl_stmt_seq * body,PyArena * arena)3409 _PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
3410 PyArena *arena)
3411 {
3412 match_case_ty p;
3413 if (!pattern) {
3414 PyErr_SetString(PyExc_ValueError,
3415 "field 'pattern' is required for match_case");
3416 return NULL;
3417 }
3418 p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
3419 if (!p)
3420 return NULL;
3421 p->pattern = pattern;
3422 p->guard = guard;
3423 p->body = body;
3424 return p;
3425 }
3426
3427 pattern_ty
_PyAST_MatchValue(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3428 _PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
3429 int end_col_offset, PyArena *arena)
3430 {
3431 pattern_ty p;
3432 if (!value) {
3433 PyErr_SetString(PyExc_ValueError,
3434 "field 'value' is required for MatchValue");
3435 return NULL;
3436 }
3437 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3438 if (!p)
3439 return NULL;
3440 p->kind = MatchValue_kind;
3441 p->v.MatchValue.value = value;
3442 p->lineno = lineno;
3443 p->col_offset = col_offset;
3444 p->end_lineno = end_lineno;
3445 p->end_col_offset = end_col_offset;
3446 return p;
3447 }
3448
3449 pattern_ty
_PyAST_MatchSingleton(constant value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3450 _PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
3451 end_lineno, int end_col_offset, PyArena *arena)
3452 {
3453 pattern_ty p;
3454 if (!value) {
3455 PyErr_SetString(PyExc_ValueError,
3456 "field 'value' is required for MatchSingleton");
3457 return NULL;
3458 }
3459 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3460 if (!p)
3461 return NULL;
3462 p->kind = MatchSingleton_kind;
3463 p->v.MatchSingleton.value = value;
3464 p->lineno = lineno;
3465 p->col_offset = col_offset;
3466 p->end_lineno = end_lineno;
3467 p->end_col_offset = end_col_offset;
3468 return p;
3469 }
3470
3471 pattern_ty
_PyAST_MatchSequence(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3472 _PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
3473 int end_lineno, int end_col_offset, PyArena *arena)
3474 {
3475 pattern_ty p;
3476 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3477 if (!p)
3478 return NULL;
3479 p->kind = MatchSequence_kind;
3480 p->v.MatchSequence.patterns = patterns;
3481 p->lineno = lineno;
3482 p->col_offset = col_offset;
3483 p->end_lineno = end_lineno;
3484 p->end_col_offset = end_col_offset;
3485 return p;
3486 }
3487
3488 pattern_ty
_PyAST_MatchMapping(asdl_expr_seq * keys,asdl_pattern_seq * patterns,identifier rest,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3489 _PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
3490 identifier rest, int lineno, int col_offset, int
3491 end_lineno, int end_col_offset, PyArena *arena)
3492 {
3493 pattern_ty p;
3494 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3495 if (!p)
3496 return NULL;
3497 p->kind = MatchMapping_kind;
3498 p->v.MatchMapping.keys = keys;
3499 p->v.MatchMapping.patterns = patterns;
3500 p->v.MatchMapping.rest = rest;
3501 p->lineno = lineno;
3502 p->col_offset = col_offset;
3503 p->end_lineno = end_lineno;
3504 p->end_col_offset = end_col_offset;
3505 return p;
3506 }
3507
3508 pattern_ty
_PyAST_MatchClass(expr_ty cls,asdl_pattern_seq * patterns,asdl_identifier_seq * kwd_attrs,asdl_pattern_seq * kwd_patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3509 _PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
3510 * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
3511 col_offset, int end_lineno, int end_col_offset, PyArena
3512 *arena)
3513 {
3514 pattern_ty p;
3515 if (!cls) {
3516 PyErr_SetString(PyExc_ValueError,
3517 "field 'cls' is required for MatchClass");
3518 return NULL;
3519 }
3520 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3521 if (!p)
3522 return NULL;
3523 p->kind = MatchClass_kind;
3524 p->v.MatchClass.cls = cls;
3525 p->v.MatchClass.patterns = patterns;
3526 p->v.MatchClass.kwd_attrs = kwd_attrs;
3527 p->v.MatchClass.kwd_patterns = kwd_patterns;
3528 p->lineno = lineno;
3529 p->col_offset = col_offset;
3530 p->end_lineno = end_lineno;
3531 p->end_col_offset = end_col_offset;
3532 return p;
3533 }
3534
3535 pattern_ty
_PyAST_MatchStar(identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3536 _PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
3537 int end_col_offset, PyArena *arena)
3538 {
3539 pattern_ty p;
3540 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3541 if (!p)
3542 return NULL;
3543 p->kind = MatchStar_kind;
3544 p->v.MatchStar.name = name;
3545 p->lineno = lineno;
3546 p->col_offset = col_offset;
3547 p->end_lineno = end_lineno;
3548 p->end_col_offset = end_col_offset;
3549 return p;
3550 }
3551
3552 pattern_ty
_PyAST_MatchAs(pattern_ty pattern,identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3553 _PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
3554 int end_lineno, int end_col_offset, PyArena *arena)
3555 {
3556 pattern_ty p;
3557 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3558 if (!p)
3559 return NULL;
3560 p->kind = MatchAs_kind;
3561 p->v.MatchAs.pattern = pattern;
3562 p->v.MatchAs.name = name;
3563 p->lineno = lineno;
3564 p->col_offset = col_offset;
3565 p->end_lineno = end_lineno;
3566 p->end_col_offset = end_col_offset;
3567 return p;
3568 }
3569
3570 pattern_ty
_PyAST_MatchOr(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3571 _PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
3572 end_lineno, int end_col_offset, PyArena *arena)
3573 {
3574 pattern_ty p;
3575 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3576 if (!p)
3577 return NULL;
3578 p->kind = MatchOr_kind;
3579 p->v.MatchOr.patterns = patterns;
3580 p->lineno = lineno;
3581 p->col_offset = col_offset;
3582 p->end_lineno = end_lineno;
3583 p->end_col_offset = end_col_offset;
3584 return p;
3585 }
3586
3587 type_ignore_ty
_PyAST_TypeIgnore(int lineno,string tag,PyArena * arena)3588 _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
3589 {
3590 type_ignore_ty p;
3591 if (!tag) {
3592 PyErr_SetString(PyExc_ValueError,
3593 "field 'tag' is required for TypeIgnore");
3594 return NULL;
3595 }
3596 p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
3597 if (!p)
3598 return NULL;
3599 p->kind = TypeIgnore_kind;
3600 p->v.TypeIgnore.lineno = lineno;
3601 p->v.TypeIgnore.tag = tag;
3602 return p;
3603 }
3604
3605
3606 PyObject*
ast2obj_mod(struct ast_state * state,void * _o)3607 ast2obj_mod(struct ast_state *state, void* _o)
3608 {
3609 mod_ty o = (mod_ty)_o;
3610 PyObject *result = NULL, *value = NULL;
3611 PyTypeObject *tp;
3612 if (!o) {
3613 Py_RETURN_NONE;
3614 }
3615 if (++state->recursion_depth > state->recursion_limit) {
3616 PyErr_SetString(PyExc_RecursionError,
3617 "maximum recursion depth exceeded during ast construction");
3618 return 0;
3619 }
3620 switch (o->kind) {
3621 case Module_kind:
3622 tp = (PyTypeObject *)state->Module_type;
3623 result = PyType_GenericNew(tp, NULL, NULL);
3624 if (!result) goto failed;
3625 value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
3626 if (!value) goto failed;
3627 if (PyObject_SetAttr(result, state->body, value) == -1)
3628 goto failed;
3629 Py_DECREF(value);
3630 value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
3631 ast2obj_type_ignore);
3632 if (!value) goto failed;
3633 if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
3634 goto failed;
3635 Py_DECREF(value);
3636 break;
3637 case Interactive_kind:
3638 tp = (PyTypeObject *)state->Interactive_type;
3639 result = PyType_GenericNew(tp, NULL, NULL);
3640 if (!result) goto failed;
3641 value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
3642 ast2obj_stmt);
3643 if (!value) goto failed;
3644 if (PyObject_SetAttr(result, state->body, value) == -1)
3645 goto failed;
3646 Py_DECREF(value);
3647 break;
3648 case Expression_kind:
3649 tp = (PyTypeObject *)state->Expression_type;
3650 result = PyType_GenericNew(tp, NULL, NULL);
3651 if (!result) goto failed;
3652 value = ast2obj_expr(state, o->v.Expression.body);
3653 if (!value) goto failed;
3654 if (PyObject_SetAttr(result, state->body, value) == -1)
3655 goto failed;
3656 Py_DECREF(value);
3657 break;
3658 case FunctionType_kind:
3659 tp = (PyTypeObject *)state->FunctionType_type;
3660 result = PyType_GenericNew(tp, NULL, NULL);
3661 if (!result) goto failed;
3662 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
3663 ast2obj_expr);
3664 if (!value) goto failed;
3665 if (PyObject_SetAttr(result, state->argtypes, value) == -1)
3666 goto failed;
3667 Py_DECREF(value);
3668 value = ast2obj_expr(state, o->v.FunctionType.returns);
3669 if (!value) goto failed;
3670 if (PyObject_SetAttr(result, state->returns, value) == -1)
3671 goto failed;
3672 Py_DECREF(value);
3673 break;
3674 }
3675 state->recursion_depth--;
3676 return result;
3677 failed:
3678 Py_XDECREF(value);
3679 Py_XDECREF(result);
3680 return NULL;
3681 }
3682
3683 PyObject*
ast2obj_stmt(struct ast_state * state,void * _o)3684 ast2obj_stmt(struct ast_state *state, void* _o)
3685 {
3686 stmt_ty o = (stmt_ty)_o;
3687 PyObject *result = NULL, *value = NULL;
3688 PyTypeObject *tp;
3689 if (!o) {
3690 Py_RETURN_NONE;
3691 }
3692 if (++state->recursion_depth > state->recursion_limit) {
3693 PyErr_SetString(PyExc_RecursionError,
3694 "maximum recursion depth exceeded during ast construction");
3695 return 0;
3696 }
3697 switch (o->kind) {
3698 case FunctionDef_kind:
3699 tp = (PyTypeObject *)state->FunctionDef_type;
3700 result = PyType_GenericNew(tp, NULL, NULL);
3701 if (!result) goto failed;
3702 value = ast2obj_identifier(state, o->v.FunctionDef.name);
3703 if (!value) goto failed;
3704 if (PyObject_SetAttr(result, state->name, value) == -1)
3705 goto failed;
3706 Py_DECREF(value);
3707 value = ast2obj_arguments(state, o->v.FunctionDef.args);
3708 if (!value) goto failed;
3709 if (PyObject_SetAttr(result, state->args, value) == -1)
3710 goto failed;
3711 Py_DECREF(value);
3712 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
3713 ast2obj_stmt);
3714 if (!value) goto failed;
3715 if (PyObject_SetAttr(result, state->body, value) == -1)
3716 goto failed;
3717 Py_DECREF(value);
3718 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
3719 ast2obj_expr);
3720 if (!value) goto failed;
3721 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3722 goto failed;
3723 Py_DECREF(value);
3724 value = ast2obj_expr(state, o->v.FunctionDef.returns);
3725 if (!value) goto failed;
3726 if (PyObject_SetAttr(result, state->returns, value) == -1)
3727 goto failed;
3728 Py_DECREF(value);
3729 value = ast2obj_string(state, o->v.FunctionDef.type_comment);
3730 if (!value) goto failed;
3731 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3732 goto failed;
3733 Py_DECREF(value);
3734 break;
3735 case AsyncFunctionDef_kind:
3736 tp = (PyTypeObject *)state->AsyncFunctionDef_type;
3737 result = PyType_GenericNew(tp, NULL, NULL);
3738 if (!result) goto failed;
3739 value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
3740 if (!value) goto failed;
3741 if (PyObject_SetAttr(result, state->name, value) == -1)
3742 goto failed;
3743 Py_DECREF(value);
3744 value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
3745 if (!value) goto failed;
3746 if (PyObject_SetAttr(result, state->args, value) == -1)
3747 goto failed;
3748 Py_DECREF(value);
3749 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
3750 ast2obj_stmt);
3751 if (!value) goto failed;
3752 if (PyObject_SetAttr(result, state->body, value) == -1)
3753 goto failed;
3754 Py_DECREF(value);
3755 value = ast2obj_list(state,
3756 (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
3757 ast2obj_expr);
3758 if (!value) goto failed;
3759 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3760 goto failed;
3761 Py_DECREF(value);
3762 value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
3763 if (!value) goto failed;
3764 if (PyObject_SetAttr(result, state->returns, value) == -1)
3765 goto failed;
3766 Py_DECREF(value);
3767 value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
3768 if (!value) goto failed;
3769 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3770 goto failed;
3771 Py_DECREF(value);
3772 break;
3773 case ClassDef_kind:
3774 tp = (PyTypeObject *)state->ClassDef_type;
3775 result = PyType_GenericNew(tp, NULL, NULL);
3776 if (!result) goto failed;
3777 value = ast2obj_identifier(state, o->v.ClassDef.name);
3778 if (!value) goto failed;
3779 if (PyObject_SetAttr(result, state->name, value) == -1)
3780 goto failed;
3781 Py_DECREF(value);
3782 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
3783 ast2obj_expr);
3784 if (!value) goto failed;
3785 if (PyObject_SetAttr(result, state->bases, value) == -1)
3786 goto failed;
3787 Py_DECREF(value);
3788 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
3789 ast2obj_keyword);
3790 if (!value) goto failed;
3791 if (PyObject_SetAttr(result, state->keywords, value) == -1)
3792 goto failed;
3793 Py_DECREF(value);
3794 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
3795 ast2obj_stmt);
3796 if (!value) goto failed;
3797 if (PyObject_SetAttr(result, state->body, value) == -1)
3798 goto failed;
3799 Py_DECREF(value);
3800 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
3801 ast2obj_expr);
3802 if (!value) goto failed;
3803 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3804 goto failed;
3805 Py_DECREF(value);
3806 break;
3807 case Return_kind:
3808 tp = (PyTypeObject *)state->Return_type;
3809 result = PyType_GenericNew(tp, NULL, NULL);
3810 if (!result) goto failed;
3811 value = ast2obj_expr(state, o->v.Return.value);
3812 if (!value) goto failed;
3813 if (PyObject_SetAttr(result, state->value, value) == -1)
3814 goto failed;
3815 Py_DECREF(value);
3816 break;
3817 case Delete_kind:
3818 tp = (PyTypeObject *)state->Delete_type;
3819 result = PyType_GenericNew(tp, NULL, NULL);
3820 if (!result) goto failed;
3821 value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
3822 ast2obj_expr);
3823 if (!value) goto failed;
3824 if (PyObject_SetAttr(result, state->targets, value) == -1)
3825 goto failed;
3826 Py_DECREF(value);
3827 break;
3828 case Assign_kind:
3829 tp = (PyTypeObject *)state->Assign_type;
3830 result = PyType_GenericNew(tp, NULL, NULL);
3831 if (!result) goto failed;
3832 value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
3833 ast2obj_expr);
3834 if (!value) goto failed;
3835 if (PyObject_SetAttr(result, state->targets, value) == -1)
3836 goto failed;
3837 Py_DECREF(value);
3838 value = ast2obj_expr(state, o->v.Assign.value);
3839 if (!value) goto failed;
3840 if (PyObject_SetAttr(result, state->value, value) == -1)
3841 goto failed;
3842 Py_DECREF(value);
3843 value = ast2obj_string(state, o->v.Assign.type_comment);
3844 if (!value) goto failed;
3845 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3846 goto failed;
3847 Py_DECREF(value);
3848 break;
3849 case AugAssign_kind:
3850 tp = (PyTypeObject *)state->AugAssign_type;
3851 result = PyType_GenericNew(tp, NULL, NULL);
3852 if (!result) goto failed;
3853 value = ast2obj_expr(state, o->v.AugAssign.target);
3854 if (!value) goto failed;
3855 if (PyObject_SetAttr(result, state->target, value) == -1)
3856 goto failed;
3857 Py_DECREF(value);
3858 value = ast2obj_operator(state, o->v.AugAssign.op);
3859 if (!value) goto failed;
3860 if (PyObject_SetAttr(result, state->op, value) == -1)
3861 goto failed;
3862 Py_DECREF(value);
3863 value = ast2obj_expr(state, o->v.AugAssign.value);
3864 if (!value) goto failed;
3865 if (PyObject_SetAttr(result, state->value, value) == -1)
3866 goto failed;
3867 Py_DECREF(value);
3868 break;
3869 case AnnAssign_kind:
3870 tp = (PyTypeObject *)state->AnnAssign_type;
3871 result = PyType_GenericNew(tp, NULL, NULL);
3872 if (!result) goto failed;
3873 value = ast2obj_expr(state, o->v.AnnAssign.target);
3874 if (!value) goto failed;
3875 if (PyObject_SetAttr(result, state->target, value) == -1)
3876 goto failed;
3877 Py_DECREF(value);
3878 value = ast2obj_expr(state, o->v.AnnAssign.annotation);
3879 if (!value) goto failed;
3880 if (PyObject_SetAttr(result, state->annotation, value) == -1)
3881 goto failed;
3882 Py_DECREF(value);
3883 value = ast2obj_expr(state, o->v.AnnAssign.value);
3884 if (!value) goto failed;
3885 if (PyObject_SetAttr(result, state->value, value) == -1)
3886 goto failed;
3887 Py_DECREF(value);
3888 value = ast2obj_int(state, o->v.AnnAssign.simple);
3889 if (!value) goto failed;
3890 if (PyObject_SetAttr(result, state->simple, value) == -1)
3891 goto failed;
3892 Py_DECREF(value);
3893 break;
3894 case For_kind:
3895 tp = (PyTypeObject *)state->For_type;
3896 result = PyType_GenericNew(tp, NULL, NULL);
3897 if (!result) goto failed;
3898 value = ast2obj_expr(state, o->v.For.target);
3899 if (!value) goto failed;
3900 if (PyObject_SetAttr(result, state->target, value) == -1)
3901 goto failed;
3902 Py_DECREF(value);
3903 value = ast2obj_expr(state, o->v.For.iter);
3904 if (!value) goto failed;
3905 if (PyObject_SetAttr(result, state->iter, value) == -1)
3906 goto failed;
3907 Py_DECREF(value);
3908 value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
3909 if (!value) goto failed;
3910 if (PyObject_SetAttr(result, state->body, value) == -1)
3911 goto failed;
3912 Py_DECREF(value);
3913 value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
3914 if (!value) goto failed;
3915 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3916 goto failed;
3917 Py_DECREF(value);
3918 value = ast2obj_string(state, o->v.For.type_comment);
3919 if (!value) goto failed;
3920 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3921 goto failed;
3922 Py_DECREF(value);
3923 break;
3924 case AsyncFor_kind:
3925 tp = (PyTypeObject *)state->AsyncFor_type;
3926 result = PyType_GenericNew(tp, NULL, NULL);
3927 if (!result) goto failed;
3928 value = ast2obj_expr(state, o->v.AsyncFor.target);
3929 if (!value) goto failed;
3930 if (PyObject_SetAttr(result, state->target, value) == -1)
3931 goto failed;
3932 Py_DECREF(value);
3933 value = ast2obj_expr(state, o->v.AsyncFor.iter);
3934 if (!value) goto failed;
3935 if (PyObject_SetAttr(result, state->iter, value) == -1)
3936 goto failed;
3937 Py_DECREF(value);
3938 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
3939 ast2obj_stmt);
3940 if (!value) goto failed;
3941 if (PyObject_SetAttr(result, state->body, value) == -1)
3942 goto failed;
3943 Py_DECREF(value);
3944 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
3945 ast2obj_stmt);
3946 if (!value) goto failed;
3947 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3948 goto failed;
3949 Py_DECREF(value);
3950 value = ast2obj_string(state, o->v.AsyncFor.type_comment);
3951 if (!value) goto failed;
3952 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3953 goto failed;
3954 Py_DECREF(value);
3955 break;
3956 case While_kind:
3957 tp = (PyTypeObject *)state->While_type;
3958 result = PyType_GenericNew(tp, NULL, NULL);
3959 if (!result) goto failed;
3960 value = ast2obj_expr(state, o->v.While.test);
3961 if (!value) goto failed;
3962 if (PyObject_SetAttr(result, state->test, value) == -1)
3963 goto failed;
3964 Py_DECREF(value);
3965 value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
3966 if (!value) goto failed;
3967 if (PyObject_SetAttr(result, state->body, value) == -1)
3968 goto failed;
3969 Py_DECREF(value);
3970 value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
3971 if (!value) goto failed;
3972 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3973 goto failed;
3974 Py_DECREF(value);
3975 break;
3976 case If_kind:
3977 tp = (PyTypeObject *)state->If_type;
3978 result = PyType_GenericNew(tp, NULL, NULL);
3979 if (!result) goto failed;
3980 value = ast2obj_expr(state, o->v.If.test);
3981 if (!value) goto failed;
3982 if (PyObject_SetAttr(result, state->test, value) == -1)
3983 goto failed;
3984 Py_DECREF(value);
3985 value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
3986 if (!value) goto failed;
3987 if (PyObject_SetAttr(result, state->body, value) == -1)
3988 goto failed;
3989 Py_DECREF(value);
3990 value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
3991 if (!value) goto failed;
3992 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3993 goto failed;
3994 Py_DECREF(value);
3995 break;
3996 case With_kind:
3997 tp = (PyTypeObject *)state->With_type;
3998 result = PyType_GenericNew(tp, NULL, NULL);
3999 if (!result) goto failed;
4000 value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
4001 ast2obj_withitem);
4002 if (!value) goto failed;
4003 if (PyObject_SetAttr(result, state->items, value) == -1)
4004 goto failed;
4005 Py_DECREF(value);
4006 value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
4007 if (!value) goto failed;
4008 if (PyObject_SetAttr(result, state->body, value) == -1)
4009 goto failed;
4010 Py_DECREF(value);
4011 value = ast2obj_string(state, o->v.With.type_comment);
4012 if (!value) goto failed;
4013 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4014 goto failed;
4015 Py_DECREF(value);
4016 break;
4017 case AsyncWith_kind:
4018 tp = (PyTypeObject *)state->AsyncWith_type;
4019 result = PyType_GenericNew(tp, NULL, NULL);
4020 if (!result) goto failed;
4021 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
4022 ast2obj_withitem);
4023 if (!value) goto failed;
4024 if (PyObject_SetAttr(result, state->items, value) == -1)
4025 goto failed;
4026 Py_DECREF(value);
4027 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
4028 ast2obj_stmt);
4029 if (!value) goto failed;
4030 if (PyObject_SetAttr(result, state->body, value) == -1)
4031 goto failed;
4032 Py_DECREF(value);
4033 value = ast2obj_string(state, o->v.AsyncWith.type_comment);
4034 if (!value) goto failed;
4035 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4036 goto failed;
4037 Py_DECREF(value);
4038 break;
4039 case Match_kind:
4040 tp = (PyTypeObject *)state->Match_type;
4041 result = PyType_GenericNew(tp, NULL, NULL);
4042 if (!result) goto failed;
4043 value = ast2obj_expr(state, o->v.Match.subject);
4044 if (!value) goto failed;
4045 if (PyObject_SetAttr(result, state->subject, value) == -1)
4046 goto failed;
4047 Py_DECREF(value);
4048 value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
4049 ast2obj_match_case);
4050 if (!value) goto failed;
4051 if (PyObject_SetAttr(result, state->cases, value) == -1)
4052 goto failed;
4053 Py_DECREF(value);
4054 break;
4055 case Raise_kind:
4056 tp = (PyTypeObject *)state->Raise_type;
4057 result = PyType_GenericNew(tp, NULL, NULL);
4058 if (!result) goto failed;
4059 value = ast2obj_expr(state, o->v.Raise.exc);
4060 if (!value) goto failed;
4061 if (PyObject_SetAttr(result, state->exc, value) == -1)
4062 goto failed;
4063 Py_DECREF(value);
4064 value = ast2obj_expr(state, o->v.Raise.cause);
4065 if (!value) goto failed;
4066 if (PyObject_SetAttr(result, state->cause, value) == -1)
4067 goto failed;
4068 Py_DECREF(value);
4069 break;
4070 case Try_kind:
4071 tp = (PyTypeObject *)state->Try_type;
4072 result = PyType_GenericNew(tp, NULL, NULL);
4073 if (!result) goto failed;
4074 value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
4075 if (!value) goto failed;
4076 if (PyObject_SetAttr(result, state->body, value) == -1)
4077 goto failed;
4078 Py_DECREF(value);
4079 value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
4080 ast2obj_excepthandler);
4081 if (!value) goto failed;
4082 if (PyObject_SetAttr(result, state->handlers, value) == -1)
4083 goto failed;
4084 Py_DECREF(value);
4085 value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
4086 if (!value) goto failed;
4087 if (PyObject_SetAttr(result, state->orelse, value) == -1)
4088 goto failed;
4089 Py_DECREF(value);
4090 value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
4091 ast2obj_stmt);
4092 if (!value) goto failed;
4093 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
4094 goto failed;
4095 Py_DECREF(value);
4096 break;
4097 case TryStar_kind:
4098 tp = (PyTypeObject *)state->TryStar_type;
4099 result = PyType_GenericNew(tp, NULL, NULL);
4100 if (!result) goto failed;
4101 value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.body, ast2obj_stmt);
4102 if (!value) goto failed;
4103 if (PyObject_SetAttr(result, state->body, value) == -1)
4104 goto failed;
4105 Py_DECREF(value);
4106 value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.handlers,
4107 ast2obj_excepthandler);
4108 if (!value) goto failed;
4109 if (PyObject_SetAttr(result, state->handlers, value) == -1)
4110 goto failed;
4111 Py_DECREF(value);
4112 value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.orelse,
4113 ast2obj_stmt);
4114 if (!value) goto failed;
4115 if (PyObject_SetAttr(result, state->orelse, value) == -1)
4116 goto failed;
4117 Py_DECREF(value);
4118 value = ast2obj_list(state, (asdl_seq*)o->v.TryStar.finalbody,
4119 ast2obj_stmt);
4120 if (!value) goto failed;
4121 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
4122 goto failed;
4123 Py_DECREF(value);
4124 break;
4125 case Assert_kind:
4126 tp = (PyTypeObject *)state->Assert_type;
4127 result = PyType_GenericNew(tp, NULL, NULL);
4128 if (!result) goto failed;
4129 value = ast2obj_expr(state, o->v.Assert.test);
4130 if (!value) goto failed;
4131 if (PyObject_SetAttr(result, state->test, value) == -1)
4132 goto failed;
4133 Py_DECREF(value);
4134 value = ast2obj_expr(state, o->v.Assert.msg);
4135 if (!value) goto failed;
4136 if (PyObject_SetAttr(result, state->msg, value) == -1)
4137 goto failed;
4138 Py_DECREF(value);
4139 break;
4140 case Import_kind:
4141 tp = (PyTypeObject *)state->Import_type;
4142 result = PyType_GenericNew(tp, NULL, NULL);
4143 if (!result) goto failed;
4144 value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
4145 ast2obj_alias);
4146 if (!value) goto failed;
4147 if (PyObject_SetAttr(result, state->names, value) == -1)
4148 goto failed;
4149 Py_DECREF(value);
4150 break;
4151 case ImportFrom_kind:
4152 tp = (PyTypeObject *)state->ImportFrom_type;
4153 result = PyType_GenericNew(tp, NULL, NULL);
4154 if (!result) goto failed;
4155 value = ast2obj_identifier(state, o->v.ImportFrom.module);
4156 if (!value) goto failed;
4157 if (PyObject_SetAttr(result, state->module, value) == -1)
4158 goto failed;
4159 Py_DECREF(value);
4160 value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
4161 ast2obj_alias);
4162 if (!value) goto failed;
4163 if (PyObject_SetAttr(result, state->names, value) == -1)
4164 goto failed;
4165 Py_DECREF(value);
4166 value = ast2obj_int(state, o->v.ImportFrom.level);
4167 if (!value) goto failed;
4168 if (PyObject_SetAttr(result, state->level, value) == -1)
4169 goto failed;
4170 Py_DECREF(value);
4171 break;
4172 case Global_kind:
4173 tp = (PyTypeObject *)state->Global_type;
4174 result = PyType_GenericNew(tp, NULL, NULL);
4175 if (!result) goto failed;
4176 value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
4177 ast2obj_identifier);
4178 if (!value) goto failed;
4179 if (PyObject_SetAttr(result, state->names, value) == -1)
4180 goto failed;
4181 Py_DECREF(value);
4182 break;
4183 case Nonlocal_kind:
4184 tp = (PyTypeObject *)state->Nonlocal_type;
4185 result = PyType_GenericNew(tp, NULL, NULL);
4186 if (!result) goto failed;
4187 value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
4188 ast2obj_identifier);
4189 if (!value) goto failed;
4190 if (PyObject_SetAttr(result, state->names, value) == -1)
4191 goto failed;
4192 Py_DECREF(value);
4193 break;
4194 case Expr_kind:
4195 tp = (PyTypeObject *)state->Expr_type;
4196 result = PyType_GenericNew(tp, NULL, NULL);
4197 if (!result) goto failed;
4198 value = ast2obj_expr(state, o->v.Expr.value);
4199 if (!value) goto failed;
4200 if (PyObject_SetAttr(result, state->value, value) == -1)
4201 goto failed;
4202 Py_DECREF(value);
4203 break;
4204 case Pass_kind:
4205 tp = (PyTypeObject *)state->Pass_type;
4206 result = PyType_GenericNew(tp, NULL, NULL);
4207 if (!result) goto failed;
4208 break;
4209 case Break_kind:
4210 tp = (PyTypeObject *)state->Break_type;
4211 result = PyType_GenericNew(tp, NULL, NULL);
4212 if (!result) goto failed;
4213 break;
4214 case Continue_kind:
4215 tp = (PyTypeObject *)state->Continue_type;
4216 result = PyType_GenericNew(tp, NULL, NULL);
4217 if (!result) goto failed;
4218 break;
4219 }
4220 value = ast2obj_int(state, o->lineno);
4221 if (!value) goto failed;
4222 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4223 goto failed;
4224 Py_DECREF(value);
4225 value = ast2obj_int(state, o->col_offset);
4226 if (!value) goto failed;
4227 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4228 goto failed;
4229 Py_DECREF(value);
4230 value = ast2obj_int(state, o->end_lineno);
4231 if (!value) goto failed;
4232 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4233 goto failed;
4234 Py_DECREF(value);
4235 value = ast2obj_int(state, o->end_col_offset);
4236 if (!value) goto failed;
4237 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4238 goto failed;
4239 Py_DECREF(value);
4240 state->recursion_depth--;
4241 return result;
4242 failed:
4243 Py_XDECREF(value);
4244 Py_XDECREF(result);
4245 return NULL;
4246 }
4247
4248 PyObject*
ast2obj_expr(struct ast_state * state,void * _o)4249 ast2obj_expr(struct ast_state *state, void* _o)
4250 {
4251 expr_ty o = (expr_ty)_o;
4252 PyObject *result = NULL, *value = NULL;
4253 PyTypeObject *tp;
4254 if (!o) {
4255 Py_RETURN_NONE;
4256 }
4257 if (++state->recursion_depth > state->recursion_limit) {
4258 PyErr_SetString(PyExc_RecursionError,
4259 "maximum recursion depth exceeded during ast construction");
4260 return 0;
4261 }
4262 switch (o->kind) {
4263 case BoolOp_kind:
4264 tp = (PyTypeObject *)state->BoolOp_type;
4265 result = PyType_GenericNew(tp, NULL, NULL);
4266 if (!result) goto failed;
4267 value = ast2obj_boolop(state, o->v.BoolOp.op);
4268 if (!value) goto failed;
4269 if (PyObject_SetAttr(result, state->op, value) == -1)
4270 goto failed;
4271 Py_DECREF(value);
4272 value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
4273 ast2obj_expr);
4274 if (!value) goto failed;
4275 if (PyObject_SetAttr(result, state->values, value) == -1)
4276 goto failed;
4277 Py_DECREF(value);
4278 break;
4279 case NamedExpr_kind:
4280 tp = (PyTypeObject *)state->NamedExpr_type;
4281 result = PyType_GenericNew(tp, NULL, NULL);
4282 if (!result) goto failed;
4283 value = ast2obj_expr(state, o->v.NamedExpr.target);
4284 if (!value) goto failed;
4285 if (PyObject_SetAttr(result, state->target, value) == -1)
4286 goto failed;
4287 Py_DECREF(value);
4288 value = ast2obj_expr(state, o->v.NamedExpr.value);
4289 if (!value) goto failed;
4290 if (PyObject_SetAttr(result, state->value, value) == -1)
4291 goto failed;
4292 Py_DECREF(value);
4293 break;
4294 case BinOp_kind:
4295 tp = (PyTypeObject *)state->BinOp_type;
4296 result = PyType_GenericNew(tp, NULL, NULL);
4297 if (!result) goto failed;
4298 value = ast2obj_expr(state, o->v.BinOp.left);
4299 if (!value) goto failed;
4300 if (PyObject_SetAttr(result, state->left, value) == -1)
4301 goto failed;
4302 Py_DECREF(value);
4303 value = ast2obj_operator(state, o->v.BinOp.op);
4304 if (!value) goto failed;
4305 if (PyObject_SetAttr(result, state->op, value) == -1)
4306 goto failed;
4307 Py_DECREF(value);
4308 value = ast2obj_expr(state, o->v.BinOp.right);
4309 if (!value) goto failed;
4310 if (PyObject_SetAttr(result, state->right, value) == -1)
4311 goto failed;
4312 Py_DECREF(value);
4313 break;
4314 case UnaryOp_kind:
4315 tp = (PyTypeObject *)state->UnaryOp_type;
4316 result = PyType_GenericNew(tp, NULL, NULL);
4317 if (!result) goto failed;
4318 value = ast2obj_unaryop(state, o->v.UnaryOp.op);
4319 if (!value) goto failed;
4320 if (PyObject_SetAttr(result, state->op, value) == -1)
4321 goto failed;
4322 Py_DECREF(value);
4323 value = ast2obj_expr(state, o->v.UnaryOp.operand);
4324 if (!value) goto failed;
4325 if (PyObject_SetAttr(result, state->operand, value) == -1)
4326 goto failed;
4327 Py_DECREF(value);
4328 break;
4329 case Lambda_kind:
4330 tp = (PyTypeObject *)state->Lambda_type;
4331 result = PyType_GenericNew(tp, NULL, NULL);
4332 if (!result) goto failed;
4333 value = ast2obj_arguments(state, o->v.Lambda.args);
4334 if (!value) goto failed;
4335 if (PyObject_SetAttr(result, state->args, value) == -1)
4336 goto failed;
4337 Py_DECREF(value);
4338 value = ast2obj_expr(state, o->v.Lambda.body);
4339 if (!value) goto failed;
4340 if (PyObject_SetAttr(result, state->body, value) == -1)
4341 goto failed;
4342 Py_DECREF(value);
4343 break;
4344 case IfExp_kind:
4345 tp = (PyTypeObject *)state->IfExp_type;
4346 result = PyType_GenericNew(tp, NULL, NULL);
4347 if (!result) goto failed;
4348 value = ast2obj_expr(state, o->v.IfExp.test);
4349 if (!value) goto failed;
4350 if (PyObject_SetAttr(result, state->test, value) == -1)
4351 goto failed;
4352 Py_DECREF(value);
4353 value = ast2obj_expr(state, o->v.IfExp.body);
4354 if (!value) goto failed;
4355 if (PyObject_SetAttr(result, state->body, value) == -1)
4356 goto failed;
4357 Py_DECREF(value);
4358 value = ast2obj_expr(state, o->v.IfExp.orelse);
4359 if (!value) goto failed;
4360 if (PyObject_SetAttr(result, state->orelse, value) == -1)
4361 goto failed;
4362 Py_DECREF(value);
4363 break;
4364 case Dict_kind:
4365 tp = (PyTypeObject *)state->Dict_type;
4366 result = PyType_GenericNew(tp, NULL, NULL);
4367 if (!result) goto failed;
4368 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
4369 if (!value) goto failed;
4370 if (PyObject_SetAttr(result, state->keys, value) == -1)
4371 goto failed;
4372 Py_DECREF(value);
4373 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
4374 if (!value) goto failed;
4375 if (PyObject_SetAttr(result, state->values, value) == -1)
4376 goto failed;
4377 Py_DECREF(value);
4378 break;
4379 case Set_kind:
4380 tp = (PyTypeObject *)state->Set_type;
4381 result = PyType_GenericNew(tp, NULL, NULL);
4382 if (!result) goto failed;
4383 value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
4384 if (!value) goto failed;
4385 if (PyObject_SetAttr(result, state->elts, value) == -1)
4386 goto failed;
4387 Py_DECREF(value);
4388 break;
4389 case ListComp_kind:
4390 tp = (PyTypeObject *)state->ListComp_type;
4391 result = PyType_GenericNew(tp, NULL, NULL);
4392 if (!result) goto failed;
4393 value = ast2obj_expr(state, o->v.ListComp.elt);
4394 if (!value) goto failed;
4395 if (PyObject_SetAttr(result, state->elt, value) == -1)
4396 goto failed;
4397 Py_DECREF(value);
4398 value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
4399 ast2obj_comprehension);
4400 if (!value) goto failed;
4401 if (PyObject_SetAttr(result, state->generators, value) == -1)
4402 goto failed;
4403 Py_DECREF(value);
4404 break;
4405 case SetComp_kind:
4406 tp = (PyTypeObject *)state->SetComp_type;
4407 result = PyType_GenericNew(tp, NULL, NULL);
4408 if (!result) goto failed;
4409 value = ast2obj_expr(state, o->v.SetComp.elt);
4410 if (!value) goto failed;
4411 if (PyObject_SetAttr(result, state->elt, value) == -1)
4412 goto failed;
4413 Py_DECREF(value);
4414 value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
4415 ast2obj_comprehension);
4416 if (!value) goto failed;
4417 if (PyObject_SetAttr(result, state->generators, value) == -1)
4418 goto failed;
4419 Py_DECREF(value);
4420 break;
4421 case DictComp_kind:
4422 tp = (PyTypeObject *)state->DictComp_type;
4423 result = PyType_GenericNew(tp, NULL, NULL);
4424 if (!result) goto failed;
4425 value = ast2obj_expr(state, o->v.DictComp.key);
4426 if (!value) goto failed;
4427 if (PyObject_SetAttr(result, state->key, value) == -1)
4428 goto failed;
4429 Py_DECREF(value);
4430 value = ast2obj_expr(state, o->v.DictComp.value);
4431 if (!value) goto failed;
4432 if (PyObject_SetAttr(result, state->value, value) == -1)
4433 goto failed;
4434 Py_DECREF(value);
4435 value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
4436 ast2obj_comprehension);
4437 if (!value) goto failed;
4438 if (PyObject_SetAttr(result, state->generators, value) == -1)
4439 goto failed;
4440 Py_DECREF(value);
4441 break;
4442 case GeneratorExp_kind:
4443 tp = (PyTypeObject *)state->GeneratorExp_type;
4444 result = PyType_GenericNew(tp, NULL, NULL);
4445 if (!result) goto failed;
4446 value = ast2obj_expr(state, o->v.GeneratorExp.elt);
4447 if (!value) goto failed;
4448 if (PyObject_SetAttr(result, state->elt, value) == -1)
4449 goto failed;
4450 Py_DECREF(value);
4451 value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
4452 ast2obj_comprehension);
4453 if (!value) goto failed;
4454 if (PyObject_SetAttr(result, state->generators, value) == -1)
4455 goto failed;
4456 Py_DECREF(value);
4457 break;
4458 case Await_kind:
4459 tp = (PyTypeObject *)state->Await_type;
4460 result = PyType_GenericNew(tp, NULL, NULL);
4461 if (!result) goto failed;
4462 value = ast2obj_expr(state, o->v.Await.value);
4463 if (!value) goto failed;
4464 if (PyObject_SetAttr(result, state->value, value) == -1)
4465 goto failed;
4466 Py_DECREF(value);
4467 break;
4468 case Yield_kind:
4469 tp = (PyTypeObject *)state->Yield_type;
4470 result = PyType_GenericNew(tp, NULL, NULL);
4471 if (!result) goto failed;
4472 value = ast2obj_expr(state, o->v.Yield.value);
4473 if (!value) goto failed;
4474 if (PyObject_SetAttr(result, state->value, value) == -1)
4475 goto failed;
4476 Py_DECREF(value);
4477 break;
4478 case YieldFrom_kind:
4479 tp = (PyTypeObject *)state->YieldFrom_type;
4480 result = PyType_GenericNew(tp, NULL, NULL);
4481 if (!result) goto failed;
4482 value = ast2obj_expr(state, o->v.YieldFrom.value);
4483 if (!value) goto failed;
4484 if (PyObject_SetAttr(result, state->value, value) == -1)
4485 goto failed;
4486 Py_DECREF(value);
4487 break;
4488 case Compare_kind:
4489 tp = (PyTypeObject *)state->Compare_type;
4490 result = PyType_GenericNew(tp, NULL, NULL);
4491 if (!result) goto failed;
4492 value = ast2obj_expr(state, o->v.Compare.left);
4493 if (!value) goto failed;
4494 if (PyObject_SetAttr(result, state->left, value) == -1)
4495 goto failed;
4496 Py_DECREF(value);
4497 {
4498 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4499 value = PyList_New(n);
4500 if (!value) goto failed;
4501 for(i = 0; i < n; i++)
4502 PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
4503 }
4504 if (!value) goto failed;
4505 if (PyObject_SetAttr(result, state->ops, value) == -1)
4506 goto failed;
4507 Py_DECREF(value);
4508 value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
4509 ast2obj_expr);
4510 if (!value) goto failed;
4511 if (PyObject_SetAttr(result, state->comparators, value) == -1)
4512 goto failed;
4513 Py_DECREF(value);
4514 break;
4515 case Call_kind:
4516 tp = (PyTypeObject *)state->Call_type;
4517 result = PyType_GenericNew(tp, NULL, NULL);
4518 if (!result) goto failed;
4519 value = ast2obj_expr(state, o->v.Call.func);
4520 if (!value) goto failed;
4521 if (PyObject_SetAttr(result, state->func, value) == -1)
4522 goto failed;
4523 Py_DECREF(value);
4524 value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
4525 if (!value) goto failed;
4526 if (PyObject_SetAttr(result, state->args, value) == -1)
4527 goto failed;
4528 Py_DECREF(value);
4529 value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
4530 ast2obj_keyword);
4531 if (!value) goto failed;
4532 if (PyObject_SetAttr(result, state->keywords, value) == -1)
4533 goto failed;
4534 Py_DECREF(value);
4535 break;
4536 case FormattedValue_kind:
4537 tp = (PyTypeObject *)state->FormattedValue_type;
4538 result = PyType_GenericNew(tp, NULL, NULL);
4539 if (!result) goto failed;
4540 value = ast2obj_expr(state, o->v.FormattedValue.value);
4541 if (!value) goto failed;
4542 if (PyObject_SetAttr(result, state->value, value) == -1)
4543 goto failed;
4544 Py_DECREF(value);
4545 value = ast2obj_int(state, o->v.FormattedValue.conversion);
4546 if (!value) goto failed;
4547 if (PyObject_SetAttr(result, state->conversion, value) == -1)
4548 goto failed;
4549 Py_DECREF(value);
4550 value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
4551 if (!value) goto failed;
4552 if (PyObject_SetAttr(result, state->format_spec, value) == -1)
4553 goto failed;
4554 Py_DECREF(value);
4555 break;
4556 case JoinedStr_kind:
4557 tp = (PyTypeObject *)state->JoinedStr_type;
4558 result = PyType_GenericNew(tp, NULL, NULL);
4559 if (!result) goto failed;
4560 value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
4561 ast2obj_expr);
4562 if (!value) goto failed;
4563 if (PyObject_SetAttr(result, state->values, value) == -1)
4564 goto failed;
4565 Py_DECREF(value);
4566 break;
4567 case Constant_kind:
4568 tp = (PyTypeObject *)state->Constant_type;
4569 result = PyType_GenericNew(tp, NULL, NULL);
4570 if (!result) goto failed;
4571 value = ast2obj_constant(state, o->v.Constant.value);
4572 if (!value) goto failed;
4573 if (PyObject_SetAttr(result, state->value, value) == -1)
4574 goto failed;
4575 Py_DECREF(value);
4576 value = ast2obj_string(state, o->v.Constant.kind);
4577 if (!value) goto failed;
4578 if (PyObject_SetAttr(result, state->kind, value) == -1)
4579 goto failed;
4580 Py_DECREF(value);
4581 break;
4582 case Attribute_kind:
4583 tp = (PyTypeObject *)state->Attribute_type;
4584 result = PyType_GenericNew(tp, NULL, NULL);
4585 if (!result) goto failed;
4586 value = ast2obj_expr(state, o->v.Attribute.value);
4587 if (!value) goto failed;
4588 if (PyObject_SetAttr(result, state->value, value) == -1)
4589 goto failed;
4590 Py_DECREF(value);
4591 value = ast2obj_identifier(state, o->v.Attribute.attr);
4592 if (!value) goto failed;
4593 if (PyObject_SetAttr(result, state->attr, value) == -1)
4594 goto failed;
4595 Py_DECREF(value);
4596 value = ast2obj_expr_context(state, o->v.Attribute.ctx);
4597 if (!value) goto failed;
4598 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4599 goto failed;
4600 Py_DECREF(value);
4601 break;
4602 case Subscript_kind:
4603 tp = (PyTypeObject *)state->Subscript_type;
4604 result = PyType_GenericNew(tp, NULL, NULL);
4605 if (!result) goto failed;
4606 value = ast2obj_expr(state, o->v.Subscript.value);
4607 if (!value) goto failed;
4608 if (PyObject_SetAttr(result, state->value, value) == -1)
4609 goto failed;
4610 Py_DECREF(value);
4611 value = ast2obj_expr(state, o->v.Subscript.slice);
4612 if (!value) goto failed;
4613 if (PyObject_SetAttr(result, state->slice, value) == -1)
4614 goto failed;
4615 Py_DECREF(value);
4616 value = ast2obj_expr_context(state, o->v.Subscript.ctx);
4617 if (!value) goto failed;
4618 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4619 goto failed;
4620 Py_DECREF(value);
4621 break;
4622 case Starred_kind:
4623 tp = (PyTypeObject *)state->Starred_type;
4624 result = PyType_GenericNew(tp, NULL, NULL);
4625 if (!result) goto failed;
4626 value = ast2obj_expr(state, o->v.Starred.value);
4627 if (!value) goto failed;
4628 if (PyObject_SetAttr(result, state->value, value) == -1)
4629 goto failed;
4630 Py_DECREF(value);
4631 value = ast2obj_expr_context(state, o->v.Starred.ctx);
4632 if (!value) goto failed;
4633 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4634 goto failed;
4635 Py_DECREF(value);
4636 break;
4637 case Name_kind:
4638 tp = (PyTypeObject *)state->Name_type;
4639 result = PyType_GenericNew(tp, NULL, NULL);
4640 if (!result) goto failed;
4641 value = ast2obj_identifier(state, o->v.Name.id);
4642 if (!value) goto failed;
4643 if (PyObject_SetAttr(result, state->id, value) == -1)
4644 goto failed;
4645 Py_DECREF(value);
4646 value = ast2obj_expr_context(state, o->v.Name.ctx);
4647 if (!value) goto failed;
4648 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4649 goto failed;
4650 Py_DECREF(value);
4651 break;
4652 case List_kind:
4653 tp = (PyTypeObject *)state->List_type;
4654 result = PyType_GenericNew(tp, NULL, NULL);
4655 if (!result) goto failed;
4656 value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
4657 if (!value) goto failed;
4658 if (PyObject_SetAttr(result, state->elts, value) == -1)
4659 goto failed;
4660 Py_DECREF(value);
4661 value = ast2obj_expr_context(state, o->v.List.ctx);
4662 if (!value) goto failed;
4663 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4664 goto failed;
4665 Py_DECREF(value);
4666 break;
4667 case Tuple_kind:
4668 tp = (PyTypeObject *)state->Tuple_type;
4669 result = PyType_GenericNew(tp, NULL, NULL);
4670 if (!result) goto failed;
4671 value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
4672 if (!value) goto failed;
4673 if (PyObject_SetAttr(result, state->elts, value) == -1)
4674 goto failed;
4675 Py_DECREF(value);
4676 value = ast2obj_expr_context(state, o->v.Tuple.ctx);
4677 if (!value) goto failed;
4678 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4679 goto failed;
4680 Py_DECREF(value);
4681 break;
4682 case Slice_kind:
4683 tp = (PyTypeObject *)state->Slice_type;
4684 result = PyType_GenericNew(tp, NULL, NULL);
4685 if (!result) goto failed;
4686 value = ast2obj_expr(state, o->v.Slice.lower);
4687 if (!value) goto failed;
4688 if (PyObject_SetAttr(result, state->lower, value) == -1)
4689 goto failed;
4690 Py_DECREF(value);
4691 value = ast2obj_expr(state, o->v.Slice.upper);
4692 if (!value) goto failed;
4693 if (PyObject_SetAttr(result, state->upper, value) == -1)
4694 goto failed;
4695 Py_DECREF(value);
4696 value = ast2obj_expr(state, o->v.Slice.step);
4697 if (!value) goto failed;
4698 if (PyObject_SetAttr(result, state->step, value) == -1)
4699 goto failed;
4700 Py_DECREF(value);
4701 break;
4702 }
4703 value = ast2obj_int(state, o->lineno);
4704 if (!value) goto failed;
4705 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4706 goto failed;
4707 Py_DECREF(value);
4708 value = ast2obj_int(state, o->col_offset);
4709 if (!value) goto failed;
4710 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4711 goto failed;
4712 Py_DECREF(value);
4713 value = ast2obj_int(state, o->end_lineno);
4714 if (!value) goto failed;
4715 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4716 goto failed;
4717 Py_DECREF(value);
4718 value = ast2obj_int(state, o->end_col_offset);
4719 if (!value) goto failed;
4720 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4721 goto failed;
4722 Py_DECREF(value);
4723 state->recursion_depth--;
4724 return result;
4725 failed:
4726 Py_XDECREF(value);
4727 Py_XDECREF(result);
4728 return NULL;
4729 }
4730
ast2obj_expr_context(struct ast_state * state,expr_context_ty o)4731 PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
4732 {
4733 switch(o) {
4734 case Load:
4735 Py_INCREF(state->Load_singleton);
4736 return state->Load_singleton;
4737 case Store:
4738 Py_INCREF(state->Store_singleton);
4739 return state->Store_singleton;
4740 case Del:
4741 Py_INCREF(state->Del_singleton);
4742 return state->Del_singleton;
4743 }
4744 Py_UNREACHABLE();
4745 }
ast2obj_boolop(struct ast_state * state,boolop_ty o)4746 PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
4747 {
4748 switch(o) {
4749 case And:
4750 Py_INCREF(state->And_singleton);
4751 return state->And_singleton;
4752 case Or:
4753 Py_INCREF(state->Or_singleton);
4754 return state->Or_singleton;
4755 }
4756 Py_UNREACHABLE();
4757 }
ast2obj_operator(struct ast_state * state,operator_ty o)4758 PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
4759 {
4760 switch(o) {
4761 case Add:
4762 Py_INCREF(state->Add_singleton);
4763 return state->Add_singleton;
4764 case Sub:
4765 Py_INCREF(state->Sub_singleton);
4766 return state->Sub_singleton;
4767 case Mult:
4768 Py_INCREF(state->Mult_singleton);
4769 return state->Mult_singleton;
4770 case MatMult:
4771 Py_INCREF(state->MatMult_singleton);
4772 return state->MatMult_singleton;
4773 case Div:
4774 Py_INCREF(state->Div_singleton);
4775 return state->Div_singleton;
4776 case Mod:
4777 Py_INCREF(state->Mod_singleton);
4778 return state->Mod_singleton;
4779 case Pow:
4780 Py_INCREF(state->Pow_singleton);
4781 return state->Pow_singleton;
4782 case LShift:
4783 Py_INCREF(state->LShift_singleton);
4784 return state->LShift_singleton;
4785 case RShift:
4786 Py_INCREF(state->RShift_singleton);
4787 return state->RShift_singleton;
4788 case BitOr:
4789 Py_INCREF(state->BitOr_singleton);
4790 return state->BitOr_singleton;
4791 case BitXor:
4792 Py_INCREF(state->BitXor_singleton);
4793 return state->BitXor_singleton;
4794 case BitAnd:
4795 Py_INCREF(state->BitAnd_singleton);
4796 return state->BitAnd_singleton;
4797 case FloorDiv:
4798 Py_INCREF(state->FloorDiv_singleton);
4799 return state->FloorDiv_singleton;
4800 }
4801 Py_UNREACHABLE();
4802 }
ast2obj_unaryop(struct ast_state * state,unaryop_ty o)4803 PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
4804 {
4805 switch(o) {
4806 case Invert:
4807 Py_INCREF(state->Invert_singleton);
4808 return state->Invert_singleton;
4809 case Not:
4810 Py_INCREF(state->Not_singleton);
4811 return state->Not_singleton;
4812 case UAdd:
4813 Py_INCREF(state->UAdd_singleton);
4814 return state->UAdd_singleton;
4815 case USub:
4816 Py_INCREF(state->USub_singleton);
4817 return state->USub_singleton;
4818 }
4819 Py_UNREACHABLE();
4820 }
ast2obj_cmpop(struct ast_state * state,cmpop_ty o)4821 PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
4822 {
4823 switch(o) {
4824 case Eq:
4825 Py_INCREF(state->Eq_singleton);
4826 return state->Eq_singleton;
4827 case NotEq:
4828 Py_INCREF(state->NotEq_singleton);
4829 return state->NotEq_singleton;
4830 case Lt:
4831 Py_INCREF(state->Lt_singleton);
4832 return state->Lt_singleton;
4833 case LtE:
4834 Py_INCREF(state->LtE_singleton);
4835 return state->LtE_singleton;
4836 case Gt:
4837 Py_INCREF(state->Gt_singleton);
4838 return state->Gt_singleton;
4839 case GtE:
4840 Py_INCREF(state->GtE_singleton);
4841 return state->GtE_singleton;
4842 case Is:
4843 Py_INCREF(state->Is_singleton);
4844 return state->Is_singleton;
4845 case IsNot:
4846 Py_INCREF(state->IsNot_singleton);
4847 return state->IsNot_singleton;
4848 case In:
4849 Py_INCREF(state->In_singleton);
4850 return state->In_singleton;
4851 case NotIn:
4852 Py_INCREF(state->NotIn_singleton);
4853 return state->NotIn_singleton;
4854 }
4855 Py_UNREACHABLE();
4856 }
4857 PyObject*
ast2obj_comprehension(struct ast_state * state,void * _o)4858 ast2obj_comprehension(struct ast_state *state, void* _o)
4859 {
4860 comprehension_ty o = (comprehension_ty)_o;
4861 PyObject *result = NULL, *value = NULL;
4862 PyTypeObject *tp;
4863 if (!o) {
4864 Py_RETURN_NONE;
4865 }
4866 if (++state->recursion_depth > state->recursion_limit) {
4867 PyErr_SetString(PyExc_RecursionError,
4868 "maximum recursion depth exceeded during ast construction");
4869 return 0;
4870 }
4871 tp = (PyTypeObject *)state->comprehension_type;
4872 result = PyType_GenericNew(tp, NULL, NULL);
4873 if (!result) return NULL;
4874 value = ast2obj_expr(state, o->target);
4875 if (!value) goto failed;
4876 if (PyObject_SetAttr(result, state->target, value) == -1)
4877 goto failed;
4878 Py_DECREF(value);
4879 value = ast2obj_expr(state, o->iter);
4880 if (!value) goto failed;
4881 if (PyObject_SetAttr(result, state->iter, value) == -1)
4882 goto failed;
4883 Py_DECREF(value);
4884 value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
4885 if (!value) goto failed;
4886 if (PyObject_SetAttr(result, state->ifs, value) == -1)
4887 goto failed;
4888 Py_DECREF(value);
4889 value = ast2obj_int(state, o->is_async);
4890 if (!value) goto failed;
4891 if (PyObject_SetAttr(result, state->is_async, value) == -1)
4892 goto failed;
4893 Py_DECREF(value);
4894 state->recursion_depth--;
4895 return result;
4896 failed:
4897 Py_XDECREF(value);
4898 Py_XDECREF(result);
4899 return NULL;
4900 }
4901
4902 PyObject*
ast2obj_excepthandler(struct ast_state * state,void * _o)4903 ast2obj_excepthandler(struct ast_state *state, void* _o)
4904 {
4905 excepthandler_ty o = (excepthandler_ty)_o;
4906 PyObject *result = NULL, *value = NULL;
4907 PyTypeObject *tp;
4908 if (!o) {
4909 Py_RETURN_NONE;
4910 }
4911 if (++state->recursion_depth > state->recursion_limit) {
4912 PyErr_SetString(PyExc_RecursionError,
4913 "maximum recursion depth exceeded during ast construction");
4914 return 0;
4915 }
4916 switch (o->kind) {
4917 case ExceptHandler_kind:
4918 tp = (PyTypeObject *)state->ExceptHandler_type;
4919 result = PyType_GenericNew(tp, NULL, NULL);
4920 if (!result) goto failed;
4921 value = ast2obj_expr(state, o->v.ExceptHandler.type);
4922 if (!value) goto failed;
4923 if (PyObject_SetAttr(result, state->type, value) == -1)
4924 goto failed;
4925 Py_DECREF(value);
4926 value = ast2obj_identifier(state, o->v.ExceptHandler.name);
4927 if (!value) goto failed;
4928 if (PyObject_SetAttr(result, state->name, value) == -1)
4929 goto failed;
4930 Py_DECREF(value);
4931 value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
4932 ast2obj_stmt);
4933 if (!value) goto failed;
4934 if (PyObject_SetAttr(result, state->body, value) == -1)
4935 goto failed;
4936 Py_DECREF(value);
4937 break;
4938 }
4939 value = ast2obj_int(state, o->lineno);
4940 if (!value) goto failed;
4941 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4942 goto failed;
4943 Py_DECREF(value);
4944 value = ast2obj_int(state, o->col_offset);
4945 if (!value) goto failed;
4946 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4947 goto failed;
4948 Py_DECREF(value);
4949 value = ast2obj_int(state, o->end_lineno);
4950 if (!value) goto failed;
4951 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4952 goto failed;
4953 Py_DECREF(value);
4954 value = ast2obj_int(state, o->end_col_offset);
4955 if (!value) goto failed;
4956 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4957 goto failed;
4958 Py_DECREF(value);
4959 state->recursion_depth--;
4960 return result;
4961 failed:
4962 Py_XDECREF(value);
4963 Py_XDECREF(result);
4964 return NULL;
4965 }
4966
4967 PyObject*
ast2obj_arguments(struct ast_state * state,void * _o)4968 ast2obj_arguments(struct ast_state *state, void* _o)
4969 {
4970 arguments_ty o = (arguments_ty)_o;
4971 PyObject *result = NULL, *value = NULL;
4972 PyTypeObject *tp;
4973 if (!o) {
4974 Py_RETURN_NONE;
4975 }
4976 if (++state->recursion_depth > state->recursion_limit) {
4977 PyErr_SetString(PyExc_RecursionError,
4978 "maximum recursion depth exceeded during ast construction");
4979 return 0;
4980 }
4981 tp = (PyTypeObject *)state->arguments_type;
4982 result = PyType_GenericNew(tp, NULL, NULL);
4983 if (!result) return NULL;
4984 value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
4985 if (!value) goto failed;
4986 if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
4987 goto failed;
4988 Py_DECREF(value);
4989 value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
4990 if (!value) goto failed;
4991 if (PyObject_SetAttr(result, state->args, value) == -1)
4992 goto failed;
4993 Py_DECREF(value);
4994 value = ast2obj_arg(state, o->vararg);
4995 if (!value) goto failed;
4996 if (PyObject_SetAttr(result, state->vararg, value) == -1)
4997 goto failed;
4998 Py_DECREF(value);
4999 value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
5000 if (!value) goto failed;
5001 if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
5002 goto failed;
5003 Py_DECREF(value);
5004 value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
5005 if (!value) goto failed;
5006 if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
5007 goto failed;
5008 Py_DECREF(value);
5009 value = ast2obj_arg(state, o->kwarg);
5010 if (!value) goto failed;
5011 if (PyObject_SetAttr(result, state->kwarg, value) == -1)
5012 goto failed;
5013 Py_DECREF(value);
5014 value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
5015 if (!value) goto failed;
5016 if (PyObject_SetAttr(result, state->defaults, value) == -1)
5017 goto failed;
5018 Py_DECREF(value);
5019 state->recursion_depth--;
5020 return result;
5021 failed:
5022 Py_XDECREF(value);
5023 Py_XDECREF(result);
5024 return NULL;
5025 }
5026
5027 PyObject*
ast2obj_arg(struct ast_state * state,void * _o)5028 ast2obj_arg(struct ast_state *state, void* _o)
5029 {
5030 arg_ty o = (arg_ty)_o;
5031 PyObject *result = NULL, *value = NULL;
5032 PyTypeObject *tp;
5033 if (!o) {
5034 Py_RETURN_NONE;
5035 }
5036 if (++state->recursion_depth > state->recursion_limit) {
5037 PyErr_SetString(PyExc_RecursionError,
5038 "maximum recursion depth exceeded during ast construction");
5039 return 0;
5040 }
5041 tp = (PyTypeObject *)state->arg_type;
5042 result = PyType_GenericNew(tp, NULL, NULL);
5043 if (!result) return NULL;
5044 value = ast2obj_identifier(state, o->arg);
5045 if (!value) goto failed;
5046 if (PyObject_SetAttr(result, state->arg, value) == -1)
5047 goto failed;
5048 Py_DECREF(value);
5049 value = ast2obj_expr(state, o->annotation);
5050 if (!value) goto failed;
5051 if (PyObject_SetAttr(result, state->annotation, value) == -1)
5052 goto failed;
5053 Py_DECREF(value);
5054 value = ast2obj_string(state, o->type_comment);
5055 if (!value) goto failed;
5056 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
5057 goto failed;
5058 Py_DECREF(value);
5059 value = ast2obj_int(state, o->lineno);
5060 if (!value) goto failed;
5061 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5062 goto failed;
5063 Py_DECREF(value);
5064 value = ast2obj_int(state, o->col_offset);
5065 if (!value) goto failed;
5066 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5067 goto failed;
5068 Py_DECREF(value);
5069 value = ast2obj_int(state, o->end_lineno);
5070 if (!value) goto failed;
5071 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5072 goto failed;
5073 Py_DECREF(value);
5074 value = ast2obj_int(state, o->end_col_offset);
5075 if (!value) goto failed;
5076 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5077 goto failed;
5078 Py_DECREF(value);
5079 state->recursion_depth--;
5080 return result;
5081 failed:
5082 Py_XDECREF(value);
5083 Py_XDECREF(result);
5084 return NULL;
5085 }
5086
5087 PyObject*
ast2obj_keyword(struct ast_state * state,void * _o)5088 ast2obj_keyword(struct ast_state *state, void* _o)
5089 {
5090 keyword_ty o = (keyword_ty)_o;
5091 PyObject *result = NULL, *value = NULL;
5092 PyTypeObject *tp;
5093 if (!o) {
5094 Py_RETURN_NONE;
5095 }
5096 if (++state->recursion_depth > state->recursion_limit) {
5097 PyErr_SetString(PyExc_RecursionError,
5098 "maximum recursion depth exceeded during ast construction");
5099 return 0;
5100 }
5101 tp = (PyTypeObject *)state->keyword_type;
5102 result = PyType_GenericNew(tp, NULL, NULL);
5103 if (!result) return NULL;
5104 value = ast2obj_identifier(state, o->arg);
5105 if (!value) goto failed;
5106 if (PyObject_SetAttr(result, state->arg, value) == -1)
5107 goto failed;
5108 Py_DECREF(value);
5109 value = ast2obj_expr(state, o->value);
5110 if (!value) goto failed;
5111 if (PyObject_SetAttr(result, state->value, value) == -1)
5112 goto failed;
5113 Py_DECREF(value);
5114 value = ast2obj_int(state, o->lineno);
5115 if (!value) goto failed;
5116 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5117 goto failed;
5118 Py_DECREF(value);
5119 value = ast2obj_int(state, o->col_offset);
5120 if (!value) goto failed;
5121 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5122 goto failed;
5123 Py_DECREF(value);
5124 value = ast2obj_int(state, o->end_lineno);
5125 if (!value) goto failed;
5126 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5127 goto failed;
5128 Py_DECREF(value);
5129 value = ast2obj_int(state, o->end_col_offset);
5130 if (!value) goto failed;
5131 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5132 goto failed;
5133 Py_DECREF(value);
5134 state->recursion_depth--;
5135 return result;
5136 failed:
5137 Py_XDECREF(value);
5138 Py_XDECREF(result);
5139 return NULL;
5140 }
5141
5142 PyObject*
ast2obj_alias(struct ast_state * state,void * _o)5143 ast2obj_alias(struct ast_state *state, void* _o)
5144 {
5145 alias_ty o = (alias_ty)_o;
5146 PyObject *result = NULL, *value = NULL;
5147 PyTypeObject *tp;
5148 if (!o) {
5149 Py_RETURN_NONE;
5150 }
5151 if (++state->recursion_depth > state->recursion_limit) {
5152 PyErr_SetString(PyExc_RecursionError,
5153 "maximum recursion depth exceeded during ast construction");
5154 return 0;
5155 }
5156 tp = (PyTypeObject *)state->alias_type;
5157 result = PyType_GenericNew(tp, NULL, NULL);
5158 if (!result) return NULL;
5159 value = ast2obj_identifier(state, o->name);
5160 if (!value) goto failed;
5161 if (PyObject_SetAttr(result, state->name, value) == -1)
5162 goto failed;
5163 Py_DECREF(value);
5164 value = ast2obj_identifier(state, o->asname);
5165 if (!value) goto failed;
5166 if (PyObject_SetAttr(result, state->asname, value) == -1)
5167 goto failed;
5168 Py_DECREF(value);
5169 value = ast2obj_int(state, o->lineno);
5170 if (!value) goto failed;
5171 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5172 goto failed;
5173 Py_DECREF(value);
5174 value = ast2obj_int(state, o->col_offset);
5175 if (!value) goto failed;
5176 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5177 goto failed;
5178 Py_DECREF(value);
5179 value = ast2obj_int(state, o->end_lineno);
5180 if (!value) goto failed;
5181 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5182 goto failed;
5183 Py_DECREF(value);
5184 value = ast2obj_int(state, o->end_col_offset);
5185 if (!value) goto failed;
5186 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5187 goto failed;
5188 Py_DECREF(value);
5189 state->recursion_depth--;
5190 return result;
5191 failed:
5192 Py_XDECREF(value);
5193 Py_XDECREF(result);
5194 return NULL;
5195 }
5196
5197 PyObject*
ast2obj_withitem(struct ast_state * state,void * _o)5198 ast2obj_withitem(struct ast_state *state, void* _o)
5199 {
5200 withitem_ty o = (withitem_ty)_o;
5201 PyObject *result = NULL, *value = NULL;
5202 PyTypeObject *tp;
5203 if (!o) {
5204 Py_RETURN_NONE;
5205 }
5206 if (++state->recursion_depth > state->recursion_limit) {
5207 PyErr_SetString(PyExc_RecursionError,
5208 "maximum recursion depth exceeded during ast construction");
5209 return 0;
5210 }
5211 tp = (PyTypeObject *)state->withitem_type;
5212 result = PyType_GenericNew(tp, NULL, NULL);
5213 if (!result) return NULL;
5214 value = ast2obj_expr(state, o->context_expr);
5215 if (!value) goto failed;
5216 if (PyObject_SetAttr(result, state->context_expr, value) == -1)
5217 goto failed;
5218 Py_DECREF(value);
5219 value = ast2obj_expr(state, o->optional_vars);
5220 if (!value) goto failed;
5221 if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
5222 goto failed;
5223 Py_DECREF(value);
5224 state->recursion_depth--;
5225 return result;
5226 failed:
5227 Py_XDECREF(value);
5228 Py_XDECREF(result);
5229 return NULL;
5230 }
5231
5232 PyObject*
ast2obj_match_case(struct ast_state * state,void * _o)5233 ast2obj_match_case(struct ast_state *state, void* _o)
5234 {
5235 match_case_ty o = (match_case_ty)_o;
5236 PyObject *result = NULL, *value = NULL;
5237 PyTypeObject *tp;
5238 if (!o) {
5239 Py_RETURN_NONE;
5240 }
5241 if (++state->recursion_depth > state->recursion_limit) {
5242 PyErr_SetString(PyExc_RecursionError,
5243 "maximum recursion depth exceeded during ast construction");
5244 return 0;
5245 }
5246 tp = (PyTypeObject *)state->match_case_type;
5247 result = PyType_GenericNew(tp, NULL, NULL);
5248 if (!result) return NULL;
5249 value = ast2obj_pattern(state, o->pattern);
5250 if (!value) goto failed;
5251 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5252 goto failed;
5253 Py_DECREF(value);
5254 value = ast2obj_expr(state, o->guard);
5255 if (!value) goto failed;
5256 if (PyObject_SetAttr(result, state->guard, value) == -1)
5257 goto failed;
5258 Py_DECREF(value);
5259 value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
5260 if (!value) goto failed;
5261 if (PyObject_SetAttr(result, state->body, value) == -1)
5262 goto failed;
5263 Py_DECREF(value);
5264 state->recursion_depth--;
5265 return result;
5266 failed:
5267 Py_XDECREF(value);
5268 Py_XDECREF(result);
5269 return NULL;
5270 }
5271
5272 PyObject*
ast2obj_pattern(struct ast_state * state,void * _o)5273 ast2obj_pattern(struct ast_state *state, void* _o)
5274 {
5275 pattern_ty o = (pattern_ty)_o;
5276 PyObject *result = NULL, *value = NULL;
5277 PyTypeObject *tp;
5278 if (!o) {
5279 Py_RETURN_NONE;
5280 }
5281 if (++state->recursion_depth > state->recursion_limit) {
5282 PyErr_SetString(PyExc_RecursionError,
5283 "maximum recursion depth exceeded during ast construction");
5284 return 0;
5285 }
5286 switch (o->kind) {
5287 case MatchValue_kind:
5288 tp = (PyTypeObject *)state->MatchValue_type;
5289 result = PyType_GenericNew(tp, NULL, NULL);
5290 if (!result) goto failed;
5291 value = ast2obj_expr(state, o->v.MatchValue.value);
5292 if (!value) goto failed;
5293 if (PyObject_SetAttr(result, state->value, value) == -1)
5294 goto failed;
5295 Py_DECREF(value);
5296 break;
5297 case MatchSingleton_kind:
5298 tp = (PyTypeObject *)state->MatchSingleton_type;
5299 result = PyType_GenericNew(tp, NULL, NULL);
5300 if (!result) goto failed;
5301 value = ast2obj_constant(state, o->v.MatchSingleton.value);
5302 if (!value) goto failed;
5303 if (PyObject_SetAttr(result, state->value, value) == -1)
5304 goto failed;
5305 Py_DECREF(value);
5306 break;
5307 case MatchSequence_kind:
5308 tp = (PyTypeObject *)state->MatchSequence_type;
5309 result = PyType_GenericNew(tp, NULL, NULL);
5310 if (!result) goto failed;
5311 value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
5312 ast2obj_pattern);
5313 if (!value) goto failed;
5314 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5315 goto failed;
5316 Py_DECREF(value);
5317 break;
5318 case MatchMapping_kind:
5319 tp = (PyTypeObject *)state->MatchMapping_type;
5320 result = PyType_GenericNew(tp, NULL, NULL);
5321 if (!result) goto failed;
5322 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
5323 ast2obj_expr);
5324 if (!value) goto failed;
5325 if (PyObject_SetAttr(result, state->keys, value) == -1)
5326 goto failed;
5327 Py_DECREF(value);
5328 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
5329 ast2obj_pattern);
5330 if (!value) goto failed;
5331 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5332 goto failed;
5333 Py_DECREF(value);
5334 value = ast2obj_identifier(state, o->v.MatchMapping.rest);
5335 if (!value) goto failed;
5336 if (PyObject_SetAttr(result, state->rest, value) == -1)
5337 goto failed;
5338 Py_DECREF(value);
5339 break;
5340 case MatchClass_kind:
5341 tp = (PyTypeObject *)state->MatchClass_type;
5342 result = PyType_GenericNew(tp, NULL, NULL);
5343 if (!result) goto failed;
5344 value = ast2obj_expr(state, o->v.MatchClass.cls);
5345 if (!value) goto failed;
5346 if (PyObject_SetAttr(result, state->cls, value) == -1)
5347 goto failed;
5348 Py_DECREF(value);
5349 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
5350 ast2obj_pattern);
5351 if (!value) goto failed;
5352 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5353 goto failed;
5354 Py_DECREF(value);
5355 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
5356 ast2obj_identifier);
5357 if (!value) goto failed;
5358 if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
5359 goto failed;
5360 Py_DECREF(value);
5361 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
5362 ast2obj_pattern);
5363 if (!value) goto failed;
5364 if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
5365 goto failed;
5366 Py_DECREF(value);
5367 break;
5368 case MatchStar_kind:
5369 tp = (PyTypeObject *)state->MatchStar_type;
5370 result = PyType_GenericNew(tp, NULL, NULL);
5371 if (!result) goto failed;
5372 value = ast2obj_identifier(state, o->v.MatchStar.name);
5373 if (!value) goto failed;
5374 if (PyObject_SetAttr(result, state->name, value) == -1)
5375 goto failed;
5376 Py_DECREF(value);
5377 break;
5378 case MatchAs_kind:
5379 tp = (PyTypeObject *)state->MatchAs_type;
5380 result = PyType_GenericNew(tp, NULL, NULL);
5381 if (!result) goto failed;
5382 value = ast2obj_pattern(state, o->v.MatchAs.pattern);
5383 if (!value) goto failed;
5384 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5385 goto failed;
5386 Py_DECREF(value);
5387 value = ast2obj_identifier(state, o->v.MatchAs.name);
5388 if (!value) goto failed;
5389 if (PyObject_SetAttr(result, state->name, value) == -1)
5390 goto failed;
5391 Py_DECREF(value);
5392 break;
5393 case MatchOr_kind:
5394 tp = (PyTypeObject *)state->MatchOr_type;
5395 result = PyType_GenericNew(tp, NULL, NULL);
5396 if (!result) goto failed;
5397 value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
5398 ast2obj_pattern);
5399 if (!value) goto failed;
5400 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5401 goto failed;
5402 Py_DECREF(value);
5403 break;
5404 }
5405 value = ast2obj_int(state, o->lineno);
5406 if (!value) goto failed;
5407 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5408 goto failed;
5409 Py_DECREF(value);
5410 value = ast2obj_int(state, o->col_offset);
5411 if (!value) goto failed;
5412 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5413 goto failed;
5414 Py_DECREF(value);
5415 value = ast2obj_int(state, o->end_lineno);
5416 if (!value) goto failed;
5417 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5418 goto failed;
5419 Py_DECREF(value);
5420 value = ast2obj_int(state, o->end_col_offset);
5421 if (!value) goto failed;
5422 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5423 goto failed;
5424 Py_DECREF(value);
5425 state->recursion_depth--;
5426 return result;
5427 failed:
5428 Py_XDECREF(value);
5429 Py_XDECREF(result);
5430 return NULL;
5431 }
5432
5433 PyObject*
ast2obj_type_ignore(struct ast_state * state,void * _o)5434 ast2obj_type_ignore(struct ast_state *state, void* _o)
5435 {
5436 type_ignore_ty o = (type_ignore_ty)_o;
5437 PyObject *result = NULL, *value = NULL;
5438 PyTypeObject *tp;
5439 if (!o) {
5440 Py_RETURN_NONE;
5441 }
5442 if (++state->recursion_depth > state->recursion_limit) {
5443 PyErr_SetString(PyExc_RecursionError,
5444 "maximum recursion depth exceeded during ast construction");
5445 return 0;
5446 }
5447 switch (o->kind) {
5448 case TypeIgnore_kind:
5449 tp = (PyTypeObject *)state->TypeIgnore_type;
5450 result = PyType_GenericNew(tp, NULL, NULL);
5451 if (!result) goto failed;
5452 value = ast2obj_int(state, o->v.TypeIgnore.lineno);
5453 if (!value) goto failed;
5454 if (PyObject_SetAttr(result, state->lineno, value) == -1)
5455 goto failed;
5456 Py_DECREF(value);
5457 value = ast2obj_string(state, o->v.TypeIgnore.tag);
5458 if (!value) goto failed;
5459 if (PyObject_SetAttr(result, state->tag, value) == -1)
5460 goto failed;
5461 Py_DECREF(value);
5462 break;
5463 }
5464 state->recursion_depth--;
5465 return result;
5466 failed:
5467 Py_XDECREF(value);
5468 Py_XDECREF(result);
5469 return NULL;
5470 }
5471
5472
5473 int
obj2ast_mod(struct ast_state * state,PyObject * obj,mod_ty * out,PyArena * arena)5474 obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
5475 {
5476 int isinstance;
5477
5478 PyObject *tmp = NULL;
5479 PyObject *tp;
5480
5481 if (obj == Py_None) {
5482 *out = NULL;
5483 return 0;
5484 }
5485 tp = state->Module_type;
5486 isinstance = PyObject_IsInstance(obj, tp);
5487 if (isinstance == -1) {
5488 return 1;
5489 }
5490 if (isinstance) {
5491 asdl_stmt_seq* body;
5492 asdl_type_ignore_seq* type_ignores;
5493
5494 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5495 return 1;
5496 }
5497 if (tmp == NULL) {
5498 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5499 return 1;
5500 }
5501 else {
5502 int res;
5503 Py_ssize_t len;
5504 Py_ssize_t i;
5505 if (!PyList_Check(tmp)) {
5506 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5507 goto failed;
5508 }
5509 len = PyList_GET_SIZE(tmp);
5510 body = _Py_asdl_stmt_seq_new(len, arena);
5511 if (body == NULL) goto failed;
5512 for (i = 0; i < len; i++) {
5513 stmt_ty val;
5514 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5515 Py_INCREF(tmp2);
5516 if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5517 goto failed;
5518 }
5519 res = obj2ast_stmt(state, tmp2, &val, arena);
5520 _Py_LeaveRecursiveCall();
5521 Py_DECREF(tmp2);
5522 if (res != 0) goto failed;
5523 if (len != PyList_GET_SIZE(tmp)) {
5524 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5525 goto failed;
5526 }
5527 asdl_seq_SET(body, i, val);
5528 }
5529 Py_CLEAR(tmp);
5530 }
5531 if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
5532 return 1;
5533 }
5534 if (tmp == NULL) {
5535 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5536 return 1;
5537 }
5538 else {
5539 int res;
5540 Py_ssize_t len;
5541 Py_ssize_t i;
5542 if (!PyList_Check(tmp)) {
5543 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5544 goto failed;
5545 }
5546 len = PyList_GET_SIZE(tmp);
5547 type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
5548 if (type_ignores == NULL) goto failed;
5549 for (i = 0; i < len; i++) {
5550 type_ignore_ty val;
5551 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5552 Py_INCREF(tmp2);
5553 if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5554 goto failed;
5555 }
5556 res = obj2ast_type_ignore(state, tmp2, &val, arena);
5557 _Py_LeaveRecursiveCall();
5558 Py_DECREF(tmp2);
5559 if (res != 0) goto failed;
5560 if (len != PyList_GET_SIZE(tmp)) {
5561 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5562 goto failed;
5563 }
5564 asdl_seq_SET(type_ignores, i, val);
5565 }
5566 Py_CLEAR(tmp);
5567 }
5568 *out = _PyAST_Module(body, type_ignores, arena);
5569 if (*out == NULL) goto failed;
5570 return 0;
5571 }
5572 tp = state->Interactive_type;
5573 isinstance = PyObject_IsInstance(obj, tp);
5574 if (isinstance == -1) {
5575 return 1;
5576 }
5577 if (isinstance) {
5578 asdl_stmt_seq* body;
5579
5580 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5581 return 1;
5582 }
5583 if (tmp == NULL) {
5584 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5585 return 1;
5586 }
5587 else {
5588 int res;
5589 Py_ssize_t len;
5590 Py_ssize_t i;
5591 if (!PyList_Check(tmp)) {
5592 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5593 goto failed;
5594 }
5595 len = PyList_GET_SIZE(tmp);
5596 body = _Py_asdl_stmt_seq_new(len, arena);
5597 if (body == NULL) goto failed;
5598 for (i = 0; i < len; i++) {
5599 stmt_ty val;
5600 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5601 Py_INCREF(tmp2);
5602 if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
5603 goto failed;
5604 }
5605 res = obj2ast_stmt(state, tmp2, &val, arena);
5606 _Py_LeaveRecursiveCall();
5607 Py_DECREF(tmp2);
5608 if (res != 0) goto failed;
5609 if (len != PyList_GET_SIZE(tmp)) {
5610 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5611 goto failed;
5612 }
5613 asdl_seq_SET(body, i, val);
5614 }
5615 Py_CLEAR(tmp);
5616 }
5617 *out = _PyAST_Interactive(body, arena);
5618 if (*out == NULL) goto failed;
5619 return 0;
5620 }
5621 tp = state->Expression_type;
5622 isinstance = PyObject_IsInstance(obj, tp);
5623 if (isinstance == -1) {
5624 return 1;
5625 }
5626 if (isinstance) {
5627 expr_ty body;
5628
5629 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5630 return 1;
5631 }
5632 if (tmp == NULL) {
5633 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5634 return 1;
5635 }
5636 else {
5637 int res;
5638 if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
5639 goto failed;
5640 }
5641 res = obj2ast_expr(state, tmp, &body, arena);
5642 _Py_LeaveRecursiveCall();
5643 if (res != 0) goto failed;
5644 Py_CLEAR(tmp);
5645 }
5646 *out = _PyAST_Expression(body, arena);
5647 if (*out == NULL) goto failed;
5648 return 0;
5649 }
5650 tp = state->FunctionType_type;
5651 isinstance = PyObject_IsInstance(obj, tp);
5652 if (isinstance == -1) {
5653 return 1;
5654 }
5655 if (isinstance) {
5656 asdl_expr_seq* argtypes;
5657 expr_ty returns;
5658
5659 if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
5660 return 1;
5661 }
5662 if (tmp == NULL) {
5663 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5664 return 1;
5665 }
5666 else {
5667 int res;
5668 Py_ssize_t len;
5669 Py_ssize_t i;
5670 if (!PyList_Check(tmp)) {
5671 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5672 goto failed;
5673 }
5674 len = PyList_GET_SIZE(tmp);
5675 argtypes = _Py_asdl_expr_seq_new(len, arena);
5676 if (argtypes == NULL) goto failed;
5677 for (i = 0; i < len; i++) {
5678 expr_ty val;
5679 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5680 Py_INCREF(tmp2);
5681 if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5682 goto failed;
5683 }
5684 res = obj2ast_expr(state, tmp2, &val, arena);
5685 _Py_LeaveRecursiveCall();
5686 Py_DECREF(tmp2);
5687 if (res != 0) goto failed;
5688 if (len != PyList_GET_SIZE(tmp)) {
5689 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5690 goto failed;
5691 }
5692 asdl_seq_SET(argtypes, i, val);
5693 }
5694 Py_CLEAR(tmp);
5695 }
5696 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5697 return 1;
5698 }
5699 if (tmp == NULL) {
5700 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5701 return 1;
5702 }
5703 else {
5704 int res;
5705 if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5706 goto failed;
5707 }
5708 res = obj2ast_expr(state, tmp, &returns, arena);
5709 _Py_LeaveRecursiveCall();
5710 if (res != 0) goto failed;
5711 Py_CLEAR(tmp);
5712 }
5713 *out = _PyAST_FunctionType(argtypes, returns, arena);
5714 if (*out == NULL) goto failed;
5715 return 0;
5716 }
5717
5718 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5719 failed:
5720 Py_XDECREF(tmp);
5721 return 1;
5722 }
5723
5724 int
obj2ast_stmt(struct ast_state * state,PyObject * obj,stmt_ty * out,PyArena * arena)5725 obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
5726 arena)
5727 {
5728 int isinstance;
5729
5730 PyObject *tmp = NULL;
5731 PyObject *tp;
5732 int lineno;
5733 int col_offset;
5734 int end_lineno;
5735 int end_col_offset;
5736
5737 if (obj == Py_None) {
5738 *out = NULL;
5739 return 0;
5740 }
5741 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
5742 return 1;
5743 }
5744 if (tmp == NULL) {
5745 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5746 return 1;
5747 }
5748 else {
5749 int res;
5750 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5751 goto failed;
5752 }
5753 res = obj2ast_int(state, tmp, &lineno, arena);
5754 _Py_LeaveRecursiveCall();
5755 if (res != 0) goto failed;
5756 Py_CLEAR(tmp);
5757 }
5758 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
5759 return 1;
5760 }
5761 if (tmp == NULL) {
5762 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5763 return 1;
5764 }
5765 else {
5766 int res;
5767 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5768 goto failed;
5769 }
5770 res = obj2ast_int(state, tmp, &col_offset, arena);
5771 _Py_LeaveRecursiveCall();
5772 if (res != 0) goto failed;
5773 Py_CLEAR(tmp);
5774 }
5775 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
5776 return 1;
5777 }
5778 if (tmp == NULL || tmp == Py_None) {
5779 Py_CLEAR(tmp);
5780 end_lineno = lineno;
5781 }
5782 else {
5783 int res;
5784 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5785 goto failed;
5786 }
5787 res = obj2ast_int(state, tmp, &end_lineno, arena);
5788 _Py_LeaveRecursiveCall();
5789 if (res != 0) goto failed;
5790 Py_CLEAR(tmp);
5791 }
5792 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
5793 return 1;
5794 }
5795 if (tmp == NULL || tmp == Py_None) {
5796 Py_CLEAR(tmp);
5797 end_col_offset = col_offset;
5798 }
5799 else {
5800 int res;
5801 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5802 goto failed;
5803 }
5804 res = obj2ast_int(state, tmp, &end_col_offset, arena);
5805 _Py_LeaveRecursiveCall();
5806 if (res != 0) goto failed;
5807 Py_CLEAR(tmp);
5808 }
5809 tp = state->FunctionDef_type;
5810 isinstance = PyObject_IsInstance(obj, tp);
5811 if (isinstance == -1) {
5812 return 1;
5813 }
5814 if (isinstance) {
5815 identifier name;
5816 arguments_ty args;
5817 asdl_stmt_seq* body;
5818 asdl_expr_seq* decorator_list;
5819 expr_ty returns;
5820 string type_comment;
5821
5822 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
5823 return 1;
5824 }
5825 if (tmp == NULL) {
5826 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5827 return 1;
5828 }
5829 else {
5830 int res;
5831 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5832 goto failed;
5833 }
5834 res = obj2ast_identifier(state, tmp, &name, arena);
5835 _Py_LeaveRecursiveCall();
5836 if (res != 0) goto failed;
5837 Py_CLEAR(tmp);
5838 }
5839 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
5840 return 1;
5841 }
5842 if (tmp == NULL) {
5843 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5844 return 1;
5845 }
5846 else {
5847 int res;
5848 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5849 goto failed;
5850 }
5851 res = obj2ast_arguments(state, tmp, &args, arena);
5852 _Py_LeaveRecursiveCall();
5853 if (res != 0) goto failed;
5854 Py_CLEAR(tmp);
5855 }
5856 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5857 return 1;
5858 }
5859 if (tmp == NULL) {
5860 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5861 return 1;
5862 }
5863 else {
5864 int res;
5865 Py_ssize_t len;
5866 Py_ssize_t i;
5867 if (!PyList_Check(tmp)) {
5868 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5869 goto failed;
5870 }
5871 len = PyList_GET_SIZE(tmp);
5872 body = _Py_asdl_stmt_seq_new(len, arena);
5873 if (body == NULL) goto failed;
5874 for (i = 0; i < len; i++) {
5875 stmt_ty val;
5876 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5877 Py_INCREF(tmp2);
5878 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5879 goto failed;
5880 }
5881 res = obj2ast_stmt(state, tmp2, &val, arena);
5882 _Py_LeaveRecursiveCall();
5883 Py_DECREF(tmp2);
5884 if (res != 0) goto failed;
5885 if (len != PyList_GET_SIZE(tmp)) {
5886 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5887 goto failed;
5888 }
5889 asdl_seq_SET(body, i, val);
5890 }
5891 Py_CLEAR(tmp);
5892 }
5893 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
5894 return 1;
5895 }
5896 if (tmp == NULL) {
5897 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5898 return 1;
5899 }
5900 else {
5901 int res;
5902 Py_ssize_t len;
5903 Py_ssize_t i;
5904 if (!PyList_Check(tmp)) {
5905 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5906 goto failed;
5907 }
5908 len = PyList_GET_SIZE(tmp);
5909 decorator_list = _Py_asdl_expr_seq_new(len, arena);
5910 if (decorator_list == NULL) goto failed;
5911 for (i = 0; i < len; i++) {
5912 expr_ty val;
5913 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5914 Py_INCREF(tmp2);
5915 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5916 goto failed;
5917 }
5918 res = obj2ast_expr(state, tmp2, &val, arena);
5919 _Py_LeaveRecursiveCall();
5920 Py_DECREF(tmp2);
5921 if (res != 0) goto failed;
5922 if (len != PyList_GET_SIZE(tmp)) {
5923 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5924 goto failed;
5925 }
5926 asdl_seq_SET(decorator_list, i, val);
5927 }
5928 Py_CLEAR(tmp);
5929 }
5930 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5931 return 1;
5932 }
5933 if (tmp == NULL || tmp == Py_None) {
5934 Py_CLEAR(tmp);
5935 returns = NULL;
5936 }
5937 else {
5938 int res;
5939 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5940 goto failed;
5941 }
5942 res = obj2ast_expr(state, tmp, &returns, arena);
5943 _Py_LeaveRecursiveCall();
5944 if (res != 0) goto failed;
5945 Py_CLEAR(tmp);
5946 }
5947 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
5948 return 1;
5949 }
5950 if (tmp == NULL || tmp == Py_None) {
5951 Py_CLEAR(tmp);
5952 type_comment = NULL;
5953 }
5954 else {
5955 int res;
5956 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5957 goto failed;
5958 }
5959 res = obj2ast_string(state, tmp, &type_comment, arena);
5960 _Py_LeaveRecursiveCall();
5961 if (res != 0) goto failed;
5962 Py_CLEAR(tmp);
5963 }
5964 *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
5965 type_comment, lineno, col_offset, end_lineno,
5966 end_col_offset, arena);
5967 if (*out == NULL) goto failed;
5968 return 0;
5969 }
5970 tp = state->AsyncFunctionDef_type;
5971 isinstance = PyObject_IsInstance(obj, tp);
5972 if (isinstance == -1) {
5973 return 1;
5974 }
5975 if (isinstance) {
5976 identifier name;
5977 arguments_ty args;
5978 asdl_stmt_seq* body;
5979 asdl_expr_seq* decorator_list;
5980 expr_ty returns;
5981 string type_comment;
5982
5983 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
5984 return 1;
5985 }
5986 if (tmp == NULL) {
5987 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5988 return 1;
5989 }
5990 else {
5991 int res;
5992 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5993 goto failed;
5994 }
5995 res = obj2ast_identifier(state, tmp, &name, arena);
5996 _Py_LeaveRecursiveCall();
5997 if (res != 0) goto failed;
5998 Py_CLEAR(tmp);
5999 }
6000 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
6001 return 1;
6002 }
6003 if (tmp == NULL) {
6004 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
6005 return 1;
6006 }
6007 else {
6008 int res;
6009 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6010 goto failed;
6011 }
6012 res = obj2ast_arguments(state, tmp, &args, arena);
6013 _Py_LeaveRecursiveCall();
6014 if (res != 0) goto failed;
6015 Py_CLEAR(tmp);
6016 }
6017 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6018 return 1;
6019 }
6020 if (tmp == NULL) {
6021 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
6022 return 1;
6023 }
6024 else {
6025 int res;
6026 Py_ssize_t len;
6027 Py_ssize_t i;
6028 if (!PyList_Check(tmp)) {
6029 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6030 goto failed;
6031 }
6032 len = PyList_GET_SIZE(tmp);
6033 body = _Py_asdl_stmt_seq_new(len, arena);
6034 if (body == NULL) goto failed;
6035 for (i = 0; i < len; i++) {
6036 stmt_ty val;
6037 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6038 Py_INCREF(tmp2);
6039 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6040 goto failed;
6041 }
6042 res = obj2ast_stmt(state, tmp2, &val, arena);
6043 _Py_LeaveRecursiveCall();
6044 Py_DECREF(tmp2);
6045 if (res != 0) goto failed;
6046 if (len != PyList_GET_SIZE(tmp)) {
6047 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
6048 goto failed;
6049 }
6050 asdl_seq_SET(body, i, val);
6051 }
6052 Py_CLEAR(tmp);
6053 }
6054 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6055 return 1;
6056 }
6057 if (tmp == NULL) {
6058 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
6059 return 1;
6060 }
6061 else {
6062 int res;
6063 Py_ssize_t len;
6064 Py_ssize_t i;
6065 if (!PyList_Check(tmp)) {
6066 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6067 goto failed;
6068 }
6069 len = PyList_GET_SIZE(tmp);
6070 decorator_list = _Py_asdl_expr_seq_new(len, arena);
6071 if (decorator_list == NULL) goto failed;
6072 for (i = 0; i < len; i++) {
6073 expr_ty val;
6074 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6075 Py_INCREF(tmp2);
6076 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6077 goto failed;
6078 }
6079 res = obj2ast_expr(state, tmp2, &val, arena);
6080 _Py_LeaveRecursiveCall();
6081 Py_DECREF(tmp2);
6082 if (res != 0) goto failed;
6083 if (len != PyList_GET_SIZE(tmp)) {
6084 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
6085 goto failed;
6086 }
6087 asdl_seq_SET(decorator_list, i, val);
6088 }
6089 Py_CLEAR(tmp);
6090 }
6091 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
6092 return 1;
6093 }
6094 if (tmp == NULL || tmp == Py_None) {
6095 Py_CLEAR(tmp);
6096 returns = NULL;
6097 }
6098 else {
6099 int res;
6100 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6101 goto failed;
6102 }
6103 res = obj2ast_expr(state, tmp, &returns, arena);
6104 _Py_LeaveRecursiveCall();
6105 if (res != 0) goto failed;
6106 Py_CLEAR(tmp);
6107 }
6108 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6109 return 1;
6110 }
6111 if (tmp == NULL || tmp == Py_None) {
6112 Py_CLEAR(tmp);
6113 type_comment = NULL;
6114 }
6115 else {
6116 int res;
6117 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
6118 goto failed;
6119 }
6120 res = obj2ast_string(state, tmp, &type_comment, arena);
6121 _Py_LeaveRecursiveCall();
6122 if (res != 0) goto failed;
6123 Py_CLEAR(tmp);
6124 }
6125 *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
6126 returns, type_comment, lineno,
6127 col_offset, end_lineno, end_col_offset,
6128 arena);
6129 if (*out == NULL) goto failed;
6130 return 0;
6131 }
6132 tp = state->ClassDef_type;
6133 isinstance = PyObject_IsInstance(obj, tp);
6134 if (isinstance == -1) {
6135 return 1;
6136 }
6137 if (isinstance) {
6138 identifier name;
6139 asdl_expr_seq* bases;
6140 asdl_keyword_seq* keywords;
6141 asdl_stmt_seq* body;
6142 asdl_expr_seq* decorator_list;
6143
6144 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6145 return 1;
6146 }
6147 if (tmp == NULL) {
6148 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
6149 return 1;
6150 }
6151 else {
6152 int res;
6153 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6154 goto failed;
6155 }
6156 res = obj2ast_identifier(state, tmp, &name, arena);
6157 _Py_LeaveRecursiveCall();
6158 if (res != 0) goto failed;
6159 Py_CLEAR(tmp);
6160 }
6161 if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
6162 return 1;
6163 }
6164 if (tmp == NULL) {
6165 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
6166 return 1;
6167 }
6168 else {
6169 int res;
6170 Py_ssize_t len;
6171 Py_ssize_t i;
6172 if (!PyList_Check(tmp)) {
6173 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6174 goto failed;
6175 }
6176 len = PyList_GET_SIZE(tmp);
6177 bases = _Py_asdl_expr_seq_new(len, arena);
6178 if (bases == NULL) goto failed;
6179 for (i = 0; i < len; i++) {
6180 expr_ty val;
6181 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6182 Py_INCREF(tmp2);
6183 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6184 goto failed;
6185 }
6186 res = obj2ast_expr(state, tmp2, &val, arena);
6187 _Py_LeaveRecursiveCall();
6188 Py_DECREF(tmp2);
6189 if (res != 0) goto failed;
6190 if (len != PyList_GET_SIZE(tmp)) {
6191 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
6192 goto failed;
6193 }
6194 asdl_seq_SET(bases, i, val);
6195 }
6196 Py_CLEAR(tmp);
6197 }
6198 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
6199 return 1;
6200 }
6201 if (tmp == NULL) {
6202 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
6203 return 1;
6204 }
6205 else {
6206 int res;
6207 Py_ssize_t len;
6208 Py_ssize_t i;
6209 if (!PyList_Check(tmp)) {
6210 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6211 goto failed;
6212 }
6213 len = PyList_GET_SIZE(tmp);
6214 keywords = _Py_asdl_keyword_seq_new(len, arena);
6215 if (keywords == NULL) goto failed;
6216 for (i = 0; i < len; i++) {
6217 keyword_ty val;
6218 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6219 Py_INCREF(tmp2);
6220 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6221 goto failed;
6222 }
6223 res = obj2ast_keyword(state, tmp2, &val, arena);
6224 _Py_LeaveRecursiveCall();
6225 Py_DECREF(tmp2);
6226 if (res != 0) goto failed;
6227 if (len != PyList_GET_SIZE(tmp)) {
6228 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
6229 goto failed;
6230 }
6231 asdl_seq_SET(keywords, i, val);
6232 }
6233 Py_CLEAR(tmp);
6234 }
6235 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6236 return 1;
6237 }
6238 if (tmp == NULL) {
6239 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
6240 return 1;
6241 }
6242 else {
6243 int res;
6244 Py_ssize_t len;
6245 Py_ssize_t i;
6246 if (!PyList_Check(tmp)) {
6247 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6248 goto failed;
6249 }
6250 len = PyList_GET_SIZE(tmp);
6251 body = _Py_asdl_stmt_seq_new(len, arena);
6252 if (body == NULL) goto failed;
6253 for (i = 0; i < len; i++) {
6254 stmt_ty val;
6255 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6256 Py_INCREF(tmp2);
6257 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6258 goto failed;
6259 }
6260 res = obj2ast_stmt(state, tmp2, &val, arena);
6261 _Py_LeaveRecursiveCall();
6262 Py_DECREF(tmp2);
6263 if (res != 0) goto failed;
6264 if (len != PyList_GET_SIZE(tmp)) {
6265 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
6266 goto failed;
6267 }
6268 asdl_seq_SET(body, i, val);
6269 }
6270 Py_CLEAR(tmp);
6271 }
6272 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6273 return 1;
6274 }
6275 if (tmp == NULL) {
6276 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
6277 return 1;
6278 }
6279 else {
6280 int res;
6281 Py_ssize_t len;
6282 Py_ssize_t i;
6283 if (!PyList_Check(tmp)) {
6284 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6285 goto failed;
6286 }
6287 len = PyList_GET_SIZE(tmp);
6288 decorator_list = _Py_asdl_expr_seq_new(len, arena);
6289 if (decorator_list == NULL) goto failed;
6290 for (i = 0; i < len; i++) {
6291 expr_ty val;
6292 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6293 Py_INCREF(tmp2);
6294 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6295 goto failed;
6296 }
6297 res = obj2ast_expr(state, tmp2, &val, arena);
6298 _Py_LeaveRecursiveCall();
6299 Py_DECREF(tmp2);
6300 if (res != 0) goto failed;
6301 if (len != PyList_GET_SIZE(tmp)) {
6302 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
6303 goto failed;
6304 }
6305 asdl_seq_SET(decorator_list, i, val);
6306 }
6307 Py_CLEAR(tmp);
6308 }
6309 *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
6310 lineno, col_offset, end_lineno, end_col_offset,
6311 arena);
6312 if (*out == NULL) goto failed;
6313 return 0;
6314 }
6315 tp = state->Return_type;
6316 isinstance = PyObject_IsInstance(obj, tp);
6317 if (isinstance == -1) {
6318 return 1;
6319 }
6320 if (isinstance) {
6321 expr_ty value;
6322
6323 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6324 return 1;
6325 }
6326 if (tmp == NULL || tmp == Py_None) {
6327 Py_CLEAR(tmp);
6328 value = NULL;
6329 }
6330 else {
6331 int res;
6332 if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
6333 goto failed;
6334 }
6335 res = obj2ast_expr(state, tmp, &value, arena);
6336 _Py_LeaveRecursiveCall();
6337 if (res != 0) goto failed;
6338 Py_CLEAR(tmp);
6339 }
6340 *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
6341 end_col_offset, arena);
6342 if (*out == NULL) goto failed;
6343 return 0;
6344 }
6345 tp = state->Delete_type;
6346 isinstance = PyObject_IsInstance(obj, tp);
6347 if (isinstance == -1) {
6348 return 1;
6349 }
6350 if (isinstance) {
6351 asdl_expr_seq* targets;
6352
6353 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6354 return 1;
6355 }
6356 if (tmp == NULL) {
6357 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
6358 return 1;
6359 }
6360 else {
6361 int res;
6362 Py_ssize_t len;
6363 Py_ssize_t i;
6364 if (!PyList_Check(tmp)) {
6365 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6366 goto failed;
6367 }
6368 len = PyList_GET_SIZE(tmp);
6369 targets = _Py_asdl_expr_seq_new(len, arena);
6370 if (targets == NULL) goto failed;
6371 for (i = 0; i < len; i++) {
6372 expr_ty val;
6373 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6374 Py_INCREF(tmp2);
6375 if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
6376 goto failed;
6377 }
6378 res = obj2ast_expr(state, tmp2, &val, arena);
6379 _Py_LeaveRecursiveCall();
6380 Py_DECREF(tmp2);
6381 if (res != 0) goto failed;
6382 if (len != PyList_GET_SIZE(tmp)) {
6383 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
6384 goto failed;
6385 }
6386 asdl_seq_SET(targets, i, val);
6387 }
6388 Py_CLEAR(tmp);
6389 }
6390 *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
6391 end_col_offset, arena);
6392 if (*out == NULL) goto failed;
6393 return 0;
6394 }
6395 tp = state->Assign_type;
6396 isinstance = PyObject_IsInstance(obj, tp);
6397 if (isinstance == -1) {
6398 return 1;
6399 }
6400 if (isinstance) {
6401 asdl_expr_seq* targets;
6402 expr_ty value;
6403 string type_comment;
6404
6405 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6406 return 1;
6407 }
6408 if (tmp == NULL) {
6409 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
6410 return 1;
6411 }
6412 else {
6413 int res;
6414 Py_ssize_t len;
6415 Py_ssize_t i;
6416 if (!PyList_Check(tmp)) {
6417 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6418 goto failed;
6419 }
6420 len = PyList_GET_SIZE(tmp);
6421 targets = _Py_asdl_expr_seq_new(len, arena);
6422 if (targets == NULL) goto failed;
6423 for (i = 0; i < len; i++) {
6424 expr_ty val;
6425 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6426 Py_INCREF(tmp2);
6427 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6428 goto failed;
6429 }
6430 res = obj2ast_expr(state, tmp2, &val, arena);
6431 _Py_LeaveRecursiveCall();
6432 Py_DECREF(tmp2);
6433 if (res != 0) goto failed;
6434 if (len != PyList_GET_SIZE(tmp)) {
6435 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
6436 goto failed;
6437 }
6438 asdl_seq_SET(targets, i, val);
6439 }
6440 Py_CLEAR(tmp);
6441 }
6442 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6443 return 1;
6444 }
6445 if (tmp == NULL) {
6446 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
6447 return 1;
6448 }
6449 else {
6450 int res;
6451 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6452 goto failed;
6453 }
6454 res = obj2ast_expr(state, tmp, &value, arena);
6455 _Py_LeaveRecursiveCall();
6456 if (res != 0) goto failed;
6457 Py_CLEAR(tmp);
6458 }
6459 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6460 return 1;
6461 }
6462 if (tmp == NULL || tmp == Py_None) {
6463 Py_CLEAR(tmp);
6464 type_comment = NULL;
6465 }
6466 else {
6467 int res;
6468 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6469 goto failed;
6470 }
6471 res = obj2ast_string(state, tmp, &type_comment, arena);
6472 _Py_LeaveRecursiveCall();
6473 if (res != 0) goto failed;
6474 Py_CLEAR(tmp);
6475 }
6476 *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
6477 end_lineno, end_col_offset, arena);
6478 if (*out == NULL) goto failed;
6479 return 0;
6480 }
6481 tp = state->AugAssign_type;
6482 isinstance = PyObject_IsInstance(obj, tp);
6483 if (isinstance == -1) {
6484 return 1;
6485 }
6486 if (isinstance) {
6487 expr_ty target;
6488 operator_ty op;
6489 expr_ty value;
6490
6491 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6492 return 1;
6493 }
6494 if (tmp == NULL) {
6495 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6496 return 1;
6497 }
6498 else {
6499 int res;
6500 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6501 goto failed;
6502 }
6503 res = obj2ast_expr(state, tmp, &target, arena);
6504 _Py_LeaveRecursiveCall();
6505 if (res != 0) goto failed;
6506 Py_CLEAR(tmp);
6507 }
6508 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
6509 return 1;
6510 }
6511 if (tmp == NULL) {
6512 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6513 return 1;
6514 }
6515 else {
6516 int res;
6517 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6518 goto failed;
6519 }
6520 res = obj2ast_operator(state, tmp, &op, arena);
6521 _Py_LeaveRecursiveCall();
6522 if (res != 0) goto failed;
6523 Py_CLEAR(tmp);
6524 }
6525 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6526 return 1;
6527 }
6528 if (tmp == NULL) {
6529 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6530 return 1;
6531 }
6532 else {
6533 int res;
6534 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6535 goto failed;
6536 }
6537 res = obj2ast_expr(state, tmp, &value, arena);
6538 _Py_LeaveRecursiveCall();
6539 if (res != 0) goto failed;
6540 Py_CLEAR(tmp);
6541 }
6542 *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
6543 end_lineno, end_col_offset, arena);
6544 if (*out == NULL) goto failed;
6545 return 0;
6546 }
6547 tp = state->AnnAssign_type;
6548 isinstance = PyObject_IsInstance(obj, tp);
6549 if (isinstance == -1) {
6550 return 1;
6551 }
6552 if (isinstance) {
6553 expr_ty target;
6554 expr_ty annotation;
6555 expr_ty value;
6556 int simple;
6557
6558 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6559 return 1;
6560 }
6561 if (tmp == NULL) {
6562 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6563 return 1;
6564 }
6565 else {
6566 int res;
6567 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6568 goto failed;
6569 }
6570 res = obj2ast_expr(state, tmp, &target, arena);
6571 _Py_LeaveRecursiveCall();
6572 if (res != 0) goto failed;
6573 Py_CLEAR(tmp);
6574 }
6575 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
6576 return 1;
6577 }
6578 if (tmp == NULL) {
6579 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6580 return 1;
6581 }
6582 else {
6583 int res;
6584 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6585 goto failed;
6586 }
6587 res = obj2ast_expr(state, tmp, &annotation, arena);
6588 _Py_LeaveRecursiveCall();
6589 if (res != 0) goto failed;
6590 Py_CLEAR(tmp);
6591 }
6592 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6593 return 1;
6594 }
6595 if (tmp == NULL || tmp == Py_None) {
6596 Py_CLEAR(tmp);
6597 value = NULL;
6598 }
6599 else {
6600 int res;
6601 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6602 goto failed;
6603 }
6604 res = obj2ast_expr(state, tmp, &value, arena);
6605 _Py_LeaveRecursiveCall();
6606 if (res != 0) goto failed;
6607 Py_CLEAR(tmp);
6608 }
6609 if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
6610 return 1;
6611 }
6612 if (tmp == NULL) {
6613 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6614 return 1;
6615 }
6616 else {
6617 int res;
6618 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6619 goto failed;
6620 }
6621 res = obj2ast_int(state, tmp, &simple, arena);
6622 _Py_LeaveRecursiveCall();
6623 if (res != 0) goto failed;
6624 Py_CLEAR(tmp);
6625 }
6626 *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
6627 col_offset, end_lineno, end_col_offset, arena);
6628 if (*out == NULL) goto failed;
6629 return 0;
6630 }
6631 tp = state->For_type;
6632 isinstance = PyObject_IsInstance(obj, tp);
6633 if (isinstance == -1) {
6634 return 1;
6635 }
6636 if (isinstance) {
6637 expr_ty target;
6638 expr_ty iter;
6639 asdl_stmt_seq* body;
6640 asdl_stmt_seq* orelse;
6641 string type_comment;
6642
6643 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6644 return 1;
6645 }
6646 if (tmp == NULL) {
6647 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6648 return 1;
6649 }
6650 else {
6651 int res;
6652 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
6653 goto failed;
6654 }
6655 res = obj2ast_expr(state, tmp, &target, arena);
6656 _Py_LeaveRecursiveCall();
6657 if (res != 0) goto failed;
6658 Py_CLEAR(tmp);
6659 }
6660 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
6661 return 1;
6662 }
6663 if (tmp == NULL) {
6664 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6665 return 1;
6666 }
6667 else {
6668 int res;
6669 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
6670 goto failed;
6671 }
6672 res = obj2ast_expr(state, tmp, &iter, arena);
6673 _Py_LeaveRecursiveCall();
6674 if (res != 0) goto failed;
6675 Py_CLEAR(tmp);
6676 }
6677 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6678 return 1;
6679 }
6680 if (tmp == NULL) {
6681 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6682 return 1;
6683 }
6684 else {
6685 int res;
6686 Py_ssize_t len;
6687 Py_ssize_t i;
6688 if (!PyList_Check(tmp)) {
6689 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6690 goto failed;
6691 }
6692 len = PyList_GET_SIZE(tmp);
6693 body = _Py_asdl_stmt_seq_new(len, arena);
6694 if (body == NULL) goto failed;
6695 for (i = 0; i < len; i++) {
6696 stmt_ty val;
6697 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6698 Py_INCREF(tmp2);
6699 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
6700 goto failed;
6701 }
6702 res = obj2ast_stmt(state, tmp2, &val, arena);
6703 _Py_LeaveRecursiveCall();
6704 Py_DECREF(tmp2);
6705 if (res != 0) goto failed;
6706 if (len != PyList_GET_SIZE(tmp)) {
6707 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6708 goto failed;
6709 }
6710 asdl_seq_SET(body, i, val);
6711 }
6712 Py_CLEAR(tmp);
6713 }
6714 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6715 return 1;
6716 }
6717 if (tmp == NULL) {
6718 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6719 return 1;
6720 }
6721 else {
6722 int res;
6723 Py_ssize_t len;
6724 Py_ssize_t i;
6725 if (!PyList_Check(tmp)) {
6726 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6727 goto failed;
6728 }
6729 len = PyList_GET_SIZE(tmp);
6730 orelse = _Py_asdl_stmt_seq_new(len, arena);
6731 if (orelse == NULL) goto failed;
6732 for (i = 0; i < len; i++) {
6733 stmt_ty val;
6734 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6735 Py_INCREF(tmp2);
6736 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
6737 goto failed;
6738 }
6739 res = obj2ast_stmt(state, tmp2, &val, arena);
6740 _Py_LeaveRecursiveCall();
6741 Py_DECREF(tmp2);
6742 if (res != 0) goto failed;
6743 if (len != PyList_GET_SIZE(tmp)) {
6744 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6745 goto failed;
6746 }
6747 asdl_seq_SET(orelse, i, val);
6748 }
6749 Py_CLEAR(tmp);
6750 }
6751 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6752 return 1;
6753 }
6754 if (tmp == NULL || tmp == Py_None) {
6755 Py_CLEAR(tmp);
6756 type_comment = NULL;
6757 }
6758 else {
6759 int res;
6760 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
6761 goto failed;
6762 }
6763 res = obj2ast_string(state, tmp, &type_comment, arena);
6764 _Py_LeaveRecursiveCall();
6765 if (res != 0) goto failed;
6766 Py_CLEAR(tmp);
6767 }
6768 *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
6769 col_offset, end_lineno, end_col_offset, arena);
6770 if (*out == NULL) goto failed;
6771 return 0;
6772 }
6773 tp = state->AsyncFor_type;
6774 isinstance = PyObject_IsInstance(obj, tp);
6775 if (isinstance == -1) {
6776 return 1;
6777 }
6778 if (isinstance) {
6779 expr_ty target;
6780 expr_ty iter;
6781 asdl_stmt_seq* body;
6782 asdl_stmt_seq* orelse;
6783 string type_comment;
6784
6785 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6786 return 1;
6787 }
6788 if (tmp == NULL) {
6789 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6790 return 1;
6791 }
6792 else {
6793 int res;
6794 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6795 goto failed;
6796 }
6797 res = obj2ast_expr(state, tmp, &target, arena);
6798 _Py_LeaveRecursiveCall();
6799 if (res != 0) goto failed;
6800 Py_CLEAR(tmp);
6801 }
6802 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
6803 return 1;
6804 }
6805 if (tmp == NULL) {
6806 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6807 return 1;
6808 }
6809 else {
6810 int res;
6811 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6812 goto failed;
6813 }
6814 res = obj2ast_expr(state, tmp, &iter, arena);
6815 _Py_LeaveRecursiveCall();
6816 if (res != 0) goto failed;
6817 Py_CLEAR(tmp);
6818 }
6819 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6820 return 1;
6821 }
6822 if (tmp == NULL) {
6823 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6824 return 1;
6825 }
6826 else {
6827 int res;
6828 Py_ssize_t len;
6829 Py_ssize_t i;
6830 if (!PyList_Check(tmp)) {
6831 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6832 goto failed;
6833 }
6834 len = PyList_GET_SIZE(tmp);
6835 body = _Py_asdl_stmt_seq_new(len, arena);
6836 if (body == NULL) goto failed;
6837 for (i = 0; i < len; i++) {
6838 stmt_ty val;
6839 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6840 Py_INCREF(tmp2);
6841 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6842 goto failed;
6843 }
6844 res = obj2ast_stmt(state, tmp2, &val, arena);
6845 _Py_LeaveRecursiveCall();
6846 Py_DECREF(tmp2);
6847 if (res != 0) goto failed;
6848 if (len != PyList_GET_SIZE(tmp)) {
6849 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6850 goto failed;
6851 }
6852 asdl_seq_SET(body, i, val);
6853 }
6854 Py_CLEAR(tmp);
6855 }
6856 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6857 return 1;
6858 }
6859 if (tmp == NULL) {
6860 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6861 return 1;
6862 }
6863 else {
6864 int res;
6865 Py_ssize_t len;
6866 Py_ssize_t i;
6867 if (!PyList_Check(tmp)) {
6868 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6869 goto failed;
6870 }
6871 len = PyList_GET_SIZE(tmp);
6872 orelse = _Py_asdl_stmt_seq_new(len, arena);
6873 if (orelse == NULL) goto failed;
6874 for (i = 0; i < len; i++) {
6875 stmt_ty val;
6876 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6877 Py_INCREF(tmp2);
6878 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6879 goto failed;
6880 }
6881 res = obj2ast_stmt(state, tmp2, &val, arena);
6882 _Py_LeaveRecursiveCall();
6883 Py_DECREF(tmp2);
6884 if (res != 0) goto failed;
6885 if (len != PyList_GET_SIZE(tmp)) {
6886 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6887 goto failed;
6888 }
6889 asdl_seq_SET(orelse, i, val);
6890 }
6891 Py_CLEAR(tmp);
6892 }
6893 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6894 return 1;
6895 }
6896 if (tmp == NULL || tmp == Py_None) {
6897 Py_CLEAR(tmp);
6898 type_comment = NULL;
6899 }
6900 else {
6901 int res;
6902 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6903 goto failed;
6904 }
6905 res = obj2ast_string(state, tmp, &type_comment, arena);
6906 _Py_LeaveRecursiveCall();
6907 if (res != 0) goto failed;
6908 Py_CLEAR(tmp);
6909 }
6910 *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
6911 lineno, col_offset, end_lineno, end_col_offset,
6912 arena);
6913 if (*out == NULL) goto failed;
6914 return 0;
6915 }
6916 tp = state->While_type;
6917 isinstance = PyObject_IsInstance(obj, tp);
6918 if (isinstance == -1) {
6919 return 1;
6920 }
6921 if (isinstance) {
6922 expr_ty test;
6923 asdl_stmt_seq* body;
6924 asdl_stmt_seq* orelse;
6925
6926 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
6927 return 1;
6928 }
6929 if (tmp == NULL) {
6930 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6931 return 1;
6932 }
6933 else {
6934 int res;
6935 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
6936 goto failed;
6937 }
6938 res = obj2ast_expr(state, tmp, &test, arena);
6939 _Py_LeaveRecursiveCall();
6940 if (res != 0) goto failed;
6941 Py_CLEAR(tmp);
6942 }
6943 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6944 return 1;
6945 }
6946 if (tmp == NULL) {
6947 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6948 return 1;
6949 }
6950 else {
6951 int res;
6952 Py_ssize_t len;
6953 Py_ssize_t i;
6954 if (!PyList_Check(tmp)) {
6955 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6956 goto failed;
6957 }
6958 len = PyList_GET_SIZE(tmp);
6959 body = _Py_asdl_stmt_seq_new(len, arena);
6960 if (body == NULL) goto failed;
6961 for (i = 0; i < len; i++) {
6962 stmt_ty val;
6963 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6964 Py_INCREF(tmp2);
6965 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
6966 goto failed;
6967 }
6968 res = obj2ast_stmt(state, tmp2, &val, arena);
6969 _Py_LeaveRecursiveCall();
6970 Py_DECREF(tmp2);
6971 if (res != 0) goto failed;
6972 if (len != PyList_GET_SIZE(tmp)) {
6973 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6974 goto failed;
6975 }
6976 asdl_seq_SET(body, i, val);
6977 }
6978 Py_CLEAR(tmp);
6979 }
6980 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6981 return 1;
6982 }
6983 if (tmp == NULL) {
6984 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6985 return 1;
6986 }
6987 else {
6988 int res;
6989 Py_ssize_t len;
6990 Py_ssize_t i;
6991 if (!PyList_Check(tmp)) {
6992 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6993 goto failed;
6994 }
6995 len = PyList_GET_SIZE(tmp);
6996 orelse = _Py_asdl_stmt_seq_new(len, arena);
6997 if (orelse == NULL) goto failed;
6998 for (i = 0; i < len; i++) {
6999 stmt_ty val;
7000 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7001 Py_INCREF(tmp2);
7002 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
7003 goto failed;
7004 }
7005 res = obj2ast_stmt(state, tmp2, &val, arena);
7006 _Py_LeaveRecursiveCall();
7007 Py_DECREF(tmp2);
7008 if (res != 0) goto failed;
7009 if (len != PyList_GET_SIZE(tmp)) {
7010 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
7011 goto failed;
7012 }
7013 asdl_seq_SET(orelse, i, val);
7014 }
7015 Py_CLEAR(tmp);
7016 }
7017 *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
7018 end_col_offset, arena);
7019 if (*out == NULL) goto failed;
7020 return 0;
7021 }
7022 tp = state->If_type;
7023 isinstance = PyObject_IsInstance(obj, tp);
7024 if (isinstance == -1) {
7025 return 1;
7026 }
7027 if (isinstance) {
7028 expr_ty test;
7029 asdl_stmt_seq* body;
7030 asdl_stmt_seq* orelse;
7031
7032 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
7033 return 1;
7034 }
7035 if (tmp == NULL) {
7036 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
7037 return 1;
7038 }
7039 else {
7040 int res;
7041 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7042 goto failed;
7043 }
7044 res = obj2ast_expr(state, tmp, &test, arena);
7045 _Py_LeaveRecursiveCall();
7046 if (res != 0) goto failed;
7047 Py_CLEAR(tmp);
7048 }
7049 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7050 return 1;
7051 }
7052 if (tmp == NULL) {
7053 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
7054 return 1;
7055 }
7056 else {
7057 int res;
7058 Py_ssize_t len;
7059 Py_ssize_t i;
7060 if (!PyList_Check(tmp)) {
7061 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7062 goto failed;
7063 }
7064 len = PyList_GET_SIZE(tmp);
7065 body = _Py_asdl_stmt_seq_new(len, arena);
7066 if (body == NULL) goto failed;
7067 for (i = 0; i < len; i++) {
7068 stmt_ty val;
7069 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7070 Py_INCREF(tmp2);
7071 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7072 goto failed;
7073 }
7074 res = obj2ast_stmt(state, tmp2, &val, arena);
7075 _Py_LeaveRecursiveCall();
7076 Py_DECREF(tmp2);
7077 if (res != 0) goto failed;
7078 if (len != PyList_GET_SIZE(tmp)) {
7079 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
7080 goto failed;
7081 }
7082 asdl_seq_SET(body, i, val);
7083 }
7084 Py_CLEAR(tmp);
7085 }
7086 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7087 return 1;
7088 }
7089 if (tmp == NULL) {
7090 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
7091 return 1;
7092 }
7093 else {
7094 int res;
7095 Py_ssize_t len;
7096 Py_ssize_t i;
7097 if (!PyList_Check(tmp)) {
7098 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7099 goto failed;
7100 }
7101 len = PyList_GET_SIZE(tmp);
7102 orelse = _Py_asdl_stmt_seq_new(len, arena);
7103 if (orelse == NULL) goto failed;
7104 for (i = 0; i < len; i++) {
7105 stmt_ty val;
7106 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7107 Py_INCREF(tmp2);
7108 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
7109 goto failed;
7110 }
7111 res = obj2ast_stmt(state, tmp2, &val, arena);
7112 _Py_LeaveRecursiveCall();
7113 Py_DECREF(tmp2);
7114 if (res != 0) goto failed;
7115 if (len != PyList_GET_SIZE(tmp)) {
7116 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
7117 goto failed;
7118 }
7119 asdl_seq_SET(orelse, i, val);
7120 }
7121 Py_CLEAR(tmp);
7122 }
7123 *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
7124 end_col_offset, arena);
7125 if (*out == NULL) goto failed;
7126 return 0;
7127 }
7128 tp = state->With_type;
7129 isinstance = PyObject_IsInstance(obj, tp);
7130 if (isinstance == -1) {
7131 return 1;
7132 }
7133 if (isinstance) {
7134 asdl_withitem_seq* items;
7135 asdl_stmt_seq* body;
7136 string type_comment;
7137
7138 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
7139 return 1;
7140 }
7141 if (tmp == NULL) {
7142 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
7143 return 1;
7144 }
7145 else {
7146 int res;
7147 Py_ssize_t len;
7148 Py_ssize_t i;
7149 if (!PyList_Check(tmp)) {
7150 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7151 goto failed;
7152 }
7153 len = PyList_GET_SIZE(tmp);
7154 items = _Py_asdl_withitem_seq_new(len, arena);
7155 if (items == NULL) goto failed;
7156 for (i = 0; i < len; i++) {
7157 withitem_ty val;
7158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7159 Py_INCREF(tmp2);
7160 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7161 goto failed;
7162 }
7163 res = obj2ast_withitem(state, tmp2, &val, arena);
7164 _Py_LeaveRecursiveCall();
7165 Py_DECREF(tmp2);
7166 if (res != 0) goto failed;
7167 if (len != PyList_GET_SIZE(tmp)) {
7168 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
7169 goto failed;
7170 }
7171 asdl_seq_SET(items, i, val);
7172 }
7173 Py_CLEAR(tmp);
7174 }
7175 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7176 return 1;
7177 }
7178 if (tmp == NULL) {
7179 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
7180 return 1;
7181 }
7182 else {
7183 int res;
7184 Py_ssize_t len;
7185 Py_ssize_t i;
7186 if (!PyList_Check(tmp)) {
7187 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7188 goto failed;
7189 }
7190 len = PyList_GET_SIZE(tmp);
7191 body = _Py_asdl_stmt_seq_new(len, arena);
7192 if (body == NULL) goto failed;
7193 for (i = 0; i < len; i++) {
7194 stmt_ty val;
7195 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7196 Py_INCREF(tmp2);
7197 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7198 goto failed;
7199 }
7200 res = obj2ast_stmt(state, tmp2, &val, arena);
7201 _Py_LeaveRecursiveCall();
7202 Py_DECREF(tmp2);
7203 if (res != 0) goto failed;
7204 if (len != PyList_GET_SIZE(tmp)) {
7205 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
7206 goto failed;
7207 }
7208 asdl_seq_SET(body, i, val);
7209 }
7210 Py_CLEAR(tmp);
7211 }
7212 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7213 return 1;
7214 }
7215 if (tmp == NULL || tmp == Py_None) {
7216 Py_CLEAR(tmp);
7217 type_comment = NULL;
7218 }
7219 else {
7220 int res;
7221 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
7222 goto failed;
7223 }
7224 res = obj2ast_string(state, tmp, &type_comment, arena);
7225 _Py_LeaveRecursiveCall();
7226 if (res != 0) goto failed;
7227 Py_CLEAR(tmp);
7228 }
7229 *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
7230 end_lineno, end_col_offset, arena);
7231 if (*out == NULL) goto failed;
7232 return 0;
7233 }
7234 tp = state->AsyncWith_type;
7235 isinstance = PyObject_IsInstance(obj, tp);
7236 if (isinstance == -1) {
7237 return 1;
7238 }
7239 if (isinstance) {
7240 asdl_withitem_seq* items;
7241 asdl_stmt_seq* body;
7242 string type_comment;
7243
7244 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
7245 return 1;
7246 }
7247 if (tmp == NULL) {
7248 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
7249 return 1;
7250 }
7251 else {
7252 int res;
7253 Py_ssize_t len;
7254 Py_ssize_t i;
7255 if (!PyList_Check(tmp)) {
7256 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7257 goto failed;
7258 }
7259 len = PyList_GET_SIZE(tmp);
7260 items = _Py_asdl_withitem_seq_new(len, arena);
7261 if (items == NULL) goto failed;
7262 for (i = 0; i < len; i++) {
7263 withitem_ty val;
7264 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7265 Py_INCREF(tmp2);
7266 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7267 goto failed;
7268 }
7269 res = obj2ast_withitem(state, tmp2, &val, arena);
7270 _Py_LeaveRecursiveCall();
7271 Py_DECREF(tmp2);
7272 if (res != 0) goto failed;
7273 if (len != PyList_GET_SIZE(tmp)) {
7274 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
7275 goto failed;
7276 }
7277 asdl_seq_SET(items, i, val);
7278 }
7279 Py_CLEAR(tmp);
7280 }
7281 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7282 return 1;
7283 }
7284 if (tmp == NULL) {
7285 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
7286 return 1;
7287 }
7288 else {
7289 int res;
7290 Py_ssize_t len;
7291 Py_ssize_t i;
7292 if (!PyList_Check(tmp)) {
7293 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7294 goto failed;
7295 }
7296 len = PyList_GET_SIZE(tmp);
7297 body = _Py_asdl_stmt_seq_new(len, arena);
7298 if (body == NULL) goto failed;
7299 for (i = 0; i < len; i++) {
7300 stmt_ty val;
7301 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7302 Py_INCREF(tmp2);
7303 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7304 goto failed;
7305 }
7306 res = obj2ast_stmt(state, tmp2, &val, arena);
7307 _Py_LeaveRecursiveCall();
7308 Py_DECREF(tmp2);
7309 if (res != 0) goto failed;
7310 if (len != PyList_GET_SIZE(tmp)) {
7311 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
7312 goto failed;
7313 }
7314 asdl_seq_SET(body, i, val);
7315 }
7316 Py_CLEAR(tmp);
7317 }
7318 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7319 return 1;
7320 }
7321 if (tmp == NULL || tmp == Py_None) {
7322 Py_CLEAR(tmp);
7323 type_comment = NULL;
7324 }
7325 else {
7326 int res;
7327 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7328 goto failed;
7329 }
7330 res = obj2ast_string(state, tmp, &type_comment, arena);
7331 _Py_LeaveRecursiveCall();
7332 if (res != 0) goto failed;
7333 Py_CLEAR(tmp);
7334 }
7335 *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
7336 end_lineno, end_col_offset, arena);
7337 if (*out == NULL) goto failed;
7338 return 0;
7339 }
7340 tp = state->Match_type;
7341 isinstance = PyObject_IsInstance(obj, tp);
7342 if (isinstance == -1) {
7343 return 1;
7344 }
7345 if (isinstance) {
7346 expr_ty subject;
7347 asdl_match_case_seq* cases;
7348
7349 if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
7350 return 1;
7351 }
7352 if (tmp == NULL) {
7353 PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
7354 return 1;
7355 }
7356 else {
7357 int res;
7358 if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7359 goto failed;
7360 }
7361 res = obj2ast_expr(state, tmp, &subject, arena);
7362 _Py_LeaveRecursiveCall();
7363 if (res != 0) goto failed;
7364 Py_CLEAR(tmp);
7365 }
7366 if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
7367 return 1;
7368 }
7369 if (tmp == NULL) {
7370 PyErr_SetString(PyExc_TypeError, "required field \"cases\" missing from Match");
7371 return 1;
7372 }
7373 else {
7374 int res;
7375 Py_ssize_t len;
7376 Py_ssize_t i;
7377 if (!PyList_Check(tmp)) {
7378 PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7379 goto failed;
7380 }
7381 len = PyList_GET_SIZE(tmp);
7382 cases = _Py_asdl_match_case_seq_new(len, arena);
7383 if (cases == NULL) goto failed;
7384 for (i = 0; i < len; i++) {
7385 match_case_ty val;
7386 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7387 Py_INCREF(tmp2);
7388 if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7389 goto failed;
7390 }
7391 res = obj2ast_match_case(state, tmp2, &val, arena);
7392 _Py_LeaveRecursiveCall();
7393 Py_DECREF(tmp2);
7394 if (res != 0) goto failed;
7395 if (len != PyList_GET_SIZE(tmp)) {
7396 PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
7397 goto failed;
7398 }
7399 asdl_seq_SET(cases, i, val);
7400 }
7401 Py_CLEAR(tmp);
7402 }
7403 *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
7404 end_col_offset, arena);
7405 if (*out == NULL) goto failed;
7406 return 0;
7407 }
7408 tp = state->Raise_type;
7409 isinstance = PyObject_IsInstance(obj, tp);
7410 if (isinstance == -1) {
7411 return 1;
7412 }
7413 if (isinstance) {
7414 expr_ty exc;
7415 expr_ty cause;
7416
7417 if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
7418 return 1;
7419 }
7420 if (tmp == NULL || tmp == Py_None) {
7421 Py_CLEAR(tmp);
7422 exc = NULL;
7423 }
7424 else {
7425 int res;
7426 if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7427 goto failed;
7428 }
7429 res = obj2ast_expr(state, tmp, &exc, arena);
7430 _Py_LeaveRecursiveCall();
7431 if (res != 0) goto failed;
7432 Py_CLEAR(tmp);
7433 }
7434 if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
7435 return 1;
7436 }
7437 if (tmp == NULL || tmp == Py_None) {
7438 Py_CLEAR(tmp);
7439 cause = NULL;
7440 }
7441 else {
7442 int res;
7443 if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7444 goto failed;
7445 }
7446 res = obj2ast_expr(state, tmp, &cause, arena);
7447 _Py_LeaveRecursiveCall();
7448 if (res != 0) goto failed;
7449 Py_CLEAR(tmp);
7450 }
7451 *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
7452 end_col_offset, arena);
7453 if (*out == NULL) goto failed;
7454 return 0;
7455 }
7456 tp = state->Try_type;
7457 isinstance = PyObject_IsInstance(obj, tp);
7458 if (isinstance == -1) {
7459 return 1;
7460 }
7461 if (isinstance) {
7462 asdl_stmt_seq* body;
7463 asdl_excepthandler_seq* handlers;
7464 asdl_stmt_seq* orelse;
7465 asdl_stmt_seq* finalbody;
7466
7467 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7468 return 1;
7469 }
7470 if (tmp == NULL) {
7471 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
7472 return 1;
7473 }
7474 else {
7475 int res;
7476 Py_ssize_t len;
7477 Py_ssize_t i;
7478 if (!PyList_Check(tmp)) {
7479 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7480 goto failed;
7481 }
7482 len = PyList_GET_SIZE(tmp);
7483 body = _Py_asdl_stmt_seq_new(len, arena);
7484 if (body == NULL) goto failed;
7485 for (i = 0; i < len; i++) {
7486 stmt_ty val;
7487 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7488 Py_INCREF(tmp2);
7489 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7490 goto failed;
7491 }
7492 res = obj2ast_stmt(state, tmp2, &val, arena);
7493 _Py_LeaveRecursiveCall();
7494 Py_DECREF(tmp2);
7495 if (res != 0) goto failed;
7496 if (len != PyList_GET_SIZE(tmp)) {
7497 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
7498 goto failed;
7499 }
7500 asdl_seq_SET(body, i, val);
7501 }
7502 Py_CLEAR(tmp);
7503 }
7504 if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
7505 return 1;
7506 }
7507 if (tmp == NULL) {
7508 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
7509 return 1;
7510 }
7511 else {
7512 int res;
7513 Py_ssize_t len;
7514 Py_ssize_t i;
7515 if (!PyList_Check(tmp)) {
7516 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7517 goto failed;
7518 }
7519 len = PyList_GET_SIZE(tmp);
7520 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
7521 if (handlers == NULL) goto failed;
7522 for (i = 0; i < len; i++) {
7523 excepthandler_ty val;
7524 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7525 Py_INCREF(tmp2);
7526 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7527 goto failed;
7528 }
7529 res = obj2ast_excepthandler(state, tmp2, &val, arena);
7530 _Py_LeaveRecursiveCall();
7531 Py_DECREF(tmp2);
7532 if (res != 0) goto failed;
7533 if (len != PyList_GET_SIZE(tmp)) {
7534 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
7535 goto failed;
7536 }
7537 asdl_seq_SET(handlers, i, val);
7538 }
7539 Py_CLEAR(tmp);
7540 }
7541 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7542 return 1;
7543 }
7544 if (tmp == NULL) {
7545 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
7546 return 1;
7547 }
7548 else {
7549 int res;
7550 Py_ssize_t len;
7551 Py_ssize_t i;
7552 if (!PyList_Check(tmp)) {
7553 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7554 goto failed;
7555 }
7556 len = PyList_GET_SIZE(tmp);
7557 orelse = _Py_asdl_stmt_seq_new(len, arena);
7558 if (orelse == NULL) goto failed;
7559 for (i = 0; i < len; i++) {
7560 stmt_ty val;
7561 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7562 Py_INCREF(tmp2);
7563 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7564 goto failed;
7565 }
7566 res = obj2ast_stmt(state, tmp2, &val, arena);
7567 _Py_LeaveRecursiveCall();
7568 Py_DECREF(tmp2);
7569 if (res != 0) goto failed;
7570 if (len != PyList_GET_SIZE(tmp)) {
7571 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
7572 goto failed;
7573 }
7574 asdl_seq_SET(orelse, i, val);
7575 }
7576 Py_CLEAR(tmp);
7577 }
7578 if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
7579 return 1;
7580 }
7581 if (tmp == NULL) {
7582 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
7583 return 1;
7584 }
7585 else {
7586 int res;
7587 Py_ssize_t len;
7588 Py_ssize_t i;
7589 if (!PyList_Check(tmp)) {
7590 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7591 goto failed;
7592 }
7593 len = PyList_GET_SIZE(tmp);
7594 finalbody = _Py_asdl_stmt_seq_new(len, arena);
7595 if (finalbody == NULL) goto failed;
7596 for (i = 0; i < len; i++) {
7597 stmt_ty val;
7598 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7599 Py_INCREF(tmp2);
7600 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7601 goto failed;
7602 }
7603 res = obj2ast_stmt(state, tmp2, &val, arena);
7604 _Py_LeaveRecursiveCall();
7605 Py_DECREF(tmp2);
7606 if (res != 0) goto failed;
7607 if (len != PyList_GET_SIZE(tmp)) {
7608 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
7609 goto failed;
7610 }
7611 asdl_seq_SET(finalbody, i, val);
7612 }
7613 Py_CLEAR(tmp);
7614 }
7615 *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
7616 col_offset, end_lineno, end_col_offset, arena);
7617 if (*out == NULL) goto failed;
7618 return 0;
7619 }
7620 tp = state->TryStar_type;
7621 isinstance = PyObject_IsInstance(obj, tp);
7622 if (isinstance == -1) {
7623 return 1;
7624 }
7625 if (isinstance) {
7626 asdl_stmt_seq* body;
7627 asdl_excepthandler_seq* handlers;
7628 asdl_stmt_seq* orelse;
7629 asdl_stmt_seq* finalbody;
7630
7631 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7632 return 1;
7633 }
7634 if (tmp == NULL) {
7635 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryStar");
7636 return 1;
7637 }
7638 else {
7639 int res;
7640 Py_ssize_t len;
7641 Py_ssize_t i;
7642 if (!PyList_Check(tmp)) {
7643 PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7644 goto failed;
7645 }
7646 len = PyList_GET_SIZE(tmp);
7647 body = _Py_asdl_stmt_seq_new(len, arena);
7648 if (body == NULL) goto failed;
7649 for (i = 0; i < len; i++) {
7650 stmt_ty val;
7651 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7652 Py_INCREF(tmp2);
7653 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
7654 goto failed;
7655 }
7656 res = obj2ast_stmt(state, tmp2, &val, arena);
7657 _Py_LeaveRecursiveCall();
7658 Py_DECREF(tmp2);
7659 if (res != 0) goto failed;
7660 if (len != PyList_GET_SIZE(tmp)) {
7661 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
7662 goto failed;
7663 }
7664 asdl_seq_SET(body, i, val);
7665 }
7666 Py_CLEAR(tmp);
7667 }
7668 if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
7669 return 1;
7670 }
7671 if (tmp == NULL) {
7672 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryStar");
7673 return 1;
7674 }
7675 else {
7676 int res;
7677 Py_ssize_t len;
7678 Py_ssize_t i;
7679 if (!PyList_Check(tmp)) {
7680 PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7681 goto failed;
7682 }
7683 len = PyList_GET_SIZE(tmp);
7684 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
7685 if (handlers == NULL) goto failed;
7686 for (i = 0; i < len; i++) {
7687 excepthandler_ty val;
7688 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7689 Py_INCREF(tmp2);
7690 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
7691 goto failed;
7692 }
7693 res = obj2ast_excepthandler(state, tmp2, &val, arena);
7694 _Py_LeaveRecursiveCall();
7695 Py_DECREF(tmp2);
7696 if (res != 0) goto failed;
7697 if (len != PyList_GET_SIZE(tmp)) {
7698 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
7699 goto failed;
7700 }
7701 asdl_seq_SET(handlers, i, val);
7702 }
7703 Py_CLEAR(tmp);
7704 }
7705 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7706 return 1;
7707 }
7708 if (tmp == NULL) {
7709 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryStar");
7710 return 1;
7711 }
7712 else {
7713 int res;
7714 Py_ssize_t len;
7715 Py_ssize_t i;
7716 if (!PyList_Check(tmp)) {
7717 PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7718 goto failed;
7719 }
7720 len = PyList_GET_SIZE(tmp);
7721 orelse = _Py_asdl_stmt_seq_new(len, arena);
7722 if (orelse == NULL) goto failed;
7723 for (i = 0; i < len; i++) {
7724 stmt_ty val;
7725 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7726 Py_INCREF(tmp2);
7727 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
7728 goto failed;
7729 }
7730 res = obj2ast_stmt(state, tmp2, &val, arena);
7731 _Py_LeaveRecursiveCall();
7732 Py_DECREF(tmp2);
7733 if (res != 0) goto failed;
7734 if (len != PyList_GET_SIZE(tmp)) {
7735 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
7736 goto failed;
7737 }
7738 asdl_seq_SET(orelse, i, val);
7739 }
7740 Py_CLEAR(tmp);
7741 }
7742 if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
7743 return 1;
7744 }
7745 if (tmp == NULL) {
7746 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryStar");
7747 return 1;
7748 }
7749 else {
7750 int res;
7751 Py_ssize_t len;
7752 Py_ssize_t i;
7753 if (!PyList_Check(tmp)) {
7754 PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7755 goto failed;
7756 }
7757 len = PyList_GET_SIZE(tmp);
7758 finalbody = _Py_asdl_stmt_seq_new(len, arena);
7759 if (finalbody == NULL) goto failed;
7760 for (i = 0; i < len; i++) {
7761 stmt_ty val;
7762 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7763 Py_INCREF(tmp2);
7764 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
7765 goto failed;
7766 }
7767 res = obj2ast_stmt(state, tmp2, &val, arena);
7768 _Py_LeaveRecursiveCall();
7769 Py_DECREF(tmp2);
7770 if (res != 0) goto failed;
7771 if (len != PyList_GET_SIZE(tmp)) {
7772 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
7773 goto failed;
7774 }
7775 asdl_seq_SET(finalbody, i, val);
7776 }
7777 Py_CLEAR(tmp);
7778 }
7779 *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
7780 col_offset, end_lineno, end_col_offset, arena);
7781 if (*out == NULL) goto failed;
7782 return 0;
7783 }
7784 tp = state->Assert_type;
7785 isinstance = PyObject_IsInstance(obj, tp);
7786 if (isinstance == -1) {
7787 return 1;
7788 }
7789 if (isinstance) {
7790 expr_ty test;
7791 expr_ty msg;
7792
7793 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
7794 return 1;
7795 }
7796 if (tmp == NULL) {
7797 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
7798 return 1;
7799 }
7800 else {
7801 int res;
7802 if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7803 goto failed;
7804 }
7805 res = obj2ast_expr(state, tmp, &test, arena);
7806 _Py_LeaveRecursiveCall();
7807 if (res != 0) goto failed;
7808 Py_CLEAR(tmp);
7809 }
7810 if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
7811 return 1;
7812 }
7813 if (tmp == NULL || tmp == Py_None) {
7814 Py_CLEAR(tmp);
7815 msg = NULL;
7816 }
7817 else {
7818 int res;
7819 if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7820 goto failed;
7821 }
7822 res = obj2ast_expr(state, tmp, &msg, arena);
7823 _Py_LeaveRecursiveCall();
7824 if (res != 0) goto failed;
7825 Py_CLEAR(tmp);
7826 }
7827 *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
7828 end_col_offset, arena);
7829 if (*out == NULL) goto failed;
7830 return 0;
7831 }
7832 tp = state->Import_type;
7833 isinstance = PyObject_IsInstance(obj, tp);
7834 if (isinstance == -1) {
7835 return 1;
7836 }
7837 if (isinstance) {
7838 asdl_alias_seq* names;
7839
7840 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7841 return 1;
7842 }
7843 if (tmp == NULL) {
7844 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
7845 return 1;
7846 }
7847 else {
7848 int res;
7849 Py_ssize_t len;
7850 Py_ssize_t i;
7851 if (!PyList_Check(tmp)) {
7852 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7853 goto failed;
7854 }
7855 len = PyList_GET_SIZE(tmp);
7856 names = _Py_asdl_alias_seq_new(len, arena);
7857 if (names == NULL) goto failed;
7858 for (i = 0; i < len; i++) {
7859 alias_ty val;
7860 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7861 Py_INCREF(tmp2);
7862 if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
7863 goto failed;
7864 }
7865 res = obj2ast_alias(state, tmp2, &val, arena);
7866 _Py_LeaveRecursiveCall();
7867 Py_DECREF(tmp2);
7868 if (res != 0) goto failed;
7869 if (len != PyList_GET_SIZE(tmp)) {
7870 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7871 goto failed;
7872 }
7873 asdl_seq_SET(names, i, val);
7874 }
7875 Py_CLEAR(tmp);
7876 }
7877 *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
7878 end_col_offset, arena);
7879 if (*out == NULL) goto failed;
7880 return 0;
7881 }
7882 tp = state->ImportFrom_type;
7883 isinstance = PyObject_IsInstance(obj, tp);
7884 if (isinstance == -1) {
7885 return 1;
7886 }
7887 if (isinstance) {
7888 identifier module;
7889 asdl_alias_seq* names;
7890 int level;
7891
7892 if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
7893 return 1;
7894 }
7895 if (tmp == NULL || tmp == Py_None) {
7896 Py_CLEAR(tmp);
7897 module = NULL;
7898 }
7899 else {
7900 int res;
7901 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7902 goto failed;
7903 }
7904 res = obj2ast_identifier(state, tmp, &module, arena);
7905 _Py_LeaveRecursiveCall();
7906 if (res != 0) goto failed;
7907 Py_CLEAR(tmp);
7908 }
7909 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7910 return 1;
7911 }
7912 if (tmp == NULL) {
7913 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7914 return 1;
7915 }
7916 else {
7917 int res;
7918 Py_ssize_t len;
7919 Py_ssize_t i;
7920 if (!PyList_Check(tmp)) {
7921 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7922 goto failed;
7923 }
7924 len = PyList_GET_SIZE(tmp);
7925 names = _Py_asdl_alias_seq_new(len, arena);
7926 if (names == NULL) goto failed;
7927 for (i = 0; i < len; i++) {
7928 alias_ty val;
7929 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7930 Py_INCREF(tmp2);
7931 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7932 goto failed;
7933 }
7934 res = obj2ast_alias(state, tmp2, &val, arena);
7935 _Py_LeaveRecursiveCall();
7936 Py_DECREF(tmp2);
7937 if (res != 0) goto failed;
7938 if (len != PyList_GET_SIZE(tmp)) {
7939 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7940 goto failed;
7941 }
7942 asdl_seq_SET(names, i, val);
7943 }
7944 Py_CLEAR(tmp);
7945 }
7946 if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
7947 return 1;
7948 }
7949 if (tmp == NULL || tmp == Py_None) {
7950 Py_CLEAR(tmp);
7951 level = 0;
7952 }
7953 else {
7954 int res;
7955 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7956 goto failed;
7957 }
7958 res = obj2ast_int(state, tmp, &level, arena);
7959 _Py_LeaveRecursiveCall();
7960 if (res != 0) goto failed;
7961 Py_CLEAR(tmp);
7962 }
7963 *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
7964 end_lineno, end_col_offset, arena);
7965 if (*out == NULL) goto failed;
7966 return 0;
7967 }
7968 tp = state->Global_type;
7969 isinstance = PyObject_IsInstance(obj, tp);
7970 if (isinstance == -1) {
7971 return 1;
7972 }
7973 if (isinstance) {
7974 asdl_identifier_seq* names;
7975
7976 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7977 return 1;
7978 }
7979 if (tmp == NULL) {
7980 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7981 return 1;
7982 }
7983 else {
7984 int res;
7985 Py_ssize_t len;
7986 Py_ssize_t i;
7987 if (!PyList_Check(tmp)) {
7988 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7989 goto failed;
7990 }
7991 len = PyList_GET_SIZE(tmp);
7992 names = _Py_asdl_identifier_seq_new(len, arena);
7993 if (names == NULL) goto failed;
7994 for (i = 0; i < len; i++) {
7995 identifier val;
7996 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7997 Py_INCREF(tmp2);
7998 if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
7999 goto failed;
8000 }
8001 res = obj2ast_identifier(state, tmp2, &val, arena);
8002 _Py_LeaveRecursiveCall();
8003 Py_DECREF(tmp2);
8004 if (res != 0) goto failed;
8005 if (len != PyList_GET_SIZE(tmp)) {
8006 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
8007 goto failed;
8008 }
8009 asdl_seq_SET(names, i, val);
8010 }
8011 Py_CLEAR(tmp);
8012 }
8013 *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
8014 end_col_offset, arena);
8015 if (*out == NULL) goto failed;
8016 return 0;
8017 }
8018 tp = state->Nonlocal_type;
8019 isinstance = PyObject_IsInstance(obj, tp);
8020 if (isinstance == -1) {
8021 return 1;
8022 }
8023 if (isinstance) {
8024 asdl_identifier_seq* names;
8025
8026 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
8027 return 1;
8028 }
8029 if (tmp == NULL) {
8030 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
8031 return 1;
8032 }
8033 else {
8034 int res;
8035 Py_ssize_t len;
8036 Py_ssize_t i;
8037 if (!PyList_Check(tmp)) {
8038 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8039 goto failed;
8040 }
8041 len = PyList_GET_SIZE(tmp);
8042 names = _Py_asdl_identifier_seq_new(len, arena);
8043 if (names == NULL) goto failed;
8044 for (i = 0; i < len; i++) {
8045 identifier val;
8046 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8047 Py_INCREF(tmp2);
8048 if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
8049 goto failed;
8050 }
8051 res = obj2ast_identifier(state, tmp2, &val, arena);
8052 _Py_LeaveRecursiveCall();
8053 Py_DECREF(tmp2);
8054 if (res != 0) goto failed;
8055 if (len != PyList_GET_SIZE(tmp)) {
8056 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
8057 goto failed;
8058 }
8059 asdl_seq_SET(names, i, val);
8060 }
8061 Py_CLEAR(tmp);
8062 }
8063 *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
8064 end_col_offset, arena);
8065 if (*out == NULL) goto failed;
8066 return 0;
8067 }
8068 tp = state->Expr_type;
8069 isinstance = PyObject_IsInstance(obj, tp);
8070 if (isinstance == -1) {
8071 return 1;
8072 }
8073 if (isinstance) {
8074 expr_ty value;
8075
8076 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8077 return 1;
8078 }
8079 if (tmp == NULL) {
8080 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
8081 return 1;
8082 }
8083 else {
8084 int res;
8085 if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
8086 goto failed;
8087 }
8088 res = obj2ast_expr(state, tmp, &value, arena);
8089 _Py_LeaveRecursiveCall();
8090 if (res != 0) goto failed;
8091 Py_CLEAR(tmp);
8092 }
8093 *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
8094 end_col_offset, arena);
8095 if (*out == NULL) goto failed;
8096 return 0;
8097 }
8098 tp = state->Pass_type;
8099 isinstance = PyObject_IsInstance(obj, tp);
8100 if (isinstance == -1) {
8101 return 1;
8102 }
8103 if (isinstance) {
8104
8105 *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
8106 arena);
8107 if (*out == NULL) goto failed;
8108 return 0;
8109 }
8110 tp = state->Break_type;
8111 isinstance = PyObject_IsInstance(obj, tp);
8112 if (isinstance == -1) {
8113 return 1;
8114 }
8115 if (isinstance) {
8116
8117 *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
8118 arena);
8119 if (*out == NULL) goto failed;
8120 return 0;
8121 }
8122 tp = state->Continue_type;
8123 isinstance = PyObject_IsInstance(obj, tp);
8124 if (isinstance == -1) {
8125 return 1;
8126 }
8127 if (isinstance) {
8128
8129 *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
8130 arena);
8131 if (*out == NULL) goto failed;
8132 return 0;
8133 }
8134
8135 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
8136 failed:
8137 Py_XDECREF(tmp);
8138 return 1;
8139 }
8140
8141 int
obj2ast_expr(struct ast_state * state,PyObject * obj,expr_ty * out,PyArena * arena)8142 obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
8143 arena)
8144 {
8145 int isinstance;
8146
8147 PyObject *tmp = NULL;
8148 PyObject *tp;
8149 int lineno;
8150 int col_offset;
8151 int end_lineno;
8152 int end_col_offset;
8153
8154 if (obj == Py_None) {
8155 *out = NULL;
8156 return 0;
8157 }
8158 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
8159 return 1;
8160 }
8161 if (tmp == NULL) {
8162 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
8163 return 1;
8164 }
8165 else {
8166 int res;
8167 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8168 goto failed;
8169 }
8170 res = obj2ast_int(state, tmp, &lineno, arena);
8171 _Py_LeaveRecursiveCall();
8172 if (res != 0) goto failed;
8173 Py_CLEAR(tmp);
8174 }
8175 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
8176 return 1;
8177 }
8178 if (tmp == NULL) {
8179 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
8180 return 1;
8181 }
8182 else {
8183 int res;
8184 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8185 goto failed;
8186 }
8187 res = obj2ast_int(state, tmp, &col_offset, arena);
8188 _Py_LeaveRecursiveCall();
8189 if (res != 0) goto failed;
8190 Py_CLEAR(tmp);
8191 }
8192 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
8193 return 1;
8194 }
8195 if (tmp == NULL || tmp == Py_None) {
8196 Py_CLEAR(tmp);
8197 end_lineno = lineno;
8198 }
8199 else {
8200 int res;
8201 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8202 goto failed;
8203 }
8204 res = obj2ast_int(state, tmp, &end_lineno, arena);
8205 _Py_LeaveRecursiveCall();
8206 if (res != 0) goto failed;
8207 Py_CLEAR(tmp);
8208 }
8209 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
8210 return 1;
8211 }
8212 if (tmp == NULL || tmp == Py_None) {
8213 Py_CLEAR(tmp);
8214 end_col_offset = col_offset;
8215 }
8216 else {
8217 int res;
8218 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
8219 goto failed;
8220 }
8221 res = obj2ast_int(state, tmp, &end_col_offset, arena);
8222 _Py_LeaveRecursiveCall();
8223 if (res != 0) goto failed;
8224 Py_CLEAR(tmp);
8225 }
8226 tp = state->BoolOp_type;
8227 isinstance = PyObject_IsInstance(obj, tp);
8228 if (isinstance == -1) {
8229 return 1;
8230 }
8231 if (isinstance) {
8232 boolop_ty op;
8233 asdl_expr_seq* values;
8234
8235 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8236 return 1;
8237 }
8238 if (tmp == NULL) {
8239 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
8240 return 1;
8241 }
8242 else {
8243 int res;
8244 if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
8245 goto failed;
8246 }
8247 res = obj2ast_boolop(state, tmp, &op, arena);
8248 _Py_LeaveRecursiveCall();
8249 if (res != 0) goto failed;
8250 Py_CLEAR(tmp);
8251 }
8252 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
8253 return 1;
8254 }
8255 if (tmp == NULL) {
8256 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
8257 return 1;
8258 }
8259 else {
8260 int res;
8261 Py_ssize_t len;
8262 Py_ssize_t i;
8263 if (!PyList_Check(tmp)) {
8264 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8265 goto failed;
8266 }
8267 len = PyList_GET_SIZE(tmp);
8268 values = _Py_asdl_expr_seq_new(len, arena);
8269 if (values == NULL) goto failed;
8270 for (i = 0; i < len; i++) {
8271 expr_ty val;
8272 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8273 Py_INCREF(tmp2);
8274 if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
8275 goto failed;
8276 }
8277 res = obj2ast_expr(state, tmp2, &val, arena);
8278 _Py_LeaveRecursiveCall();
8279 Py_DECREF(tmp2);
8280 if (res != 0) goto failed;
8281 if (len != PyList_GET_SIZE(tmp)) {
8282 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
8283 goto failed;
8284 }
8285 asdl_seq_SET(values, i, val);
8286 }
8287 Py_CLEAR(tmp);
8288 }
8289 *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
8290 end_col_offset, arena);
8291 if (*out == NULL) goto failed;
8292 return 0;
8293 }
8294 tp = state->NamedExpr_type;
8295 isinstance = PyObject_IsInstance(obj, tp);
8296 if (isinstance == -1) {
8297 return 1;
8298 }
8299 if (isinstance) {
8300 expr_ty target;
8301 expr_ty value;
8302
8303 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
8304 return 1;
8305 }
8306 if (tmp == NULL) {
8307 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
8308 return 1;
8309 }
8310 else {
8311 int res;
8312 if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8313 goto failed;
8314 }
8315 res = obj2ast_expr(state, tmp, &target, arena);
8316 _Py_LeaveRecursiveCall();
8317 if (res != 0) goto failed;
8318 Py_CLEAR(tmp);
8319 }
8320 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8321 return 1;
8322 }
8323 if (tmp == NULL) {
8324 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
8325 return 1;
8326 }
8327 else {
8328 int res;
8329 if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8330 goto failed;
8331 }
8332 res = obj2ast_expr(state, tmp, &value, arena);
8333 _Py_LeaveRecursiveCall();
8334 if (res != 0) goto failed;
8335 Py_CLEAR(tmp);
8336 }
8337 *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
8338 end_col_offset, arena);
8339 if (*out == NULL) goto failed;
8340 return 0;
8341 }
8342 tp = state->BinOp_type;
8343 isinstance = PyObject_IsInstance(obj, tp);
8344 if (isinstance == -1) {
8345 return 1;
8346 }
8347 if (isinstance) {
8348 expr_ty left;
8349 operator_ty op;
8350 expr_ty right;
8351
8352 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
8353 return 1;
8354 }
8355 if (tmp == NULL) {
8356 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
8357 return 1;
8358 }
8359 else {
8360 int res;
8361 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8362 goto failed;
8363 }
8364 res = obj2ast_expr(state, tmp, &left, arena);
8365 _Py_LeaveRecursiveCall();
8366 if (res != 0) goto failed;
8367 Py_CLEAR(tmp);
8368 }
8369 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8370 return 1;
8371 }
8372 if (tmp == NULL) {
8373 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
8374 return 1;
8375 }
8376 else {
8377 int res;
8378 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8379 goto failed;
8380 }
8381 res = obj2ast_operator(state, tmp, &op, arena);
8382 _Py_LeaveRecursiveCall();
8383 if (res != 0) goto failed;
8384 Py_CLEAR(tmp);
8385 }
8386 if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
8387 return 1;
8388 }
8389 if (tmp == NULL) {
8390 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
8391 return 1;
8392 }
8393 else {
8394 int res;
8395 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8396 goto failed;
8397 }
8398 res = obj2ast_expr(state, tmp, &right, arena);
8399 _Py_LeaveRecursiveCall();
8400 if (res != 0) goto failed;
8401 Py_CLEAR(tmp);
8402 }
8403 *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
8404 end_col_offset, arena);
8405 if (*out == NULL) goto failed;
8406 return 0;
8407 }
8408 tp = state->UnaryOp_type;
8409 isinstance = PyObject_IsInstance(obj, tp);
8410 if (isinstance == -1) {
8411 return 1;
8412 }
8413 if (isinstance) {
8414 unaryop_ty op;
8415 expr_ty operand;
8416
8417 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8418 return 1;
8419 }
8420 if (tmp == NULL) {
8421 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
8422 return 1;
8423 }
8424 else {
8425 int res;
8426 if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8427 goto failed;
8428 }
8429 res = obj2ast_unaryop(state, tmp, &op, arena);
8430 _Py_LeaveRecursiveCall();
8431 if (res != 0) goto failed;
8432 Py_CLEAR(tmp);
8433 }
8434 if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
8435 return 1;
8436 }
8437 if (tmp == NULL) {
8438 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
8439 return 1;
8440 }
8441 else {
8442 int res;
8443 if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8444 goto failed;
8445 }
8446 res = obj2ast_expr(state, tmp, &operand, arena);
8447 _Py_LeaveRecursiveCall();
8448 if (res != 0) goto failed;
8449 Py_CLEAR(tmp);
8450 }
8451 *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
8452 end_col_offset, arena);
8453 if (*out == NULL) goto failed;
8454 return 0;
8455 }
8456 tp = state->Lambda_type;
8457 isinstance = PyObject_IsInstance(obj, tp);
8458 if (isinstance == -1) {
8459 return 1;
8460 }
8461 if (isinstance) {
8462 arguments_ty args;
8463 expr_ty body;
8464
8465 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
8466 return 1;
8467 }
8468 if (tmp == NULL) {
8469 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
8470 return 1;
8471 }
8472 else {
8473 int res;
8474 if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8475 goto failed;
8476 }
8477 res = obj2ast_arguments(state, tmp, &args, arena);
8478 _Py_LeaveRecursiveCall();
8479 if (res != 0) goto failed;
8480 Py_CLEAR(tmp);
8481 }
8482 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8483 return 1;
8484 }
8485 if (tmp == NULL) {
8486 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
8487 return 1;
8488 }
8489 else {
8490 int res;
8491 if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8492 goto failed;
8493 }
8494 res = obj2ast_expr(state, tmp, &body, arena);
8495 _Py_LeaveRecursiveCall();
8496 if (res != 0) goto failed;
8497 Py_CLEAR(tmp);
8498 }
8499 *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
8500 end_col_offset, arena);
8501 if (*out == NULL) goto failed;
8502 return 0;
8503 }
8504 tp = state->IfExp_type;
8505 isinstance = PyObject_IsInstance(obj, tp);
8506 if (isinstance == -1) {
8507 return 1;
8508 }
8509 if (isinstance) {
8510 expr_ty test;
8511 expr_ty body;
8512 expr_ty orelse;
8513
8514 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
8515 return 1;
8516 }
8517 if (tmp == NULL) {
8518 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
8519 return 1;
8520 }
8521 else {
8522 int res;
8523 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8524 goto failed;
8525 }
8526 res = obj2ast_expr(state, tmp, &test, arena);
8527 _Py_LeaveRecursiveCall();
8528 if (res != 0) goto failed;
8529 Py_CLEAR(tmp);
8530 }
8531 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8532 return 1;
8533 }
8534 if (tmp == NULL) {
8535 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
8536 return 1;
8537 }
8538 else {
8539 int res;
8540 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8541 goto failed;
8542 }
8543 res = obj2ast_expr(state, tmp, &body, arena);
8544 _Py_LeaveRecursiveCall();
8545 if (res != 0) goto failed;
8546 Py_CLEAR(tmp);
8547 }
8548 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
8549 return 1;
8550 }
8551 if (tmp == NULL) {
8552 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
8553 return 1;
8554 }
8555 else {
8556 int res;
8557 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8558 goto failed;
8559 }
8560 res = obj2ast_expr(state, tmp, &orelse, arena);
8561 _Py_LeaveRecursiveCall();
8562 if (res != 0) goto failed;
8563 Py_CLEAR(tmp);
8564 }
8565 *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
8566 end_col_offset, arena);
8567 if (*out == NULL) goto failed;
8568 return 0;
8569 }
8570 tp = state->Dict_type;
8571 isinstance = PyObject_IsInstance(obj, tp);
8572 if (isinstance == -1) {
8573 return 1;
8574 }
8575 if (isinstance) {
8576 asdl_expr_seq* keys;
8577 asdl_expr_seq* values;
8578
8579 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
8580 return 1;
8581 }
8582 if (tmp == NULL) {
8583 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
8584 return 1;
8585 }
8586 else {
8587 int res;
8588 Py_ssize_t len;
8589 Py_ssize_t i;
8590 if (!PyList_Check(tmp)) {
8591 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8592 goto failed;
8593 }
8594 len = PyList_GET_SIZE(tmp);
8595 keys = _Py_asdl_expr_seq_new(len, arena);
8596 if (keys == NULL) goto failed;
8597 for (i = 0; i < len; i++) {
8598 expr_ty val;
8599 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8600 Py_INCREF(tmp2);
8601 if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8602 goto failed;
8603 }
8604 res = obj2ast_expr(state, tmp2, &val, arena);
8605 _Py_LeaveRecursiveCall();
8606 Py_DECREF(tmp2);
8607 if (res != 0) goto failed;
8608 if (len != PyList_GET_SIZE(tmp)) {
8609 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
8610 goto failed;
8611 }
8612 asdl_seq_SET(keys, i, val);
8613 }
8614 Py_CLEAR(tmp);
8615 }
8616 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
8617 return 1;
8618 }
8619 if (tmp == NULL) {
8620 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
8621 return 1;
8622 }
8623 else {
8624 int res;
8625 Py_ssize_t len;
8626 Py_ssize_t i;
8627 if (!PyList_Check(tmp)) {
8628 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8629 goto failed;
8630 }
8631 len = PyList_GET_SIZE(tmp);
8632 values = _Py_asdl_expr_seq_new(len, arena);
8633 if (values == NULL) goto failed;
8634 for (i = 0; i < len; i++) {
8635 expr_ty val;
8636 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8637 Py_INCREF(tmp2);
8638 if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8639 goto failed;
8640 }
8641 res = obj2ast_expr(state, tmp2, &val, arena);
8642 _Py_LeaveRecursiveCall();
8643 Py_DECREF(tmp2);
8644 if (res != 0) goto failed;
8645 if (len != PyList_GET_SIZE(tmp)) {
8646 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
8647 goto failed;
8648 }
8649 asdl_seq_SET(values, i, val);
8650 }
8651 Py_CLEAR(tmp);
8652 }
8653 *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
8654 end_col_offset, arena);
8655 if (*out == NULL) goto failed;
8656 return 0;
8657 }
8658 tp = state->Set_type;
8659 isinstance = PyObject_IsInstance(obj, tp);
8660 if (isinstance == -1) {
8661 return 1;
8662 }
8663 if (isinstance) {
8664 asdl_expr_seq* elts;
8665
8666 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
8667 return 1;
8668 }
8669 if (tmp == NULL) {
8670 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
8671 return 1;
8672 }
8673 else {
8674 int res;
8675 Py_ssize_t len;
8676 Py_ssize_t i;
8677 if (!PyList_Check(tmp)) {
8678 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8679 goto failed;
8680 }
8681 len = PyList_GET_SIZE(tmp);
8682 elts = _Py_asdl_expr_seq_new(len, arena);
8683 if (elts == NULL) goto failed;
8684 for (i = 0; i < len; i++) {
8685 expr_ty val;
8686 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8687 Py_INCREF(tmp2);
8688 if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
8689 goto failed;
8690 }
8691 res = obj2ast_expr(state, tmp2, &val, arena);
8692 _Py_LeaveRecursiveCall();
8693 Py_DECREF(tmp2);
8694 if (res != 0) goto failed;
8695 if (len != PyList_GET_SIZE(tmp)) {
8696 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
8697 goto failed;
8698 }
8699 asdl_seq_SET(elts, i, val);
8700 }
8701 Py_CLEAR(tmp);
8702 }
8703 *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
8704 arena);
8705 if (*out == NULL) goto failed;
8706 return 0;
8707 }
8708 tp = state->ListComp_type;
8709 isinstance = PyObject_IsInstance(obj, tp);
8710 if (isinstance == -1) {
8711 return 1;
8712 }
8713 if (isinstance) {
8714 expr_ty elt;
8715 asdl_comprehension_seq* generators;
8716
8717 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8718 return 1;
8719 }
8720 if (tmp == NULL) {
8721 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
8722 return 1;
8723 }
8724 else {
8725 int res;
8726 if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8727 goto failed;
8728 }
8729 res = obj2ast_expr(state, tmp, &elt, arena);
8730 _Py_LeaveRecursiveCall();
8731 if (res != 0) goto failed;
8732 Py_CLEAR(tmp);
8733 }
8734 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8735 return 1;
8736 }
8737 if (tmp == NULL) {
8738 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
8739 return 1;
8740 }
8741 else {
8742 int res;
8743 Py_ssize_t len;
8744 Py_ssize_t i;
8745 if (!PyList_Check(tmp)) {
8746 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8747 goto failed;
8748 }
8749 len = PyList_GET_SIZE(tmp);
8750 generators = _Py_asdl_comprehension_seq_new(len, arena);
8751 if (generators == NULL) goto failed;
8752 for (i = 0; i < len; i++) {
8753 comprehension_ty val;
8754 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8755 Py_INCREF(tmp2);
8756 if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8757 goto failed;
8758 }
8759 res = obj2ast_comprehension(state, tmp2, &val, arena);
8760 _Py_LeaveRecursiveCall();
8761 Py_DECREF(tmp2);
8762 if (res != 0) goto failed;
8763 if (len != PyList_GET_SIZE(tmp)) {
8764 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
8765 goto failed;
8766 }
8767 asdl_seq_SET(generators, i, val);
8768 }
8769 Py_CLEAR(tmp);
8770 }
8771 *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
8772 end_col_offset, arena);
8773 if (*out == NULL) goto failed;
8774 return 0;
8775 }
8776 tp = state->SetComp_type;
8777 isinstance = PyObject_IsInstance(obj, tp);
8778 if (isinstance == -1) {
8779 return 1;
8780 }
8781 if (isinstance) {
8782 expr_ty elt;
8783 asdl_comprehension_seq* generators;
8784
8785 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8786 return 1;
8787 }
8788 if (tmp == NULL) {
8789 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
8790 return 1;
8791 }
8792 else {
8793 int res;
8794 if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8795 goto failed;
8796 }
8797 res = obj2ast_expr(state, tmp, &elt, arena);
8798 _Py_LeaveRecursiveCall();
8799 if (res != 0) goto failed;
8800 Py_CLEAR(tmp);
8801 }
8802 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8803 return 1;
8804 }
8805 if (tmp == NULL) {
8806 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
8807 return 1;
8808 }
8809 else {
8810 int res;
8811 Py_ssize_t len;
8812 Py_ssize_t i;
8813 if (!PyList_Check(tmp)) {
8814 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8815 goto failed;
8816 }
8817 len = PyList_GET_SIZE(tmp);
8818 generators = _Py_asdl_comprehension_seq_new(len, arena);
8819 if (generators == NULL) goto failed;
8820 for (i = 0; i < len; i++) {
8821 comprehension_ty val;
8822 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8823 Py_INCREF(tmp2);
8824 if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8825 goto failed;
8826 }
8827 res = obj2ast_comprehension(state, tmp2, &val, arena);
8828 _Py_LeaveRecursiveCall();
8829 Py_DECREF(tmp2);
8830 if (res != 0) goto failed;
8831 if (len != PyList_GET_SIZE(tmp)) {
8832 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
8833 goto failed;
8834 }
8835 asdl_seq_SET(generators, i, val);
8836 }
8837 Py_CLEAR(tmp);
8838 }
8839 *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
8840 end_col_offset, arena);
8841 if (*out == NULL) goto failed;
8842 return 0;
8843 }
8844 tp = state->DictComp_type;
8845 isinstance = PyObject_IsInstance(obj, tp);
8846 if (isinstance == -1) {
8847 return 1;
8848 }
8849 if (isinstance) {
8850 expr_ty key;
8851 expr_ty value;
8852 asdl_comprehension_seq* generators;
8853
8854 if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
8855 return 1;
8856 }
8857 if (tmp == NULL) {
8858 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
8859 return 1;
8860 }
8861 else {
8862 int res;
8863 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8864 goto failed;
8865 }
8866 res = obj2ast_expr(state, tmp, &key, arena);
8867 _Py_LeaveRecursiveCall();
8868 if (res != 0) goto failed;
8869 Py_CLEAR(tmp);
8870 }
8871 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8872 return 1;
8873 }
8874 if (tmp == NULL) {
8875 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
8876 return 1;
8877 }
8878 else {
8879 int res;
8880 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8881 goto failed;
8882 }
8883 res = obj2ast_expr(state, tmp, &value, arena);
8884 _Py_LeaveRecursiveCall();
8885 if (res != 0) goto failed;
8886 Py_CLEAR(tmp);
8887 }
8888 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8889 return 1;
8890 }
8891 if (tmp == NULL) {
8892 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
8893 return 1;
8894 }
8895 else {
8896 int res;
8897 Py_ssize_t len;
8898 Py_ssize_t i;
8899 if (!PyList_Check(tmp)) {
8900 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8901 goto failed;
8902 }
8903 len = PyList_GET_SIZE(tmp);
8904 generators = _Py_asdl_comprehension_seq_new(len, arena);
8905 if (generators == NULL) goto failed;
8906 for (i = 0; i < len; i++) {
8907 comprehension_ty val;
8908 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8909 Py_INCREF(tmp2);
8910 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8911 goto failed;
8912 }
8913 res = obj2ast_comprehension(state, tmp2, &val, arena);
8914 _Py_LeaveRecursiveCall();
8915 Py_DECREF(tmp2);
8916 if (res != 0) goto failed;
8917 if (len != PyList_GET_SIZE(tmp)) {
8918 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
8919 goto failed;
8920 }
8921 asdl_seq_SET(generators, i, val);
8922 }
8923 Py_CLEAR(tmp);
8924 }
8925 *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
8926 end_lineno, end_col_offset, arena);
8927 if (*out == NULL) goto failed;
8928 return 0;
8929 }
8930 tp = state->GeneratorExp_type;
8931 isinstance = PyObject_IsInstance(obj, tp);
8932 if (isinstance == -1) {
8933 return 1;
8934 }
8935 if (isinstance) {
8936 expr_ty elt;
8937 asdl_comprehension_seq* generators;
8938
8939 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8940 return 1;
8941 }
8942 if (tmp == NULL) {
8943 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
8944 return 1;
8945 }
8946 else {
8947 int res;
8948 if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8949 goto failed;
8950 }
8951 res = obj2ast_expr(state, tmp, &elt, arena);
8952 _Py_LeaveRecursiveCall();
8953 if (res != 0) goto failed;
8954 Py_CLEAR(tmp);
8955 }
8956 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8957 return 1;
8958 }
8959 if (tmp == NULL) {
8960 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
8961 return 1;
8962 }
8963 else {
8964 int res;
8965 Py_ssize_t len;
8966 Py_ssize_t i;
8967 if (!PyList_Check(tmp)) {
8968 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8969 goto failed;
8970 }
8971 len = PyList_GET_SIZE(tmp);
8972 generators = _Py_asdl_comprehension_seq_new(len, arena);
8973 if (generators == NULL) goto failed;
8974 for (i = 0; i < len; i++) {
8975 comprehension_ty val;
8976 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8977 Py_INCREF(tmp2);
8978 if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8979 goto failed;
8980 }
8981 res = obj2ast_comprehension(state, tmp2, &val, arena);
8982 _Py_LeaveRecursiveCall();
8983 Py_DECREF(tmp2);
8984 if (res != 0) goto failed;
8985 if (len != PyList_GET_SIZE(tmp)) {
8986 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
8987 goto failed;
8988 }
8989 asdl_seq_SET(generators, i, val);
8990 }
8991 Py_CLEAR(tmp);
8992 }
8993 *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
8994 end_lineno, end_col_offset, arena);
8995 if (*out == NULL) goto failed;
8996 return 0;
8997 }
8998 tp = state->Await_type;
8999 isinstance = PyObject_IsInstance(obj, tp);
9000 if (isinstance == -1) {
9001 return 1;
9002 }
9003 if (isinstance) {
9004 expr_ty value;
9005
9006 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9007 return 1;
9008 }
9009 if (tmp == NULL) {
9010 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
9011 return 1;
9012 }
9013 else {
9014 int res;
9015 if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
9016 goto failed;
9017 }
9018 res = obj2ast_expr(state, tmp, &value, arena);
9019 _Py_LeaveRecursiveCall();
9020 if (res != 0) goto failed;
9021 Py_CLEAR(tmp);
9022 }
9023 *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
9024 end_col_offset, arena);
9025 if (*out == NULL) goto failed;
9026 return 0;
9027 }
9028 tp = state->Yield_type;
9029 isinstance = PyObject_IsInstance(obj, tp);
9030 if (isinstance == -1) {
9031 return 1;
9032 }
9033 if (isinstance) {
9034 expr_ty value;
9035
9036 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9037 return 1;
9038 }
9039 if (tmp == NULL || tmp == Py_None) {
9040 Py_CLEAR(tmp);
9041 value = NULL;
9042 }
9043 else {
9044 int res;
9045 if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
9046 goto failed;
9047 }
9048 res = obj2ast_expr(state, tmp, &value, arena);
9049 _Py_LeaveRecursiveCall();
9050 if (res != 0) goto failed;
9051 Py_CLEAR(tmp);
9052 }
9053 *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
9054 end_col_offset, arena);
9055 if (*out == NULL) goto failed;
9056 return 0;
9057 }
9058 tp = state->YieldFrom_type;
9059 isinstance = PyObject_IsInstance(obj, tp);
9060 if (isinstance == -1) {
9061 return 1;
9062 }
9063 if (isinstance) {
9064 expr_ty value;
9065
9066 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9067 return 1;
9068 }
9069 if (tmp == NULL) {
9070 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
9071 return 1;
9072 }
9073 else {
9074 int res;
9075 if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
9076 goto failed;
9077 }
9078 res = obj2ast_expr(state, tmp, &value, arena);
9079 _Py_LeaveRecursiveCall();
9080 if (res != 0) goto failed;
9081 Py_CLEAR(tmp);
9082 }
9083 *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
9084 end_col_offset, arena);
9085 if (*out == NULL) goto failed;
9086 return 0;
9087 }
9088 tp = state->Compare_type;
9089 isinstance = PyObject_IsInstance(obj, tp);
9090 if (isinstance == -1) {
9091 return 1;
9092 }
9093 if (isinstance) {
9094 expr_ty left;
9095 asdl_int_seq* ops;
9096 asdl_expr_seq* comparators;
9097
9098 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
9099 return 1;
9100 }
9101 if (tmp == NULL) {
9102 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
9103 return 1;
9104 }
9105 else {
9106 int res;
9107 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9108 goto failed;
9109 }
9110 res = obj2ast_expr(state, tmp, &left, arena);
9111 _Py_LeaveRecursiveCall();
9112 if (res != 0) goto failed;
9113 Py_CLEAR(tmp);
9114 }
9115 if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
9116 return 1;
9117 }
9118 if (tmp == NULL) {
9119 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
9120 return 1;
9121 }
9122 else {
9123 int res;
9124 Py_ssize_t len;
9125 Py_ssize_t i;
9126 if (!PyList_Check(tmp)) {
9127 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9128 goto failed;
9129 }
9130 len = PyList_GET_SIZE(tmp);
9131 ops = _Py_asdl_int_seq_new(len, arena);
9132 if (ops == NULL) goto failed;
9133 for (i = 0; i < len; i++) {
9134 cmpop_ty val;
9135 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9136 Py_INCREF(tmp2);
9137 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9138 goto failed;
9139 }
9140 res = obj2ast_cmpop(state, tmp2, &val, arena);
9141 _Py_LeaveRecursiveCall();
9142 Py_DECREF(tmp2);
9143 if (res != 0) goto failed;
9144 if (len != PyList_GET_SIZE(tmp)) {
9145 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
9146 goto failed;
9147 }
9148 asdl_seq_SET(ops, i, val);
9149 }
9150 Py_CLEAR(tmp);
9151 }
9152 if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
9153 return 1;
9154 }
9155 if (tmp == NULL) {
9156 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
9157 return 1;
9158 }
9159 else {
9160 int res;
9161 Py_ssize_t len;
9162 Py_ssize_t i;
9163 if (!PyList_Check(tmp)) {
9164 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9165 goto failed;
9166 }
9167 len = PyList_GET_SIZE(tmp);
9168 comparators = _Py_asdl_expr_seq_new(len, arena);
9169 if (comparators == NULL) goto failed;
9170 for (i = 0; i < len; i++) {
9171 expr_ty val;
9172 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9173 Py_INCREF(tmp2);
9174 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
9175 goto failed;
9176 }
9177 res = obj2ast_expr(state, tmp2, &val, arena);
9178 _Py_LeaveRecursiveCall();
9179 Py_DECREF(tmp2);
9180 if (res != 0) goto failed;
9181 if (len != PyList_GET_SIZE(tmp)) {
9182 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
9183 goto failed;
9184 }
9185 asdl_seq_SET(comparators, i, val);
9186 }
9187 Py_CLEAR(tmp);
9188 }
9189 *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
9190 end_lineno, end_col_offset, arena);
9191 if (*out == NULL) goto failed;
9192 return 0;
9193 }
9194 tp = state->Call_type;
9195 isinstance = PyObject_IsInstance(obj, tp);
9196 if (isinstance == -1) {
9197 return 1;
9198 }
9199 if (isinstance) {
9200 expr_ty func;
9201 asdl_expr_seq* args;
9202 asdl_keyword_seq* keywords;
9203
9204 if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
9205 return 1;
9206 }
9207 if (tmp == NULL) {
9208 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
9209 return 1;
9210 }
9211 else {
9212 int res;
9213 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9214 goto failed;
9215 }
9216 res = obj2ast_expr(state, tmp, &func, arena);
9217 _Py_LeaveRecursiveCall();
9218 if (res != 0) goto failed;
9219 Py_CLEAR(tmp);
9220 }
9221 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
9222 return 1;
9223 }
9224 if (tmp == NULL) {
9225 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
9226 return 1;
9227 }
9228 else {
9229 int res;
9230 Py_ssize_t len;
9231 Py_ssize_t i;
9232 if (!PyList_Check(tmp)) {
9233 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9234 goto failed;
9235 }
9236 len = PyList_GET_SIZE(tmp);
9237 args = _Py_asdl_expr_seq_new(len, arena);
9238 if (args == NULL) goto failed;
9239 for (i = 0; i < len; i++) {
9240 expr_ty val;
9241 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9242 Py_INCREF(tmp2);
9243 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9244 goto failed;
9245 }
9246 res = obj2ast_expr(state, tmp2, &val, arena);
9247 _Py_LeaveRecursiveCall();
9248 Py_DECREF(tmp2);
9249 if (res != 0) goto failed;
9250 if (len != PyList_GET_SIZE(tmp)) {
9251 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
9252 goto failed;
9253 }
9254 asdl_seq_SET(args, i, val);
9255 }
9256 Py_CLEAR(tmp);
9257 }
9258 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
9259 return 1;
9260 }
9261 if (tmp == NULL) {
9262 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
9263 return 1;
9264 }
9265 else {
9266 int res;
9267 Py_ssize_t len;
9268 Py_ssize_t i;
9269 if (!PyList_Check(tmp)) {
9270 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9271 goto failed;
9272 }
9273 len = PyList_GET_SIZE(tmp);
9274 keywords = _Py_asdl_keyword_seq_new(len, arena);
9275 if (keywords == NULL) goto failed;
9276 for (i = 0; i < len; i++) {
9277 keyword_ty val;
9278 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9279 Py_INCREF(tmp2);
9280 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
9281 goto failed;
9282 }
9283 res = obj2ast_keyword(state, tmp2, &val, arena);
9284 _Py_LeaveRecursiveCall();
9285 Py_DECREF(tmp2);
9286 if (res != 0) goto failed;
9287 if (len != PyList_GET_SIZE(tmp)) {
9288 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
9289 goto failed;
9290 }
9291 asdl_seq_SET(keywords, i, val);
9292 }
9293 Py_CLEAR(tmp);
9294 }
9295 *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
9296 end_lineno, end_col_offset, arena);
9297 if (*out == NULL) goto failed;
9298 return 0;
9299 }
9300 tp = state->FormattedValue_type;
9301 isinstance = PyObject_IsInstance(obj, tp);
9302 if (isinstance == -1) {
9303 return 1;
9304 }
9305 if (isinstance) {
9306 expr_ty value;
9307 int conversion;
9308 expr_ty format_spec;
9309
9310 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9311 return 1;
9312 }
9313 if (tmp == NULL) {
9314 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
9315 return 1;
9316 }
9317 else {
9318 int res;
9319 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9320 goto failed;
9321 }
9322 res = obj2ast_expr(state, tmp, &value, arena);
9323 _Py_LeaveRecursiveCall();
9324 if (res != 0) goto failed;
9325 Py_CLEAR(tmp);
9326 }
9327 if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
9328 return 1;
9329 }
9330 if (tmp == NULL) {
9331 PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
9332 return 1;
9333 }
9334 else {
9335 int res;
9336 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9337 goto failed;
9338 }
9339 res = obj2ast_int(state, tmp, &conversion, arena);
9340 _Py_LeaveRecursiveCall();
9341 if (res != 0) goto failed;
9342 Py_CLEAR(tmp);
9343 }
9344 if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
9345 return 1;
9346 }
9347 if (tmp == NULL || tmp == Py_None) {
9348 Py_CLEAR(tmp);
9349 format_spec = NULL;
9350 }
9351 else {
9352 int res;
9353 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9354 goto failed;
9355 }
9356 res = obj2ast_expr(state, tmp, &format_spec, arena);
9357 _Py_LeaveRecursiveCall();
9358 if (res != 0) goto failed;
9359 Py_CLEAR(tmp);
9360 }
9361 *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
9362 col_offset, end_lineno, end_col_offset,
9363 arena);
9364 if (*out == NULL) goto failed;
9365 return 0;
9366 }
9367 tp = state->JoinedStr_type;
9368 isinstance = PyObject_IsInstance(obj, tp);
9369 if (isinstance == -1) {
9370 return 1;
9371 }
9372 if (isinstance) {
9373 asdl_expr_seq* values;
9374
9375 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
9376 return 1;
9377 }
9378 if (tmp == NULL) {
9379 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
9380 return 1;
9381 }
9382 else {
9383 int res;
9384 Py_ssize_t len;
9385 Py_ssize_t i;
9386 if (!PyList_Check(tmp)) {
9387 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9388 goto failed;
9389 }
9390 len = PyList_GET_SIZE(tmp);
9391 values = _Py_asdl_expr_seq_new(len, arena);
9392 if (values == NULL) goto failed;
9393 for (i = 0; i < len; i++) {
9394 expr_ty val;
9395 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9396 Py_INCREF(tmp2);
9397 if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
9398 goto failed;
9399 }
9400 res = obj2ast_expr(state, tmp2, &val, arena);
9401 _Py_LeaveRecursiveCall();
9402 Py_DECREF(tmp2);
9403 if (res != 0) goto failed;
9404 if (len != PyList_GET_SIZE(tmp)) {
9405 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
9406 goto failed;
9407 }
9408 asdl_seq_SET(values, i, val);
9409 }
9410 Py_CLEAR(tmp);
9411 }
9412 *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
9413 end_col_offset, arena);
9414 if (*out == NULL) goto failed;
9415 return 0;
9416 }
9417 tp = state->Constant_type;
9418 isinstance = PyObject_IsInstance(obj, tp);
9419 if (isinstance == -1) {
9420 return 1;
9421 }
9422 if (isinstance) {
9423 constant value;
9424 string kind;
9425
9426 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9427 return 1;
9428 }
9429 if (tmp == NULL) {
9430 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
9431 return 1;
9432 }
9433 else {
9434 int res;
9435 if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9436 goto failed;
9437 }
9438 res = obj2ast_constant(state, tmp, &value, arena);
9439 _Py_LeaveRecursiveCall();
9440 if (res != 0) goto failed;
9441 Py_CLEAR(tmp);
9442 }
9443 if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
9444 return 1;
9445 }
9446 if (tmp == NULL || tmp == Py_None) {
9447 Py_CLEAR(tmp);
9448 kind = NULL;
9449 }
9450 else {
9451 int res;
9452 if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9453 goto failed;
9454 }
9455 res = obj2ast_string(state, tmp, &kind, arena);
9456 _Py_LeaveRecursiveCall();
9457 if (res != 0) goto failed;
9458 Py_CLEAR(tmp);
9459 }
9460 *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
9461 end_col_offset, arena);
9462 if (*out == NULL) goto failed;
9463 return 0;
9464 }
9465 tp = state->Attribute_type;
9466 isinstance = PyObject_IsInstance(obj, tp);
9467 if (isinstance == -1) {
9468 return 1;
9469 }
9470 if (isinstance) {
9471 expr_ty value;
9472 identifier attr;
9473 expr_context_ty ctx;
9474
9475 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9476 return 1;
9477 }
9478 if (tmp == NULL) {
9479 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
9480 return 1;
9481 }
9482 else {
9483 int res;
9484 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9485 goto failed;
9486 }
9487 res = obj2ast_expr(state, tmp, &value, arena);
9488 _Py_LeaveRecursiveCall();
9489 if (res != 0) goto failed;
9490 Py_CLEAR(tmp);
9491 }
9492 if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
9493 return 1;
9494 }
9495 if (tmp == NULL) {
9496 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
9497 return 1;
9498 }
9499 else {
9500 int res;
9501 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9502 goto failed;
9503 }
9504 res = obj2ast_identifier(state, tmp, &attr, arena);
9505 _Py_LeaveRecursiveCall();
9506 if (res != 0) goto failed;
9507 Py_CLEAR(tmp);
9508 }
9509 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9510 return 1;
9511 }
9512 if (tmp == NULL) {
9513 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
9514 return 1;
9515 }
9516 else {
9517 int res;
9518 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9519 goto failed;
9520 }
9521 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9522 _Py_LeaveRecursiveCall();
9523 if (res != 0) goto failed;
9524 Py_CLEAR(tmp);
9525 }
9526 *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
9527 end_lineno, end_col_offset, arena);
9528 if (*out == NULL) goto failed;
9529 return 0;
9530 }
9531 tp = state->Subscript_type;
9532 isinstance = PyObject_IsInstance(obj, tp);
9533 if (isinstance == -1) {
9534 return 1;
9535 }
9536 if (isinstance) {
9537 expr_ty value;
9538 expr_ty slice;
9539 expr_context_ty ctx;
9540
9541 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9542 return 1;
9543 }
9544 if (tmp == NULL) {
9545 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
9546 return 1;
9547 }
9548 else {
9549 int res;
9550 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9551 goto failed;
9552 }
9553 res = obj2ast_expr(state, tmp, &value, arena);
9554 _Py_LeaveRecursiveCall();
9555 if (res != 0) goto failed;
9556 Py_CLEAR(tmp);
9557 }
9558 if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
9559 return 1;
9560 }
9561 if (tmp == NULL) {
9562 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
9563 return 1;
9564 }
9565 else {
9566 int res;
9567 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9568 goto failed;
9569 }
9570 res = obj2ast_expr(state, tmp, &slice, arena);
9571 _Py_LeaveRecursiveCall();
9572 if (res != 0) goto failed;
9573 Py_CLEAR(tmp);
9574 }
9575 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9576 return 1;
9577 }
9578 if (tmp == NULL) {
9579 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
9580 return 1;
9581 }
9582 else {
9583 int res;
9584 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9585 goto failed;
9586 }
9587 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9588 _Py_LeaveRecursiveCall();
9589 if (res != 0) goto failed;
9590 Py_CLEAR(tmp);
9591 }
9592 *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
9593 end_lineno, end_col_offset, arena);
9594 if (*out == NULL) goto failed;
9595 return 0;
9596 }
9597 tp = state->Starred_type;
9598 isinstance = PyObject_IsInstance(obj, tp);
9599 if (isinstance == -1) {
9600 return 1;
9601 }
9602 if (isinstance) {
9603 expr_ty value;
9604 expr_context_ty ctx;
9605
9606 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9607 return 1;
9608 }
9609 if (tmp == NULL) {
9610 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
9611 return 1;
9612 }
9613 else {
9614 int res;
9615 if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9616 goto failed;
9617 }
9618 res = obj2ast_expr(state, tmp, &value, arena);
9619 _Py_LeaveRecursiveCall();
9620 if (res != 0) goto failed;
9621 Py_CLEAR(tmp);
9622 }
9623 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9624 return 1;
9625 }
9626 if (tmp == NULL) {
9627 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
9628 return 1;
9629 }
9630 else {
9631 int res;
9632 if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9633 goto failed;
9634 }
9635 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9636 _Py_LeaveRecursiveCall();
9637 if (res != 0) goto failed;
9638 Py_CLEAR(tmp);
9639 }
9640 *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
9641 end_col_offset, arena);
9642 if (*out == NULL) goto failed;
9643 return 0;
9644 }
9645 tp = state->Name_type;
9646 isinstance = PyObject_IsInstance(obj, tp);
9647 if (isinstance == -1) {
9648 return 1;
9649 }
9650 if (isinstance) {
9651 identifier id;
9652 expr_context_ty ctx;
9653
9654 if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
9655 return 1;
9656 }
9657 if (tmp == NULL) {
9658 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
9659 return 1;
9660 }
9661 else {
9662 int res;
9663 if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9664 goto failed;
9665 }
9666 res = obj2ast_identifier(state, tmp, &id, arena);
9667 _Py_LeaveRecursiveCall();
9668 if (res != 0) goto failed;
9669 Py_CLEAR(tmp);
9670 }
9671 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9672 return 1;
9673 }
9674 if (tmp == NULL) {
9675 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
9676 return 1;
9677 }
9678 else {
9679 int res;
9680 if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9681 goto failed;
9682 }
9683 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9684 _Py_LeaveRecursiveCall();
9685 if (res != 0) goto failed;
9686 Py_CLEAR(tmp);
9687 }
9688 *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
9689 end_col_offset, arena);
9690 if (*out == NULL) goto failed;
9691 return 0;
9692 }
9693 tp = state->List_type;
9694 isinstance = PyObject_IsInstance(obj, tp);
9695 if (isinstance == -1) {
9696 return 1;
9697 }
9698 if (isinstance) {
9699 asdl_expr_seq* elts;
9700 expr_context_ty ctx;
9701
9702 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
9703 return 1;
9704 }
9705 if (tmp == NULL) {
9706 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
9707 return 1;
9708 }
9709 else {
9710 int res;
9711 Py_ssize_t len;
9712 Py_ssize_t i;
9713 if (!PyList_Check(tmp)) {
9714 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9715 goto failed;
9716 }
9717 len = PyList_GET_SIZE(tmp);
9718 elts = _Py_asdl_expr_seq_new(len, arena);
9719 if (elts == NULL) goto failed;
9720 for (i = 0; i < len; i++) {
9721 expr_ty val;
9722 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9723 Py_INCREF(tmp2);
9724 if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
9725 goto failed;
9726 }
9727 res = obj2ast_expr(state, tmp2, &val, arena);
9728 _Py_LeaveRecursiveCall();
9729 Py_DECREF(tmp2);
9730 if (res != 0) goto failed;
9731 if (len != PyList_GET_SIZE(tmp)) {
9732 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
9733 goto failed;
9734 }
9735 asdl_seq_SET(elts, i, val);
9736 }
9737 Py_CLEAR(tmp);
9738 }
9739 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9740 return 1;
9741 }
9742 if (tmp == NULL) {
9743 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
9744 return 1;
9745 }
9746 else {
9747 int res;
9748 if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
9749 goto failed;
9750 }
9751 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9752 _Py_LeaveRecursiveCall();
9753 if (res != 0) goto failed;
9754 Py_CLEAR(tmp);
9755 }
9756 *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
9757 end_col_offset, arena);
9758 if (*out == NULL) goto failed;
9759 return 0;
9760 }
9761 tp = state->Tuple_type;
9762 isinstance = PyObject_IsInstance(obj, tp);
9763 if (isinstance == -1) {
9764 return 1;
9765 }
9766 if (isinstance) {
9767 asdl_expr_seq* elts;
9768 expr_context_ty ctx;
9769
9770 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
9771 return 1;
9772 }
9773 if (tmp == NULL) {
9774 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
9775 return 1;
9776 }
9777 else {
9778 int res;
9779 Py_ssize_t len;
9780 Py_ssize_t i;
9781 if (!PyList_Check(tmp)) {
9782 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9783 goto failed;
9784 }
9785 len = PyList_GET_SIZE(tmp);
9786 elts = _Py_asdl_expr_seq_new(len, arena);
9787 if (elts == NULL) goto failed;
9788 for (i = 0; i < len; i++) {
9789 expr_ty val;
9790 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9791 Py_INCREF(tmp2);
9792 if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9793 goto failed;
9794 }
9795 res = obj2ast_expr(state, tmp2, &val, arena);
9796 _Py_LeaveRecursiveCall();
9797 Py_DECREF(tmp2);
9798 if (res != 0) goto failed;
9799 if (len != PyList_GET_SIZE(tmp)) {
9800 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
9801 goto failed;
9802 }
9803 asdl_seq_SET(elts, i, val);
9804 }
9805 Py_CLEAR(tmp);
9806 }
9807 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9808 return 1;
9809 }
9810 if (tmp == NULL) {
9811 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
9812 return 1;
9813 }
9814 else {
9815 int res;
9816 if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9817 goto failed;
9818 }
9819 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9820 _Py_LeaveRecursiveCall();
9821 if (res != 0) goto failed;
9822 Py_CLEAR(tmp);
9823 }
9824 *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
9825 end_col_offset, arena);
9826 if (*out == NULL) goto failed;
9827 return 0;
9828 }
9829 tp = state->Slice_type;
9830 isinstance = PyObject_IsInstance(obj, tp);
9831 if (isinstance == -1) {
9832 return 1;
9833 }
9834 if (isinstance) {
9835 expr_ty lower;
9836 expr_ty upper;
9837 expr_ty step;
9838
9839 if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
9840 return 1;
9841 }
9842 if (tmp == NULL || tmp == Py_None) {
9843 Py_CLEAR(tmp);
9844 lower = NULL;
9845 }
9846 else {
9847 int res;
9848 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9849 goto failed;
9850 }
9851 res = obj2ast_expr(state, tmp, &lower, arena);
9852 _Py_LeaveRecursiveCall();
9853 if (res != 0) goto failed;
9854 Py_CLEAR(tmp);
9855 }
9856 if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
9857 return 1;
9858 }
9859 if (tmp == NULL || tmp == Py_None) {
9860 Py_CLEAR(tmp);
9861 upper = NULL;
9862 }
9863 else {
9864 int res;
9865 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9866 goto failed;
9867 }
9868 res = obj2ast_expr(state, tmp, &upper, arena);
9869 _Py_LeaveRecursiveCall();
9870 if (res != 0) goto failed;
9871 Py_CLEAR(tmp);
9872 }
9873 if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
9874 return 1;
9875 }
9876 if (tmp == NULL || tmp == Py_None) {
9877 Py_CLEAR(tmp);
9878 step = NULL;
9879 }
9880 else {
9881 int res;
9882 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9883 goto failed;
9884 }
9885 res = obj2ast_expr(state, tmp, &step, arena);
9886 _Py_LeaveRecursiveCall();
9887 if (res != 0) goto failed;
9888 Py_CLEAR(tmp);
9889 }
9890 *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
9891 end_col_offset, arena);
9892 if (*out == NULL) goto failed;
9893 return 0;
9894 }
9895
9896 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
9897 failed:
9898 Py_XDECREF(tmp);
9899 return 1;
9900 }
9901
9902 int
obj2ast_expr_context(struct ast_state * state,PyObject * obj,expr_context_ty * out,PyArena * arena)9903 obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
9904 out, PyArena* arena)
9905 {
9906 int isinstance;
9907
9908 isinstance = PyObject_IsInstance(obj, state->Load_type);
9909 if (isinstance == -1) {
9910 return 1;
9911 }
9912 if (isinstance) {
9913 *out = Load;
9914 return 0;
9915 }
9916 isinstance = PyObject_IsInstance(obj, state->Store_type);
9917 if (isinstance == -1) {
9918 return 1;
9919 }
9920 if (isinstance) {
9921 *out = Store;
9922 return 0;
9923 }
9924 isinstance = PyObject_IsInstance(obj, state->Del_type);
9925 if (isinstance == -1) {
9926 return 1;
9927 }
9928 if (isinstance) {
9929 *out = Del;
9930 return 0;
9931 }
9932
9933 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
9934 return 1;
9935 }
9936
9937 int
obj2ast_boolop(struct ast_state * state,PyObject * obj,boolop_ty * out,PyArena * arena)9938 obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
9939 arena)
9940 {
9941 int isinstance;
9942
9943 isinstance = PyObject_IsInstance(obj, state->And_type);
9944 if (isinstance == -1) {
9945 return 1;
9946 }
9947 if (isinstance) {
9948 *out = And;
9949 return 0;
9950 }
9951 isinstance = PyObject_IsInstance(obj, state->Or_type);
9952 if (isinstance == -1) {
9953 return 1;
9954 }
9955 if (isinstance) {
9956 *out = Or;
9957 return 0;
9958 }
9959
9960 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
9961 return 1;
9962 }
9963
9964 int
obj2ast_operator(struct ast_state * state,PyObject * obj,operator_ty * out,PyArena * arena)9965 obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
9966 PyArena* arena)
9967 {
9968 int isinstance;
9969
9970 isinstance = PyObject_IsInstance(obj, state->Add_type);
9971 if (isinstance == -1) {
9972 return 1;
9973 }
9974 if (isinstance) {
9975 *out = Add;
9976 return 0;
9977 }
9978 isinstance = PyObject_IsInstance(obj, state->Sub_type);
9979 if (isinstance == -1) {
9980 return 1;
9981 }
9982 if (isinstance) {
9983 *out = Sub;
9984 return 0;
9985 }
9986 isinstance = PyObject_IsInstance(obj, state->Mult_type);
9987 if (isinstance == -1) {
9988 return 1;
9989 }
9990 if (isinstance) {
9991 *out = Mult;
9992 return 0;
9993 }
9994 isinstance = PyObject_IsInstance(obj, state->MatMult_type);
9995 if (isinstance == -1) {
9996 return 1;
9997 }
9998 if (isinstance) {
9999 *out = MatMult;
10000 return 0;
10001 }
10002 isinstance = PyObject_IsInstance(obj, state->Div_type);
10003 if (isinstance == -1) {
10004 return 1;
10005 }
10006 if (isinstance) {
10007 *out = Div;
10008 return 0;
10009 }
10010 isinstance = PyObject_IsInstance(obj, state->Mod_type);
10011 if (isinstance == -1) {
10012 return 1;
10013 }
10014 if (isinstance) {
10015 *out = Mod;
10016 return 0;
10017 }
10018 isinstance = PyObject_IsInstance(obj, state->Pow_type);
10019 if (isinstance == -1) {
10020 return 1;
10021 }
10022 if (isinstance) {
10023 *out = Pow;
10024 return 0;
10025 }
10026 isinstance = PyObject_IsInstance(obj, state->LShift_type);
10027 if (isinstance == -1) {
10028 return 1;
10029 }
10030 if (isinstance) {
10031 *out = LShift;
10032 return 0;
10033 }
10034 isinstance = PyObject_IsInstance(obj, state->RShift_type);
10035 if (isinstance == -1) {
10036 return 1;
10037 }
10038 if (isinstance) {
10039 *out = RShift;
10040 return 0;
10041 }
10042 isinstance = PyObject_IsInstance(obj, state->BitOr_type);
10043 if (isinstance == -1) {
10044 return 1;
10045 }
10046 if (isinstance) {
10047 *out = BitOr;
10048 return 0;
10049 }
10050 isinstance = PyObject_IsInstance(obj, state->BitXor_type);
10051 if (isinstance == -1) {
10052 return 1;
10053 }
10054 if (isinstance) {
10055 *out = BitXor;
10056 return 0;
10057 }
10058 isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
10059 if (isinstance == -1) {
10060 return 1;
10061 }
10062 if (isinstance) {
10063 *out = BitAnd;
10064 return 0;
10065 }
10066 isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
10067 if (isinstance == -1) {
10068 return 1;
10069 }
10070 if (isinstance) {
10071 *out = FloorDiv;
10072 return 0;
10073 }
10074
10075 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
10076 return 1;
10077 }
10078
10079 int
obj2ast_unaryop(struct ast_state * state,PyObject * obj,unaryop_ty * out,PyArena * arena)10080 obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
10081 PyArena* arena)
10082 {
10083 int isinstance;
10084
10085 isinstance = PyObject_IsInstance(obj, state->Invert_type);
10086 if (isinstance == -1) {
10087 return 1;
10088 }
10089 if (isinstance) {
10090 *out = Invert;
10091 return 0;
10092 }
10093 isinstance = PyObject_IsInstance(obj, state->Not_type);
10094 if (isinstance == -1) {
10095 return 1;
10096 }
10097 if (isinstance) {
10098 *out = Not;
10099 return 0;
10100 }
10101 isinstance = PyObject_IsInstance(obj, state->UAdd_type);
10102 if (isinstance == -1) {
10103 return 1;
10104 }
10105 if (isinstance) {
10106 *out = UAdd;
10107 return 0;
10108 }
10109 isinstance = PyObject_IsInstance(obj, state->USub_type);
10110 if (isinstance == -1) {
10111 return 1;
10112 }
10113 if (isinstance) {
10114 *out = USub;
10115 return 0;
10116 }
10117
10118 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
10119 return 1;
10120 }
10121
10122 int
obj2ast_cmpop(struct ast_state * state,PyObject * obj,cmpop_ty * out,PyArena * arena)10123 obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
10124 arena)
10125 {
10126 int isinstance;
10127
10128 isinstance = PyObject_IsInstance(obj, state->Eq_type);
10129 if (isinstance == -1) {
10130 return 1;
10131 }
10132 if (isinstance) {
10133 *out = Eq;
10134 return 0;
10135 }
10136 isinstance = PyObject_IsInstance(obj, state->NotEq_type);
10137 if (isinstance == -1) {
10138 return 1;
10139 }
10140 if (isinstance) {
10141 *out = NotEq;
10142 return 0;
10143 }
10144 isinstance = PyObject_IsInstance(obj, state->Lt_type);
10145 if (isinstance == -1) {
10146 return 1;
10147 }
10148 if (isinstance) {
10149 *out = Lt;
10150 return 0;
10151 }
10152 isinstance = PyObject_IsInstance(obj, state->LtE_type);
10153 if (isinstance == -1) {
10154 return 1;
10155 }
10156 if (isinstance) {
10157 *out = LtE;
10158 return 0;
10159 }
10160 isinstance = PyObject_IsInstance(obj, state->Gt_type);
10161 if (isinstance == -1) {
10162 return 1;
10163 }
10164 if (isinstance) {
10165 *out = Gt;
10166 return 0;
10167 }
10168 isinstance = PyObject_IsInstance(obj, state->GtE_type);
10169 if (isinstance == -1) {
10170 return 1;
10171 }
10172 if (isinstance) {
10173 *out = GtE;
10174 return 0;
10175 }
10176 isinstance = PyObject_IsInstance(obj, state->Is_type);
10177 if (isinstance == -1) {
10178 return 1;
10179 }
10180 if (isinstance) {
10181 *out = Is;
10182 return 0;
10183 }
10184 isinstance = PyObject_IsInstance(obj, state->IsNot_type);
10185 if (isinstance == -1) {
10186 return 1;
10187 }
10188 if (isinstance) {
10189 *out = IsNot;
10190 return 0;
10191 }
10192 isinstance = PyObject_IsInstance(obj, state->In_type);
10193 if (isinstance == -1) {
10194 return 1;
10195 }
10196 if (isinstance) {
10197 *out = In;
10198 return 0;
10199 }
10200 isinstance = PyObject_IsInstance(obj, state->NotIn_type);
10201 if (isinstance == -1) {
10202 return 1;
10203 }
10204 if (isinstance) {
10205 *out = NotIn;
10206 return 0;
10207 }
10208
10209 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
10210 return 1;
10211 }
10212
10213 int
obj2ast_comprehension(struct ast_state * state,PyObject * obj,comprehension_ty * out,PyArena * arena)10214 obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
10215 out, PyArena* arena)
10216 {
10217 PyObject* tmp = NULL;
10218 expr_ty target;
10219 expr_ty iter;
10220 asdl_expr_seq* ifs;
10221 int is_async;
10222
10223 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
10224 return 1;
10225 }
10226 if (tmp == NULL) {
10227 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
10228 return 1;
10229 }
10230 else {
10231 int res;
10232 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10233 goto failed;
10234 }
10235 res = obj2ast_expr(state, tmp, &target, arena);
10236 _Py_LeaveRecursiveCall();
10237 if (res != 0) goto failed;
10238 Py_CLEAR(tmp);
10239 }
10240 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
10241 return 1;
10242 }
10243 if (tmp == NULL) {
10244 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
10245 return 1;
10246 }
10247 else {
10248 int res;
10249 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10250 goto failed;
10251 }
10252 res = obj2ast_expr(state, tmp, &iter, arena);
10253 _Py_LeaveRecursiveCall();
10254 if (res != 0) goto failed;
10255 Py_CLEAR(tmp);
10256 }
10257 if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
10258 return 1;
10259 }
10260 if (tmp == NULL) {
10261 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
10262 return 1;
10263 }
10264 else {
10265 int res;
10266 Py_ssize_t len;
10267 Py_ssize_t i;
10268 if (!PyList_Check(tmp)) {
10269 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10270 goto failed;
10271 }
10272 len = PyList_GET_SIZE(tmp);
10273 ifs = _Py_asdl_expr_seq_new(len, arena);
10274 if (ifs == NULL) goto failed;
10275 for (i = 0; i < len; i++) {
10276 expr_ty val;
10277 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10278 Py_INCREF(tmp2);
10279 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10280 goto failed;
10281 }
10282 res = obj2ast_expr(state, tmp2, &val, arena);
10283 _Py_LeaveRecursiveCall();
10284 Py_DECREF(tmp2);
10285 if (res != 0) goto failed;
10286 if (len != PyList_GET_SIZE(tmp)) {
10287 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
10288 goto failed;
10289 }
10290 asdl_seq_SET(ifs, i, val);
10291 }
10292 Py_CLEAR(tmp);
10293 }
10294 if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
10295 return 1;
10296 }
10297 if (tmp == NULL) {
10298 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
10299 return 1;
10300 }
10301 else {
10302 int res;
10303 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10304 goto failed;
10305 }
10306 res = obj2ast_int(state, tmp, &is_async, arena);
10307 _Py_LeaveRecursiveCall();
10308 if (res != 0) goto failed;
10309 Py_CLEAR(tmp);
10310 }
10311 *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
10312 return 0;
10313 failed:
10314 Py_XDECREF(tmp);
10315 return 1;
10316 }
10317
10318 int
obj2ast_excepthandler(struct ast_state * state,PyObject * obj,excepthandler_ty * out,PyArena * arena)10319 obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
10320 out, PyArena* arena)
10321 {
10322 int isinstance;
10323
10324 PyObject *tmp = NULL;
10325 PyObject *tp;
10326 int lineno;
10327 int col_offset;
10328 int end_lineno;
10329 int end_col_offset;
10330
10331 if (obj == Py_None) {
10332 *out = NULL;
10333 return 0;
10334 }
10335 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10336 return 1;
10337 }
10338 if (tmp == NULL) {
10339 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
10340 return 1;
10341 }
10342 else {
10343 int res;
10344 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10345 goto failed;
10346 }
10347 res = obj2ast_int(state, tmp, &lineno, arena);
10348 _Py_LeaveRecursiveCall();
10349 if (res != 0) goto failed;
10350 Py_CLEAR(tmp);
10351 }
10352 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10353 return 1;
10354 }
10355 if (tmp == NULL) {
10356 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
10357 return 1;
10358 }
10359 else {
10360 int res;
10361 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10362 goto failed;
10363 }
10364 res = obj2ast_int(state, tmp, &col_offset, arena);
10365 _Py_LeaveRecursiveCall();
10366 if (res != 0) goto failed;
10367 Py_CLEAR(tmp);
10368 }
10369 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10370 return 1;
10371 }
10372 if (tmp == NULL || tmp == Py_None) {
10373 Py_CLEAR(tmp);
10374 end_lineno = lineno;
10375 }
10376 else {
10377 int res;
10378 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10379 goto failed;
10380 }
10381 res = obj2ast_int(state, tmp, &end_lineno, arena);
10382 _Py_LeaveRecursiveCall();
10383 if (res != 0) goto failed;
10384 Py_CLEAR(tmp);
10385 }
10386 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10387 return 1;
10388 }
10389 if (tmp == NULL || tmp == Py_None) {
10390 Py_CLEAR(tmp);
10391 end_col_offset = col_offset;
10392 }
10393 else {
10394 int res;
10395 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10396 goto failed;
10397 }
10398 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10399 _Py_LeaveRecursiveCall();
10400 if (res != 0) goto failed;
10401 Py_CLEAR(tmp);
10402 }
10403 tp = state->ExceptHandler_type;
10404 isinstance = PyObject_IsInstance(obj, tp);
10405 if (isinstance == -1) {
10406 return 1;
10407 }
10408 if (isinstance) {
10409 expr_ty type;
10410 identifier name;
10411 asdl_stmt_seq* body;
10412
10413 if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
10414 return 1;
10415 }
10416 if (tmp == NULL || tmp == Py_None) {
10417 Py_CLEAR(tmp);
10418 type = NULL;
10419 }
10420 else {
10421 int res;
10422 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10423 goto failed;
10424 }
10425 res = obj2ast_expr(state, tmp, &type, arena);
10426 _Py_LeaveRecursiveCall();
10427 if (res != 0) goto failed;
10428 Py_CLEAR(tmp);
10429 }
10430 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
10431 return 1;
10432 }
10433 if (tmp == NULL || tmp == Py_None) {
10434 Py_CLEAR(tmp);
10435 name = NULL;
10436 }
10437 else {
10438 int res;
10439 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10440 goto failed;
10441 }
10442 res = obj2ast_identifier(state, tmp, &name, arena);
10443 _Py_LeaveRecursiveCall();
10444 if (res != 0) goto failed;
10445 Py_CLEAR(tmp);
10446 }
10447 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10448 return 1;
10449 }
10450 if (tmp == NULL) {
10451 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
10452 return 1;
10453 }
10454 else {
10455 int res;
10456 Py_ssize_t len;
10457 Py_ssize_t i;
10458 if (!PyList_Check(tmp)) {
10459 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10460 goto failed;
10461 }
10462 len = PyList_GET_SIZE(tmp);
10463 body = _Py_asdl_stmt_seq_new(len, arena);
10464 if (body == NULL) goto failed;
10465 for (i = 0; i < len; i++) {
10466 stmt_ty val;
10467 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10468 Py_INCREF(tmp2);
10469 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10470 goto failed;
10471 }
10472 res = obj2ast_stmt(state, tmp2, &val, arena);
10473 _Py_LeaveRecursiveCall();
10474 Py_DECREF(tmp2);
10475 if (res != 0) goto failed;
10476 if (len != PyList_GET_SIZE(tmp)) {
10477 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
10478 goto failed;
10479 }
10480 asdl_seq_SET(body, i, val);
10481 }
10482 Py_CLEAR(tmp);
10483 }
10484 *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
10485 end_lineno, end_col_offset, arena);
10486 if (*out == NULL) goto failed;
10487 return 0;
10488 }
10489
10490 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
10491 failed:
10492 Py_XDECREF(tmp);
10493 return 1;
10494 }
10495
10496 int
obj2ast_arguments(struct ast_state * state,PyObject * obj,arguments_ty * out,PyArena * arena)10497 obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
10498 PyArena* arena)
10499 {
10500 PyObject* tmp = NULL;
10501 asdl_arg_seq* posonlyargs;
10502 asdl_arg_seq* args;
10503 arg_ty vararg;
10504 asdl_arg_seq* kwonlyargs;
10505 asdl_expr_seq* kw_defaults;
10506 arg_ty kwarg;
10507 asdl_expr_seq* defaults;
10508
10509 if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
10510 return 1;
10511 }
10512 if (tmp == NULL) {
10513 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
10514 return 1;
10515 }
10516 else {
10517 int res;
10518 Py_ssize_t len;
10519 Py_ssize_t i;
10520 if (!PyList_Check(tmp)) {
10521 PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10522 goto failed;
10523 }
10524 len = PyList_GET_SIZE(tmp);
10525 posonlyargs = _Py_asdl_arg_seq_new(len, arena);
10526 if (posonlyargs == NULL) goto failed;
10527 for (i = 0; i < len; i++) {
10528 arg_ty val;
10529 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10530 Py_INCREF(tmp2);
10531 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10532 goto failed;
10533 }
10534 res = obj2ast_arg(state, tmp2, &val, arena);
10535 _Py_LeaveRecursiveCall();
10536 Py_DECREF(tmp2);
10537 if (res != 0) goto failed;
10538 if (len != PyList_GET_SIZE(tmp)) {
10539 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
10540 goto failed;
10541 }
10542 asdl_seq_SET(posonlyargs, i, val);
10543 }
10544 Py_CLEAR(tmp);
10545 }
10546 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
10547 return 1;
10548 }
10549 if (tmp == NULL) {
10550 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
10551 return 1;
10552 }
10553 else {
10554 int res;
10555 Py_ssize_t len;
10556 Py_ssize_t i;
10557 if (!PyList_Check(tmp)) {
10558 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10559 goto failed;
10560 }
10561 len = PyList_GET_SIZE(tmp);
10562 args = _Py_asdl_arg_seq_new(len, arena);
10563 if (args == NULL) goto failed;
10564 for (i = 0; i < len; i++) {
10565 arg_ty val;
10566 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10567 Py_INCREF(tmp2);
10568 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10569 goto failed;
10570 }
10571 res = obj2ast_arg(state, tmp2, &val, arena);
10572 _Py_LeaveRecursiveCall();
10573 Py_DECREF(tmp2);
10574 if (res != 0) goto failed;
10575 if (len != PyList_GET_SIZE(tmp)) {
10576 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
10577 goto failed;
10578 }
10579 asdl_seq_SET(args, i, val);
10580 }
10581 Py_CLEAR(tmp);
10582 }
10583 if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
10584 return 1;
10585 }
10586 if (tmp == NULL || tmp == Py_None) {
10587 Py_CLEAR(tmp);
10588 vararg = NULL;
10589 }
10590 else {
10591 int res;
10592 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10593 goto failed;
10594 }
10595 res = obj2ast_arg(state, tmp, &vararg, arena);
10596 _Py_LeaveRecursiveCall();
10597 if (res != 0) goto failed;
10598 Py_CLEAR(tmp);
10599 }
10600 if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
10601 return 1;
10602 }
10603 if (tmp == NULL) {
10604 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
10605 return 1;
10606 }
10607 else {
10608 int res;
10609 Py_ssize_t len;
10610 Py_ssize_t i;
10611 if (!PyList_Check(tmp)) {
10612 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10613 goto failed;
10614 }
10615 len = PyList_GET_SIZE(tmp);
10616 kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
10617 if (kwonlyargs == NULL) goto failed;
10618 for (i = 0; i < len; i++) {
10619 arg_ty val;
10620 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10621 Py_INCREF(tmp2);
10622 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10623 goto failed;
10624 }
10625 res = obj2ast_arg(state, tmp2, &val, arena);
10626 _Py_LeaveRecursiveCall();
10627 Py_DECREF(tmp2);
10628 if (res != 0) goto failed;
10629 if (len != PyList_GET_SIZE(tmp)) {
10630 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
10631 goto failed;
10632 }
10633 asdl_seq_SET(kwonlyargs, i, val);
10634 }
10635 Py_CLEAR(tmp);
10636 }
10637 if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
10638 return 1;
10639 }
10640 if (tmp == NULL) {
10641 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
10642 return 1;
10643 }
10644 else {
10645 int res;
10646 Py_ssize_t len;
10647 Py_ssize_t i;
10648 if (!PyList_Check(tmp)) {
10649 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10650 goto failed;
10651 }
10652 len = PyList_GET_SIZE(tmp);
10653 kw_defaults = _Py_asdl_expr_seq_new(len, arena);
10654 if (kw_defaults == NULL) goto failed;
10655 for (i = 0; i < len; i++) {
10656 expr_ty val;
10657 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10658 Py_INCREF(tmp2);
10659 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10660 goto failed;
10661 }
10662 res = obj2ast_expr(state, tmp2, &val, arena);
10663 _Py_LeaveRecursiveCall();
10664 Py_DECREF(tmp2);
10665 if (res != 0) goto failed;
10666 if (len != PyList_GET_SIZE(tmp)) {
10667 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
10668 goto failed;
10669 }
10670 asdl_seq_SET(kw_defaults, i, val);
10671 }
10672 Py_CLEAR(tmp);
10673 }
10674 if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
10675 return 1;
10676 }
10677 if (tmp == NULL || tmp == Py_None) {
10678 Py_CLEAR(tmp);
10679 kwarg = NULL;
10680 }
10681 else {
10682 int res;
10683 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10684 goto failed;
10685 }
10686 res = obj2ast_arg(state, tmp, &kwarg, arena);
10687 _Py_LeaveRecursiveCall();
10688 if (res != 0) goto failed;
10689 Py_CLEAR(tmp);
10690 }
10691 if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
10692 return 1;
10693 }
10694 if (tmp == NULL) {
10695 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
10696 return 1;
10697 }
10698 else {
10699 int res;
10700 Py_ssize_t len;
10701 Py_ssize_t i;
10702 if (!PyList_Check(tmp)) {
10703 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10704 goto failed;
10705 }
10706 len = PyList_GET_SIZE(tmp);
10707 defaults = _Py_asdl_expr_seq_new(len, arena);
10708 if (defaults == NULL) goto failed;
10709 for (i = 0; i < len; i++) {
10710 expr_ty val;
10711 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10712 Py_INCREF(tmp2);
10713 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10714 goto failed;
10715 }
10716 res = obj2ast_expr(state, tmp2, &val, arena);
10717 _Py_LeaveRecursiveCall();
10718 Py_DECREF(tmp2);
10719 if (res != 0) goto failed;
10720 if (len != PyList_GET_SIZE(tmp)) {
10721 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
10722 goto failed;
10723 }
10724 asdl_seq_SET(defaults, i, val);
10725 }
10726 Py_CLEAR(tmp);
10727 }
10728 *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
10729 kwarg, defaults, arena);
10730 return 0;
10731 failed:
10732 Py_XDECREF(tmp);
10733 return 1;
10734 }
10735
10736 int
obj2ast_arg(struct ast_state * state,PyObject * obj,arg_ty * out,PyArena * arena)10737 obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
10738 {
10739 PyObject* tmp = NULL;
10740 identifier arg;
10741 expr_ty annotation;
10742 string type_comment;
10743 int lineno;
10744 int col_offset;
10745 int end_lineno;
10746 int end_col_offset;
10747
10748 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
10749 return 1;
10750 }
10751 if (tmp == NULL) {
10752 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
10753 return 1;
10754 }
10755 else {
10756 int res;
10757 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10758 goto failed;
10759 }
10760 res = obj2ast_identifier(state, tmp, &arg, arena);
10761 _Py_LeaveRecursiveCall();
10762 if (res != 0) goto failed;
10763 Py_CLEAR(tmp);
10764 }
10765 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
10766 return 1;
10767 }
10768 if (tmp == NULL || tmp == Py_None) {
10769 Py_CLEAR(tmp);
10770 annotation = NULL;
10771 }
10772 else {
10773 int res;
10774 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10775 goto failed;
10776 }
10777 res = obj2ast_expr(state, tmp, &annotation, arena);
10778 _Py_LeaveRecursiveCall();
10779 if (res != 0) goto failed;
10780 Py_CLEAR(tmp);
10781 }
10782 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
10783 return 1;
10784 }
10785 if (tmp == NULL || tmp == Py_None) {
10786 Py_CLEAR(tmp);
10787 type_comment = NULL;
10788 }
10789 else {
10790 int res;
10791 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10792 goto failed;
10793 }
10794 res = obj2ast_string(state, tmp, &type_comment, arena);
10795 _Py_LeaveRecursiveCall();
10796 if (res != 0) goto failed;
10797 Py_CLEAR(tmp);
10798 }
10799 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10800 return 1;
10801 }
10802 if (tmp == NULL) {
10803 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
10804 return 1;
10805 }
10806 else {
10807 int res;
10808 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10809 goto failed;
10810 }
10811 res = obj2ast_int(state, tmp, &lineno, arena);
10812 _Py_LeaveRecursiveCall();
10813 if (res != 0) goto failed;
10814 Py_CLEAR(tmp);
10815 }
10816 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10817 return 1;
10818 }
10819 if (tmp == NULL) {
10820 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
10821 return 1;
10822 }
10823 else {
10824 int res;
10825 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10826 goto failed;
10827 }
10828 res = obj2ast_int(state, tmp, &col_offset, arena);
10829 _Py_LeaveRecursiveCall();
10830 if (res != 0) goto failed;
10831 Py_CLEAR(tmp);
10832 }
10833 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10834 return 1;
10835 }
10836 if (tmp == NULL || tmp == Py_None) {
10837 Py_CLEAR(tmp);
10838 end_lineno = lineno;
10839 }
10840 else {
10841 int res;
10842 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10843 goto failed;
10844 }
10845 res = obj2ast_int(state, tmp, &end_lineno, arena);
10846 _Py_LeaveRecursiveCall();
10847 if (res != 0) goto failed;
10848 Py_CLEAR(tmp);
10849 }
10850 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10851 return 1;
10852 }
10853 if (tmp == NULL || tmp == Py_None) {
10854 Py_CLEAR(tmp);
10855 end_col_offset = col_offset;
10856 }
10857 else {
10858 int res;
10859 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10860 goto failed;
10861 }
10862 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10863 _Py_LeaveRecursiveCall();
10864 if (res != 0) goto failed;
10865 Py_CLEAR(tmp);
10866 }
10867 *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
10868 end_lineno, end_col_offset, arena);
10869 return 0;
10870 failed:
10871 Py_XDECREF(tmp);
10872 return 1;
10873 }
10874
10875 int
obj2ast_keyword(struct ast_state * state,PyObject * obj,keyword_ty * out,PyArena * arena)10876 obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
10877 PyArena* arena)
10878 {
10879 PyObject* tmp = NULL;
10880 identifier arg;
10881 expr_ty value;
10882 int lineno;
10883 int col_offset;
10884 int end_lineno;
10885 int end_col_offset;
10886
10887 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
10888 return 1;
10889 }
10890 if (tmp == NULL || tmp == Py_None) {
10891 Py_CLEAR(tmp);
10892 arg = NULL;
10893 }
10894 else {
10895 int res;
10896 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10897 goto failed;
10898 }
10899 res = obj2ast_identifier(state, tmp, &arg, arena);
10900 _Py_LeaveRecursiveCall();
10901 if (res != 0) goto failed;
10902 Py_CLEAR(tmp);
10903 }
10904 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
10905 return 1;
10906 }
10907 if (tmp == NULL) {
10908 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
10909 return 1;
10910 }
10911 else {
10912 int res;
10913 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10914 goto failed;
10915 }
10916 res = obj2ast_expr(state, tmp, &value, arena);
10917 _Py_LeaveRecursiveCall();
10918 if (res != 0) goto failed;
10919 Py_CLEAR(tmp);
10920 }
10921 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10922 return 1;
10923 }
10924 if (tmp == NULL) {
10925 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
10926 return 1;
10927 }
10928 else {
10929 int res;
10930 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10931 goto failed;
10932 }
10933 res = obj2ast_int(state, tmp, &lineno, arena);
10934 _Py_LeaveRecursiveCall();
10935 if (res != 0) goto failed;
10936 Py_CLEAR(tmp);
10937 }
10938 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10939 return 1;
10940 }
10941 if (tmp == NULL) {
10942 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
10943 return 1;
10944 }
10945 else {
10946 int res;
10947 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10948 goto failed;
10949 }
10950 res = obj2ast_int(state, tmp, &col_offset, arena);
10951 _Py_LeaveRecursiveCall();
10952 if (res != 0) goto failed;
10953 Py_CLEAR(tmp);
10954 }
10955 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10956 return 1;
10957 }
10958 if (tmp == NULL || tmp == Py_None) {
10959 Py_CLEAR(tmp);
10960 end_lineno = lineno;
10961 }
10962 else {
10963 int res;
10964 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10965 goto failed;
10966 }
10967 res = obj2ast_int(state, tmp, &end_lineno, arena);
10968 _Py_LeaveRecursiveCall();
10969 if (res != 0) goto failed;
10970 Py_CLEAR(tmp);
10971 }
10972 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10973 return 1;
10974 }
10975 if (tmp == NULL || tmp == Py_None) {
10976 Py_CLEAR(tmp);
10977 end_col_offset = col_offset;
10978 }
10979 else {
10980 int res;
10981 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10982 goto failed;
10983 }
10984 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10985 _Py_LeaveRecursiveCall();
10986 if (res != 0) goto failed;
10987 Py_CLEAR(tmp);
10988 }
10989 *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
10990 end_col_offset, arena);
10991 return 0;
10992 failed:
10993 Py_XDECREF(tmp);
10994 return 1;
10995 }
10996
10997 int
obj2ast_alias(struct ast_state * state,PyObject * obj,alias_ty * out,PyArena * arena)10998 obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
10999 arena)
11000 {
11001 PyObject* tmp = NULL;
11002 identifier name;
11003 identifier asname;
11004 int lineno;
11005 int col_offset;
11006 int end_lineno;
11007 int end_col_offset;
11008
11009 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11010 return 1;
11011 }
11012 if (tmp == NULL) {
11013 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
11014 return 1;
11015 }
11016 else {
11017 int res;
11018 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11019 goto failed;
11020 }
11021 res = obj2ast_identifier(state, tmp, &name, arena);
11022 _Py_LeaveRecursiveCall();
11023 if (res != 0) goto failed;
11024 Py_CLEAR(tmp);
11025 }
11026 if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
11027 return 1;
11028 }
11029 if (tmp == NULL || tmp == Py_None) {
11030 Py_CLEAR(tmp);
11031 asname = NULL;
11032 }
11033 else {
11034 int res;
11035 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11036 goto failed;
11037 }
11038 res = obj2ast_identifier(state, tmp, &asname, arena);
11039 _Py_LeaveRecursiveCall();
11040 if (res != 0) goto failed;
11041 Py_CLEAR(tmp);
11042 }
11043 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11044 return 1;
11045 }
11046 if (tmp == NULL) {
11047 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
11048 return 1;
11049 }
11050 else {
11051 int res;
11052 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11053 goto failed;
11054 }
11055 res = obj2ast_int(state, tmp, &lineno, arena);
11056 _Py_LeaveRecursiveCall();
11057 if (res != 0) goto failed;
11058 Py_CLEAR(tmp);
11059 }
11060 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11061 return 1;
11062 }
11063 if (tmp == NULL) {
11064 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
11065 return 1;
11066 }
11067 else {
11068 int res;
11069 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11070 goto failed;
11071 }
11072 res = obj2ast_int(state, tmp, &col_offset, arena);
11073 _Py_LeaveRecursiveCall();
11074 if (res != 0) goto failed;
11075 Py_CLEAR(tmp);
11076 }
11077 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11078 return 1;
11079 }
11080 if (tmp == NULL || tmp == Py_None) {
11081 Py_CLEAR(tmp);
11082 end_lineno = lineno;
11083 }
11084 else {
11085 int res;
11086 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11087 goto failed;
11088 }
11089 res = obj2ast_int(state, tmp, &end_lineno, arena);
11090 _Py_LeaveRecursiveCall();
11091 if (res != 0) goto failed;
11092 Py_CLEAR(tmp);
11093 }
11094 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11095 return 1;
11096 }
11097 if (tmp == NULL || tmp == Py_None) {
11098 Py_CLEAR(tmp);
11099 end_col_offset = col_offset;
11100 }
11101 else {
11102 int res;
11103 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
11104 goto failed;
11105 }
11106 res = obj2ast_int(state, tmp, &end_col_offset, arena);
11107 _Py_LeaveRecursiveCall();
11108 if (res != 0) goto failed;
11109 Py_CLEAR(tmp);
11110 }
11111 *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
11112 end_col_offset, arena);
11113 return 0;
11114 failed:
11115 Py_XDECREF(tmp);
11116 return 1;
11117 }
11118
11119 int
obj2ast_withitem(struct ast_state * state,PyObject * obj,withitem_ty * out,PyArena * arena)11120 obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
11121 PyArena* arena)
11122 {
11123 PyObject* tmp = NULL;
11124 expr_ty context_expr;
11125 expr_ty optional_vars;
11126
11127 if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
11128 return 1;
11129 }
11130 if (tmp == NULL) {
11131 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
11132 return 1;
11133 }
11134 else {
11135 int res;
11136 if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
11137 goto failed;
11138 }
11139 res = obj2ast_expr(state, tmp, &context_expr, arena);
11140 _Py_LeaveRecursiveCall();
11141 if (res != 0) goto failed;
11142 Py_CLEAR(tmp);
11143 }
11144 if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
11145 return 1;
11146 }
11147 if (tmp == NULL || tmp == Py_None) {
11148 Py_CLEAR(tmp);
11149 optional_vars = NULL;
11150 }
11151 else {
11152 int res;
11153 if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
11154 goto failed;
11155 }
11156 res = obj2ast_expr(state, tmp, &optional_vars, arena);
11157 _Py_LeaveRecursiveCall();
11158 if (res != 0) goto failed;
11159 Py_CLEAR(tmp);
11160 }
11161 *out = _PyAST_withitem(context_expr, optional_vars, arena);
11162 return 0;
11163 failed:
11164 Py_XDECREF(tmp);
11165 return 1;
11166 }
11167
11168 int
obj2ast_match_case(struct ast_state * state,PyObject * obj,match_case_ty * out,PyArena * arena)11169 obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
11170 PyArena* arena)
11171 {
11172 PyObject* tmp = NULL;
11173 pattern_ty pattern;
11174 expr_ty guard;
11175 asdl_stmt_seq* body;
11176
11177 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11178 return 1;
11179 }
11180 if (tmp == NULL) {
11181 PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
11182 return 1;
11183 }
11184 else {
11185 int res;
11186 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11187 goto failed;
11188 }
11189 res = obj2ast_pattern(state, tmp, &pattern, arena);
11190 _Py_LeaveRecursiveCall();
11191 if (res != 0) goto failed;
11192 Py_CLEAR(tmp);
11193 }
11194 if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
11195 return 1;
11196 }
11197 if (tmp == NULL || tmp == Py_None) {
11198 Py_CLEAR(tmp);
11199 guard = NULL;
11200 }
11201 else {
11202 int res;
11203 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11204 goto failed;
11205 }
11206 res = obj2ast_expr(state, tmp, &guard, arena);
11207 _Py_LeaveRecursiveCall();
11208 if (res != 0) goto failed;
11209 Py_CLEAR(tmp);
11210 }
11211 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
11212 return 1;
11213 }
11214 if (tmp == NULL) {
11215 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from match_case");
11216 return 1;
11217 }
11218 else {
11219 int res;
11220 Py_ssize_t len;
11221 Py_ssize_t i;
11222 if (!PyList_Check(tmp)) {
11223 PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11224 goto failed;
11225 }
11226 len = PyList_GET_SIZE(tmp);
11227 body = _Py_asdl_stmt_seq_new(len, arena);
11228 if (body == NULL) goto failed;
11229 for (i = 0; i < len; i++) {
11230 stmt_ty val;
11231 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11232 Py_INCREF(tmp2);
11233 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
11234 goto failed;
11235 }
11236 res = obj2ast_stmt(state, tmp2, &val, arena);
11237 _Py_LeaveRecursiveCall();
11238 Py_DECREF(tmp2);
11239 if (res != 0) goto failed;
11240 if (len != PyList_GET_SIZE(tmp)) {
11241 PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
11242 goto failed;
11243 }
11244 asdl_seq_SET(body, i, val);
11245 }
11246 Py_CLEAR(tmp);
11247 }
11248 *out = _PyAST_match_case(pattern, guard, body, arena);
11249 return 0;
11250 failed:
11251 Py_XDECREF(tmp);
11252 return 1;
11253 }
11254
11255 int
obj2ast_pattern(struct ast_state * state,PyObject * obj,pattern_ty * out,PyArena * arena)11256 obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
11257 PyArena* arena)
11258 {
11259 int isinstance;
11260
11261 PyObject *tmp = NULL;
11262 PyObject *tp;
11263 int lineno;
11264 int col_offset;
11265 int end_lineno;
11266 int end_col_offset;
11267
11268 if (obj == Py_None) {
11269 *out = NULL;
11270 return 0;
11271 }
11272 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11273 return 1;
11274 }
11275 if (tmp == NULL) {
11276 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
11277 return 1;
11278 }
11279 else {
11280 int res;
11281 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11282 goto failed;
11283 }
11284 res = obj2ast_int(state, tmp, &lineno, arena);
11285 _Py_LeaveRecursiveCall();
11286 if (res != 0) goto failed;
11287 Py_CLEAR(tmp);
11288 }
11289 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
11290 return 1;
11291 }
11292 if (tmp == NULL) {
11293 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
11294 return 1;
11295 }
11296 else {
11297 int res;
11298 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11299 goto failed;
11300 }
11301 res = obj2ast_int(state, tmp, &col_offset, arena);
11302 _Py_LeaveRecursiveCall();
11303 if (res != 0) goto failed;
11304 Py_CLEAR(tmp);
11305 }
11306 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11307 return 1;
11308 }
11309 if (tmp == NULL) {
11310 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
11311 return 1;
11312 }
11313 else {
11314 int res;
11315 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11316 goto failed;
11317 }
11318 res = obj2ast_int(state, tmp, &end_lineno, arena);
11319 _Py_LeaveRecursiveCall();
11320 if (res != 0) goto failed;
11321 Py_CLEAR(tmp);
11322 }
11323 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11324 return 1;
11325 }
11326 if (tmp == NULL) {
11327 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
11328 return 1;
11329 }
11330 else {
11331 int res;
11332 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11333 goto failed;
11334 }
11335 res = obj2ast_int(state, tmp, &end_col_offset, arena);
11336 _Py_LeaveRecursiveCall();
11337 if (res != 0) goto failed;
11338 Py_CLEAR(tmp);
11339 }
11340 tp = state->MatchValue_type;
11341 isinstance = PyObject_IsInstance(obj, tp);
11342 if (isinstance == -1) {
11343 return 1;
11344 }
11345 if (isinstance) {
11346 expr_ty value;
11347
11348 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11349 return 1;
11350 }
11351 if (tmp == NULL) {
11352 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
11353 return 1;
11354 }
11355 else {
11356 int res;
11357 if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
11358 goto failed;
11359 }
11360 res = obj2ast_expr(state, tmp, &value, arena);
11361 _Py_LeaveRecursiveCall();
11362 if (res != 0) goto failed;
11363 Py_CLEAR(tmp);
11364 }
11365 *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
11366 end_col_offset, arena);
11367 if (*out == NULL) goto failed;
11368 return 0;
11369 }
11370 tp = state->MatchSingleton_type;
11371 isinstance = PyObject_IsInstance(obj, tp);
11372 if (isinstance == -1) {
11373 return 1;
11374 }
11375 if (isinstance) {
11376 constant value;
11377
11378 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11379 return 1;
11380 }
11381 if (tmp == NULL) {
11382 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
11383 return 1;
11384 }
11385 else {
11386 int res;
11387 if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
11388 goto failed;
11389 }
11390 res = obj2ast_constant(state, tmp, &value, arena);
11391 _Py_LeaveRecursiveCall();
11392 if (res != 0) goto failed;
11393 Py_CLEAR(tmp);
11394 }
11395 *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
11396 end_col_offset, arena);
11397 if (*out == NULL) goto failed;
11398 return 0;
11399 }
11400 tp = state->MatchSequence_type;
11401 isinstance = PyObject_IsInstance(obj, tp);
11402 if (isinstance == -1) {
11403 return 1;
11404 }
11405 if (isinstance) {
11406 asdl_pattern_seq* patterns;
11407
11408 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11409 return 1;
11410 }
11411 if (tmp == NULL) {
11412 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchSequence");
11413 return 1;
11414 }
11415 else {
11416 int res;
11417 Py_ssize_t len;
11418 Py_ssize_t i;
11419 if (!PyList_Check(tmp)) {
11420 PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11421 goto failed;
11422 }
11423 len = PyList_GET_SIZE(tmp);
11424 patterns = _Py_asdl_pattern_seq_new(len, arena);
11425 if (patterns == NULL) goto failed;
11426 for (i = 0; i < len; i++) {
11427 pattern_ty val;
11428 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11429 Py_INCREF(tmp2);
11430 if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
11431 goto failed;
11432 }
11433 res = obj2ast_pattern(state, tmp2, &val, arena);
11434 _Py_LeaveRecursiveCall();
11435 Py_DECREF(tmp2);
11436 if (res != 0) goto failed;
11437 if (len != PyList_GET_SIZE(tmp)) {
11438 PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
11439 goto failed;
11440 }
11441 asdl_seq_SET(patterns, i, val);
11442 }
11443 Py_CLEAR(tmp);
11444 }
11445 *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
11446 end_col_offset, arena);
11447 if (*out == NULL) goto failed;
11448 return 0;
11449 }
11450 tp = state->MatchMapping_type;
11451 isinstance = PyObject_IsInstance(obj, tp);
11452 if (isinstance == -1) {
11453 return 1;
11454 }
11455 if (isinstance) {
11456 asdl_expr_seq* keys;
11457 asdl_pattern_seq* patterns;
11458 identifier rest;
11459
11460 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
11461 return 1;
11462 }
11463 if (tmp == NULL) {
11464 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from MatchMapping");
11465 return 1;
11466 }
11467 else {
11468 int res;
11469 Py_ssize_t len;
11470 Py_ssize_t i;
11471 if (!PyList_Check(tmp)) {
11472 PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11473 goto failed;
11474 }
11475 len = PyList_GET_SIZE(tmp);
11476 keys = _Py_asdl_expr_seq_new(len, arena);
11477 if (keys == NULL) goto failed;
11478 for (i = 0; i < len; i++) {
11479 expr_ty val;
11480 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11481 Py_INCREF(tmp2);
11482 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11483 goto failed;
11484 }
11485 res = obj2ast_expr(state, tmp2, &val, arena);
11486 _Py_LeaveRecursiveCall();
11487 Py_DECREF(tmp2);
11488 if (res != 0) goto failed;
11489 if (len != PyList_GET_SIZE(tmp)) {
11490 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
11491 goto failed;
11492 }
11493 asdl_seq_SET(keys, i, val);
11494 }
11495 Py_CLEAR(tmp);
11496 }
11497 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11498 return 1;
11499 }
11500 if (tmp == NULL) {
11501 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchMapping");
11502 return 1;
11503 }
11504 else {
11505 int res;
11506 Py_ssize_t len;
11507 Py_ssize_t i;
11508 if (!PyList_Check(tmp)) {
11509 PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11510 goto failed;
11511 }
11512 len = PyList_GET_SIZE(tmp);
11513 patterns = _Py_asdl_pattern_seq_new(len, arena);
11514 if (patterns == NULL) goto failed;
11515 for (i = 0; i < len; i++) {
11516 pattern_ty val;
11517 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11518 Py_INCREF(tmp2);
11519 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11520 goto failed;
11521 }
11522 res = obj2ast_pattern(state, tmp2, &val, arena);
11523 _Py_LeaveRecursiveCall();
11524 Py_DECREF(tmp2);
11525 if (res != 0) goto failed;
11526 if (len != PyList_GET_SIZE(tmp)) {
11527 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
11528 goto failed;
11529 }
11530 asdl_seq_SET(patterns, i, val);
11531 }
11532 Py_CLEAR(tmp);
11533 }
11534 if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
11535 return 1;
11536 }
11537 if (tmp == NULL || tmp == Py_None) {
11538 Py_CLEAR(tmp);
11539 rest = NULL;
11540 }
11541 else {
11542 int res;
11543 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11544 goto failed;
11545 }
11546 res = obj2ast_identifier(state, tmp, &rest, arena);
11547 _Py_LeaveRecursiveCall();
11548 if (res != 0) goto failed;
11549 Py_CLEAR(tmp);
11550 }
11551 *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
11552 end_lineno, end_col_offset, arena);
11553 if (*out == NULL) goto failed;
11554 return 0;
11555 }
11556 tp = state->MatchClass_type;
11557 isinstance = PyObject_IsInstance(obj, tp);
11558 if (isinstance == -1) {
11559 return 1;
11560 }
11561 if (isinstance) {
11562 expr_ty cls;
11563 asdl_pattern_seq* patterns;
11564 asdl_identifier_seq* kwd_attrs;
11565 asdl_pattern_seq* kwd_patterns;
11566
11567 if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
11568 return 1;
11569 }
11570 if (tmp == NULL) {
11571 PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
11572 return 1;
11573 }
11574 else {
11575 int res;
11576 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11577 goto failed;
11578 }
11579 res = obj2ast_expr(state, tmp, &cls, arena);
11580 _Py_LeaveRecursiveCall();
11581 if (res != 0) goto failed;
11582 Py_CLEAR(tmp);
11583 }
11584 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11585 return 1;
11586 }
11587 if (tmp == NULL) {
11588 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchClass");
11589 return 1;
11590 }
11591 else {
11592 int res;
11593 Py_ssize_t len;
11594 Py_ssize_t i;
11595 if (!PyList_Check(tmp)) {
11596 PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11597 goto failed;
11598 }
11599 len = PyList_GET_SIZE(tmp);
11600 patterns = _Py_asdl_pattern_seq_new(len, arena);
11601 if (patterns == NULL) goto failed;
11602 for (i = 0; i < len; i++) {
11603 pattern_ty val;
11604 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11605 Py_INCREF(tmp2);
11606 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11607 goto failed;
11608 }
11609 res = obj2ast_pattern(state, tmp2, &val, arena);
11610 _Py_LeaveRecursiveCall();
11611 Py_DECREF(tmp2);
11612 if (res != 0) goto failed;
11613 if (len != PyList_GET_SIZE(tmp)) {
11614 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
11615 goto failed;
11616 }
11617 asdl_seq_SET(patterns, i, val);
11618 }
11619 Py_CLEAR(tmp);
11620 }
11621 if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
11622 return 1;
11623 }
11624 if (tmp == NULL) {
11625 PyErr_SetString(PyExc_TypeError, "required field \"kwd_attrs\" missing from MatchClass");
11626 return 1;
11627 }
11628 else {
11629 int res;
11630 Py_ssize_t len;
11631 Py_ssize_t i;
11632 if (!PyList_Check(tmp)) {
11633 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11634 goto failed;
11635 }
11636 len = PyList_GET_SIZE(tmp);
11637 kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
11638 if (kwd_attrs == NULL) goto failed;
11639 for (i = 0; i < len; i++) {
11640 identifier val;
11641 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11642 Py_INCREF(tmp2);
11643 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11644 goto failed;
11645 }
11646 res = obj2ast_identifier(state, tmp2, &val, arena);
11647 _Py_LeaveRecursiveCall();
11648 Py_DECREF(tmp2);
11649 if (res != 0) goto failed;
11650 if (len != PyList_GET_SIZE(tmp)) {
11651 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
11652 goto failed;
11653 }
11654 asdl_seq_SET(kwd_attrs, i, val);
11655 }
11656 Py_CLEAR(tmp);
11657 }
11658 if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
11659 return 1;
11660 }
11661 if (tmp == NULL) {
11662 PyErr_SetString(PyExc_TypeError, "required field \"kwd_patterns\" missing from MatchClass");
11663 return 1;
11664 }
11665 else {
11666 int res;
11667 Py_ssize_t len;
11668 Py_ssize_t i;
11669 if (!PyList_Check(tmp)) {
11670 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11671 goto failed;
11672 }
11673 len = PyList_GET_SIZE(tmp);
11674 kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
11675 if (kwd_patterns == NULL) goto failed;
11676 for (i = 0; i < len; i++) {
11677 pattern_ty val;
11678 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11679 Py_INCREF(tmp2);
11680 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11681 goto failed;
11682 }
11683 res = obj2ast_pattern(state, tmp2, &val, arena);
11684 _Py_LeaveRecursiveCall();
11685 Py_DECREF(tmp2);
11686 if (res != 0) goto failed;
11687 if (len != PyList_GET_SIZE(tmp)) {
11688 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
11689 goto failed;
11690 }
11691 asdl_seq_SET(kwd_patterns, i, val);
11692 }
11693 Py_CLEAR(tmp);
11694 }
11695 *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
11696 lineno, col_offset, end_lineno,
11697 end_col_offset, arena);
11698 if (*out == NULL) goto failed;
11699 return 0;
11700 }
11701 tp = state->MatchStar_type;
11702 isinstance = PyObject_IsInstance(obj, tp);
11703 if (isinstance == -1) {
11704 return 1;
11705 }
11706 if (isinstance) {
11707 identifier name;
11708
11709 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11710 return 1;
11711 }
11712 if (tmp == NULL || tmp == Py_None) {
11713 Py_CLEAR(tmp);
11714 name = NULL;
11715 }
11716 else {
11717 int res;
11718 if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
11719 goto failed;
11720 }
11721 res = obj2ast_identifier(state, tmp, &name, arena);
11722 _Py_LeaveRecursiveCall();
11723 if (res != 0) goto failed;
11724 Py_CLEAR(tmp);
11725 }
11726 *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
11727 end_col_offset, arena);
11728 if (*out == NULL) goto failed;
11729 return 0;
11730 }
11731 tp = state->MatchAs_type;
11732 isinstance = PyObject_IsInstance(obj, tp);
11733 if (isinstance == -1) {
11734 return 1;
11735 }
11736 if (isinstance) {
11737 pattern_ty pattern;
11738 identifier name;
11739
11740 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11741 return 1;
11742 }
11743 if (tmp == NULL || tmp == Py_None) {
11744 Py_CLEAR(tmp);
11745 pattern = NULL;
11746 }
11747 else {
11748 int res;
11749 if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11750 goto failed;
11751 }
11752 res = obj2ast_pattern(state, tmp, &pattern, arena);
11753 _Py_LeaveRecursiveCall();
11754 if (res != 0) goto failed;
11755 Py_CLEAR(tmp);
11756 }
11757 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11758 return 1;
11759 }
11760 if (tmp == NULL || tmp == Py_None) {
11761 Py_CLEAR(tmp);
11762 name = NULL;
11763 }
11764 else {
11765 int res;
11766 if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11767 goto failed;
11768 }
11769 res = obj2ast_identifier(state, tmp, &name, arena);
11770 _Py_LeaveRecursiveCall();
11771 if (res != 0) goto failed;
11772 Py_CLEAR(tmp);
11773 }
11774 *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
11775 end_col_offset, arena);
11776 if (*out == NULL) goto failed;
11777 return 0;
11778 }
11779 tp = state->MatchOr_type;
11780 isinstance = PyObject_IsInstance(obj, tp);
11781 if (isinstance == -1) {
11782 return 1;
11783 }
11784 if (isinstance) {
11785 asdl_pattern_seq* patterns;
11786
11787 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11788 return 1;
11789 }
11790 if (tmp == NULL) {
11791 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchOr");
11792 return 1;
11793 }
11794 else {
11795 int res;
11796 Py_ssize_t len;
11797 Py_ssize_t i;
11798 if (!PyList_Check(tmp)) {
11799 PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11800 goto failed;
11801 }
11802 len = PyList_GET_SIZE(tmp);
11803 patterns = _Py_asdl_pattern_seq_new(len, arena);
11804 if (patterns == NULL) goto failed;
11805 for (i = 0; i < len; i++) {
11806 pattern_ty val;
11807 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11808 Py_INCREF(tmp2);
11809 if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
11810 goto failed;
11811 }
11812 res = obj2ast_pattern(state, tmp2, &val, arena);
11813 _Py_LeaveRecursiveCall();
11814 Py_DECREF(tmp2);
11815 if (res != 0) goto failed;
11816 if (len != PyList_GET_SIZE(tmp)) {
11817 PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
11818 goto failed;
11819 }
11820 asdl_seq_SET(patterns, i, val);
11821 }
11822 Py_CLEAR(tmp);
11823 }
11824 *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
11825 end_col_offset, arena);
11826 if (*out == NULL) goto failed;
11827 return 0;
11828 }
11829
11830 PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
11831 failed:
11832 Py_XDECREF(tmp);
11833 return 1;
11834 }
11835
11836 int
obj2ast_type_ignore(struct ast_state * state,PyObject * obj,type_ignore_ty * out,PyArena * arena)11837 obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
11838 out, PyArena* arena)
11839 {
11840 int isinstance;
11841
11842 PyObject *tmp = NULL;
11843 PyObject *tp;
11844
11845 if (obj == Py_None) {
11846 *out = NULL;
11847 return 0;
11848 }
11849 tp = state->TypeIgnore_type;
11850 isinstance = PyObject_IsInstance(obj, tp);
11851 if (isinstance == -1) {
11852 return 1;
11853 }
11854 if (isinstance) {
11855 int lineno;
11856 string tag;
11857
11858 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11859 return 1;
11860 }
11861 if (tmp == NULL) {
11862 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
11863 return 1;
11864 }
11865 else {
11866 int res;
11867 if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11868 goto failed;
11869 }
11870 res = obj2ast_int(state, tmp, &lineno, arena);
11871 _Py_LeaveRecursiveCall();
11872 if (res != 0) goto failed;
11873 Py_CLEAR(tmp);
11874 }
11875 if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
11876 return 1;
11877 }
11878 if (tmp == NULL) {
11879 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
11880 return 1;
11881 }
11882 else {
11883 int res;
11884 if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11885 goto failed;
11886 }
11887 res = obj2ast_string(state, tmp, &tag, arena);
11888 _Py_LeaveRecursiveCall();
11889 if (res != 0) goto failed;
11890 Py_CLEAR(tmp);
11891 }
11892 *out = _PyAST_TypeIgnore(lineno, tag, arena);
11893 if (*out == NULL) goto failed;
11894 return 0;
11895 }
11896
11897 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
11898 failed:
11899 Py_XDECREF(tmp);
11900 return 1;
11901 }
11902
11903
11904 static int
astmodule_exec(PyObject * m)11905 astmodule_exec(PyObject *m)
11906 {
11907 struct ast_state *state = get_ast_state();
11908 if (state == NULL) {
11909 return -1;
11910 }
11911 if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
11912 return -1;
11913 }
11914 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
11915 return -1;
11916 }
11917 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
11918 return -1;
11919 }
11920 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
11921 return -1;
11922 }
11923 if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
11924 return -1;
11925 }
11926 if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
11927 return -1;
11928 }
11929 if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
11930 return -1;
11931 }
11932 if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
11933 return -1;
11934 }
11935 if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
11936 {
11937 return -1;
11938 }
11939 if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
11940 return -1;
11941 }
11942 if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
11943 return -1;
11944 }
11945 if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
11946 state->AsyncFunctionDef_type) < 0) {
11947 return -1;
11948 }
11949 if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
11950 return -1;
11951 }
11952 if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
11953 return -1;
11954 }
11955 if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
11956 return -1;
11957 }
11958 if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
11959 return -1;
11960 }
11961 if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
11962 return -1;
11963 }
11964 if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
11965 return -1;
11966 }
11967 if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
11968 return -1;
11969 }
11970 if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
11971 return -1;
11972 }
11973 if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
11974 return -1;
11975 }
11976 if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
11977 return -1;
11978 }
11979 if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
11980 return -1;
11981 }
11982 if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
11983 return -1;
11984 }
11985 if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
11986 return -1;
11987 }
11988 if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
11989 return -1;
11990 }
11991 if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
11992 return -1;
11993 }
11994 if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
11995 return -1;
11996 }
11997 if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
11998 return -1;
11999 }
12000 if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
12001 return -1;
12002 }
12003 if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
12004 return -1;
12005 }
12006 if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
12007 return -1;
12008 }
12009 if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
12010 return -1;
12011 }
12012 if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
12013 return -1;
12014 }
12015 if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
12016 return -1;
12017 }
12018 if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
12019 return -1;
12020 }
12021 if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
12022 return -1;
12023 }
12024 if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
12025 return -1;
12026 }
12027 if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
12028 return -1;
12029 }
12030 if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
12031 return -1;
12032 }
12033 if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
12034 return -1;
12035 }
12036 if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
12037 return -1;
12038 }
12039 if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
12040 return -1;
12041 }
12042 if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
12043 return -1;
12044 }
12045 if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
12046 return -1;
12047 }
12048 if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
12049 return -1;
12050 }
12051 if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
12052 return -1;
12053 }
12054 if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
12055 return -1;
12056 }
12057 if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
12058 return -1;
12059 }
12060 if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
12061 {
12062 return -1;
12063 }
12064 if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
12065 return -1;
12066 }
12067 if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
12068 return -1;
12069 }
12070 if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
12071 return -1;
12072 }
12073 if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
12074 return -1;
12075 }
12076 if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
12077 return -1;
12078 }
12079 if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
12080 < 0) {
12081 return -1;
12082 }
12083 if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
12084 return -1;
12085 }
12086 if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
12087 return -1;
12088 }
12089 if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
12090 return -1;
12091 }
12092 if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
12093 return -1;
12094 }
12095 if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
12096 return -1;
12097 }
12098 if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
12099 return -1;
12100 }
12101 if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
12102 return -1;
12103 }
12104 if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
12105 return -1;
12106 }
12107 if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
12108 return -1;
12109 }
12110 if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
12111 {
12112 return -1;
12113 }
12114 if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
12115 return -1;
12116 }
12117 if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
12118 return -1;
12119 }
12120 if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
12121 return -1;
12122 }
12123 if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
12124 return -1;
12125 }
12126 if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
12127 return -1;
12128 }
12129 if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
12130 return -1;
12131 }
12132 if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
12133 return -1;
12134 }
12135 if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
12136 return -1;
12137 }
12138 if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
12139 return -1;
12140 }
12141 if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
12142 return -1;
12143 }
12144 if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
12145 return -1;
12146 }
12147 if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
12148 return -1;
12149 }
12150 if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
12151 return -1;
12152 }
12153 if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
12154 return -1;
12155 }
12156 if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
12157 return -1;
12158 }
12159 if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
12160 return -1;
12161 }
12162 if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
12163 return -1;
12164 }
12165 if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
12166 return -1;
12167 }
12168 if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
12169 return -1;
12170 }
12171 if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
12172 return -1;
12173 }
12174 if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
12175 return -1;
12176 }
12177 if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
12178 return -1;
12179 }
12180 if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
12181 return -1;
12182 }
12183 if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
12184 return -1;
12185 }
12186 if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
12187 return -1;
12188 }
12189 if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
12190 return -1;
12191 }
12192 if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
12193 return -1;
12194 }
12195 if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
12196 return -1;
12197 }
12198 if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
12199 return -1;
12200 }
12201 if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
12202 return -1;
12203 }
12204 if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
12205 return -1;
12206 }
12207 if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
12208 return -1;
12209 }
12210 if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
12211 return -1;
12212 }
12213 if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
12214 return -1;
12215 }
12216 if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
12217 return -1;
12218 }
12219 if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
12220 return -1;
12221 }
12222 if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
12223 0) {
12224 return -1;
12225 }
12226 if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
12227 0) {
12228 return -1;
12229 }
12230 if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
12231 0) {
12232 return -1;
12233 }
12234 if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
12235 return -1;
12236 }
12237 if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
12238 return -1;
12239 }
12240 if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
12241 return -1;
12242 }
12243 if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
12244 return -1;
12245 }
12246 if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
12247 return -1;
12248 }
12249 if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
12250 return -1;
12251 }
12252 if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
12253 return -1;
12254 }
12255 if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
12256 return -1;
12257 }
12258 if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
12259 < 0) {
12260 return -1;
12261 }
12262 if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
12263 0) {
12264 return -1;
12265 }
12266 if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
12267 {
12268 return -1;
12269 }
12270 if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
12271 return -1;
12272 }
12273 if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
12274 return -1;
12275 }
12276 if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
12277 return -1;
12278 }
12279 if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
12280 return -1;
12281 }
12282 if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
12283 return -1;
12284 }
12285 if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
12286 return -1;
12287 }
12288 return 0;
12289 }
12290
12291 static PyModuleDef_Slot astmodule_slots[] = {
12292 {Py_mod_exec, astmodule_exec},
12293 {0, NULL}
12294 };
12295
12296 static struct PyModuleDef _astmodule = {
12297 PyModuleDef_HEAD_INIT,
12298 .m_name = "_ast",
12299 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
12300 .m_size = 0,
12301 .m_slots = astmodule_slots,
12302 };
12303
12304 PyMODINIT_FUNC
PyInit__ast(void)12305 PyInit__ast(void)
12306 {
12307 return PyModuleDef_Init(&_astmodule);
12308 }
12309
12310
PyAST_mod2obj(mod_ty t)12311 PyObject* PyAST_mod2obj(mod_ty t)
12312 {
12313 struct ast_state *state = get_ast_state();
12314 if (state == NULL) {
12315 return NULL;
12316 }
12317
12318 int recursion_limit = Py_GetRecursionLimit();
12319 int starting_recursion_depth;
12320 /* Be careful here to prevent overflow. */
12321 int COMPILER_STACK_FRAME_SCALE = 3;
12322 PyThreadState *tstate = _PyThreadState_GET();
12323 if (!tstate) {
12324 return 0;
12325 }
12326 state->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
12327 recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
12328 int recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
12329 starting_recursion_depth = (recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
12330 recursion_depth * COMPILER_STACK_FRAME_SCALE : recursion_depth;
12331 state->recursion_depth = starting_recursion_depth;
12332
12333 PyObject *result = ast2obj_mod(state, t);
12334
12335 /* Check that the recursion depth counting balanced correctly */
12336 if (result && state->recursion_depth != starting_recursion_depth) {
12337 PyErr_Format(PyExc_SystemError,
12338 "AST constructor recursion depth mismatch (before=%d, after=%d)",
12339 starting_recursion_depth, state->recursion_depth);
12340 return 0;
12341 }
12342 return result;
12343 }
12344
12345 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
PyAST_obj2mod(PyObject * ast,PyArena * arena,int mode)12346 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
12347 {
12348 const char * const req_name[] = {"Module", "Expression", "Interactive"};
12349 int isinstance;
12350
12351 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
12352 return NULL;
12353 }
12354
12355 struct ast_state *state = get_ast_state();
12356 if (state == NULL) {
12357 return NULL;
12358 }
12359
12360 PyObject *req_type[3];
12361 req_type[0] = state->Module_type;
12362 req_type[1] = state->Expression_type;
12363 req_type[2] = state->Interactive_type;
12364
12365 assert(0 <= mode && mode <= 2);
12366
12367 isinstance = PyObject_IsInstance(ast, req_type[mode]);
12368 if (isinstance == -1)
12369 return NULL;
12370 if (!isinstance) {
12371 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
12372 req_name[mode], _PyType_Name(Py_TYPE(ast)));
12373 return NULL;
12374 }
12375
12376 mod_ty res = NULL;
12377 if (obj2ast_mod(state, ast, &res, arena) != 0)
12378 return NULL;
12379 else
12380 return res;
12381 }
12382
PyAST_Check(PyObject * obj)12383 int PyAST_Check(PyObject* obj)
12384 {
12385 struct ast_state *state = get_ast_state();
12386 if (state == NULL) {
12387 return -1;
12388 }
12389 return PyObject_IsInstance(obj, state->AST_type);
12390 }
12391
12392
12393