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_lock.h" // _PyOnceFlag
8 #include "pycore_interp.h" // _PyInterpreterState.ast
9 #include "pycore_pystate.h" // _PyInterpreterState_GET()
10 #include "pycore_unionobject.h" // _Py_union_type_or
11 #include "structmember.h"
12 #include <stddef.h>
13
14 struct validator {
15 int recursion_depth; /* current recursion depth */
16 int recursion_limit; /* recursion limit */
17 };
18
19 // Forward declaration
20 static int init_types(struct ast_state *state);
21
22 static struct ast_state*
get_ast_state(void)23 get_ast_state(void)
24 {
25 PyInterpreterState *interp = _PyInterpreterState_GET();
26 struct ast_state *state = &interp->ast;
27 assert(!state->finalized);
28 if (_PyOnceFlag_CallOnce(&state->once, (_Py_once_fn_t *)&init_types, state) < 0) {
29 return NULL;
30 }
31 return state;
32 }
33
_PyAST_Fini(PyInterpreterState * interp)34 void _PyAST_Fini(PyInterpreterState *interp)
35 {
36 struct ast_state *state = &interp->ast;
37
38 Py_CLEAR(state->AST_type);
39 Py_CLEAR(state->Add_singleton);
40 Py_CLEAR(state->Add_type);
41 Py_CLEAR(state->And_singleton);
42 Py_CLEAR(state->And_type);
43 Py_CLEAR(state->AnnAssign_type);
44 Py_CLEAR(state->Assert_type);
45 Py_CLEAR(state->Assign_type);
46 Py_CLEAR(state->AsyncFor_type);
47 Py_CLEAR(state->AsyncFunctionDef_type);
48 Py_CLEAR(state->AsyncWith_type);
49 Py_CLEAR(state->Attribute_type);
50 Py_CLEAR(state->AugAssign_type);
51 Py_CLEAR(state->Await_type);
52 Py_CLEAR(state->BinOp_type);
53 Py_CLEAR(state->BitAnd_singleton);
54 Py_CLEAR(state->BitAnd_type);
55 Py_CLEAR(state->BitOr_singleton);
56 Py_CLEAR(state->BitOr_type);
57 Py_CLEAR(state->BitXor_singleton);
58 Py_CLEAR(state->BitXor_type);
59 Py_CLEAR(state->BoolOp_type);
60 Py_CLEAR(state->Break_type);
61 Py_CLEAR(state->Call_type);
62 Py_CLEAR(state->ClassDef_type);
63 Py_CLEAR(state->Compare_type);
64 Py_CLEAR(state->Constant_type);
65 Py_CLEAR(state->Continue_type);
66 Py_CLEAR(state->Del_singleton);
67 Py_CLEAR(state->Del_type);
68 Py_CLEAR(state->Delete_type);
69 Py_CLEAR(state->DictComp_type);
70 Py_CLEAR(state->Dict_type);
71 Py_CLEAR(state->Div_singleton);
72 Py_CLEAR(state->Div_type);
73 Py_CLEAR(state->Eq_singleton);
74 Py_CLEAR(state->Eq_type);
75 Py_CLEAR(state->ExceptHandler_type);
76 Py_CLEAR(state->Expr_type);
77 Py_CLEAR(state->Expression_type);
78 Py_CLEAR(state->FloorDiv_singleton);
79 Py_CLEAR(state->FloorDiv_type);
80 Py_CLEAR(state->For_type);
81 Py_CLEAR(state->FormattedValue_type);
82 Py_CLEAR(state->FunctionDef_type);
83 Py_CLEAR(state->FunctionType_type);
84 Py_CLEAR(state->GeneratorExp_type);
85 Py_CLEAR(state->Global_type);
86 Py_CLEAR(state->GtE_singleton);
87 Py_CLEAR(state->GtE_type);
88 Py_CLEAR(state->Gt_singleton);
89 Py_CLEAR(state->Gt_type);
90 Py_CLEAR(state->IfExp_type);
91 Py_CLEAR(state->If_type);
92 Py_CLEAR(state->ImportFrom_type);
93 Py_CLEAR(state->Import_type);
94 Py_CLEAR(state->In_singleton);
95 Py_CLEAR(state->In_type);
96 Py_CLEAR(state->Interactive_type);
97 Py_CLEAR(state->Invert_singleton);
98 Py_CLEAR(state->Invert_type);
99 Py_CLEAR(state->IsNot_singleton);
100 Py_CLEAR(state->IsNot_type);
101 Py_CLEAR(state->Is_singleton);
102 Py_CLEAR(state->Is_type);
103 Py_CLEAR(state->JoinedStr_type);
104 Py_CLEAR(state->LShift_singleton);
105 Py_CLEAR(state->LShift_type);
106 Py_CLEAR(state->Lambda_type);
107 Py_CLEAR(state->ListComp_type);
108 Py_CLEAR(state->List_type);
109 Py_CLEAR(state->Load_singleton);
110 Py_CLEAR(state->Load_type);
111 Py_CLEAR(state->LtE_singleton);
112 Py_CLEAR(state->LtE_type);
113 Py_CLEAR(state->Lt_singleton);
114 Py_CLEAR(state->Lt_type);
115 Py_CLEAR(state->MatMult_singleton);
116 Py_CLEAR(state->MatMult_type);
117 Py_CLEAR(state->MatchAs_type);
118 Py_CLEAR(state->MatchClass_type);
119 Py_CLEAR(state->MatchMapping_type);
120 Py_CLEAR(state->MatchOr_type);
121 Py_CLEAR(state->MatchSequence_type);
122 Py_CLEAR(state->MatchSingleton_type);
123 Py_CLEAR(state->MatchStar_type);
124 Py_CLEAR(state->MatchValue_type);
125 Py_CLEAR(state->Match_type);
126 Py_CLEAR(state->Mod_singleton);
127 Py_CLEAR(state->Mod_type);
128 Py_CLEAR(state->Module_type);
129 Py_CLEAR(state->Mult_singleton);
130 Py_CLEAR(state->Mult_type);
131 Py_CLEAR(state->Name_type);
132 Py_CLEAR(state->NamedExpr_type);
133 Py_CLEAR(state->Nonlocal_type);
134 Py_CLEAR(state->NotEq_singleton);
135 Py_CLEAR(state->NotEq_type);
136 Py_CLEAR(state->NotIn_singleton);
137 Py_CLEAR(state->NotIn_type);
138 Py_CLEAR(state->Not_singleton);
139 Py_CLEAR(state->Not_type);
140 Py_CLEAR(state->Or_singleton);
141 Py_CLEAR(state->Or_type);
142 Py_CLEAR(state->ParamSpec_type);
143 Py_CLEAR(state->Pass_type);
144 Py_CLEAR(state->Pow_singleton);
145 Py_CLEAR(state->Pow_type);
146 Py_CLEAR(state->RShift_singleton);
147 Py_CLEAR(state->RShift_type);
148 Py_CLEAR(state->Raise_type);
149 Py_CLEAR(state->Return_type);
150 Py_CLEAR(state->SetComp_type);
151 Py_CLEAR(state->Set_type);
152 Py_CLEAR(state->Slice_type);
153 Py_CLEAR(state->Starred_type);
154 Py_CLEAR(state->Store_singleton);
155 Py_CLEAR(state->Store_type);
156 Py_CLEAR(state->Sub_singleton);
157 Py_CLEAR(state->Sub_type);
158 Py_CLEAR(state->Subscript_type);
159 Py_CLEAR(state->TryStar_type);
160 Py_CLEAR(state->Try_type);
161 Py_CLEAR(state->Tuple_type);
162 Py_CLEAR(state->TypeAlias_type);
163 Py_CLEAR(state->TypeIgnore_type);
164 Py_CLEAR(state->TypeVarTuple_type);
165 Py_CLEAR(state->TypeVar_type);
166 Py_CLEAR(state->UAdd_singleton);
167 Py_CLEAR(state->UAdd_type);
168 Py_CLEAR(state->USub_singleton);
169 Py_CLEAR(state->USub_type);
170 Py_CLEAR(state->UnaryOp_type);
171 Py_CLEAR(state->While_type);
172 Py_CLEAR(state->With_type);
173 Py_CLEAR(state->YieldFrom_type);
174 Py_CLEAR(state->Yield_type);
175 Py_CLEAR(state->__dict__);
176 Py_CLEAR(state->__doc__);
177 Py_CLEAR(state->__match_args__);
178 Py_CLEAR(state->__module__);
179 Py_CLEAR(state->_attributes);
180 Py_CLEAR(state->_fields);
181 Py_CLEAR(state->alias_type);
182 Py_CLEAR(state->annotation);
183 Py_CLEAR(state->arg);
184 Py_CLEAR(state->arg_type);
185 Py_CLEAR(state->args);
186 Py_CLEAR(state->argtypes);
187 Py_CLEAR(state->arguments_type);
188 Py_CLEAR(state->asname);
189 Py_CLEAR(state->ast);
190 Py_CLEAR(state->attr);
191 Py_CLEAR(state->bases);
192 Py_CLEAR(state->body);
193 Py_CLEAR(state->boolop_type);
194 Py_CLEAR(state->bound);
195 Py_CLEAR(state->cases);
196 Py_CLEAR(state->cause);
197 Py_CLEAR(state->cls);
198 Py_CLEAR(state->cmpop_type);
199 Py_CLEAR(state->col_offset);
200 Py_CLEAR(state->comparators);
201 Py_CLEAR(state->comprehension_type);
202 Py_CLEAR(state->context_expr);
203 Py_CLEAR(state->conversion);
204 Py_CLEAR(state->ctx);
205 Py_CLEAR(state->decorator_list);
206 Py_CLEAR(state->default_value);
207 Py_CLEAR(state->defaults);
208 Py_CLEAR(state->elt);
209 Py_CLEAR(state->elts);
210 Py_CLEAR(state->end_col_offset);
211 Py_CLEAR(state->end_lineno);
212 Py_CLEAR(state->exc);
213 Py_CLEAR(state->excepthandler_type);
214 Py_CLEAR(state->expr_context_type);
215 Py_CLEAR(state->expr_type);
216 Py_CLEAR(state->finalbody);
217 Py_CLEAR(state->format_spec);
218 Py_CLEAR(state->func);
219 Py_CLEAR(state->generators);
220 Py_CLEAR(state->guard);
221 Py_CLEAR(state->handlers);
222 Py_CLEAR(state->id);
223 Py_CLEAR(state->ifs);
224 Py_CLEAR(state->is_async);
225 Py_CLEAR(state->items);
226 Py_CLEAR(state->iter);
227 Py_CLEAR(state->key);
228 Py_CLEAR(state->keys);
229 Py_CLEAR(state->keyword_type);
230 Py_CLEAR(state->keywords);
231 Py_CLEAR(state->kind);
232 Py_CLEAR(state->kw_defaults);
233 Py_CLEAR(state->kwarg);
234 Py_CLEAR(state->kwd_attrs);
235 Py_CLEAR(state->kwd_patterns);
236 Py_CLEAR(state->kwonlyargs);
237 Py_CLEAR(state->left);
238 Py_CLEAR(state->level);
239 Py_CLEAR(state->lineno);
240 Py_CLEAR(state->lower);
241 Py_CLEAR(state->match_case_type);
242 Py_CLEAR(state->mod_type);
243 Py_CLEAR(state->module);
244 Py_CLEAR(state->msg);
245 Py_CLEAR(state->name);
246 Py_CLEAR(state->names);
247 Py_CLEAR(state->op);
248 Py_CLEAR(state->operand);
249 Py_CLEAR(state->operator_type);
250 Py_CLEAR(state->ops);
251 Py_CLEAR(state->optional_vars);
252 Py_CLEAR(state->orelse);
253 Py_CLEAR(state->pattern);
254 Py_CLEAR(state->pattern_type);
255 Py_CLEAR(state->patterns);
256 Py_CLEAR(state->posonlyargs);
257 Py_CLEAR(state->rest);
258 Py_CLEAR(state->returns);
259 Py_CLEAR(state->right);
260 Py_CLEAR(state->simple);
261 Py_CLEAR(state->slice);
262 Py_CLEAR(state->step);
263 Py_CLEAR(state->stmt_type);
264 Py_CLEAR(state->subject);
265 Py_CLEAR(state->tag);
266 Py_CLEAR(state->target);
267 Py_CLEAR(state->targets);
268 Py_CLEAR(state->test);
269 Py_CLEAR(state->type);
270 Py_CLEAR(state->type_comment);
271 Py_CLEAR(state->type_ignore_type);
272 Py_CLEAR(state->type_ignores);
273 Py_CLEAR(state->type_param_type);
274 Py_CLEAR(state->type_params);
275 Py_CLEAR(state->unaryop_type);
276 Py_CLEAR(state->upper);
277 Py_CLEAR(state->value);
278 Py_CLEAR(state->values);
279 Py_CLEAR(state->vararg);
280 Py_CLEAR(state->withitem_type);
281
282 state->finalized = 1;
283 state->once = (_PyOnceFlag){0};
284 }
285
init_identifiers(struct ast_state * state)286 static int init_identifiers(struct ast_state *state)
287 {
288 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return -1;
289 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return -1;
290 if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return -1;
291 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return -1;
292 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return -1;
293 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return -1;
294 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return -1;
295 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return -1;
296 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return -1;
297 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return -1;
298 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return -1;
299 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return -1;
300 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return -1;
301 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return -1;
302 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return -1;
303 if ((state->bound = PyUnicode_InternFromString("bound")) == NULL) return -1;
304 if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return -1;
305 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return -1;
306 if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return -1;
307 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return -1;
308 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return -1;
309 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return -1;
310 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return -1;
311 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return -1;
312 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return -1;
313 if ((state->default_value = PyUnicode_InternFromString("default_value")) == NULL) return -1;
314 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return -1;
315 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return -1;
316 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return -1;
317 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return -1;
318 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return -1;
319 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return -1;
320 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return -1;
321 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return -1;
322 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return -1;
323 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return -1;
324 if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return -1;
325 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return -1;
326 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return -1;
327 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return -1;
328 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return -1;
329 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return -1;
330 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return -1;
331 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return -1;
332 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return -1;
333 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return -1;
334 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return -1;
335 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return -1;
336 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return -1;
337 if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return -1;
338 if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return -1;
339 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return -1;
340 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return -1;
341 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return -1;
342 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return -1;
343 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return -1;
344 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return -1;
345 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return -1;
346 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return -1;
347 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return -1;
348 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return -1;
349 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return -1;
350 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return -1;
351 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return -1;
352 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return -1;
353 if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return -1;
354 if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return -1;
355 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return -1;
356 if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return -1;
357 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return -1;
358 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return -1;
359 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return -1;
360 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return -1;
361 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return -1;
362 if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return -1;
363 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return -1;
364 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return -1;
365 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return -1;
366 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return -1;
367 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return -1;
368 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return -1;
369 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return -1;
370 if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return -1;
371 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return -1;
372 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return -1;
373 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return -1;
374 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return -1;
375 return 0;
376 };
377
378 GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
379 GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
380 GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
381 GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
382 GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
383 GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
384 GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
385 GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
386 GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
387 GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
388 GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
389 GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
390 GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
391 GENERATE_ASDL_SEQ_CONSTRUCTOR(type_param, type_param_ty)
392
393 static PyObject* ast2obj_mod(struct ast_state *state, struct validator *vstate,
394 void*);
395 static const char * const Module_fields[]={
396 "body",
397 "type_ignores",
398 };
399 static const char * const Interactive_fields[]={
400 "body",
401 };
402 static const char * const Expression_fields[]={
403 "body",
404 };
405 static const char * const FunctionType_fields[]={
406 "argtypes",
407 "returns",
408 };
409 static const char * const stmt_attributes[] = {
410 "lineno",
411 "col_offset",
412 "end_lineno",
413 "end_col_offset",
414 };
415 static PyObject* ast2obj_stmt(struct ast_state *state, struct validator
416 *vstate, void*);
417 static const char * const FunctionDef_fields[]={
418 "name",
419 "args",
420 "body",
421 "decorator_list",
422 "returns",
423 "type_comment",
424 "type_params",
425 };
426 static const char * const AsyncFunctionDef_fields[]={
427 "name",
428 "args",
429 "body",
430 "decorator_list",
431 "returns",
432 "type_comment",
433 "type_params",
434 };
435 static const char * const ClassDef_fields[]={
436 "name",
437 "bases",
438 "keywords",
439 "body",
440 "decorator_list",
441 "type_params",
442 };
443 static const char * const Return_fields[]={
444 "value",
445 };
446 static const char * const Delete_fields[]={
447 "targets",
448 };
449 static const char * const Assign_fields[]={
450 "targets",
451 "value",
452 "type_comment",
453 };
454 static const char * const TypeAlias_fields[]={
455 "name",
456 "type_params",
457 "value",
458 };
459 static const char * const AugAssign_fields[]={
460 "target",
461 "op",
462 "value",
463 };
464 static const char * const AnnAssign_fields[]={
465 "target",
466 "annotation",
467 "value",
468 "simple",
469 };
470 static const char * const For_fields[]={
471 "target",
472 "iter",
473 "body",
474 "orelse",
475 "type_comment",
476 };
477 static const char * const AsyncFor_fields[]={
478 "target",
479 "iter",
480 "body",
481 "orelse",
482 "type_comment",
483 };
484 static const char * const While_fields[]={
485 "test",
486 "body",
487 "orelse",
488 };
489 static const char * const If_fields[]={
490 "test",
491 "body",
492 "orelse",
493 };
494 static const char * const With_fields[]={
495 "items",
496 "body",
497 "type_comment",
498 };
499 static const char * const AsyncWith_fields[]={
500 "items",
501 "body",
502 "type_comment",
503 };
504 static const char * const Match_fields[]={
505 "subject",
506 "cases",
507 };
508 static const char * const Raise_fields[]={
509 "exc",
510 "cause",
511 };
512 static const char * const Try_fields[]={
513 "body",
514 "handlers",
515 "orelse",
516 "finalbody",
517 };
518 static const char * const TryStar_fields[]={
519 "body",
520 "handlers",
521 "orelse",
522 "finalbody",
523 };
524 static const char * const Assert_fields[]={
525 "test",
526 "msg",
527 };
528 static const char * const Import_fields[]={
529 "names",
530 };
531 static const char * const ImportFrom_fields[]={
532 "module",
533 "names",
534 "level",
535 };
536 static const char * const Global_fields[]={
537 "names",
538 };
539 static const char * const Nonlocal_fields[]={
540 "names",
541 };
542 static const char * const Expr_fields[]={
543 "value",
544 };
545 static const char * const expr_attributes[] = {
546 "lineno",
547 "col_offset",
548 "end_lineno",
549 "end_col_offset",
550 };
551 static PyObject* ast2obj_expr(struct ast_state *state, struct validator
552 *vstate, void*);
553 static const char * const BoolOp_fields[]={
554 "op",
555 "values",
556 };
557 static const char * const NamedExpr_fields[]={
558 "target",
559 "value",
560 };
561 static const char * const BinOp_fields[]={
562 "left",
563 "op",
564 "right",
565 };
566 static const char * const UnaryOp_fields[]={
567 "op",
568 "operand",
569 };
570 static const char * const Lambda_fields[]={
571 "args",
572 "body",
573 };
574 static const char * const IfExp_fields[]={
575 "test",
576 "body",
577 "orelse",
578 };
579 static const char * const Dict_fields[]={
580 "keys",
581 "values",
582 };
583 static const char * const Set_fields[]={
584 "elts",
585 };
586 static const char * const ListComp_fields[]={
587 "elt",
588 "generators",
589 };
590 static const char * const SetComp_fields[]={
591 "elt",
592 "generators",
593 };
594 static const char * const DictComp_fields[]={
595 "key",
596 "value",
597 "generators",
598 };
599 static const char * const GeneratorExp_fields[]={
600 "elt",
601 "generators",
602 };
603 static const char * const Await_fields[]={
604 "value",
605 };
606 static const char * const Yield_fields[]={
607 "value",
608 };
609 static const char * const YieldFrom_fields[]={
610 "value",
611 };
612 static const char * const Compare_fields[]={
613 "left",
614 "ops",
615 "comparators",
616 };
617 static const char * const Call_fields[]={
618 "func",
619 "args",
620 "keywords",
621 };
622 static const char * const FormattedValue_fields[]={
623 "value",
624 "conversion",
625 "format_spec",
626 };
627 static const char * const JoinedStr_fields[]={
628 "values",
629 };
630 static const char * const Constant_fields[]={
631 "value",
632 "kind",
633 };
634 static const char * const Attribute_fields[]={
635 "value",
636 "attr",
637 "ctx",
638 };
639 static const char * const Subscript_fields[]={
640 "value",
641 "slice",
642 "ctx",
643 };
644 static const char * const Starred_fields[]={
645 "value",
646 "ctx",
647 };
648 static const char * const Name_fields[]={
649 "id",
650 "ctx",
651 };
652 static const char * const List_fields[]={
653 "elts",
654 "ctx",
655 };
656 static const char * const Tuple_fields[]={
657 "elts",
658 "ctx",
659 };
660 static const char * const Slice_fields[]={
661 "lower",
662 "upper",
663 "step",
664 };
665 static PyObject* ast2obj_expr_context(struct ast_state *state, struct validator
666 *vstate, expr_context_ty);
667 static PyObject* ast2obj_boolop(struct ast_state *state, struct validator
668 *vstate, boolop_ty);
669 static PyObject* ast2obj_operator(struct ast_state *state, struct validator
670 *vstate, operator_ty);
671 static PyObject* ast2obj_unaryop(struct ast_state *state, struct validator
672 *vstate, unaryop_ty);
673 static PyObject* ast2obj_cmpop(struct ast_state *state, struct validator
674 *vstate, cmpop_ty);
675 static PyObject* ast2obj_comprehension(struct ast_state *state, struct
676 validator *vstate, void*);
677 static const char * const comprehension_fields[]={
678 "target",
679 "iter",
680 "ifs",
681 "is_async",
682 };
683 static const char * const excepthandler_attributes[] = {
684 "lineno",
685 "col_offset",
686 "end_lineno",
687 "end_col_offset",
688 };
689 static PyObject* ast2obj_excepthandler(struct ast_state *state, struct
690 validator *vstate, void*);
691 static const char * const ExceptHandler_fields[]={
692 "type",
693 "name",
694 "body",
695 };
696 static PyObject* ast2obj_arguments(struct ast_state *state, struct validator
697 *vstate, void*);
698 static const char * const arguments_fields[]={
699 "posonlyargs",
700 "args",
701 "vararg",
702 "kwonlyargs",
703 "kw_defaults",
704 "kwarg",
705 "defaults",
706 };
707 static PyObject* ast2obj_arg(struct ast_state *state, struct validator *vstate,
708 void*);
709 static const char * const arg_attributes[] = {
710 "lineno",
711 "col_offset",
712 "end_lineno",
713 "end_col_offset",
714 };
715 static const char * const arg_fields[]={
716 "arg",
717 "annotation",
718 "type_comment",
719 };
720 static PyObject* ast2obj_keyword(struct ast_state *state, struct validator
721 *vstate, void*);
722 static const char * const keyword_attributes[] = {
723 "lineno",
724 "col_offset",
725 "end_lineno",
726 "end_col_offset",
727 };
728 static const char * const keyword_fields[]={
729 "arg",
730 "value",
731 };
732 static PyObject* ast2obj_alias(struct ast_state *state, struct validator
733 *vstate, void*);
734 static const char * const alias_attributes[] = {
735 "lineno",
736 "col_offset",
737 "end_lineno",
738 "end_col_offset",
739 };
740 static const char * const alias_fields[]={
741 "name",
742 "asname",
743 };
744 static PyObject* ast2obj_withitem(struct ast_state *state, struct validator
745 *vstate, void*);
746 static const char * const withitem_fields[]={
747 "context_expr",
748 "optional_vars",
749 };
750 static PyObject* ast2obj_match_case(struct ast_state *state, struct validator
751 *vstate, void*);
752 static const char * const match_case_fields[]={
753 "pattern",
754 "guard",
755 "body",
756 };
757 static const char * const pattern_attributes[] = {
758 "lineno",
759 "col_offset",
760 "end_lineno",
761 "end_col_offset",
762 };
763 static PyObject* ast2obj_pattern(struct ast_state *state, struct validator
764 *vstate, void*);
765 static const char * const MatchValue_fields[]={
766 "value",
767 };
768 static const char * const MatchSingleton_fields[]={
769 "value",
770 };
771 static const char * const MatchSequence_fields[]={
772 "patterns",
773 };
774 static const char * const MatchMapping_fields[]={
775 "keys",
776 "patterns",
777 "rest",
778 };
779 static const char * const MatchClass_fields[]={
780 "cls",
781 "patterns",
782 "kwd_attrs",
783 "kwd_patterns",
784 };
785 static const char * const MatchStar_fields[]={
786 "name",
787 };
788 static const char * const MatchAs_fields[]={
789 "pattern",
790 "name",
791 };
792 static const char * const MatchOr_fields[]={
793 "patterns",
794 };
795 static PyObject* ast2obj_type_ignore(struct ast_state *state, struct validator
796 *vstate, void*);
797 static const char * const TypeIgnore_fields[]={
798 "lineno",
799 "tag",
800 };
801 static const char * const type_param_attributes[] = {
802 "lineno",
803 "col_offset",
804 "end_lineno",
805 "end_col_offset",
806 };
807 static PyObject* ast2obj_type_param(struct ast_state *state, struct validator
808 *vstate, void*);
809 static const char * const TypeVar_fields[]={
810 "name",
811 "bound",
812 "default_value",
813 };
814 static const char * const ParamSpec_fields[]={
815 "name",
816 "default_value",
817 };
818 static const char * const TypeVarTuple_fields[]={
819 "name",
820 "default_value",
821 };
822
823
824 static int
add_ast_annotations(struct ast_state * state)825 add_ast_annotations(struct ast_state *state)
826 {
827 bool cond;
828 PyObject *Module_annotations = PyDict_New();
829 if (!Module_annotations) return 0;
830 {
831 PyObject *type = state->stmt_type;
832 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
833 cond = type != NULL;
834 if (!cond) {
835 Py_DECREF(Module_annotations);
836 return 0;
837 }
838 cond = PyDict_SetItemString(Module_annotations, "body", type) == 0;
839 Py_DECREF(type);
840 if (!cond) {
841 Py_DECREF(Module_annotations);
842 return 0;
843 }
844 }
845 {
846 PyObject *type = state->type_ignore_type;
847 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
848 cond = type != NULL;
849 if (!cond) {
850 Py_DECREF(Module_annotations);
851 return 0;
852 }
853 cond = PyDict_SetItemString(Module_annotations, "type_ignores", type)
854 == 0;
855 Py_DECREF(type);
856 if (!cond) {
857 Py_DECREF(Module_annotations);
858 return 0;
859 }
860 }
861 cond = PyObject_SetAttrString(state->Module_type, "_field_types",
862 Module_annotations) == 0;
863 if (!cond) {
864 Py_DECREF(Module_annotations);
865 return 0;
866 }
867 cond = PyObject_SetAttrString(state->Module_type, "__annotations__",
868 Module_annotations) == 0;
869 if (!cond) {
870 Py_DECREF(Module_annotations);
871 return 0;
872 }
873 Py_DECREF(Module_annotations);
874 PyObject *Interactive_annotations = PyDict_New();
875 if (!Interactive_annotations) return 0;
876 {
877 PyObject *type = state->stmt_type;
878 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
879 cond = type != NULL;
880 if (!cond) {
881 Py_DECREF(Interactive_annotations);
882 return 0;
883 }
884 cond = PyDict_SetItemString(Interactive_annotations, "body", type) == 0;
885 Py_DECREF(type);
886 if (!cond) {
887 Py_DECREF(Interactive_annotations);
888 return 0;
889 }
890 }
891 cond = PyObject_SetAttrString(state->Interactive_type, "_field_types",
892 Interactive_annotations) == 0;
893 if (!cond) {
894 Py_DECREF(Interactive_annotations);
895 return 0;
896 }
897 cond = PyObject_SetAttrString(state->Interactive_type, "__annotations__",
898 Interactive_annotations) == 0;
899 if (!cond) {
900 Py_DECREF(Interactive_annotations);
901 return 0;
902 }
903 Py_DECREF(Interactive_annotations);
904 PyObject *Expression_annotations = PyDict_New();
905 if (!Expression_annotations) return 0;
906 {
907 PyObject *type = state->expr_type;
908 Py_INCREF(type);
909 cond = PyDict_SetItemString(Expression_annotations, "body", type) == 0;
910 Py_DECREF(type);
911 if (!cond) {
912 Py_DECREF(Expression_annotations);
913 return 0;
914 }
915 }
916 cond = PyObject_SetAttrString(state->Expression_type, "_field_types",
917 Expression_annotations) == 0;
918 if (!cond) {
919 Py_DECREF(Expression_annotations);
920 return 0;
921 }
922 cond = PyObject_SetAttrString(state->Expression_type, "__annotations__",
923 Expression_annotations) == 0;
924 if (!cond) {
925 Py_DECREF(Expression_annotations);
926 return 0;
927 }
928 Py_DECREF(Expression_annotations);
929 PyObject *FunctionType_annotations = PyDict_New();
930 if (!FunctionType_annotations) return 0;
931 {
932 PyObject *type = state->expr_type;
933 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
934 cond = type != NULL;
935 if (!cond) {
936 Py_DECREF(FunctionType_annotations);
937 return 0;
938 }
939 cond = PyDict_SetItemString(FunctionType_annotations, "argtypes", type)
940 == 0;
941 Py_DECREF(type);
942 if (!cond) {
943 Py_DECREF(FunctionType_annotations);
944 return 0;
945 }
946 }
947 {
948 PyObject *type = state->expr_type;
949 Py_INCREF(type);
950 cond = PyDict_SetItemString(FunctionType_annotations, "returns", type)
951 == 0;
952 Py_DECREF(type);
953 if (!cond) {
954 Py_DECREF(FunctionType_annotations);
955 return 0;
956 }
957 }
958 cond = PyObject_SetAttrString(state->FunctionType_type, "_field_types",
959 FunctionType_annotations) == 0;
960 if (!cond) {
961 Py_DECREF(FunctionType_annotations);
962 return 0;
963 }
964 cond = PyObject_SetAttrString(state->FunctionType_type, "__annotations__",
965 FunctionType_annotations) == 0;
966 if (!cond) {
967 Py_DECREF(FunctionType_annotations);
968 return 0;
969 }
970 Py_DECREF(FunctionType_annotations);
971 PyObject *FunctionDef_annotations = PyDict_New();
972 if (!FunctionDef_annotations) return 0;
973 {
974 PyObject *type = (PyObject *)&PyUnicode_Type;
975 Py_INCREF(type);
976 cond = PyDict_SetItemString(FunctionDef_annotations, "name", type) == 0;
977 Py_DECREF(type);
978 if (!cond) {
979 Py_DECREF(FunctionDef_annotations);
980 return 0;
981 }
982 }
983 {
984 PyObject *type = state->arguments_type;
985 Py_INCREF(type);
986 cond = PyDict_SetItemString(FunctionDef_annotations, "args", type) == 0;
987 Py_DECREF(type);
988 if (!cond) {
989 Py_DECREF(FunctionDef_annotations);
990 return 0;
991 }
992 }
993 {
994 PyObject *type = state->stmt_type;
995 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
996 cond = type != NULL;
997 if (!cond) {
998 Py_DECREF(FunctionDef_annotations);
999 return 0;
1000 }
1001 cond = PyDict_SetItemString(FunctionDef_annotations, "body", type) == 0;
1002 Py_DECREF(type);
1003 if (!cond) {
1004 Py_DECREF(FunctionDef_annotations);
1005 return 0;
1006 }
1007 }
1008 {
1009 PyObject *type = state->expr_type;
1010 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1011 cond = type != NULL;
1012 if (!cond) {
1013 Py_DECREF(FunctionDef_annotations);
1014 return 0;
1015 }
1016 cond = PyDict_SetItemString(FunctionDef_annotations, "decorator_list",
1017 type) == 0;
1018 Py_DECREF(type);
1019 if (!cond) {
1020 Py_DECREF(FunctionDef_annotations);
1021 return 0;
1022 }
1023 }
1024 {
1025 PyObject *type = state->expr_type;
1026 type = _Py_union_type_or(type, Py_None);
1027 cond = type != NULL;
1028 if (!cond) {
1029 Py_DECREF(FunctionDef_annotations);
1030 return 0;
1031 }
1032 cond = PyDict_SetItemString(FunctionDef_annotations, "returns", type)
1033 == 0;
1034 Py_DECREF(type);
1035 if (!cond) {
1036 Py_DECREF(FunctionDef_annotations);
1037 return 0;
1038 }
1039 }
1040 {
1041 PyObject *type = (PyObject *)&PyUnicode_Type;
1042 type = _Py_union_type_or(type, Py_None);
1043 cond = type != NULL;
1044 if (!cond) {
1045 Py_DECREF(FunctionDef_annotations);
1046 return 0;
1047 }
1048 cond = PyDict_SetItemString(FunctionDef_annotations, "type_comment",
1049 type) == 0;
1050 Py_DECREF(type);
1051 if (!cond) {
1052 Py_DECREF(FunctionDef_annotations);
1053 return 0;
1054 }
1055 }
1056 {
1057 PyObject *type = state->type_param_type;
1058 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1059 cond = type != NULL;
1060 if (!cond) {
1061 Py_DECREF(FunctionDef_annotations);
1062 return 0;
1063 }
1064 cond = PyDict_SetItemString(FunctionDef_annotations, "type_params",
1065 type) == 0;
1066 Py_DECREF(type);
1067 if (!cond) {
1068 Py_DECREF(FunctionDef_annotations);
1069 return 0;
1070 }
1071 }
1072 cond = PyObject_SetAttrString(state->FunctionDef_type, "_field_types",
1073 FunctionDef_annotations) == 0;
1074 if (!cond) {
1075 Py_DECREF(FunctionDef_annotations);
1076 return 0;
1077 }
1078 cond = PyObject_SetAttrString(state->FunctionDef_type, "__annotations__",
1079 FunctionDef_annotations) == 0;
1080 if (!cond) {
1081 Py_DECREF(FunctionDef_annotations);
1082 return 0;
1083 }
1084 Py_DECREF(FunctionDef_annotations);
1085 PyObject *AsyncFunctionDef_annotations = PyDict_New();
1086 if (!AsyncFunctionDef_annotations) return 0;
1087 {
1088 PyObject *type = (PyObject *)&PyUnicode_Type;
1089 Py_INCREF(type);
1090 cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "name", type)
1091 == 0;
1092 Py_DECREF(type);
1093 if (!cond) {
1094 Py_DECREF(AsyncFunctionDef_annotations);
1095 return 0;
1096 }
1097 }
1098 {
1099 PyObject *type = state->arguments_type;
1100 Py_INCREF(type);
1101 cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "args", type)
1102 == 0;
1103 Py_DECREF(type);
1104 if (!cond) {
1105 Py_DECREF(AsyncFunctionDef_annotations);
1106 return 0;
1107 }
1108 }
1109 {
1110 PyObject *type = state->stmt_type;
1111 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1112 cond = type != NULL;
1113 if (!cond) {
1114 Py_DECREF(AsyncFunctionDef_annotations);
1115 return 0;
1116 }
1117 cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "body", type)
1118 == 0;
1119 Py_DECREF(type);
1120 if (!cond) {
1121 Py_DECREF(AsyncFunctionDef_annotations);
1122 return 0;
1123 }
1124 }
1125 {
1126 PyObject *type = state->expr_type;
1127 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1128 cond = type != NULL;
1129 if (!cond) {
1130 Py_DECREF(AsyncFunctionDef_annotations);
1131 return 0;
1132 }
1133 cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
1134 "decorator_list", type) == 0;
1135 Py_DECREF(type);
1136 if (!cond) {
1137 Py_DECREF(AsyncFunctionDef_annotations);
1138 return 0;
1139 }
1140 }
1141 {
1142 PyObject *type = state->expr_type;
1143 type = _Py_union_type_or(type, Py_None);
1144 cond = type != NULL;
1145 if (!cond) {
1146 Py_DECREF(AsyncFunctionDef_annotations);
1147 return 0;
1148 }
1149 cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "returns",
1150 type) == 0;
1151 Py_DECREF(type);
1152 if (!cond) {
1153 Py_DECREF(AsyncFunctionDef_annotations);
1154 return 0;
1155 }
1156 }
1157 {
1158 PyObject *type = (PyObject *)&PyUnicode_Type;
1159 type = _Py_union_type_or(type, Py_None);
1160 cond = type != NULL;
1161 if (!cond) {
1162 Py_DECREF(AsyncFunctionDef_annotations);
1163 return 0;
1164 }
1165 cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
1166 "type_comment", type) == 0;
1167 Py_DECREF(type);
1168 if (!cond) {
1169 Py_DECREF(AsyncFunctionDef_annotations);
1170 return 0;
1171 }
1172 }
1173 {
1174 PyObject *type = state->type_param_type;
1175 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1176 cond = type != NULL;
1177 if (!cond) {
1178 Py_DECREF(AsyncFunctionDef_annotations);
1179 return 0;
1180 }
1181 cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
1182 "type_params", type) == 0;
1183 Py_DECREF(type);
1184 if (!cond) {
1185 Py_DECREF(AsyncFunctionDef_annotations);
1186 return 0;
1187 }
1188 }
1189 cond = PyObject_SetAttrString(state->AsyncFunctionDef_type, "_field_types",
1190 AsyncFunctionDef_annotations) == 0;
1191 if (!cond) {
1192 Py_DECREF(AsyncFunctionDef_annotations);
1193 return 0;
1194 }
1195 cond = PyObject_SetAttrString(state->AsyncFunctionDef_type,
1196 "__annotations__",
1197 AsyncFunctionDef_annotations) == 0;
1198 if (!cond) {
1199 Py_DECREF(AsyncFunctionDef_annotations);
1200 return 0;
1201 }
1202 Py_DECREF(AsyncFunctionDef_annotations);
1203 PyObject *ClassDef_annotations = PyDict_New();
1204 if (!ClassDef_annotations) return 0;
1205 {
1206 PyObject *type = (PyObject *)&PyUnicode_Type;
1207 Py_INCREF(type);
1208 cond = PyDict_SetItemString(ClassDef_annotations, "name", type) == 0;
1209 Py_DECREF(type);
1210 if (!cond) {
1211 Py_DECREF(ClassDef_annotations);
1212 return 0;
1213 }
1214 }
1215 {
1216 PyObject *type = state->expr_type;
1217 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1218 cond = type != NULL;
1219 if (!cond) {
1220 Py_DECREF(ClassDef_annotations);
1221 return 0;
1222 }
1223 cond = PyDict_SetItemString(ClassDef_annotations, "bases", type) == 0;
1224 Py_DECREF(type);
1225 if (!cond) {
1226 Py_DECREF(ClassDef_annotations);
1227 return 0;
1228 }
1229 }
1230 {
1231 PyObject *type = state->keyword_type;
1232 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1233 cond = type != NULL;
1234 if (!cond) {
1235 Py_DECREF(ClassDef_annotations);
1236 return 0;
1237 }
1238 cond = PyDict_SetItemString(ClassDef_annotations, "keywords", type) ==
1239 0;
1240 Py_DECREF(type);
1241 if (!cond) {
1242 Py_DECREF(ClassDef_annotations);
1243 return 0;
1244 }
1245 }
1246 {
1247 PyObject *type = state->stmt_type;
1248 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1249 cond = type != NULL;
1250 if (!cond) {
1251 Py_DECREF(ClassDef_annotations);
1252 return 0;
1253 }
1254 cond = PyDict_SetItemString(ClassDef_annotations, "body", type) == 0;
1255 Py_DECREF(type);
1256 if (!cond) {
1257 Py_DECREF(ClassDef_annotations);
1258 return 0;
1259 }
1260 }
1261 {
1262 PyObject *type = state->expr_type;
1263 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1264 cond = type != NULL;
1265 if (!cond) {
1266 Py_DECREF(ClassDef_annotations);
1267 return 0;
1268 }
1269 cond = PyDict_SetItemString(ClassDef_annotations, "decorator_list",
1270 type) == 0;
1271 Py_DECREF(type);
1272 if (!cond) {
1273 Py_DECREF(ClassDef_annotations);
1274 return 0;
1275 }
1276 }
1277 {
1278 PyObject *type = state->type_param_type;
1279 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1280 cond = type != NULL;
1281 if (!cond) {
1282 Py_DECREF(ClassDef_annotations);
1283 return 0;
1284 }
1285 cond = PyDict_SetItemString(ClassDef_annotations, "type_params", type)
1286 == 0;
1287 Py_DECREF(type);
1288 if (!cond) {
1289 Py_DECREF(ClassDef_annotations);
1290 return 0;
1291 }
1292 }
1293 cond = PyObject_SetAttrString(state->ClassDef_type, "_field_types",
1294 ClassDef_annotations) == 0;
1295 if (!cond) {
1296 Py_DECREF(ClassDef_annotations);
1297 return 0;
1298 }
1299 cond = PyObject_SetAttrString(state->ClassDef_type, "__annotations__",
1300 ClassDef_annotations) == 0;
1301 if (!cond) {
1302 Py_DECREF(ClassDef_annotations);
1303 return 0;
1304 }
1305 Py_DECREF(ClassDef_annotations);
1306 PyObject *Return_annotations = PyDict_New();
1307 if (!Return_annotations) return 0;
1308 {
1309 PyObject *type = state->expr_type;
1310 type = _Py_union_type_or(type, Py_None);
1311 cond = type != NULL;
1312 if (!cond) {
1313 Py_DECREF(Return_annotations);
1314 return 0;
1315 }
1316 cond = PyDict_SetItemString(Return_annotations, "value", type) == 0;
1317 Py_DECREF(type);
1318 if (!cond) {
1319 Py_DECREF(Return_annotations);
1320 return 0;
1321 }
1322 }
1323 cond = PyObject_SetAttrString(state->Return_type, "_field_types",
1324 Return_annotations) == 0;
1325 if (!cond) {
1326 Py_DECREF(Return_annotations);
1327 return 0;
1328 }
1329 cond = PyObject_SetAttrString(state->Return_type, "__annotations__",
1330 Return_annotations) == 0;
1331 if (!cond) {
1332 Py_DECREF(Return_annotations);
1333 return 0;
1334 }
1335 Py_DECREF(Return_annotations);
1336 PyObject *Delete_annotations = PyDict_New();
1337 if (!Delete_annotations) return 0;
1338 {
1339 PyObject *type = state->expr_type;
1340 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1341 cond = type != NULL;
1342 if (!cond) {
1343 Py_DECREF(Delete_annotations);
1344 return 0;
1345 }
1346 cond = PyDict_SetItemString(Delete_annotations, "targets", type) == 0;
1347 Py_DECREF(type);
1348 if (!cond) {
1349 Py_DECREF(Delete_annotations);
1350 return 0;
1351 }
1352 }
1353 cond = PyObject_SetAttrString(state->Delete_type, "_field_types",
1354 Delete_annotations) == 0;
1355 if (!cond) {
1356 Py_DECREF(Delete_annotations);
1357 return 0;
1358 }
1359 cond = PyObject_SetAttrString(state->Delete_type, "__annotations__",
1360 Delete_annotations) == 0;
1361 if (!cond) {
1362 Py_DECREF(Delete_annotations);
1363 return 0;
1364 }
1365 Py_DECREF(Delete_annotations);
1366 PyObject *Assign_annotations = PyDict_New();
1367 if (!Assign_annotations) return 0;
1368 {
1369 PyObject *type = state->expr_type;
1370 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1371 cond = type != NULL;
1372 if (!cond) {
1373 Py_DECREF(Assign_annotations);
1374 return 0;
1375 }
1376 cond = PyDict_SetItemString(Assign_annotations, "targets", type) == 0;
1377 Py_DECREF(type);
1378 if (!cond) {
1379 Py_DECREF(Assign_annotations);
1380 return 0;
1381 }
1382 }
1383 {
1384 PyObject *type = state->expr_type;
1385 Py_INCREF(type);
1386 cond = PyDict_SetItemString(Assign_annotations, "value", type) == 0;
1387 Py_DECREF(type);
1388 if (!cond) {
1389 Py_DECREF(Assign_annotations);
1390 return 0;
1391 }
1392 }
1393 {
1394 PyObject *type = (PyObject *)&PyUnicode_Type;
1395 type = _Py_union_type_or(type, Py_None);
1396 cond = type != NULL;
1397 if (!cond) {
1398 Py_DECREF(Assign_annotations);
1399 return 0;
1400 }
1401 cond = PyDict_SetItemString(Assign_annotations, "type_comment", type)
1402 == 0;
1403 Py_DECREF(type);
1404 if (!cond) {
1405 Py_DECREF(Assign_annotations);
1406 return 0;
1407 }
1408 }
1409 cond = PyObject_SetAttrString(state->Assign_type, "_field_types",
1410 Assign_annotations) == 0;
1411 if (!cond) {
1412 Py_DECREF(Assign_annotations);
1413 return 0;
1414 }
1415 cond = PyObject_SetAttrString(state->Assign_type, "__annotations__",
1416 Assign_annotations) == 0;
1417 if (!cond) {
1418 Py_DECREF(Assign_annotations);
1419 return 0;
1420 }
1421 Py_DECREF(Assign_annotations);
1422 PyObject *TypeAlias_annotations = PyDict_New();
1423 if (!TypeAlias_annotations) return 0;
1424 {
1425 PyObject *type = state->expr_type;
1426 Py_INCREF(type);
1427 cond = PyDict_SetItemString(TypeAlias_annotations, "name", type) == 0;
1428 Py_DECREF(type);
1429 if (!cond) {
1430 Py_DECREF(TypeAlias_annotations);
1431 return 0;
1432 }
1433 }
1434 {
1435 PyObject *type = state->type_param_type;
1436 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1437 cond = type != NULL;
1438 if (!cond) {
1439 Py_DECREF(TypeAlias_annotations);
1440 return 0;
1441 }
1442 cond = PyDict_SetItemString(TypeAlias_annotations, "type_params", type)
1443 == 0;
1444 Py_DECREF(type);
1445 if (!cond) {
1446 Py_DECREF(TypeAlias_annotations);
1447 return 0;
1448 }
1449 }
1450 {
1451 PyObject *type = state->expr_type;
1452 Py_INCREF(type);
1453 cond = PyDict_SetItemString(TypeAlias_annotations, "value", type) == 0;
1454 Py_DECREF(type);
1455 if (!cond) {
1456 Py_DECREF(TypeAlias_annotations);
1457 return 0;
1458 }
1459 }
1460 cond = PyObject_SetAttrString(state->TypeAlias_type, "_field_types",
1461 TypeAlias_annotations) == 0;
1462 if (!cond) {
1463 Py_DECREF(TypeAlias_annotations);
1464 return 0;
1465 }
1466 cond = PyObject_SetAttrString(state->TypeAlias_type, "__annotations__",
1467 TypeAlias_annotations) == 0;
1468 if (!cond) {
1469 Py_DECREF(TypeAlias_annotations);
1470 return 0;
1471 }
1472 Py_DECREF(TypeAlias_annotations);
1473 PyObject *AugAssign_annotations = PyDict_New();
1474 if (!AugAssign_annotations) return 0;
1475 {
1476 PyObject *type = state->expr_type;
1477 Py_INCREF(type);
1478 cond = PyDict_SetItemString(AugAssign_annotations, "target", type) == 0;
1479 Py_DECREF(type);
1480 if (!cond) {
1481 Py_DECREF(AugAssign_annotations);
1482 return 0;
1483 }
1484 }
1485 {
1486 PyObject *type = state->operator_type;
1487 Py_INCREF(type);
1488 cond = PyDict_SetItemString(AugAssign_annotations, "op", type) == 0;
1489 Py_DECREF(type);
1490 if (!cond) {
1491 Py_DECREF(AugAssign_annotations);
1492 return 0;
1493 }
1494 }
1495 {
1496 PyObject *type = state->expr_type;
1497 Py_INCREF(type);
1498 cond = PyDict_SetItemString(AugAssign_annotations, "value", type) == 0;
1499 Py_DECREF(type);
1500 if (!cond) {
1501 Py_DECREF(AugAssign_annotations);
1502 return 0;
1503 }
1504 }
1505 cond = PyObject_SetAttrString(state->AugAssign_type, "_field_types",
1506 AugAssign_annotations) == 0;
1507 if (!cond) {
1508 Py_DECREF(AugAssign_annotations);
1509 return 0;
1510 }
1511 cond = PyObject_SetAttrString(state->AugAssign_type, "__annotations__",
1512 AugAssign_annotations) == 0;
1513 if (!cond) {
1514 Py_DECREF(AugAssign_annotations);
1515 return 0;
1516 }
1517 Py_DECREF(AugAssign_annotations);
1518 PyObject *AnnAssign_annotations = PyDict_New();
1519 if (!AnnAssign_annotations) return 0;
1520 {
1521 PyObject *type = state->expr_type;
1522 Py_INCREF(type);
1523 cond = PyDict_SetItemString(AnnAssign_annotations, "target", type) == 0;
1524 Py_DECREF(type);
1525 if (!cond) {
1526 Py_DECREF(AnnAssign_annotations);
1527 return 0;
1528 }
1529 }
1530 {
1531 PyObject *type = state->expr_type;
1532 Py_INCREF(type);
1533 cond = PyDict_SetItemString(AnnAssign_annotations, "annotation", type)
1534 == 0;
1535 Py_DECREF(type);
1536 if (!cond) {
1537 Py_DECREF(AnnAssign_annotations);
1538 return 0;
1539 }
1540 }
1541 {
1542 PyObject *type = state->expr_type;
1543 type = _Py_union_type_or(type, Py_None);
1544 cond = type != NULL;
1545 if (!cond) {
1546 Py_DECREF(AnnAssign_annotations);
1547 return 0;
1548 }
1549 cond = PyDict_SetItemString(AnnAssign_annotations, "value", type) == 0;
1550 Py_DECREF(type);
1551 if (!cond) {
1552 Py_DECREF(AnnAssign_annotations);
1553 return 0;
1554 }
1555 }
1556 {
1557 PyObject *type = (PyObject *)&PyLong_Type;
1558 Py_INCREF(type);
1559 cond = PyDict_SetItemString(AnnAssign_annotations, "simple", type) == 0;
1560 Py_DECREF(type);
1561 if (!cond) {
1562 Py_DECREF(AnnAssign_annotations);
1563 return 0;
1564 }
1565 }
1566 cond = PyObject_SetAttrString(state->AnnAssign_type, "_field_types",
1567 AnnAssign_annotations) == 0;
1568 if (!cond) {
1569 Py_DECREF(AnnAssign_annotations);
1570 return 0;
1571 }
1572 cond = PyObject_SetAttrString(state->AnnAssign_type, "__annotations__",
1573 AnnAssign_annotations) == 0;
1574 if (!cond) {
1575 Py_DECREF(AnnAssign_annotations);
1576 return 0;
1577 }
1578 Py_DECREF(AnnAssign_annotations);
1579 PyObject *For_annotations = PyDict_New();
1580 if (!For_annotations) return 0;
1581 {
1582 PyObject *type = state->expr_type;
1583 Py_INCREF(type);
1584 cond = PyDict_SetItemString(For_annotations, "target", type) == 0;
1585 Py_DECREF(type);
1586 if (!cond) {
1587 Py_DECREF(For_annotations);
1588 return 0;
1589 }
1590 }
1591 {
1592 PyObject *type = state->expr_type;
1593 Py_INCREF(type);
1594 cond = PyDict_SetItemString(For_annotations, "iter", type) == 0;
1595 Py_DECREF(type);
1596 if (!cond) {
1597 Py_DECREF(For_annotations);
1598 return 0;
1599 }
1600 }
1601 {
1602 PyObject *type = state->stmt_type;
1603 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1604 cond = type != NULL;
1605 if (!cond) {
1606 Py_DECREF(For_annotations);
1607 return 0;
1608 }
1609 cond = PyDict_SetItemString(For_annotations, "body", type) == 0;
1610 Py_DECREF(type);
1611 if (!cond) {
1612 Py_DECREF(For_annotations);
1613 return 0;
1614 }
1615 }
1616 {
1617 PyObject *type = state->stmt_type;
1618 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1619 cond = type != NULL;
1620 if (!cond) {
1621 Py_DECREF(For_annotations);
1622 return 0;
1623 }
1624 cond = PyDict_SetItemString(For_annotations, "orelse", type) == 0;
1625 Py_DECREF(type);
1626 if (!cond) {
1627 Py_DECREF(For_annotations);
1628 return 0;
1629 }
1630 }
1631 {
1632 PyObject *type = (PyObject *)&PyUnicode_Type;
1633 type = _Py_union_type_or(type, Py_None);
1634 cond = type != NULL;
1635 if (!cond) {
1636 Py_DECREF(For_annotations);
1637 return 0;
1638 }
1639 cond = PyDict_SetItemString(For_annotations, "type_comment", type) == 0;
1640 Py_DECREF(type);
1641 if (!cond) {
1642 Py_DECREF(For_annotations);
1643 return 0;
1644 }
1645 }
1646 cond = PyObject_SetAttrString(state->For_type, "_field_types",
1647 For_annotations) == 0;
1648 if (!cond) {
1649 Py_DECREF(For_annotations);
1650 return 0;
1651 }
1652 cond = PyObject_SetAttrString(state->For_type, "__annotations__",
1653 For_annotations) == 0;
1654 if (!cond) {
1655 Py_DECREF(For_annotations);
1656 return 0;
1657 }
1658 Py_DECREF(For_annotations);
1659 PyObject *AsyncFor_annotations = PyDict_New();
1660 if (!AsyncFor_annotations) return 0;
1661 {
1662 PyObject *type = state->expr_type;
1663 Py_INCREF(type);
1664 cond = PyDict_SetItemString(AsyncFor_annotations, "target", type) == 0;
1665 Py_DECREF(type);
1666 if (!cond) {
1667 Py_DECREF(AsyncFor_annotations);
1668 return 0;
1669 }
1670 }
1671 {
1672 PyObject *type = state->expr_type;
1673 Py_INCREF(type);
1674 cond = PyDict_SetItemString(AsyncFor_annotations, "iter", type) == 0;
1675 Py_DECREF(type);
1676 if (!cond) {
1677 Py_DECREF(AsyncFor_annotations);
1678 return 0;
1679 }
1680 }
1681 {
1682 PyObject *type = state->stmt_type;
1683 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1684 cond = type != NULL;
1685 if (!cond) {
1686 Py_DECREF(AsyncFor_annotations);
1687 return 0;
1688 }
1689 cond = PyDict_SetItemString(AsyncFor_annotations, "body", type) == 0;
1690 Py_DECREF(type);
1691 if (!cond) {
1692 Py_DECREF(AsyncFor_annotations);
1693 return 0;
1694 }
1695 }
1696 {
1697 PyObject *type = state->stmt_type;
1698 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1699 cond = type != NULL;
1700 if (!cond) {
1701 Py_DECREF(AsyncFor_annotations);
1702 return 0;
1703 }
1704 cond = PyDict_SetItemString(AsyncFor_annotations, "orelse", type) == 0;
1705 Py_DECREF(type);
1706 if (!cond) {
1707 Py_DECREF(AsyncFor_annotations);
1708 return 0;
1709 }
1710 }
1711 {
1712 PyObject *type = (PyObject *)&PyUnicode_Type;
1713 type = _Py_union_type_or(type, Py_None);
1714 cond = type != NULL;
1715 if (!cond) {
1716 Py_DECREF(AsyncFor_annotations);
1717 return 0;
1718 }
1719 cond = PyDict_SetItemString(AsyncFor_annotations, "type_comment", type)
1720 == 0;
1721 Py_DECREF(type);
1722 if (!cond) {
1723 Py_DECREF(AsyncFor_annotations);
1724 return 0;
1725 }
1726 }
1727 cond = PyObject_SetAttrString(state->AsyncFor_type, "_field_types",
1728 AsyncFor_annotations) == 0;
1729 if (!cond) {
1730 Py_DECREF(AsyncFor_annotations);
1731 return 0;
1732 }
1733 cond = PyObject_SetAttrString(state->AsyncFor_type, "__annotations__",
1734 AsyncFor_annotations) == 0;
1735 if (!cond) {
1736 Py_DECREF(AsyncFor_annotations);
1737 return 0;
1738 }
1739 Py_DECREF(AsyncFor_annotations);
1740 PyObject *While_annotations = PyDict_New();
1741 if (!While_annotations) return 0;
1742 {
1743 PyObject *type = state->expr_type;
1744 Py_INCREF(type);
1745 cond = PyDict_SetItemString(While_annotations, "test", type) == 0;
1746 Py_DECREF(type);
1747 if (!cond) {
1748 Py_DECREF(While_annotations);
1749 return 0;
1750 }
1751 }
1752 {
1753 PyObject *type = state->stmt_type;
1754 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1755 cond = type != NULL;
1756 if (!cond) {
1757 Py_DECREF(While_annotations);
1758 return 0;
1759 }
1760 cond = PyDict_SetItemString(While_annotations, "body", type) == 0;
1761 Py_DECREF(type);
1762 if (!cond) {
1763 Py_DECREF(While_annotations);
1764 return 0;
1765 }
1766 }
1767 {
1768 PyObject *type = state->stmt_type;
1769 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1770 cond = type != NULL;
1771 if (!cond) {
1772 Py_DECREF(While_annotations);
1773 return 0;
1774 }
1775 cond = PyDict_SetItemString(While_annotations, "orelse", type) == 0;
1776 Py_DECREF(type);
1777 if (!cond) {
1778 Py_DECREF(While_annotations);
1779 return 0;
1780 }
1781 }
1782 cond = PyObject_SetAttrString(state->While_type, "_field_types",
1783 While_annotations) == 0;
1784 if (!cond) {
1785 Py_DECREF(While_annotations);
1786 return 0;
1787 }
1788 cond = PyObject_SetAttrString(state->While_type, "__annotations__",
1789 While_annotations) == 0;
1790 if (!cond) {
1791 Py_DECREF(While_annotations);
1792 return 0;
1793 }
1794 Py_DECREF(While_annotations);
1795 PyObject *If_annotations = PyDict_New();
1796 if (!If_annotations) return 0;
1797 {
1798 PyObject *type = state->expr_type;
1799 Py_INCREF(type);
1800 cond = PyDict_SetItemString(If_annotations, "test", type) == 0;
1801 Py_DECREF(type);
1802 if (!cond) {
1803 Py_DECREF(If_annotations);
1804 return 0;
1805 }
1806 }
1807 {
1808 PyObject *type = state->stmt_type;
1809 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1810 cond = type != NULL;
1811 if (!cond) {
1812 Py_DECREF(If_annotations);
1813 return 0;
1814 }
1815 cond = PyDict_SetItemString(If_annotations, "body", type) == 0;
1816 Py_DECREF(type);
1817 if (!cond) {
1818 Py_DECREF(If_annotations);
1819 return 0;
1820 }
1821 }
1822 {
1823 PyObject *type = state->stmt_type;
1824 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1825 cond = type != NULL;
1826 if (!cond) {
1827 Py_DECREF(If_annotations);
1828 return 0;
1829 }
1830 cond = PyDict_SetItemString(If_annotations, "orelse", type) == 0;
1831 Py_DECREF(type);
1832 if (!cond) {
1833 Py_DECREF(If_annotations);
1834 return 0;
1835 }
1836 }
1837 cond = PyObject_SetAttrString(state->If_type, "_field_types",
1838 If_annotations) == 0;
1839 if (!cond) {
1840 Py_DECREF(If_annotations);
1841 return 0;
1842 }
1843 cond = PyObject_SetAttrString(state->If_type, "__annotations__",
1844 If_annotations) == 0;
1845 if (!cond) {
1846 Py_DECREF(If_annotations);
1847 return 0;
1848 }
1849 Py_DECREF(If_annotations);
1850 PyObject *With_annotations = PyDict_New();
1851 if (!With_annotations) return 0;
1852 {
1853 PyObject *type = state->withitem_type;
1854 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1855 cond = type != NULL;
1856 if (!cond) {
1857 Py_DECREF(With_annotations);
1858 return 0;
1859 }
1860 cond = PyDict_SetItemString(With_annotations, "items", type) == 0;
1861 Py_DECREF(type);
1862 if (!cond) {
1863 Py_DECREF(With_annotations);
1864 return 0;
1865 }
1866 }
1867 {
1868 PyObject *type = state->stmt_type;
1869 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1870 cond = type != NULL;
1871 if (!cond) {
1872 Py_DECREF(With_annotations);
1873 return 0;
1874 }
1875 cond = PyDict_SetItemString(With_annotations, "body", type) == 0;
1876 Py_DECREF(type);
1877 if (!cond) {
1878 Py_DECREF(With_annotations);
1879 return 0;
1880 }
1881 }
1882 {
1883 PyObject *type = (PyObject *)&PyUnicode_Type;
1884 type = _Py_union_type_or(type, Py_None);
1885 cond = type != NULL;
1886 if (!cond) {
1887 Py_DECREF(With_annotations);
1888 return 0;
1889 }
1890 cond = PyDict_SetItemString(With_annotations, "type_comment", type) ==
1891 0;
1892 Py_DECREF(type);
1893 if (!cond) {
1894 Py_DECREF(With_annotations);
1895 return 0;
1896 }
1897 }
1898 cond = PyObject_SetAttrString(state->With_type, "_field_types",
1899 With_annotations) == 0;
1900 if (!cond) {
1901 Py_DECREF(With_annotations);
1902 return 0;
1903 }
1904 cond = PyObject_SetAttrString(state->With_type, "__annotations__",
1905 With_annotations) == 0;
1906 if (!cond) {
1907 Py_DECREF(With_annotations);
1908 return 0;
1909 }
1910 Py_DECREF(With_annotations);
1911 PyObject *AsyncWith_annotations = PyDict_New();
1912 if (!AsyncWith_annotations) return 0;
1913 {
1914 PyObject *type = state->withitem_type;
1915 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1916 cond = type != NULL;
1917 if (!cond) {
1918 Py_DECREF(AsyncWith_annotations);
1919 return 0;
1920 }
1921 cond = PyDict_SetItemString(AsyncWith_annotations, "items", type) == 0;
1922 Py_DECREF(type);
1923 if (!cond) {
1924 Py_DECREF(AsyncWith_annotations);
1925 return 0;
1926 }
1927 }
1928 {
1929 PyObject *type = state->stmt_type;
1930 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1931 cond = type != NULL;
1932 if (!cond) {
1933 Py_DECREF(AsyncWith_annotations);
1934 return 0;
1935 }
1936 cond = PyDict_SetItemString(AsyncWith_annotations, "body", type) == 0;
1937 Py_DECREF(type);
1938 if (!cond) {
1939 Py_DECREF(AsyncWith_annotations);
1940 return 0;
1941 }
1942 }
1943 {
1944 PyObject *type = (PyObject *)&PyUnicode_Type;
1945 type = _Py_union_type_or(type, Py_None);
1946 cond = type != NULL;
1947 if (!cond) {
1948 Py_DECREF(AsyncWith_annotations);
1949 return 0;
1950 }
1951 cond = PyDict_SetItemString(AsyncWith_annotations, "type_comment",
1952 type) == 0;
1953 Py_DECREF(type);
1954 if (!cond) {
1955 Py_DECREF(AsyncWith_annotations);
1956 return 0;
1957 }
1958 }
1959 cond = PyObject_SetAttrString(state->AsyncWith_type, "_field_types",
1960 AsyncWith_annotations) == 0;
1961 if (!cond) {
1962 Py_DECREF(AsyncWith_annotations);
1963 return 0;
1964 }
1965 cond = PyObject_SetAttrString(state->AsyncWith_type, "__annotations__",
1966 AsyncWith_annotations) == 0;
1967 if (!cond) {
1968 Py_DECREF(AsyncWith_annotations);
1969 return 0;
1970 }
1971 Py_DECREF(AsyncWith_annotations);
1972 PyObject *Match_annotations = PyDict_New();
1973 if (!Match_annotations) return 0;
1974 {
1975 PyObject *type = state->expr_type;
1976 Py_INCREF(type);
1977 cond = PyDict_SetItemString(Match_annotations, "subject", type) == 0;
1978 Py_DECREF(type);
1979 if (!cond) {
1980 Py_DECREF(Match_annotations);
1981 return 0;
1982 }
1983 }
1984 {
1985 PyObject *type = state->match_case_type;
1986 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
1987 cond = type != NULL;
1988 if (!cond) {
1989 Py_DECREF(Match_annotations);
1990 return 0;
1991 }
1992 cond = PyDict_SetItemString(Match_annotations, "cases", type) == 0;
1993 Py_DECREF(type);
1994 if (!cond) {
1995 Py_DECREF(Match_annotations);
1996 return 0;
1997 }
1998 }
1999 cond = PyObject_SetAttrString(state->Match_type, "_field_types",
2000 Match_annotations) == 0;
2001 if (!cond) {
2002 Py_DECREF(Match_annotations);
2003 return 0;
2004 }
2005 cond = PyObject_SetAttrString(state->Match_type, "__annotations__",
2006 Match_annotations) == 0;
2007 if (!cond) {
2008 Py_DECREF(Match_annotations);
2009 return 0;
2010 }
2011 Py_DECREF(Match_annotations);
2012 PyObject *Raise_annotations = PyDict_New();
2013 if (!Raise_annotations) return 0;
2014 {
2015 PyObject *type = state->expr_type;
2016 type = _Py_union_type_or(type, Py_None);
2017 cond = type != NULL;
2018 if (!cond) {
2019 Py_DECREF(Raise_annotations);
2020 return 0;
2021 }
2022 cond = PyDict_SetItemString(Raise_annotations, "exc", type) == 0;
2023 Py_DECREF(type);
2024 if (!cond) {
2025 Py_DECREF(Raise_annotations);
2026 return 0;
2027 }
2028 }
2029 {
2030 PyObject *type = state->expr_type;
2031 type = _Py_union_type_or(type, Py_None);
2032 cond = type != NULL;
2033 if (!cond) {
2034 Py_DECREF(Raise_annotations);
2035 return 0;
2036 }
2037 cond = PyDict_SetItemString(Raise_annotations, "cause", type) == 0;
2038 Py_DECREF(type);
2039 if (!cond) {
2040 Py_DECREF(Raise_annotations);
2041 return 0;
2042 }
2043 }
2044 cond = PyObject_SetAttrString(state->Raise_type, "_field_types",
2045 Raise_annotations) == 0;
2046 if (!cond) {
2047 Py_DECREF(Raise_annotations);
2048 return 0;
2049 }
2050 cond = PyObject_SetAttrString(state->Raise_type, "__annotations__",
2051 Raise_annotations) == 0;
2052 if (!cond) {
2053 Py_DECREF(Raise_annotations);
2054 return 0;
2055 }
2056 Py_DECREF(Raise_annotations);
2057 PyObject *Try_annotations = PyDict_New();
2058 if (!Try_annotations) return 0;
2059 {
2060 PyObject *type = state->stmt_type;
2061 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2062 cond = type != NULL;
2063 if (!cond) {
2064 Py_DECREF(Try_annotations);
2065 return 0;
2066 }
2067 cond = PyDict_SetItemString(Try_annotations, "body", type) == 0;
2068 Py_DECREF(type);
2069 if (!cond) {
2070 Py_DECREF(Try_annotations);
2071 return 0;
2072 }
2073 }
2074 {
2075 PyObject *type = state->excepthandler_type;
2076 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2077 cond = type != NULL;
2078 if (!cond) {
2079 Py_DECREF(Try_annotations);
2080 return 0;
2081 }
2082 cond = PyDict_SetItemString(Try_annotations, "handlers", type) == 0;
2083 Py_DECREF(type);
2084 if (!cond) {
2085 Py_DECREF(Try_annotations);
2086 return 0;
2087 }
2088 }
2089 {
2090 PyObject *type = state->stmt_type;
2091 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2092 cond = type != NULL;
2093 if (!cond) {
2094 Py_DECREF(Try_annotations);
2095 return 0;
2096 }
2097 cond = PyDict_SetItemString(Try_annotations, "orelse", type) == 0;
2098 Py_DECREF(type);
2099 if (!cond) {
2100 Py_DECREF(Try_annotations);
2101 return 0;
2102 }
2103 }
2104 {
2105 PyObject *type = state->stmt_type;
2106 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2107 cond = type != NULL;
2108 if (!cond) {
2109 Py_DECREF(Try_annotations);
2110 return 0;
2111 }
2112 cond = PyDict_SetItemString(Try_annotations, "finalbody", type) == 0;
2113 Py_DECREF(type);
2114 if (!cond) {
2115 Py_DECREF(Try_annotations);
2116 return 0;
2117 }
2118 }
2119 cond = PyObject_SetAttrString(state->Try_type, "_field_types",
2120 Try_annotations) == 0;
2121 if (!cond) {
2122 Py_DECREF(Try_annotations);
2123 return 0;
2124 }
2125 cond = PyObject_SetAttrString(state->Try_type, "__annotations__",
2126 Try_annotations) == 0;
2127 if (!cond) {
2128 Py_DECREF(Try_annotations);
2129 return 0;
2130 }
2131 Py_DECREF(Try_annotations);
2132 PyObject *TryStar_annotations = PyDict_New();
2133 if (!TryStar_annotations) return 0;
2134 {
2135 PyObject *type = state->stmt_type;
2136 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2137 cond = type != NULL;
2138 if (!cond) {
2139 Py_DECREF(TryStar_annotations);
2140 return 0;
2141 }
2142 cond = PyDict_SetItemString(TryStar_annotations, "body", type) == 0;
2143 Py_DECREF(type);
2144 if (!cond) {
2145 Py_DECREF(TryStar_annotations);
2146 return 0;
2147 }
2148 }
2149 {
2150 PyObject *type = state->excepthandler_type;
2151 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2152 cond = type != NULL;
2153 if (!cond) {
2154 Py_DECREF(TryStar_annotations);
2155 return 0;
2156 }
2157 cond = PyDict_SetItemString(TryStar_annotations, "handlers", type) == 0;
2158 Py_DECREF(type);
2159 if (!cond) {
2160 Py_DECREF(TryStar_annotations);
2161 return 0;
2162 }
2163 }
2164 {
2165 PyObject *type = state->stmt_type;
2166 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2167 cond = type != NULL;
2168 if (!cond) {
2169 Py_DECREF(TryStar_annotations);
2170 return 0;
2171 }
2172 cond = PyDict_SetItemString(TryStar_annotations, "orelse", type) == 0;
2173 Py_DECREF(type);
2174 if (!cond) {
2175 Py_DECREF(TryStar_annotations);
2176 return 0;
2177 }
2178 }
2179 {
2180 PyObject *type = state->stmt_type;
2181 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2182 cond = type != NULL;
2183 if (!cond) {
2184 Py_DECREF(TryStar_annotations);
2185 return 0;
2186 }
2187 cond = PyDict_SetItemString(TryStar_annotations, "finalbody", type) ==
2188 0;
2189 Py_DECREF(type);
2190 if (!cond) {
2191 Py_DECREF(TryStar_annotations);
2192 return 0;
2193 }
2194 }
2195 cond = PyObject_SetAttrString(state->TryStar_type, "_field_types",
2196 TryStar_annotations) == 0;
2197 if (!cond) {
2198 Py_DECREF(TryStar_annotations);
2199 return 0;
2200 }
2201 cond = PyObject_SetAttrString(state->TryStar_type, "__annotations__",
2202 TryStar_annotations) == 0;
2203 if (!cond) {
2204 Py_DECREF(TryStar_annotations);
2205 return 0;
2206 }
2207 Py_DECREF(TryStar_annotations);
2208 PyObject *Assert_annotations = PyDict_New();
2209 if (!Assert_annotations) return 0;
2210 {
2211 PyObject *type = state->expr_type;
2212 Py_INCREF(type);
2213 cond = PyDict_SetItemString(Assert_annotations, "test", type) == 0;
2214 Py_DECREF(type);
2215 if (!cond) {
2216 Py_DECREF(Assert_annotations);
2217 return 0;
2218 }
2219 }
2220 {
2221 PyObject *type = state->expr_type;
2222 type = _Py_union_type_or(type, Py_None);
2223 cond = type != NULL;
2224 if (!cond) {
2225 Py_DECREF(Assert_annotations);
2226 return 0;
2227 }
2228 cond = PyDict_SetItemString(Assert_annotations, "msg", type) == 0;
2229 Py_DECREF(type);
2230 if (!cond) {
2231 Py_DECREF(Assert_annotations);
2232 return 0;
2233 }
2234 }
2235 cond = PyObject_SetAttrString(state->Assert_type, "_field_types",
2236 Assert_annotations) == 0;
2237 if (!cond) {
2238 Py_DECREF(Assert_annotations);
2239 return 0;
2240 }
2241 cond = PyObject_SetAttrString(state->Assert_type, "__annotations__",
2242 Assert_annotations) == 0;
2243 if (!cond) {
2244 Py_DECREF(Assert_annotations);
2245 return 0;
2246 }
2247 Py_DECREF(Assert_annotations);
2248 PyObject *Import_annotations = PyDict_New();
2249 if (!Import_annotations) return 0;
2250 {
2251 PyObject *type = state->alias_type;
2252 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2253 cond = type != NULL;
2254 if (!cond) {
2255 Py_DECREF(Import_annotations);
2256 return 0;
2257 }
2258 cond = PyDict_SetItemString(Import_annotations, "names", type) == 0;
2259 Py_DECREF(type);
2260 if (!cond) {
2261 Py_DECREF(Import_annotations);
2262 return 0;
2263 }
2264 }
2265 cond = PyObject_SetAttrString(state->Import_type, "_field_types",
2266 Import_annotations) == 0;
2267 if (!cond) {
2268 Py_DECREF(Import_annotations);
2269 return 0;
2270 }
2271 cond = PyObject_SetAttrString(state->Import_type, "__annotations__",
2272 Import_annotations) == 0;
2273 if (!cond) {
2274 Py_DECREF(Import_annotations);
2275 return 0;
2276 }
2277 Py_DECREF(Import_annotations);
2278 PyObject *ImportFrom_annotations = PyDict_New();
2279 if (!ImportFrom_annotations) return 0;
2280 {
2281 PyObject *type = (PyObject *)&PyUnicode_Type;
2282 type = _Py_union_type_or(type, Py_None);
2283 cond = type != NULL;
2284 if (!cond) {
2285 Py_DECREF(ImportFrom_annotations);
2286 return 0;
2287 }
2288 cond = PyDict_SetItemString(ImportFrom_annotations, "module", type) ==
2289 0;
2290 Py_DECREF(type);
2291 if (!cond) {
2292 Py_DECREF(ImportFrom_annotations);
2293 return 0;
2294 }
2295 }
2296 {
2297 PyObject *type = state->alias_type;
2298 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2299 cond = type != NULL;
2300 if (!cond) {
2301 Py_DECREF(ImportFrom_annotations);
2302 return 0;
2303 }
2304 cond = PyDict_SetItemString(ImportFrom_annotations, "names", type) == 0;
2305 Py_DECREF(type);
2306 if (!cond) {
2307 Py_DECREF(ImportFrom_annotations);
2308 return 0;
2309 }
2310 }
2311 {
2312 PyObject *type = (PyObject *)&PyLong_Type;
2313 type = _Py_union_type_or(type, Py_None);
2314 cond = type != NULL;
2315 if (!cond) {
2316 Py_DECREF(ImportFrom_annotations);
2317 return 0;
2318 }
2319 cond = PyDict_SetItemString(ImportFrom_annotations, "level", type) == 0;
2320 Py_DECREF(type);
2321 if (!cond) {
2322 Py_DECREF(ImportFrom_annotations);
2323 return 0;
2324 }
2325 }
2326 cond = PyObject_SetAttrString(state->ImportFrom_type, "_field_types",
2327 ImportFrom_annotations) == 0;
2328 if (!cond) {
2329 Py_DECREF(ImportFrom_annotations);
2330 return 0;
2331 }
2332 cond = PyObject_SetAttrString(state->ImportFrom_type, "__annotations__",
2333 ImportFrom_annotations) == 0;
2334 if (!cond) {
2335 Py_DECREF(ImportFrom_annotations);
2336 return 0;
2337 }
2338 Py_DECREF(ImportFrom_annotations);
2339 PyObject *Global_annotations = PyDict_New();
2340 if (!Global_annotations) return 0;
2341 {
2342 PyObject *type = (PyObject *)&PyUnicode_Type;
2343 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2344 cond = type != NULL;
2345 if (!cond) {
2346 Py_DECREF(Global_annotations);
2347 return 0;
2348 }
2349 cond = PyDict_SetItemString(Global_annotations, "names", type) == 0;
2350 Py_DECREF(type);
2351 if (!cond) {
2352 Py_DECREF(Global_annotations);
2353 return 0;
2354 }
2355 }
2356 cond = PyObject_SetAttrString(state->Global_type, "_field_types",
2357 Global_annotations) == 0;
2358 if (!cond) {
2359 Py_DECREF(Global_annotations);
2360 return 0;
2361 }
2362 cond = PyObject_SetAttrString(state->Global_type, "__annotations__",
2363 Global_annotations) == 0;
2364 if (!cond) {
2365 Py_DECREF(Global_annotations);
2366 return 0;
2367 }
2368 Py_DECREF(Global_annotations);
2369 PyObject *Nonlocal_annotations = PyDict_New();
2370 if (!Nonlocal_annotations) return 0;
2371 {
2372 PyObject *type = (PyObject *)&PyUnicode_Type;
2373 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2374 cond = type != NULL;
2375 if (!cond) {
2376 Py_DECREF(Nonlocal_annotations);
2377 return 0;
2378 }
2379 cond = PyDict_SetItemString(Nonlocal_annotations, "names", type) == 0;
2380 Py_DECREF(type);
2381 if (!cond) {
2382 Py_DECREF(Nonlocal_annotations);
2383 return 0;
2384 }
2385 }
2386 cond = PyObject_SetAttrString(state->Nonlocal_type, "_field_types",
2387 Nonlocal_annotations) == 0;
2388 if (!cond) {
2389 Py_DECREF(Nonlocal_annotations);
2390 return 0;
2391 }
2392 cond = PyObject_SetAttrString(state->Nonlocal_type, "__annotations__",
2393 Nonlocal_annotations) == 0;
2394 if (!cond) {
2395 Py_DECREF(Nonlocal_annotations);
2396 return 0;
2397 }
2398 Py_DECREF(Nonlocal_annotations);
2399 PyObject *Expr_annotations = PyDict_New();
2400 if (!Expr_annotations) return 0;
2401 {
2402 PyObject *type = state->expr_type;
2403 Py_INCREF(type);
2404 cond = PyDict_SetItemString(Expr_annotations, "value", type) == 0;
2405 Py_DECREF(type);
2406 if (!cond) {
2407 Py_DECREF(Expr_annotations);
2408 return 0;
2409 }
2410 }
2411 cond = PyObject_SetAttrString(state->Expr_type, "_field_types",
2412 Expr_annotations) == 0;
2413 if (!cond) {
2414 Py_DECREF(Expr_annotations);
2415 return 0;
2416 }
2417 cond = PyObject_SetAttrString(state->Expr_type, "__annotations__",
2418 Expr_annotations) == 0;
2419 if (!cond) {
2420 Py_DECREF(Expr_annotations);
2421 return 0;
2422 }
2423 Py_DECREF(Expr_annotations);
2424 PyObject *Pass_annotations = PyDict_New();
2425 if (!Pass_annotations) return 0;
2426 cond = PyObject_SetAttrString(state->Pass_type, "_field_types",
2427 Pass_annotations) == 0;
2428 if (!cond) {
2429 Py_DECREF(Pass_annotations);
2430 return 0;
2431 }
2432 cond = PyObject_SetAttrString(state->Pass_type, "__annotations__",
2433 Pass_annotations) == 0;
2434 if (!cond) {
2435 Py_DECREF(Pass_annotations);
2436 return 0;
2437 }
2438 Py_DECREF(Pass_annotations);
2439 PyObject *Break_annotations = PyDict_New();
2440 if (!Break_annotations) return 0;
2441 cond = PyObject_SetAttrString(state->Break_type, "_field_types",
2442 Break_annotations) == 0;
2443 if (!cond) {
2444 Py_DECREF(Break_annotations);
2445 return 0;
2446 }
2447 cond = PyObject_SetAttrString(state->Break_type, "__annotations__",
2448 Break_annotations) == 0;
2449 if (!cond) {
2450 Py_DECREF(Break_annotations);
2451 return 0;
2452 }
2453 Py_DECREF(Break_annotations);
2454 PyObject *Continue_annotations = PyDict_New();
2455 if (!Continue_annotations) return 0;
2456 cond = PyObject_SetAttrString(state->Continue_type, "_field_types",
2457 Continue_annotations) == 0;
2458 if (!cond) {
2459 Py_DECREF(Continue_annotations);
2460 return 0;
2461 }
2462 cond = PyObject_SetAttrString(state->Continue_type, "__annotations__",
2463 Continue_annotations) == 0;
2464 if (!cond) {
2465 Py_DECREF(Continue_annotations);
2466 return 0;
2467 }
2468 Py_DECREF(Continue_annotations);
2469 PyObject *BoolOp_annotations = PyDict_New();
2470 if (!BoolOp_annotations) return 0;
2471 {
2472 PyObject *type = state->boolop_type;
2473 Py_INCREF(type);
2474 cond = PyDict_SetItemString(BoolOp_annotations, "op", type) == 0;
2475 Py_DECREF(type);
2476 if (!cond) {
2477 Py_DECREF(BoolOp_annotations);
2478 return 0;
2479 }
2480 }
2481 {
2482 PyObject *type = state->expr_type;
2483 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2484 cond = type != NULL;
2485 if (!cond) {
2486 Py_DECREF(BoolOp_annotations);
2487 return 0;
2488 }
2489 cond = PyDict_SetItemString(BoolOp_annotations, "values", type) == 0;
2490 Py_DECREF(type);
2491 if (!cond) {
2492 Py_DECREF(BoolOp_annotations);
2493 return 0;
2494 }
2495 }
2496 cond = PyObject_SetAttrString(state->BoolOp_type, "_field_types",
2497 BoolOp_annotations) == 0;
2498 if (!cond) {
2499 Py_DECREF(BoolOp_annotations);
2500 return 0;
2501 }
2502 cond = PyObject_SetAttrString(state->BoolOp_type, "__annotations__",
2503 BoolOp_annotations) == 0;
2504 if (!cond) {
2505 Py_DECREF(BoolOp_annotations);
2506 return 0;
2507 }
2508 Py_DECREF(BoolOp_annotations);
2509 PyObject *NamedExpr_annotations = PyDict_New();
2510 if (!NamedExpr_annotations) return 0;
2511 {
2512 PyObject *type = state->expr_type;
2513 Py_INCREF(type);
2514 cond = PyDict_SetItemString(NamedExpr_annotations, "target", type) == 0;
2515 Py_DECREF(type);
2516 if (!cond) {
2517 Py_DECREF(NamedExpr_annotations);
2518 return 0;
2519 }
2520 }
2521 {
2522 PyObject *type = state->expr_type;
2523 Py_INCREF(type);
2524 cond = PyDict_SetItemString(NamedExpr_annotations, "value", type) == 0;
2525 Py_DECREF(type);
2526 if (!cond) {
2527 Py_DECREF(NamedExpr_annotations);
2528 return 0;
2529 }
2530 }
2531 cond = PyObject_SetAttrString(state->NamedExpr_type, "_field_types",
2532 NamedExpr_annotations) == 0;
2533 if (!cond) {
2534 Py_DECREF(NamedExpr_annotations);
2535 return 0;
2536 }
2537 cond = PyObject_SetAttrString(state->NamedExpr_type, "__annotations__",
2538 NamedExpr_annotations) == 0;
2539 if (!cond) {
2540 Py_DECREF(NamedExpr_annotations);
2541 return 0;
2542 }
2543 Py_DECREF(NamedExpr_annotations);
2544 PyObject *BinOp_annotations = PyDict_New();
2545 if (!BinOp_annotations) return 0;
2546 {
2547 PyObject *type = state->expr_type;
2548 Py_INCREF(type);
2549 cond = PyDict_SetItemString(BinOp_annotations, "left", type) == 0;
2550 Py_DECREF(type);
2551 if (!cond) {
2552 Py_DECREF(BinOp_annotations);
2553 return 0;
2554 }
2555 }
2556 {
2557 PyObject *type = state->operator_type;
2558 Py_INCREF(type);
2559 cond = PyDict_SetItemString(BinOp_annotations, "op", type) == 0;
2560 Py_DECREF(type);
2561 if (!cond) {
2562 Py_DECREF(BinOp_annotations);
2563 return 0;
2564 }
2565 }
2566 {
2567 PyObject *type = state->expr_type;
2568 Py_INCREF(type);
2569 cond = PyDict_SetItemString(BinOp_annotations, "right", type) == 0;
2570 Py_DECREF(type);
2571 if (!cond) {
2572 Py_DECREF(BinOp_annotations);
2573 return 0;
2574 }
2575 }
2576 cond = PyObject_SetAttrString(state->BinOp_type, "_field_types",
2577 BinOp_annotations) == 0;
2578 if (!cond) {
2579 Py_DECREF(BinOp_annotations);
2580 return 0;
2581 }
2582 cond = PyObject_SetAttrString(state->BinOp_type, "__annotations__",
2583 BinOp_annotations) == 0;
2584 if (!cond) {
2585 Py_DECREF(BinOp_annotations);
2586 return 0;
2587 }
2588 Py_DECREF(BinOp_annotations);
2589 PyObject *UnaryOp_annotations = PyDict_New();
2590 if (!UnaryOp_annotations) return 0;
2591 {
2592 PyObject *type = state->unaryop_type;
2593 Py_INCREF(type);
2594 cond = PyDict_SetItemString(UnaryOp_annotations, "op", type) == 0;
2595 Py_DECREF(type);
2596 if (!cond) {
2597 Py_DECREF(UnaryOp_annotations);
2598 return 0;
2599 }
2600 }
2601 {
2602 PyObject *type = state->expr_type;
2603 Py_INCREF(type);
2604 cond = PyDict_SetItemString(UnaryOp_annotations, "operand", type) == 0;
2605 Py_DECREF(type);
2606 if (!cond) {
2607 Py_DECREF(UnaryOp_annotations);
2608 return 0;
2609 }
2610 }
2611 cond = PyObject_SetAttrString(state->UnaryOp_type, "_field_types",
2612 UnaryOp_annotations) == 0;
2613 if (!cond) {
2614 Py_DECREF(UnaryOp_annotations);
2615 return 0;
2616 }
2617 cond = PyObject_SetAttrString(state->UnaryOp_type, "__annotations__",
2618 UnaryOp_annotations) == 0;
2619 if (!cond) {
2620 Py_DECREF(UnaryOp_annotations);
2621 return 0;
2622 }
2623 Py_DECREF(UnaryOp_annotations);
2624 PyObject *Lambda_annotations = PyDict_New();
2625 if (!Lambda_annotations) return 0;
2626 {
2627 PyObject *type = state->arguments_type;
2628 Py_INCREF(type);
2629 cond = PyDict_SetItemString(Lambda_annotations, "args", type) == 0;
2630 Py_DECREF(type);
2631 if (!cond) {
2632 Py_DECREF(Lambda_annotations);
2633 return 0;
2634 }
2635 }
2636 {
2637 PyObject *type = state->expr_type;
2638 Py_INCREF(type);
2639 cond = PyDict_SetItemString(Lambda_annotations, "body", type) == 0;
2640 Py_DECREF(type);
2641 if (!cond) {
2642 Py_DECREF(Lambda_annotations);
2643 return 0;
2644 }
2645 }
2646 cond = PyObject_SetAttrString(state->Lambda_type, "_field_types",
2647 Lambda_annotations) == 0;
2648 if (!cond) {
2649 Py_DECREF(Lambda_annotations);
2650 return 0;
2651 }
2652 cond = PyObject_SetAttrString(state->Lambda_type, "__annotations__",
2653 Lambda_annotations) == 0;
2654 if (!cond) {
2655 Py_DECREF(Lambda_annotations);
2656 return 0;
2657 }
2658 Py_DECREF(Lambda_annotations);
2659 PyObject *IfExp_annotations = PyDict_New();
2660 if (!IfExp_annotations) return 0;
2661 {
2662 PyObject *type = state->expr_type;
2663 Py_INCREF(type);
2664 cond = PyDict_SetItemString(IfExp_annotations, "test", type) == 0;
2665 Py_DECREF(type);
2666 if (!cond) {
2667 Py_DECREF(IfExp_annotations);
2668 return 0;
2669 }
2670 }
2671 {
2672 PyObject *type = state->expr_type;
2673 Py_INCREF(type);
2674 cond = PyDict_SetItemString(IfExp_annotations, "body", type) == 0;
2675 Py_DECREF(type);
2676 if (!cond) {
2677 Py_DECREF(IfExp_annotations);
2678 return 0;
2679 }
2680 }
2681 {
2682 PyObject *type = state->expr_type;
2683 Py_INCREF(type);
2684 cond = PyDict_SetItemString(IfExp_annotations, "orelse", type) == 0;
2685 Py_DECREF(type);
2686 if (!cond) {
2687 Py_DECREF(IfExp_annotations);
2688 return 0;
2689 }
2690 }
2691 cond = PyObject_SetAttrString(state->IfExp_type, "_field_types",
2692 IfExp_annotations) == 0;
2693 if (!cond) {
2694 Py_DECREF(IfExp_annotations);
2695 return 0;
2696 }
2697 cond = PyObject_SetAttrString(state->IfExp_type, "__annotations__",
2698 IfExp_annotations) == 0;
2699 if (!cond) {
2700 Py_DECREF(IfExp_annotations);
2701 return 0;
2702 }
2703 Py_DECREF(IfExp_annotations);
2704 PyObject *Dict_annotations = PyDict_New();
2705 if (!Dict_annotations) return 0;
2706 {
2707 PyObject *type = state->expr_type;
2708 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2709 cond = type != NULL;
2710 if (!cond) {
2711 Py_DECREF(Dict_annotations);
2712 return 0;
2713 }
2714 cond = PyDict_SetItemString(Dict_annotations, "keys", type) == 0;
2715 Py_DECREF(type);
2716 if (!cond) {
2717 Py_DECREF(Dict_annotations);
2718 return 0;
2719 }
2720 }
2721 {
2722 PyObject *type = state->expr_type;
2723 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2724 cond = type != NULL;
2725 if (!cond) {
2726 Py_DECREF(Dict_annotations);
2727 return 0;
2728 }
2729 cond = PyDict_SetItemString(Dict_annotations, "values", type) == 0;
2730 Py_DECREF(type);
2731 if (!cond) {
2732 Py_DECREF(Dict_annotations);
2733 return 0;
2734 }
2735 }
2736 cond = PyObject_SetAttrString(state->Dict_type, "_field_types",
2737 Dict_annotations) == 0;
2738 if (!cond) {
2739 Py_DECREF(Dict_annotations);
2740 return 0;
2741 }
2742 cond = PyObject_SetAttrString(state->Dict_type, "__annotations__",
2743 Dict_annotations) == 0;
2744 if (!cond) {
2745 Py_DECREF(Dict_annotations);
2746 return 0;
2747 }
2748 Py_DECREF(Dict_annotations);
2749 PyObject *Set_annotations = PyDict_New();
2750 if (!Set_annotations) return 0;
2751 {
2752 PyObject *type = state->expr_type;
2753 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2754 cond = type != NULL;
2755 if (!cond) {
2756 Py_DECREF(Set_annotations);
2757 return 0;
2758 }
2759 cond = PyDict_SetItemString(Set_annotations, "elts", type) == 0;
2760 Py_DECREF(type);
2761 if (!cond) {
2762 Py_DECREF(Set_annotations);
2763 return 0;
2764 }
2765 }
2766 cond = PyObject_SetAttrString(state->Set_type, "_field_types",
2767 Set_annotations) == 0;
2768 if (!cond) {
2769 Py_DECREF(Set_annotations);
2770 return 0;
2771 }
2772 cond = PyObject_SetAttrString(state->Set_type, "__annotations__",
2773 Set_annotations) == 0;
2774 if (!cond) {
2775 Py_DECREF(Set_annotations);
2776 return 0;
2777 }
2778 Py_DECREF(Set_annotations);
2779 PyObject *ListComp_annotations = PyDict_New();
2780 if (!ListComp_annotations) return 0;
2781 {
2782 PyObject *type = state->expr_type;
2783 Py_INCREF(type);
2784 cond = PyDict_SetItemString(ListComp_annotations, "elt", type) == 0;
2785 Py_DECREF(type);
2786 if (!cond) {
2787 Py_DECREF(ListComp_annotations);
2788 return 0;
2789 }
2790 }
2791 {
2792 PyObject *type = state->comprehension_type;
2793 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2794 cond = type != NULL;
2795 if (!cond) {
2796 Py_DECREF(ListComp_annotations);
2797 return 0;
2798 }
2799 cond = PyDict_SetItemString(ListComp_annotations, "generators", type)
2800 == 0;
2801 Py_DECREF(type);
2802 if (!cond) {
2803 Py_DECREF(ListComp_annotations);
2804 return 0;
2805 }
2806 }
2807 cond = PyObject_SetAttrString(state->ListComp_type, "_field_types",
2808 ListComp_annotations) == 0;
2809 if (!cond) {
2810 Py_DECREF(ListComp_annotations);
2811 return 0;
2812 }
2813 cond = PyObject_SetAttrString(state->ListComp_type, "__annotations__",
2814 ListComp_annotations) == 0;
2815 if (!cond) {
2816 Py_DECREF(ListComp_annotations);
2817 return 0;
2818 }
2819 Py_DECREF(ListComp_annotations);
2820 PyObject *SetComp_annotations = PyDict_New();
2821 if (!SetComp_annotations) return 0;
2822 {
2823 PyObject *type = state->expr_type;
2824 Py_INCREF(type);
2825 cond = PyDict_SetItemString(SetComp_annotations, "elt", type) == 0;
2826 Py_DECREF(type);
2827 if (!cond) {
2828 Py_DECREF(SetComp_annotations);
2829 return 0;
2830 }
2831 }
2832 {
2833 PyObject *type = state->comprehension_type;
2834 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2835 cond = type != NULL;
2836 if (!cond) {
2837 Py_DECREF(SetComp_annotations);
2838 return 0;
2839 }
2840 cond = PyDict_SetItemString(SetComp_annotations, "generators", type) ==
2841 0;
2842 Py_DECREF(type);
2843 if (!cond) {
2844 Py_DECREF(SetComp_annotations);
2845 return 0;
2846 }
2847 }
2848 cond = PyObject_SetAttrString(state->SetComp_type, "_field_types",
2849 SetComp_annotations) == 0;
2850 if (!cond) {
2851 Py_DECREF(SetComp_annotations);
2852 return 0;
2853 }
2854 cond = PyObject_SetAttrString(state->SetComp_type, "__annotations__",
2855 SetComp_annotations) == 0;
2856 if (!cond) {
2857 Py_DECREF(SetComp_annotations);
2858 return 0;
2859 }
2860 Py_DECREF(SetComp_annotations);
2861 PyObject *DictComp_annotations = PyDict_New();
2862 if (!DictComp_annotations) return 0;
2863 {
2864 PyObject *type = state->expr_type;
2865 Py_INCREF(type);
2866 cond = PyDict_SetItemString(DictComp_annotations, "key", type) == 0;
2867 Py_DECREF(type);
2868 if (!cond) {
2869 Py_DECREF(DictComp_annotations);
2870 return 0;
2871 }
2872 }
2873 {
2874 PyObject *type = state->expr_type;
2875 Py_INCREF(type);
2876 cond = PyDict_SetItemString(DictComp_annotations, "value", type) == 0;
2877 Py_DECREF(type);
2878 if (!cond) {
2879 Py_DECREF(DictComp_annotations);
2880 return 0;
2881 }
2882 }
2883 {
2884 PyObject *type = state->comprehension_type;
2885 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2886 cond = type != NULL;
2887 if (!cond) {
2888 Py_DECREF(DictComp_annotations);
2889 return 0;
2890 }
2891 cond = PyDict_SetItemString(DictComp_annotations, "generators", type)
2892 == 0;
2893 Py_DECREF(type);
2894 if (!cond) {
2895 Py_DECREF(DictComp_annotations);
2896 return 0;
2897 }
2898 }
2899 cond = PyObject_SetAttrString(state->DictComp_type, "_field_types",
2900 DictComp_annotations) == 0;
2901 if (!cond) {
2902 Py_DECREF(DictComp_annotations);
2903 return 0;
2904 }
2905 cond = PyObject_SetAttrString(state->DictComp_type, "__annotations__",
2906 DictComp_annotations) == 0;
2907 if (!cond) {
2908 Py_DECREF(DictComp_annotations);
2909 return 0;
2910 }
2911 Py_DECREF(DictComp_annotations);
2912 PyObject *GeneratorExp_annotations = PyDict_New();
2913 if (!GeneratorExp_annotations) return 0;
2914 {
2915 PyObject *type = state->expr_type;
2916 Py_INCREF(type);
2917 cond = PyDict_SetItemString(GeneratorExp_annotations, "elt", type) == 0;
2918 Py_DECREF(type);
2919 if (!cond) {
2920 Py_DECREF(GeneratorExp_annotations);
2921 return 0;
2922 }
2923 }
2924 {
2925 PyObject *type = state->comprehension_type;
2926 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
2927 cond = type != NULL;
2928 if (!cond) {
2929 Py_DECREF(GeneratorExp_annotations);
2930 return 0;
2931 }
2932 cond = PyDict_SetItemString(GeneratorExp_annotations, "generators",
2933 type) == 0;
2934 Py_DECREF(type);
2935 if (!cond) {
2936 Py_DECREF(GeneratorExp_annotations);
2937 return 0;
2938 }
2939 }
2940 cond = PyObject_SetAttrString(state->GeneratorExp_type, "_field_types",
2941 GeneratorExp_annotations) == 0;
2942 if (!cond) {
2943 Py_DECREF(GeneratorExp_annotations);
2944 return 0;
2945 }
2946 cond = PyObject_SetAttrString(state->GeneratorExp_type, "__annotations__",
2947 GeneratorExp_annotations) == 0;
2948 if (!cond) {
2949 Py_DECREF(GeneratorExp_annotations);
2950 return 0;
2951 }
2952 Py_DECREF(GeneratorExp_annotations);
2953 PyObject *Await_annotations = PyDict_New();
2954 if (!Await_annotations) return 0;
2955 {
2956 PyObject *type = state->expr_type;
2957 Py_INCREF(type);
2958 cond = PyDict_SetItemString(Await_annotations, "value", type) == 0;
2959 Py_DECREF(type);
2960 if (!cond) {
2961 Py_DECREF(Await_annotations);
2962 return 0;
2963 }
2964 }
2965 cond = PyObject_SetAttrString(state->Await_type, "_field_types",
2966 Await_annotations) == 0;
2967 if (!cond) {
2968 Py_DECREF(Await_annotations);
2969 return 0;
2970 }
2971 cond = PyObject_SetAttrString(state->Await_type, "__annotations__",
2972 Await_annotations) == 0;
2973 if (!cond) {
2974 Py_DECREF(Await_annotations);
2975 return 0;
2976 }
2977 Py_DECREF(Await_annotations);
2978 PyObject *Yield_annotations = PyDict_New();
2979 if (!Yield_annotations) return 0;
2980 {
2981 PyObject *type = state->expr_type;
2982 type = _Py_union_type_or(type, Py_None);
2983 cond = type != NULL;
2984 if (!cond) {
2985 Py_DECREF(Yield_annotations);
2986 return 0;
2987 }
2988 cond = PyDict_SetItemString(Yield_annotations, "value", type) == 0;
2989 Py_DECREF(type);
2990 if (!cond) {
2991 Py_DECREF(Yield_annotations);
2992 return 0;
2993 }
2994 }
2995 cond = PyObject_SetAttrString(state->Yield_type, "_field_types",
2996 Yield_annotations) == 0;
2997 if (!cond) {
2998 Py_DECREF(Yield_annotations);
2999 return 0;
3000 }
3001 cond = PyObject_SetAttrString(state->Yield_type, "__annotations__",
3002 Yield_annotations) == 0;
3003 if (!cond) {
3004 Py_DECREF(Yield_annotations);
3005 return 0;
3006 }
3007 Py_DECREF(Yield_annotations);
3008 PyObject *YieldFrom_annotations = PyDict_New();
3009 if (!YieldFrom_annotations) return 0;
3010 {
3011 PyObject *type = state->expr_type;
3012 Py_INCREF(type);
3013 cond = PyDict_SetItemString(YieldFrom_annotations, "value", type) == 0;
3014 Py_DECREF(type);
3015 if (!cond) {
3016 Py_DECREF(YieldFrom_annotations);
3017 return 0;
3018 }
3019 }
3020 cond = PyObject_SetAttrString(state->YieldFrom_type, "_field_types",
3021 YieldFrom_annotations) == 0;
3022 if (!cond) {
3023 Py_DECREF(YieldFrom_annotations);
3024 return 0;
3025 }
3026 cond = PyObject_SetAttrString(state->YieldFrom_type, "__annotations__",
3027 YieldFrom_annotations) == 0;
3028 if (!cond) {
3029 Py_DECREF(YieldFrom_annotations);
3030 return 0;
3031 }
3032 Py_DECREF(YieldFrom_annotations);
3033 PyObject *Compare_annotations = PyDict_New();
3034 if (!Compare_annotations) return 0;
3035 {
3036 PyObject *type = state->expr_type;
3037 Py_INCREF(type);
3038 cond = PyDict_SetItemString(Compare_annotations, "left", type) == 0;
3039 Py_DECREF(type);
3040 if (!cond) {
3041 Py_DECREF(Compare_annotations);
3042 return 0;
3043 }
3044 }
3045 {
3046 PyObject *type = state->cmpop_type;
3047 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3048 cond = type != NULL;
3049 if (!cond) {
3050 Py_DECREF(Compare_annotations);
3051 return 0;
3052 }
3053 cond = PyDict_SetItemString(Compare_annotations, "ops", type) == 0;
3054 Py_DECREF(type);
3055 if (!cond) {
3056 Py_DECREF(Compare_annotations);
3057 return 0;
3058 }
3059 }
3060 {
3061 PyObject *type = state->expr_type;
3062 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3063 cond = type != NULL;
3064 if (!cond) {
3065 Py_DECREF(Compare_annotations);
3066 return 0;
3067 }
3068 cond = PyDict_SetItemString(Compare_annotations, "comparators", type)
3069 == 0;
3070 Py_DECREF(type);
3071 if (!cond) {
3072 Py_DECREF(Compare_annotations);
3073 return 0;
3074 }
3075 }
3076 cond = PyObject_SetAttrString(state->Compare_type, "_field_types",
3077 Compare_annotations) == 0;
3078 if (!cond) {
3079 Py_DECREF(Compare_annotations);
3080 return 0;
3081 }
3082 cond = PyObject_SetAttrString(state->Compare_type, "__annotations__",
3083 Compare_annotations) == 0;
3084 if (!cond) {
3085 Py_DECREF(Compare_annotations);
3086 return 0;
3087 }
3088 Py_DECREF(Compare_annotations);
3089 PyObject *Call_annotations = PyDict_New();
3090 if (!Call_annotations) return 0;
3091 {
3092 PyObject *type = state->expr_type;
3093 Py_INCREF(type);
3094 cond = PyDict_SetItemString(Call_annotations, "func", type) == 0;
3095 Py_DECREF(type);
3096 if (!cond) {
3097 Py_DECREF(Call_annotations);
3098 return 0;
3099 }
3100 }
3101 {
3102 PyObject *type = state->expr_type;
3103 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3104 cond = type != NULL;
3105 if (!cond) {
3106 Py_DECREF(Call_annotations);
3107 return 0;
3108 }
3109 cond = PyDict_SetItemString(Call_annotations, "args", type) == 0;
3110 Py_DECREF(type);
3111 if (!cond) {
3112 Py_DECREF(Call_annotations);
3113 return 0;
3114 }
3115 }
3116 {
3117 PyObject *type = state->keyword_type;
3118 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3119 cond = type != NULL;
3120 if (!cond) {
3121 Py_DECREF(Call_annotations);
3122 return 0;
3123 }
3124 cond = PyDict_SetItemString(Call_annotations, "keywords", type) == 0;
3125 Py_DECREF(type);
3126 if (!cond) {
3127 Py_DECREF(Call_annotations);
3128 return 0;
3129 }
3130 }
3131 cond = PyObject_SetAttrString(state->Call_type, "_field_types",
3132 Call_annotations) == 0;
3133 if (!cond) {
3134 Py_DECREF(Call_annotations);
3135 return 0;
3136 }
3137 cond = PyObject_SetAttrString(state->Call_type, "__annotations__",
3138 Call_annotations) == 0;
3139 if (!cond) {
3140 Py_DECREF(Call_annotations);
3141 return 0;
3142 }
3143 Py_DECREF(Call_annotations);
3144 PyObject *FormattedValue_annotations = PyDict_New();
3145 if (!FormattedValue_annotations) return 0;
3146 {
3147 PyObject *type = state->expr_type;
3148 Py_INCREF(type);
3149 cond = PyDict_SetItemString(FormattedValue_annotations, "value", type)
3150 == 0;
3151 Py_DECREF(type);
3152 if (!cond) {
3153 Py_DECREF(FormattedValue_annotations);
3154 return 0;
3155 }
3156 }
3157 {
3158 PyObject *type = (PyObject *)&PyLong_Type;
3159 Py_INCREF(type);
3160 cond = PyDict_SetItemString(FormattedValue_annotations, "conversion",
3161 type) == 0;
3162 Py_DECREF(type);
3163 if (!cond) {
3164 Py_DECREF(FormattedValue_annotations);
3165 return 0;
3166 }
3167 }
3168 {
3169 PyObject *type = state->expr_type;
3170 type = _Py_union_type_or(type, Py_None);
3171 cond = type != NULL;
3172 if (!cond) {
3173 Py_DECREF(FormattedValue_annotations);
3174 return 0;
3175 }
3176 cond = PyDict_SetItemString(FormattedValue_annotations, "format_spec",
3177 type) == 0;
3178 Py_DECREF(type);
3179 if (!cond) {
3180 Py_DECREF(FormattedValue_annotations);
3181 return 0;
3182 }
3183 }
3184 cond = PyObject_SetAttrString(state->FormattedValue_type, "_field_types",
3185 FormattedValue_annotations) == 0;
3186 if (!cond) {
3187 Py_DECREF(FormattedValue_annotations);
3188 return 0;
3189 }
3190 cond = PyObject_SetAttrString(state->FormattedValue_type,
3191 "__annotations__",
3192 FormattedValue_annotations) == 0;
3193 if (!cond) {
3194 Py_DECREF(FormattedValue_annotations);
3195 return 0;
3196 }
3197 Py_DECREF(FormattedValue_annotations);
3198 PyObject *JoinedStr_annotations = PyDict_New();
3199 if (!JoinedStr_annotations) return 0;
3200 {
3201 PyObject *type = state->expr_type;
3202 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3203 cond = type != NULL;
3204 if (!cond) {
3205 Py_DECREF(JoinedStr_annotations);
3206 return 0;
3207 }
3208 cond = PyDict_SetItemString(JoinedStr_annotations, "values", type) == 0;
3209 Py_DECREF(type);
3210 if (!cond) {
3211 Py_DECREF(JoinedStr_annotations);
3212 return 0;
3213 }
3214 }
3215 cond = PyObject_SetAttrString(state->JoinedStr_type, "_field_types",
3216 JoinedStr_annotations) == 0;
3217 if (!cond) {
3218 Py_DECREF(JoinedStr_annotations);
3219 return 0;
3220 }
3221 cond = PyObject_SetAttrString(state->JoinedStr_type, "__annotations__",
3222 JoinedStr_annotations) == 0;
3223 if (!cond) {
3224 Py_DECREF(JoinedStr_annotations);
3225 return 0;
3226 }
3227 Py_DECREF(JoinedStr_annotations);
3228 PyObject *Constant_annotations = PyDict_New();
3229 if (!Constant_annotations) return 0;
3230 {
3231 PyObject *type = (PyObject *)&PyBaseObject_Type;
3232 Py_INCREF(type);
3233 cond = PyDict_SetItemString(Constant_annotations, "value", type) == 0;
3234 Py_DECREF(type);
3235 if (!cond) {
3236 Py_DECREF(Constant_annotations);
3237 return 0;
3238 }
3239 }
3240 {
3241 PyObject *type = (PyObject *)&PyUnicode_Type;
3242 type = _Py_union_type_or(type, Py_None);
3243 cond = type != NULL;
3244 if (!cond) {
3245 Py_DECREF(Constant_annotations);
3246 return 0;
3247 }
3248 cond = PyDict_SetItemString(Constant_annotations, "kind", type) == 0;
3249 Py_DECREF(type);
3250 if (!cond) {
3251 Py_DECREF(Constant_annotations);
3252 return 0;
3253 }
3254 }
3255 cond = PyObject_SetAttrString(state->Constant_type, "_field_types",
3256 Constant_annotations) == 0;
3257 if (!cond) {
3258 Py_DECREF(Constant_annotations);
3259 return 0;
3260 }
3261 cond = PyObject_SetAttrString(state->Constant_type, "__annotations__",
3262 Constant_annotations) == 0;
3263 if (!cond) {
3264 Py_DECREF(Constant_annotations);
3265 return 0;
3266 }
3267 Py_DECREF(Constant_annotations);
3268 PyObject *Attribute_annotations = PyDict_New();
3269 if (!Attribute_annotations) return 0;
3270 {
3271 PyObject *type = state->expr_type;
3272 Py_INCREF(type);
3273 cond = PyDict_SetItemString(Attribute_annotations, "value", type) == 0;
3274 Py_DECREF(type);
3275 if (!cond) {
3276 Py_DECREF(Attribute_annotations);
3277 return 0;
3278 }
3279 }
3280 {
3281 PyObject *type = (PyObject *)&PyUnicode_Type;
3282 Py_INCREF(type);
3283 cond = PyDict_SetItemString(Attribute_annotations, "attr", type) == 0;
3284 Py_DECREF(type);
3285 if (!cond) {
3286 Py_DECREF(Attribute_annotations);
3287 return 0;
3288 }
3289 }
3290 {
3291 PyObject *type = state->expr_context_type;
3292 Py_INCREF(type);
3293 cond = PyDict_SetItemString(Attribute_annotations, "ctx", type) == 0;
3294 Py_DECREF(type);
3295 if (!cond) {
3296 Py_DECREF(Attribute_annotations);
3297 return 0;
3298 }
3299 }
3300 cond = PyObject_SetAttrString(state->Attribute_type, "_field_types",
3301 Attribute_annotations) == 0;
3302 if (!cond) {
3303 Py_DECREF(Attribute_annotations);
3304 return 0;
3305 }
3306 cond = PyObject_SetAttrString(state->Attribute_type, "__annotations__",
3307 Attribute_annotations) == 0;
3308 if (!cond) {
3309 Py_DECREF(Attribute_annotations);
3310 return 0;
3311 }
3312 Py_DECREF(Attribute_annotations);
3313 PyObject *Subscript_annotations = PyDict_New();
3314 if (!Subscript_annotations) return 0;
3315 {
3316 PyObject *type = state->expr_type;
3317 Py_INCREF(type);
3318 cond = PyDict_SetItemString(Subscript_annotations, "value", type) == 0;
3319 Py_DECREF(type);
3320 if (!cond) {
3321 Py_DECREF(Subscript_annotations);
3322 return 0;
3323 }
3324 }
3325 {
3326 PyObject *type = state->expr_type;
3327 Py_INCREF(type);
3328 cond = PyDict_SetItemString(Subscript_annotations, "slice", type) == 0;
3329 Py_DECREF(type);
3330 if (!cond) {
3331 Py_DECREF(Subscript_annotations);
3332 return 0;
3333 }
3334 }
3335 {
3336 PyObject *type = state->expr_context_type;
3337 Py_INCREF(type);
3338 cond = PyDict_SetItemString(Subscript_annotations, "ctx", type) == 0;
3339 Py_DECREF(type);
3340 if (!cond) {
3341 Py_DECREF(Subscript_annotations);
3342 return 0;
3343 }
3344 }
3345 cond = PyObject_SetAttrString(state->Subscript_type, "_field_types",
3346 Subscript_annotations) == 0;
3347 if (!cond) {
3348 Py_DECREF(Subscript_annotations);
3349 return 0;
3350 }
3351 cond = PyObject_SetAttrString(state->Subscript_type, "__annotations__",
3352 Subscript_annotations) == 0;
3353 if (!cond) {
3354 Py_DECREF(Subscript_annotations);
3355 return 0;
3356 }
3357 Py_DECREF(Subscript_annotations);
3358 PyObject *Starred_annotations = PyDict_New();
3359 if (!Starred_annotations) return 0;
3360 {
3361 PyObject *type = state->expr_type;
3362 Py_INCREF(type);
3363 cond = PyDict_SetItemString(Starred_annotations, "value", type) == 0;
3364 Py_DECREF(type);
3365 if (!cond) {
3366 Py_DECREF(Starred_annotations);
3367 return 0;
3368 }
3369 }
3370 {
3371 PyObject *type = state->expr_context_type;
3372 Py_INCREF(type);
3373 cond = PyDict_SetItemString(Starred_annotations, "ctx", type) == 0;
3374 Py_DECREF(type);
3375 if (!cond) {
3376 Py_DECREF(Starred_annotations);
3377 return 0;
3378 }
3379 }
3380 cond = PyObject_SetAttrString(state->Starred_type, "_field_types",
3381 Starred_annotations) == 0;
3382 if (!cond) {
3383 Py_DECREF(Starred_annotations);
3384 return 0;
3385 }
3386 cond = PyObject_SetAttrString(state->Starred_type, "__annotations__",
3387 Starred_annotations) == 0;
3388 if (!cond) {
3389 Py_DECREF(Starred_annotations);
3390 return 0;
3391 }
3392 Py_DECREF(Starred_annotations);
3393 PyObject *Name_annotations = PyDict_New();
3394 if (!Name_annotations) return 0;
3395 {
3396 PyObject *type = (PyObject *)&PyUnicode_Type;
3397 Py_INCREF(type);
3398 cond = PyDict_SetItemString(Name_annotations, "id", type) == 0;
3399 Py_DECREF(type);
3400 if (!cond) {
3401 Py_DECREF(Name_annotations);
3402 return 0;
3403 }
3404 }
3405 {
3406 PyObject *type = state->expr_context_type;
3407 Py_INCREF(type);
3408 cond = PyDict_SetItemString(Name_annotations, "ctx", type) == 0;
3409 Py_DECREF(type);
3410 if (!cond) {
3411 Py_DECREF(Name_annotations);
3412 return 0;
3413 }
3414 }
3415 cond = PyObject_SetAttrString(state->Name_type, "_field_types",
3416 Name_annotations) == 0;
3417 if (!cond) {
3418 Py_DECREF(Name_annotations);
3419 return 0;
3420 }
3421 cond = PyObject_SetAttrString(state->Name_type, "__annotations__",
3422 Name_annotations) == 0;
3423 if (!cond) {
3424 Py_DECREF(Name_annotations);
3425 return 0;
3426 }
3427 Py_DECREF(Name_annotations);
3428 PyObject *List_annotations = PyDict_New();
3429 if (!List_annotations) return 0;
3430 {
3431 PyObject *type = state->expr_type;
3432 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3433 cond = type != NULL;
3434 if (!cond) {
3435 Py_DECREF(List_annotations);
3436 return 0;
3437 }
3438 cond = PyDict_SetItemString(List_annotations, "elts", type) == 0;
3439 Py_DECREF(type);
3440 if (!cond) {
3441 Py_DECREF(List_annotations);
3442 return 0;
3443 }
3444 }
3445 {
3446 PyObject *type = state->expr_context_type;
3447 Py_INCREF(type);
3448 cond = PyDict_SetItemString(List_annotations, "ctx", type) == 0;
3449 Py_DECREF(type);
3450 if (!cond) {
3451 Py_DECREF(List_annotations);
3452 return 0;
3453 }
3454 }
3455 cond = PyObject_SetAttrString(state->List_type, "_field_types",
3456 List_annotations) == 0;
3457 if (!cond) {
3458 Py_DECREF(List_annotations);
3459 return 0;
3460 }
3461 cond = PyObject_SetAttrString(state->List_type, "__annotations__",
3462 List_annotations) == 0;
3463 if (!cond) {
3464 Py_DECREF(List_annotations);
3465 return 0;
3466 }
3467 Py_DECREF(List_annotations);
3468 PyObject *Tuple_annotations = PyDict_New();
3469 if (!Tuple_annotations) return 0;
3470 {
3471 PyObject *type = state->expr_type;
3472 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
3473 cond = type != NULL;
3474 if (!cond) {
3475 Py_DECREF(Tuple_annotations);
3476 return 0;
3477 }
3478 cond = PyDict_SetItemString(Tuple_annotations, "elts", type) == 0;
3479 Py_DECREF(type);
3480 if (!cond) {
3481 Py_DECREF(Tuple_annotations);
3482 return 0;
3483 }
3484 }
3485 {
3486 PyObject *type = state->expr_context_type;
3487 Py_INCREF(type);
3488 cond = PyDict_SetItemString(Tuple_annotations, "ctx", type) == 0;
3489 Py_DECREF(type);
3490 if (!cond) {
3491 Py_DECREF(Tuple_annotations);
3492 return 0;
3493 }
3494 }
3495 cond = PyObject_SetAttrString(state->Tuple_type, "_field_types",
3496 Tuple_annotations) == 0;
3497 if (!cond) {
3498 Py_DECREF(Tuple_annotations);
3499 return 0;
3500 }
3501 cond = PyObject_SetAttrString(state->Tuple_type, "__annotations__",
3502 Tuple_annotations) == 0;
3503 if (!cond) {
3504 Py_DECREF(Tuple_annotations);
3505 return 0;
3506 }
3507 Py_DECREF(Tuple_annotations);
3508 PyObject *Slice_annotations = PyDict_New();
3509 if (!Slice_annotations) return 0;
3510 {
3511 PyObject *type = state->expr_type;
3512 type = _Py_union_type_or(type, Py_None);
3513 cond = type != NULL;
3514 if (!cond) {
3515 Py_DECREF(Slice_annotations);
3516 return 0;
3517 }
3518 cond = PyDict_SetItemString(Slice_annotations, "lower", type) == 0;
3519 Py_DECREF(type);
3520 if (!cond) {
3521 Py_DECREF(Slice_annotations);
3522 return 0;
3523 }
3524 }
3525 {
3526 PyObject *type = state->expr_type;
3527 type = _Py_union_type_or(type, Py_None);
3528 cond = type != NULL;
3529 if (!cond) {
3530 Py_DECREF(Slice_annotations);
3531 return 0;
3532 }
3533 cond = PyDict_SetItemString(Slice_annotations, "upper", type) == 0;
3534 Py_DECREF(type);
3535 if (!cond) {
3536 Py_DECREF(Slice_annotations);
3537 return 0;
3538 }
3539 }
3540 {
3541 PyObject *type = state->expr_type;
3542 type = _Py_union_type_or(type, Py_None);
3543 cond = type != NULL;
3544 if (!cond) {
3545 Py_DECREF(Slice_annotations);
3546 return 0;
3547 }
3548 cond = PyDict_SetItemString(Slice_annotations, "step", type) == 0;
3549 Py_DECREF(type);
3550 if (!cond) {
3551 Py_DECREF(Slice_annotations);
3552 return 0;
3553 }
3554 }
3555 cond = PyObject_SetAttrString(state->Slice_type, "_field_types",
3556 Slice_annotations) == 0;
3557 if (!cond) {
3558 Py_DECREF(Slice_annotations);
3559 return 0;
3560 }
3561 cond = PyObject_SetAttrString(state->Slice_type, "__annotations__",
3562 Slice_annotations) == 0;
3563 if (!cond) {
3564 Py_DECREF(Slice_annotations);
3565 return 0;
3566 }
3567 Py_DECREF(Slice_annotations);
3568 PyObject *Load_annotations = PyDict_New();
3569 if (!Load_annotations) return 0;
3570 cond = PyObject_SetAttrString(state->Load_type, "_field_types",
3571 Load_annotations) == 0;
3572 if (!cond) {
3573 Py_DECREF(Load_annotations);
3574 return 0;
3575 }
3576 cond = PyObject_SetAttrString(state->Load_type, "__annotations__",
3577 Load_annotations) == 0;
3578 if (!cond) {
3579 Py_DECREF(Load_annotations);
3580 return 0;
3581 }
3582 Py_DECREF(Load_annotations);
3583 PyObject *Store_annotations = PyDict_New();
3584 if (!Store_annotations) return 0;
3585 cond = PyObject_SetAttrString(state->Store_type, "_field_types",
3586 Store_annotations) == 0;
3587 if (!cond) {
3588 Py_DECREF(Store_annotations);
3589 return 0;
3590 }
3591 cond = PyObject_SetAttrString(state->Store_type, "__annotations__",
3592 Store_annotations) == 0;
3593 if (!cond) {
3594 Py_DECREF(Store_annotations);
3595 return 0;
3596 }
3597 Py_DECREF(Store_annotations);
3598 PyObject *Del_annotations = PyDict_New();
3599 if (!Del_annotations) return 0;
3600 cond = PyObject_SetAttrString(state->Del_type, "_field_types",
3601 Del_annotations) == 0;
3602 if (!cond) {
3603 Py_DECREF(Del_annotations);
3604 return 0;
3605 }
3606 cond = PyObject_SetAttrString(state->Del_type, "__annotations__",
3607 Del_annotations) == 0;
3608 if (!cond) {
3609 Py_DECREF(Del_annotations);
3610 return 0;
3611 }
3612 Py_DECREF(Del_annotations);
3613 PyObject *And_annotations = PyDict_New();
3614 if (!And_annotations) return 0;
3615 cond = PyObject_SetAttrString(state->And_type, "_field_types",
3616 And_annotations) == 0;
3617 if (!cond) {
3618 Py_DECREF(And_annotations);
3619 return 0;
3620 }
3621 cond = PyObject_SetAttrString(state->And_type, "__annotations__",
3622 And_annotations) == 0;
3623 if (!cond) {
3624 Py_DECREF(And_annotations);
3625 return 0;
3626 }
3627 Py_DECREF(And_annotations);
3628 PyObject *Or_annotations = PyDict_New();
3629 if (!Or_annotations) return 0;
3630 cond = PyObject_SetAttrString(state->Or_type, "_field_types",
3631 Or_annotations) == 0;
3632 if (!cond) {
3633 Py_DECREF(Or_annotations);
3634 return 0;
3635 }
3636 cond = PyObject_SetAttrString(state->Or_type, "__annotations__",
3637 Or_annotations) == 0;
3638 if (!cond) {
3639 Py_DECREF(Or_annotations);
3640 return 0;
3641 }
3642 Py_DECREF(Or_annotations);
3643 PyObject *Add_annotations = PyDict_New();
3644 if (!Add_annotations) return 0;
3645 cond = PyObject_SetAttrString(state->Add_type, "_field_types",
3646 Add_annotations) == 0;
3647 if (!cond) {
3648 Py_DECREF(Add_annotations);
3649 return 0;
3650 }
3651 cond = PyObject_SetAttrString(state->Add_type, "__annotations__",
3652 Add_annotations) == 0;
3653 if (!cond) {
3654 Py_DECREF(Add_annotations);
3655 return 0;
3656 }
3657 Py_DECREF(Add_annotations);
3658 PyObject *Sub_annotations = PyDict_New();
3659 if (!Sub_annotations) return 0;
3660 cond = PyObject_SetAttrString(state->Sub_type, "_field_types",
3661 Sub_annotations) == 0;
3662 if (!cond) {
3663 Py_DECREF(Sub_annotations);
3664 return 0;
3665 }
3666 cond = PyObject_SetAttrString(state->Sub_type, "__annotations__",
3667 Sub_annotations) == 0;
3668 if (!cond) {
3669 Py_DECREF(Sub_annotations);
3670 return 0;
3671 }
3672 Py_DECREF(Sub_annotations);
3673 PyObject *Mult_annotations = PyDict_New();
3674 if (!Mult_annotations) return 0;
3675 cond = PyObject_SetAttrString(state->Mult_type, "_field_types",
3676 Mult_annotations) == 0;
3677 if (!cond) {
3678 Py_DECREF(Mult_annotations);
3679 return 0;
3680 }
3681 cond = PyObject_SetAttrString(state->Mult_type, "__annotations__",
3682 Mult_annotations) == 0;
3683 if (!cond) {
3684 Py_DECREF(Mult_annotations);
3685 return 0;
3686 }
3687 Py_DECREF(Mult_annotations);
3688 PyObject *MatMult_annotations = PyDict_New();
3689 if (!MatMult_annotations) return 0;
3690 cond = PyObject_SetAttrString(state->MatMult_type, "_field_types",
3691 MatMult_annotations) == 0;
3692 if (!cond) {
3693 Py_DECREF(MatMult_annotations);
3694 return 0;
3695 }
3696 cond = PyObject_SetAttrString(state->MatMult_type, "__annotations__",
3697 MatMult_annotations) == 0;
3698 if (!cond) {
3699 Py_DECREF(MatMult_annotations);
3700 return 0;
3701 }
3702 Py_DECREF(MatMult_annotations);
3703 PyObject *Div_annotations = PyDict_New();
3704 if (!Div_annotations) return 0;
3705 cond = PyObject_SetAttrString(state->Div_type, "_field_types",
3706 Div_annotations) == 0;
3707 if (!cond) {
3708 Py_DECREF(Div_annotations);
3709 return 0;
3710 }
3711 cond = PyObject_SetAttrString(state->Div_type, "__annotations__",
3712 Div_annotations) == 0;
3713 if (!cond) {
3714 Py_DECREF(Div_annotations);
3715 return 0;
3716 }
3717 Py_DECREF(Div_annotations);
3718 PyObject *Mod_annotations = PyDict_New();
3719 if (!Mod_annotations) return 0;
3720 cond = PyObject_SetAttrString(state->Mod_type, "_field_types",
3721 Mod_annotations) == 0;
3722 if (!cond) {
3723 Py_DECREF(Mod_annotations);
3724 return 0;
3725 }
3726 cond = PyObject_SetAttrString(state->Mod_type, "__annotations__",
3727 Mod_annotations) == 0;
3728 if (!cond) {
3729 Py_DECREF(Mod_annotations);
3730 return 0;
3731 }
3732 Py_DECREF(Mod_annotations);
3733 PyObject *Pow_annotations = PyDict_New();
3734 if (!Pow_annotations) return 0;
3735 cond = PyObject_SetAttrString(state->Pow_type, "_field_types",
3736 Pow_annotations) == 0;
3737 if (!cond) {
3738 Py_DECREF(Pow_annotations);
3739 return 0;
3740 }
3741 cond = PyObject_SetAttrString(state->Pow_type, "__annotations__",
3742 Pow_annotations) == 0;
3743 if (!cond) {
3744 Py_DECREF(Pow_annotations);
3745 return 0;
3746 }
3747 Py_DECREF(Pow_annotations);
3748 PyObject *LShift_annotations = PyDict_New();
3749 if (!LShift_annotations) return 0;
3750 cond = PyObject_SetAttrString(state->LShift_type, "_field_types",
3751 LShift_annotations) == 0;
3752 if (!cond) {
3753 Py_DECREF(LShift_annotations);
3754 return 0;
3755 }
3756 cond = PyObject_SetAttrString(state->LShift_type, "__annotations__",
3757 LShift_annotations) == 0;
3758 if (!cond) {
3759 Py_DECREF(LShift_annotations);
3760 return 0;
3761 }
3762 Py_DECREF(LShift_annotations);
3763 PyObject *RShift_annotations = PyDict_New();
3764 if (!RShift_annotations) return 0;
3765 cond = PyObject_SetAttrString(state->RShift_type, "_field_types",
3766 RShift_annotations) == 0;
3767 if (!cond) {
3768 Py_DECREF(RShift_annotations);
3769 return 0;
3770 }
3771 cond = PyObject_SetAttrString(state->RShift_type, "__annotations__",
3772 RShift_annotations) == 0;
3773 if (!cond) {
3774 Py_DECREF(RShift_annotations);
3775 return 0;
3776 }
3777 Py_DECREF(RShift_annotations);
3778 PyObject *BitOr_annotations = PyDict_New();
3779 if (!BitOr_annotations) return 0;
3780 cond = PyObject_SetAttrString(state->BitOr_type, "_field_types",
3781 BitOr_annotations) == 0;
3782 if (!cond) {
3783 Py_DECREF(BitOr_annotations);
3784 return 0;
3785 }
3786 cond = PyObject_SetAttrString(state->BitOr_type, "__annotations__",
3787 BitOr_annotations) == 0;
3788 if (!cond) {
3789 Py_DECREF(BitOr_annotations);
3790 return 0;
3791 }
3792 Py_DECREF(BitOr_annotations);
3793 PyObject *BitXor_annotations = PyDict_New();
3794 if (!BitXor_annotations) return 0;
3795 cond = PyObject_SetAttrString(state->BitXor_type, "_field_types",
3796 BitXor_annotations) == 0;
3797 if (!cond) {
3798 Py_DECREF(BitXor_annotations);
3799 return 0;
3800 }
3801 cond = PyObject_SetAttrString(state->BitXor_type, "__annotations__",
3802 BitXor_annotations) == 0;
3803 if (!cond) {
3804 Py_DECREF(BitXor_annotations);
3805 return 0;
3806 }
3807 Py_DECREF(BitXor_annotations);
3808 PyObject *BitAnd_annotations = PyDict_New();
3809 if (!BitAnd_annotations) return 0;
3810 cond = PyObject_SetAttrString(state->BitAnd_type, "_field_types",
3811 BitAnd_annotations) == 0;
3812 if (!cond) {
3813 Py_DECREF(BitAnd_annotations);
3814 return 0;
3815 }
3816 cond = PyObject_SetAttrString(state->BitAnd_type, "__annotations__",
3817 BitAnd_annotations) == 0;
3818 if (!cond) {
3819 Py_DECREF(BitAnd_annotations);
3820 return 0;
3821 }
3822 Py_DECREF(BitAnd_annotations);
3823 PyObject *FloorDiv_annotations = PyDict_New();
3824 if (!FloorDiv_annotations) return 0;
3825 cond = PyObject_SetAttrString(state->FloorDiv_type, "_field_types",
3826 FloorDiv_annotations) == 0;
3827 if (!cond) {
3828 Py_DECREF(FloorDiv_annotations);
3829 return 0;
3830 }
3831 cond = PyObject_SetAttrString(state->FloorDiv_type, "__annotations__",
3832 FloorDiv_annotations) == 0;
3833 if (!cond) {
3834 Py_DECREF(FloorDiv_annotations);
3835 return 0;
3836 }
3837 Py_DECREF(FloorDiv_annotations);
3838 PyObject *Invert_annotations = PyDict_New();
3839 if (!Invert_annotations) return 0;
3840 cond = PyObject_SetAttrString(state->Invert_type, "_field_types",
3841 Invert_annotations) == 0;
3842 if (!cond) {
3843 Py_DECREF(Invert_annotations);
3844 return 0;
3845 }
3846 cond = PyObject_SetAttrString(state->Invert_type, "__annotations__",
3847 Invert_annotations) == 0;
3848 if (!cond) {
3849 Py_DECREF(Invert_annotations);
3850 return 0;
3851 }
3852 Py_DECREF(Invert_annotations);
3853 PyObject *Not_annotations = PyDict_New();
3854 if (!Not_annotations) return 0;
3855 cond = PyObject_SetAttrString(state->Not_type, "_field_types",
3856 Not_annotations) == 0;
3857 if (!cond) {
3858 Py_DECREF(Not_annotations);
3859 return 0;
3860 }
3861 cond = PyObject_SetAttrString(state->Not_type, "__annotations__",
3862 Not_annotations) == 0;
3863 if (!cond) {
3864 Py_DECREF(Not_annotations);
3865 return 0;
3866 }
3867 Py_DECREF(Not_annotations);
3868 PyObject *UAdd_annotations = PyDict_New();
3869 if (!UAdd_annotations) return 0;
3870 cond = PyObject_SetAttrString(state->UAdd_type, "_field_types",
3871 UAdd_annotations) == 0;
3872 if (!cond) {
3873 Py_DECREF(UAdd_annotations);
3874 return 0;
3875 }
3876 cond = PyObject_SetAttrString(state->UAdd_type, "__annotations__",
3877 UAdd_annotations) == 0;
3878 if (!cond) {
3879 Py_DECREF(UAdd_annotations);
3880 return 0;
3881 }
3882 Py_DECREF(UAdd_annotations);
3883 PyObject *USub_annotations = PyDict_New();
3884 if (!USub_annotations) return 0;
3885 cond = PyObject_SetAttrString(state->USub_type, "_field_types",
3886 USub_annotations) == 0;
3887 if (!cond) {
3888 Py_DECREF(USub_annotations);
3889 return 0;
3890 }
3891 cond = PyObject_SetAttrString(state->USub_type, "__annotations__",
3892 USub_annotations) == 0;
3893 if (!cond) {
3894 Py_DECREF(USub_annotations);
3895 return 0;
3896 }
3897 Py_DECREF(USub_annotations);
3898 PyObject *Eq_annotations = PyDict_New();
3899 if (!Eq_annotations) return 0;
3900 cond = PyObject_SetAttrString(state->Eq_type, "_field_types",
3901 Eq_annotations) == 0;
3902 if (!cond) {
3903 Py_DECREF(Eq_annotations);
3904 return 0;
3905 }
3906 cond = PyObject_SetAttrString(state->Eq_type, "__annotations__",
3907 Eq_annotations) == 0;
3908 if (!cond) {
3909 Py_DECREF(Eq_annotations);
3910 return 0;
3911 }
3912 Py_DECREF(Eq_annotations);
3913 PyObject *NotEq_annotations = PyDict_New();
3914 if (!NotEq_annotations) return 0;
3915 cond = PyObject_SetAttrString(state->NotEq_type, "_field_types",
3916 NotEq_annotations) == 0;
3917 if (!cond) {
3918 Py_DECREF(NotEq_annotations);
3919 return 0;
3920 }
3921 cond = PyObject_SetAttrString(state->NotEq_type, "__annotations__",
3922 NotEq_annotations) == 0;
3923 if (!cond) {
3924 Py_DECREF(NotEq_annotations);
3925 return 0;
3926 }
3927 Py_DECREF(NotEq_annotations);
3928 PyObject *Lt_annotations = PyDict_New();
3929 if (!Lt_annotations) return 0;
3930 cond = PyObject_SetAttrString(state->Lt_type, "_field_types",
3931 Lt_annotations) == 0;
3932 if (!cond) {
3933 Py_DECREF(Lt_annotations);
3934 return 0;
3935 }
3936 cond = PyObject_SetAttrString(state->Lt_type, "__annotations__",
3937 Lt_annotations) == 0;
3938 if (!cond) {
3939 Py_DECREF(Lt_annotations);
3940 return 0;
3941 }
3942 Py_DECREF(Lt_annotations);
3943 PyObject *LtE_annotations = PyDict_New();
3944 if (!LtE_annotations) return 0;
3945 cond = PyObject_SetAttrString(state->LtE_type, "_field_types",
3946 LtE_annotations) == 0;
3947 if (!cond) {
3948 Py_DECREF(LtE_annotations);
3949 return 0;
3950 }
3951 cond = PyObject_SetAttrString(state->LtE_type, "__annotations__",
3952 LtE_annotations) == 0;
3953 if (!cond) {
3954 Py_DECREF(LtE_annotations);
3955 return 0;
3956 }
3957 Py_DECREF(LtE_annotations);
3958 PyObject *Gt_annotations = PyDict_New();
3959 if (!Gt_annotations) return 0;
3960 cond = PyObject_SetAttrString(state->Gt_type, "_field_types",
3961 Gt_annotations) == 0;
3962 if (!cond) {
3963 Py_DECREF(Gt_annotations);
3964 return 0;
3965 }
3966 cond = PyObject_SetAttrString(state->Gt_type, "__annotations__",
3967 Gt_annotations) == 0;
3968 if (!cond) {
3969 Py_DECREF(Gt_annotations);
3970 return 0;
3971 }
3972 Py_DECREF(Gt_annotations);
3973 PyObject *GtE_annotations = PyDict_New();
3974 if (!GtE_annotations) return 0;
3975 cond = PyObject_SetAttrString(state->GtE_type, "_field_types",
3976 GtE_annotations) == 0;
3977 if (!cond) {
3978 Py_DECREF(GtE_annotations);
3979 return 0;
3980 }
3981 cond = PyObject_SetAttrString(state->GtE_type, "__annotations__",
3982 GtE_annotations) == 0;
3983 if (!cond) {
3984 Py_DECREF(GtE_annotations);
3985 return 0;
3986 }
3987 Py_DECREF(GtE_annotations);
3988 PyObject *Is_annotations = PyDict_New();
3989 if (!Is_annotations) return 0;
3990 cond = PyObject_SetAttrString(state->Is_type, "_field_types",
3991 Is_annotations) == 0;
3992 if (!cond) {
3993 Py_DECREF(Is_annotations);
3994 return 0;
3995 }
3996 cond = PyObject_SetAttrString(state->Is_type, "__annotations__",
3997 Is_annotations) == 0;
3998 if (!cond) {
3999 Py_DECREF(Is_annotations);
4000 return 0;
4001 }
4002 Py_DECREF(Is_annotations);
4003 PyObject *IsNot_annotations = PyDict_New();
4004 if (!IsNot_annotations) return 0;
4005 cond = PyObject_SetAttrString(state->IsNot_type, "_field_types",
4006 IsNot_annotations) == 0;
4007 if (!cond) {
4008 Py_DECREF(IsNot_annotations);
4009 return 0;
4010 }
4011 cond = PyObject_SetAttrString(state->IsNot_type, "__annotations__",
4012 IsNot_annotations) == 0;
4013 if (!cond) {
4014 Py_DECREF(IsNot_annotations);
4015 return 0;
4016 }
4017 Py_DECREF(IsNot_annotations);
4018 PyObject *In_annotations = PyDict_New();
4019 if (!In_annotations) return 0;
4020 cond = PyObject_SetAttrString(state->In_type, "_field_types",
4021 In_annotations) == 0;
4022 if (!cond) {
4023 Py_DECREF(In_annotations);
4024 return 0;
4025 }
4026 cond = PyObject_SetAttrString(state->In_type, "__annotations__",
4027 In_annotations) == 0;
4028 if (!cond) {
4029 Py_DECREF(In_annotations);
4030 return 0;
4031 }
4032 Py_DECREF(In_annotations);
4033 PyObject *NotIn_annotations = PyDict_New();
4034 if (!NotIn_annotations) return 0;
4035 cond = PyObject_SetAttrString(state->NotIn_type, "_field_types",
4036 NotIn_annotations) == 0;
4037 if (!cond) {
4038 Py_DECREF(NotIn_annotations);
4039 return 0;
4040 }
4041 cond = PyObject_SetAttrString(state->NotIn_type, "__annotations__",
4042 NotIn_annotations) == 0;
4043 if (!cond) {
4044 Py_DECREF(NotIn_annotations);
4045 return 0;
4046 }
4047 Py_DECREF(NotIn_annotations);
4048 PyObject *comprehension_annotations = PyDict_New();
4049 if (!comprehension_annotations) return 0;
4050 {
4051 PyObject *type = state->expr_type;
4052 Py_INCREF(type);
4053 cond = PyDict_SetItemString(comprehension_annotations, "target", type)
4054 == 0;
4055 Py_DECREF(type);
4056 if (!cond) {
4057 Py_DECREF(comprehension_annotations);
4058 return 0;
4059 }
4060 }
4061 {
4062 PyObject *type = state->expr_type;
4063 Py_INCREF(type);
4064 cond = PyDict_SetItemString(comprehension_annotations, "iter", type) ==
4065 0;
4066 Py_DECREF(type);
4067 if (!cond) {
4068 Py_DECREF(comprehension_annotations);
4069 return 0;
4070 }
4071 }
4072 {
4073 PyObject *type = state->expr_type;
4074 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4075 cond = type != NULL;
4076 if (!cond) {
4077 Py_DECREF(comprehension_annotations);
4078 return 0;
4079 }
4080 cond = PyDict_SetItemString(comprehension_annotations, "ifs", type) ==
4081 0;
4082 Py_DECREF(type);
4083 if (!cond) {
4084 Py_DECREF(comprehension_annotations);
4085 return 0;
4086 }
4087 }
4088 {
4089 PyObject *type = (PyObject *)&PyLong_Type;
4090 Py_INCREF(type);
4091 cond = PyDict_SetItemString(comprehension_annotations, "is_async",
4092 type) == 0;
4093 Py_DECREF(type);
4094 if (!cond) {
4095 Py_DECREF(comprehension_annotations);
4096 return 0;
4097 }
4098 }
4099 cond = PyObject_SetAttrString(state->comprehension_type, "_field_types",
4100 comprehension_annotations) == 0;
4101 if (!cond) {
4102 Py_DECREF(comprehension_annotations);
4103 return 0;
4104 }
4105 cond = PyObject_SetAttrString(state->comprehension_type, "__annotations__",
4106 comprehension_annotations) == 0;
4107 if (!cond) {
4108 Py_DECREF(comprehension_annotations);
4109 return 0;
4110 }
4111 Py_DECREF(comprehension_annotations);
4112 PyObject *ExceptHandler_annotations = PyDict_New();
4113 if (!ExceptHandler_annotations) return 0;
4114 {
4115 PyObject *type = state->expr_type;
4116 type = _Py_union_type_or(type, Py_None);
4117 cond = type != NULL;
4118 if (!cond) {
4119 Py_DECREF(ExceptHandler_annotations);
4120 return 0;
4121 }
4122 cond = PyDict_SetItemString(ExceptHandler_annotations, "type", type) ==
4123 0;
4124 Py_DECREF(type);
4125 if (!cond) {
4126 Py_DECREF(ExceptHandler_annotations);
4127 return 0;
4128 }
4129 }
4130 {
4131 PyObject *type = (PyObject *)&PyUnicode_Type;
4132 type = _Py_union_type_or(type, Py_None);
4133 cond = type != NULL;
4134 if (!cond) {
4135 Py_DECREF(ExceptHandler_annotations);
4136 return 0;
4137 }
4138 cond = PyDict_SetItemString(ExceptHandler_annotations, "name", type) ==
4139 0;
4140 Py_DECREF(type);
4141 if (!cond) {
4142 Py_DECREF(ExceptHandler_annotations);
4143 return 0;
4144 }
4145 }
4146 {
4147 PyObject *type = state->stmt_type;
4148 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4149 cond = type != NULL;
4150 if (!cond) {
4151 Py_DECREF(ExceptHandler_annotations);
4152 return 0;
4153 }
4154 cond = PyDict_SetItemString(ExceptHandler_annotations, "body", type) ==
4155 0;
4156 Py_DECREF(type);
4157 if (!cond) {
4158 Py_DECREF(ExceptHandler_annotations);
4159 return 0;
4160 }
4161 }
4162 cond = PyObject_SetAttrString(state->ExceptHandler_type, "_field_types",
4163 ExceptHandler_annotations) == 0;
4164 if (!cond) {
4165 Py_DECREF(ExceptHandler_annotations);
4166 return 0;
4167 }
4168 cond = PyObject_SetAttrString(state->ExceptHandler_type, "__annotations__",
4169 ExceptHandler_annotations) == 0;
4170 if (!cond) {
4171 Py_DECREF(ExceptHandler_annotations);
4172 return 0;
4173 }
4174 Py_DECREF(ExceptHandler_annotations);
4175 PyObject *arguments_annotations = PyDict_New();
4176 if (!arguments_annotations) return 0;
4177 {
4178 PyObject *type = state->arg_type;
4179 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4180 cond = type != NULL;
4181 if (!cond) {
4182 Py_DECREF(arguments_annotations);
4183 return 0;
4184 }
4185 cond = PyDict_SetItemString(arguments_annotations, "posonlyargs", type)
4186 == 0;
4187 Py_DECREF(type);
4188 if (!cond) {
4189 Py_DECREF(arguments_annotations);
4190 return 0;
4191 }
4192 }
4193 {
4194 PyObject *type = state->arg_type;
4195 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4196 cond = type != NULL;
4197 if (!cond) {
4198 Py_DECREF(arguments_annotations);
4199 return 0;
4200 }
4201 cond = PyDict_SetItemString(arguments_annotations, "args", type) == 0;
4202 Py_DECREF(type);
4203 if (!cond) {
4204 Py_DECREF(arguments_annotations);
4205 return 0;
4206 }
4207 }
4208 {
4209 PyObject *type = state->arg_type;
4210 type = _Py_union_type_or(type, Py_None);
4211 cond = type != NULL;
4212 if (!cond) {
4213 Py_DECREF(arguments_annotations);
4214 return 0;
4215 }
4216 cond = PyDict_SetItemString(arguments_annotations, "vararg", type) == 0;
4217 Py_DECREF(type);
4218 if (!cond) {
4219 Py_DECREF(arguments_annotations);
4220 return 0;
4221 }
4222 }
4223 {
4224 PyObject *type = state->arg_type;
4225 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4226 cond = type != NULL;
4227 if (!cond) {
4228 Py_DECREF(arguments_annotations);
4229 return 0;
4230 }
4231 cond = PyDict_SetItemString(arguments_annotations, "kwonlyargs", type)
4232 == 0;
4233 Py_DECREF(type);
4234 if (!cond) {
4235 Py_DECREF(arguments_annotations);
4236 return 0;
4237 }
4238 }
4239 {
4240 PyObject *type = state->expr_type;
4241 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4242 cond = type != NULL;
4243 if (!cond) {
4244 Py_DECREF(arguments_annotations);
4245 return 0;
4246 }
4247 cond = PyDict_SetItemString(arguments_annotations, "kw_defaults", type)
4248 == 0;
4249 Py_DECREF(type);
4250 if (!cond) {
4251 Py_DECREF(arguments_annotations);
4252 return 0;
4253 }
4254 }
4255 {
4256 PyObject *type = state->arg_type;
4257 type = _Py_union_type_or(type, Py_None);
4258 cond = type != NULL;
4259 if (!cond) {
4260 Py_DECREF(arguments_annotations);
4261 return 0;
4262 }
4263 cond = PyDict_SetItemString(arguments_annotations, "kwarg", type) == 0;
4264 Py_DECREF(type);
4265 if (!cond) {
4266 Py_DECREF(arguments_annotations);
4267 return 0;
4268 }
4269 }
4270 {
4271 PyObject *type = state->expr_type;
4272 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4273 cond = type != NULL;
4274 if (!cond) {
4275 Py_DECREF(arguments_annotations);
4276 return 0;
4277 }
4278 cond = PyDict_SetItemString(arguments_annotations, "defaults", type) ==
4279 0;
4280 Py_DECREF(type);
4281 if (!cond) {
4282 Py_DECREF(arguments_annotations);
4283 return 0;
4284 }
4285 }
4286 cond = PyObject_SetAttrString(state->arguments_type, "_field_types",
4287 arguments_annotations) == 0;
4288 if (!cond) {
4289 Py_DECREF(arguments_annotations);
4290 return 0;
4291 }
4292 cond = PyObject_SetAttrString(state->arguments_type, "__annotations__",
4293 arguments_annotations) == 0;
4294 if (!cond) {
4295 Py_DECREF(arguments_annotations);
4296 return 0;
4297 }
4298 Py_DECREF(arguments_annotations);
4299 PyObject *arg_annotations = PyDict_New();
4300 if (!arg_annotations) return 0;
4301 {
4302 PyObject *type = (PyObject *)&PyUnicode_Type;
4303 Py_INCREF(type);
4304 cond = PyDict_SetItemString(arg_annotations, "arg", type) == 0;
4305 Py_DECREF(type);
4306 if (!cond) {
4307 Py_DECREF(arg_annotations);
4308 return 0;
4309 }
4310 }
4311 {
4312 PyObject *type = state->expr_type;
4313 type = _Py_union_type_or(type, Py_None);
4314 cond = type != NULL;
4315 if (!cond) {
4316 Py_DECREF(arg_annotations);
4317 return 0;
4318 }
4319 cond = PyDict_SetItemString(arg_annotations, "annotation", type) == 0;
4320 Py_DECREF(type);
4321 if (!cond) {
4322 Py_DECREF(arg_annotations);
4323 return 0;
4324 }
4325 }
4326 {
4327 PyObject *type = (PyObject *)&PyUnicode_Type;
4328 type = _Py_union_type_or(type, Py_None);
4329 cond = type != NULL;
4330 if (!cond) {
4331 Py_DECREF(arg_annotations);
4332 return 0;
4333 }
4334 cond = PyDict_SetItemString(arg_annotations, "type_comment", type) == 0;
4335 Py_DECREF(type);
4336 if (!cond) {
4337 Py_DECREF(arg_annotations);
4338 return 0;
4339 }
4340 }
4341 cond = PyObject_SetAttrString(state->arg_type, "_field_types",
4342 arg_annotations) == 0;
4343 if (!cond) {
4344 Py_DECREF(arg_annotations);
4345 return 0;
4346 }
4347 cond = PyObject_SetAttrString(state->arg_type, "__annotations__",
4348 arg_annotations) == 0;
4349 if (!cond) {
4350 Py_DECREF(arg_annotations);
4351 return 0;
4352 }
4353 Py_DECREF(arg_annotations);
4354 PyObject *keyword_annotations = PyDict_New();
4355 if (!keyword_annotations) return 0;
4356 {
4357 PyObject *type = (PyObject *)&PyUnicode_Type;
4358 type = _Py_union_type_or(type, Py_None);
4359 cond = type != NULL;
4360 if (!cond) {
4361 Py_DECREF(keyword_annotations);
4362 return 0;
4363 }
4364 cond = PyDict_SetItemString(keyword_annotations, "arg", type) == 0;
4365 Py_DECREF(type);
4366 if (!cond) {
4367 Py_DECREF(keyword_annotations);
4368 return 0;
4369 }
4370 }
4371 {
4372 PyObject *type = state->expr_type;
4373 Py_INCREF(type);
4374 cond = PyDict_SetItemString(keyword_annotations, "value", type) == 0;
4375 Py_DECREF(type);
4376 if (!cond) {
4377 Py_DECREF(keyword_annotations);
4378 return 0;
4379 }
4380 }
4381 cond = PyObject_SetAttrString(state->keyword_type, "_field_types",
4382 keyword_annotations) == 0;
4383 if (!cond) {
4384 Py_DECREF(keyword_annotations);
4385 return 0;
4386 }
4387 cond = PyObject_SetAttrString(state->keyword_type, "__annotations__",
4388 keyword_annotations) == 0;
4389 if (!cond) {
4390 Py_DECREF(keyword_annotations);
4391 return 0;
4392 }
4393 Py_DECREF(keyword_annotations);
4394 PyObject *alias_annotations = PyDict_New();
4395 if (!alias_annotations) return 0;
4396 {
4397 PyObject *type = (PyObject *)&PyUnicode_Type;
4398 Py_INCREF(type);
4399 cond = PyDict_SetItemString(alias_annotations, "name", type) == 0;
4400 Py_DECREF(type);
4401 if (!cond) {
4402 Py_DECREF(alias_annotations);
4403 return 0;
4404 }
4405 }
4406 {
4407 PyObject *type = (PyObject *)&PyUnicode_Type;
4408 type = _Py_union_type_or(type, Py_None);
4409 cond = type != NULL;
4410 if (!cond) {
4411 Py_DECREF(alias_annotations);
4412 return 0;
4413 }
4414 cond = PyDict_SetItemString(alias_annotations, "asname", type) == 0;
4415 Py_DECREF(type);
4416 if (!cond) {
4417 Py_DECREF(alias_annotations);
4418 return 0;
4419 }
4420 }
4421 cond = PyObject_SetAttrString(state->alias_type, "_field_types",
4422 alias_annotations) == 0;
4423 if (!cond) {
4424 Py_DECREF(alias_annotations);
4425 return 0;
4426 }
4427 cond = PyObject_SetAttrString(state->alias_type, "__annotations__",
4428 alias_annotations) == 0;
4429 if (!cond) {
4430 Py_DECREF(alias_annotations);
4431 return 0;
4432 }
4433 Py_DECREF(alias_annotations);
4434 PyObject *withitem_annotations = PyDict_New();
4435 if (!withitem_annotations) return 0;
4436 {
4437 PyObject *type = state->expr_type;
4438 Py_INCREF(type);
4439 cond = PyDict_SetItemString(withitem_annotations, "context_expr", type)
4440 == 0;
4441 Py_DECREF(type);
4442 if (!cond) {
4443 Py_DECREF(withitem_annotations);
4444 return 0;
4445 }
4446 }
4447 {
4448 PyObject *type = state->expr_type;
4449 type = _Py_union_type_or(type, Py_None);
4450 cond = type != NULL;
4451 if (!cond) {
4452 Py_DECREF(withitem_annotations);
4453 return 0;
4454 }
4455 cond = PyDict_SetItemString(withitem_annotations, "optional_vars",
4456 type) == 0;
4457 Py_DECREF(type);
4458 if (!cond) {
4459 Py_DECREF(withitem_annotations);
4460 return 0;
4461 }
4462 }
4463 cond = PyObject_SetAttrString(state->withitem_type, "_field_types",
4464 withitem_annotations) == 0;
4465 if (!cond) {
4466 Py_DECREF(withitem_annotations);
4467 return 0;
4468 }
4469 cond = PyObject_SetAttrString(state->withitem_type, "__annotations__",
4470 withitem_annotations) == 0;
4471 if (!cond) {
4472 Py_DECREF(withitem_annotations);
4473 return 0;
4474 }
4475 Py_DECREF(withitem_annotations);
4476 PyObject *match_case_annotations = PyDict_New();
4477 if (!match_case_annotations) return 0;
4478 {
4479 PyObject *type = state->pattern_type;
4480 Py_INCREF(type);
4481 cond = PyDict_SetItemString(match_case_annotations, "pattern", type) ==
4482 0;
4483 Py_DECREF(type);
4484 if (!cond) {
4485 Py_DECREF(match_case_annotations);
4486 return 0;
4487 }
4488 }
4489 {
4490 PyObject *type = state->expr_type;
4491 type = _Py_union_type_or(type, Py_None);
4492 cond = type != NULL;
4493 if (!cond) {
4494 Py_DECREF(match_case_annotations);
4495 return 0;
4496 }
4497 cond = PyDict_SetItemString(match_case_annotations, "guard", type) == 0;
4498 Py_DECREF(type);
4499 if (!cond) {
4500 Py_DECREF(match_case_annotations);
4501 return 0;
4502 }
4503 }
4504 {
4505 PyObject *type = state->stmt_type;
4506 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4507 cond = type != NULL;
4508 if (!cond) {
4509 Py_DECREF(match_case_annotations);
4510 return 0;
4511 }
4512 cond = PyDict_SetItemString(match_case_annotations, "body", type) == 0;
4513 Py_DECREF(type);
4514 if (!cond) {
4515 Py_DECREF(match_case_annotations);
4516 return 0;
4517 }
4518 }
4519 cond = PyObject_SetAttrString(state->match_case_type, "_field_types",
4520 match_case_annotations) == 0;
4521 if (!cond) {
4522 Py_DECREF(match_case_annotations);
4523 return 0;
4524 }
4525 cond = PyObject_SetAttrString(state->match_case_type, "__annotations__",
4526 match_case_annotations) == 0;
4527 if (!cond) {
4528 Py_DECREF(match_case_annotations);
4529 return 0;
4530 }
4531 Py_DECREF(match_case_annotations);
4532 PyObject *MatchValue_annotations = PyDict_New();
4533 if (!MatchValue_annotations) return 0;
4534 {
4535 PyObject *type = state->expr_type;
4536 Py_INCREF(type);
4537 cond = PyDict_SetItemString(MatchValue_annotations, "value", type) == 0;
4538 Py_DECREF(type);
4539 if (!cond) {
4540 Py_DECREF(MatchValue_annotations);
4541 return 0;
4542 }
4543 }
4544 cond = PyObject_SetAttrString(state->MatchValue_type, "_field_types",
4545 MatchValue_annotations) == 0;
4546 if (!cond) {
4547 Py_DECREF(MatchValue_annotations);
4548 return 0;
4549 }
4550 cond = PyObject_SetAttrString(state->MatchValue_type, "__annotations__",
4551 MatchValue_annotations) == 0;
4552 if (!cond) {
4553 Py_DECREF(MatchValue_annotations);
4554 return 0;
4555 }
4556 Py_DECREF(MatchValue_annotations);
4557 PyObject *MatchSingleton_annotations = PyDict_New();
4558 if (!MatchSingleton_annotations) return 0;
4559 {
4560 PyObject *type = (PyObject *)&PyBaseObject_Type;
4561 Py_INCREF(type);
4562 cond = PyDict_SetItemString(MatchSingleton_annotations, "value", type)
4563 == 0;
4564 Py_DECREF(type);
4565 if (!cond) {
4566 Py_DECREF(MatchSingleton_annotations);
4567 return 0;
4568 }
4569 }
4570 cond = PyObject_SetAttrString(state->MatchSingleton_type, "_field_types",
4571 MatchSingleton_annotations) == 0;
4572 if (!cond) {
4573 Py_DECREF(MatchSingleton_annotations);
4574 return 0;
4575 }
4576 cond = PyObject_SetAttrString(state->MatchSingleton_type,
4577 "__annotations__",
4578 MatchSingleton_annotations) == 0;
4579 if (!cond) {
4580 Py_DECREF(MatchSingleton_annotations);
4581 return 0;
4582 }
4583 Py_DECREF(MatchSingleton_annotations);
4584 PyObject *MatchSequence_annotations = PyDict_New();
4585 if (!MatchSequence_annotations) return 0;
4586 {
4587 PyObject *type = state->pattern_type;
4588 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4589 cond = type != NULL;
4590 if (!cond) {
4591 Py_DECREF(MatchSequence_annotations);
4592 return 0;
4593 }
4594 cond = PyDict_SetItemString(MatchSequence_annotations, "patterns",
4595 type) == 0;
4596 Py_DECREF(type);
4597 if (!cond) {
4598 Py_DECREF(MatchSequence_annotations);
4599 return 0;
4600 }
4601 }
4602 cond = PyObject_SetAttrString(state->MatchSequence_type, "_field_types",
4603 MatchSequence_annotations) == 0;
4604 if (!cond) {
4605 Py_DECREF(MatchSequence_annotations);
4606 return 0;
4607 }
4608 cond = PyObject_SetAttrString(state->MatchSequence_type, "__annotations__",
4609 MatchSequence_annotations) == 0;
4610 if (!cond) {
4611 Py_DECREF(MatchSequence_annotations);
4612 return 0;
4613 }
4614 Py_DECREF(MatchSequence_annotations);
4615 PyObject *MatchMapping_annotations = PyDict_New();
4616 if (!MatchMapping_annotations) return 0;
4617 {
4618 PyObject *type = state->expr_type;
4619 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4620 cond = type != NULL;
4621 if (!cond) {
4622 Py_DECREF(MatchMapping_annotations);
4623 return 0;
4624 }
4625 cond = PyDict_SetItemString(MatchMapping_annotations, "keys", type) ==
4626 0;
4627 Py_DECREF(type);
4628 if (!cond) {
4629 Py_DECREF(MatchMapping_annotations);
4630 return 0;
4631 }
4632 }
4633 {
4634 PyObject *type = state->pattern_type;
4635 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4636 cond = type != NULL;
4637 if (!cond) {
4638 Py_DECREF(MatchMapping_annotations);
4639 return 0;
4640 }
4641 cond = PyDict_SetItemString(MatchMapping_annotations, "patterns", type)
4642 == 0;
4643 Py_DECREF(type);
4644 if (!cond) {
4645 Py_DECREF(MatchMapping_annotations);
4646 return 0;
4647 }
4648 }
4649 {
4650 PyObject *type = (PyObject *)&PyUnicode_Type;
4651 type = _Py_union_type_or(type, Py_None);
4652 cond = type != NULL;
4653 if (!cond) {
4654 Py_DECREF(MatchMapping_annotations);
4655 return 0;
4656 }
4657 cond = PyDict_SetItemString(MatchMapping_annotations, "rest", type) ==
4658 0;
4659 Py_DECREF(type);
4660 if (!cond) {
4661 Py_DECREF(MatchMapping_annotations);
4662 return 0;
4663 }
4664 }
4665 cond = PyObject_SetAttrString(state->MatchMapping_type, "_field_types",
4666 MatchMapping_annotations) == 0;
4667 if (!cond) {
4668 Py_DECREF(MatchMapping_annotations);
4669 return 0;
4670 }
4671 cond = PyObject_SetAttrString(state->MatchMapping_type, "__annotations__",
4672 MatchMapping_annotations) == 0;
4673 if (!cond) {
4674 Py_DECREF(MatchMapping_annotations);
4675 return 0;
4676 }
4677 Py_DECREF(MatchMapping_annotations);
4678 PyObject *MatchClass_annotations = PyDict_New();
4679 if (!MatchClass_annotations) return 0;
4680 {
4681 PyObject *type = state->expr_type;
4682 Py_INCREF(type);
4683 cond = PyDict_SetItemString(MatchClass_annotations, "cls", type) == 0;
4684 Py_DECREF(type);
4685 if (!cond) {
4686 Py_DECREF(MatchClass_annotations);
4687 return 0;
4688 }
4689 }
4690 {
4691 PyObject *type = state->pattern_type;
4692 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4693 cond = type != NULL;
4694 if (!cond) {
4695 Py_DECREF(MatchClass_annotations);
4696 return 0;
4697 }
4698 cond = PyDict_SetItemString(MatchClass_annotations, "patterns", type)
4699 == 0;
4700 Py_DECREF(type);
4701 if (!cond) {
4702 Py_DECREF(MatchClass_annotations);
4703 return 0;
4704 }
4705 }
4706 {
4707 PyObject *type = (PyObject *)&PyUnicode_Type;
4708 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4709 cond = type != NULL;
4710 if (!cond) {
4711 Py_DECREF(MatchClass_annotations);
4712 return 0;
4713 }
4714 cond = PyDict_SetItemString(MatchClass_annotations, "kwd_attrs", type)
4715 == 0;
4716 Py_DECREF(type);
4717 if (!cond) {
4718 Py_DECREF(MatchClass_annotations);
4719 return 0;
4720 }
4721 }
4722 {
4723 PyObject *type = state->pattern_type;
4724 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4725 cond = type != NULL;
4726 if (!cond) {
4727 Py_DECREF(MatchClass_annotations);
4728 return 0;
4729 }
4730 cond = PyDict_SetItemString(MatchClass_annotations, "kwd_patterns",
4731 type) == 0;
4732 Py_DECREF(type);
4733 if (!cond) {
4734 Py_DECREF(MatchClass_annotations);
4735 return 0;
4736 }
4737 }
4738 cond = PyObject_SetAttrString(state->MatchClass_type, "_field_types",
4739 MatchClass_annotations) == 0;
4740 if (!cond) {
4741 Py_DECREF(MatchClass_annotations);
4742 return 0;
4743 }
4744 cond = PyObject_SetAttrString(state->MatchClass_type, "__annotations__",
4745 MatchClass_annotations) == 0;
4746 if (!cond) {
4747 Py_DECREF(MatchClass_annotations);
4748 return 0;
4749 }
4750 Py_DECREF(MatchClass_annotations);
4751 PyObject *MatchStar_annotations = PyDict_New();
4752 if (!MatchStar_annotations) return 0;
4753 {
4754 PyObject *type = (PyObject *)&PyUnicode_Type;
4755 type = _Py_union_type_or(type, Py_None);
4756 cond = type != NULL;
4757 if (!cond) {
4758 Py_DECREF(MatchStar_annotations);
4759 return 0;
4760 }
4761 cond = PyDict_SetItemString(MatchStar_annotations, "name", type) == 0;
4762 Py_DECREF(type);
4763 if (!cond) {
4764 Py_DECREF(MatchStar_annotations);
4765 return 0;
4766 }
4767 }
4768 cond = PyObject_SetAttrString(state->MatchStar_type, "_field_types",
4769 MatchStar_annotations) == 0;
4770 if (!cond) {
4771 Py_DECREF(MatchStar_annotations);
4772 return 0;
4773 }
4774 cond = PyObject_SetAttrString(state->MatchStar_type, "__annotations__",
4775 MatchStar_annotations) == 0;
4776 if (!cond) {
4777 Py_DECREF(MatchStar_annotations);
4778 return 0;
4779 }
4780 Py_DECREF(MatchStar_annotations);
4781 PyObject *MatchAs_annotations = PyDict_New();
4782 if (!MatchAs_annotations) return 0;
4783 {
4784 PyObject *type = state->pattern_type;
4785 type = _Py_union_type_or(type, Py_None);
4786 cond = type != NULL;
4787 if (!cond) {
4788 Py_DECREF(MatchAs_annotations);
4789 return 0;
4790 }
4791 cond = PyDict_SetItemString(MatchAs_annotations, "pattern", type) == 0;
4792 Py_DECREF(type);
4793 if (!cond) {
4794 Py_DECREF(MatchAs_annotations);
4795 return 0;
4796 }
4797 }
4798 {
4799 PyObject *type = (PyObject *)&PyUnicode_Type;
4800 type = _Py_union_type_or(type, Py_None);
4801 cond = type != NULL;
4802 if (!cond) {
4803 Py_DECREF(MatchAs_annotations);
4804 return 0;
4805 }
4806 cond = PyDict_SetItemString(MatchAs_annotations, "name", type) == 0;
4807 Py_DECREF(type);
4808 if (!cond) {
4809 Py_DECREF(MatchAs_annotations);
4810 return 0;
4811 }
4812 }
4813 cond = PyObject_SetAttrString(state->MatchAs_type, "_field_types",
4814 MatchAs_annotations) == 0;
4815 if (!cond) {
4816 Py_DECREF(MatchAs_annotations);
4817 return 0;
4818 }
4819 cond = PyObject_SetAttrString(state->MatchAs_type, "__annotations__",
4820 MatchAs_annotations) == 0;
4821 if (!cond) {
4822 Py_DECREF(MatchAs_annotations);
4823 return 0;
4824 }
4825 Py_DECREF(MatchAs_annotations);
4826 PyObject *MatchOr_annotations = PyDict_New();
4827 if (!MatchOr_annotations) return 0;
4828 {
4829 PyObject *type = state->pattern_type;
4830 type = Py_GenericAlias((PyObject *)&PyList_Type, type);
4831 cond = type != NULL;
4832 if (!cond) {
4833 Py_DECREF(MatchOr_annotations);
4834 return 0;
4835 }
4836 cond = PyDict_SetItemString(MatchOr_annotations, "patterns", type) == 0;
4837 Py_DECREF(type);
4838 if (!cond) {
4839 Py_DECREF(MatchOr_annotations);
4840 return 0;
4841 }
4842 }
4843 cond = PyObject_SetAttrString(state->MatchOr_type, "_field_types",
4844 MatchOr_annotations) == 0;
4845 if (!cond) {
4846 Py_DECREF(MatchOr_annotations);
4847 return 0;
4848 }
4849 cond = PyObject_SetAttrString(state->MatchOr_type, "__annotations__",
4850 MatchOr_annotations) == 0;
4851 if (!cond) {
4852 Py_DECREF(MatchOr_annotations);
4853 return 0;
4854 }
4855 Py_DECREF(MatchOr_annotations);
4856 PyObject *TypeIgnore_annotations = PyDict_New();
4857 if (!TypeIgnore_annotations) return 0;
4858 {
4859 PyObject *type = (PyObject *)&PyLong_Type;
4860 Py_INCREF(type);
4861 cond = PyDict_SetItemString(TypeIgnore_annotations, "lineno", type) ==
4862 0;
4863 Py_DECREF(type);
4864 if (!cond) {
4865 Py_DECREF(TypeIgnore_annotations);
4866 return 0;
4867 }
4868 }
4869 {
4870 PyObject *type = (PyObject *)&PyUnicode_Type;
4871 Py_INCREF(type);
4872 cond = PyDict_SetItemString(TypeIgnore_annotations, "tag", type) == 0;
4873 Py_DECREF(type);
4874 if (!cond) {
4875 Py_DECREF(TypeIgnore_annotations);
4876 return 0;
4877 }
4878 }
4879 cond = PyObject_SetAttrString(state->TypeIgnore_type, "_field_types",
4880 TypeIgnore_annotations) == 0;
4881 if (!cond) {
4882 Py_DECREF(TypeIgnore_annotations);
4883 return 0;
4884 }
4885 cond = PyObject_SetAttrString(state->TypeIgnore_type, "__annotations__",
4886 TypeIgnore_annotations) == 0;
4887 if (!cond) {
4888 Py_DECREF(TypeIgnore_annotations);
4889 return 0;
4890 }
4891 Py_DECREF(TypeIgnore_annotations);
4892 PyObject *TypeVar_annotations = PyDict_New();
4893 if (!TypeVar_annotations) return 0;
4894 {
4895 PyObject *type = (PyObject *)&PyUnicode_Type;
4896 Py_INCREF(type);
4897 cond = PyDict_SetItemString(TypeVar_annotations, "name", type) == 0;
4898 Py_DECREF(type);
4899 if (!cond) {
4900 Py_DECREF(TypeVar_annotations);
4901 return 0;
4902 }
4903 }
4904 {
4905 PyObject *type = state->expr_type;
4906 type = _Py_union_type_or(type, Py_None);
4907 cond = type != NULL;
4908 if (!cond) {
4909 Py_DECREF(TypeVar_annotations);
4910 return 0;
4911 }
4912 cond = PyDict_SetItemString(TypeVar_annotations, "bound", type) == 0;
4913 Py_DECREF(type);
4914 if (!cond) {
4915 Py_DECREF(TypeVar_annotations);
4916 return 0;
4917 }
4918 }
4919 {
4920 PyObject *type = state->expr_type;
4921 type = _Py_union_type_or(type, Py_None);
4922 cond = type != NULL;
4923 if (!cond) {
4924 Py_DECREF(TypeVar_annotations);
4925 return 0;
4926 }
4927 cond = PyDict_SetItemString(TypeVar_annotations, "default_value", type)
4928 == 0;
4929 Py_DECREF(type);
4930 if (!cond) {
4931 Py_DECREF(TypeVar_annotations);
4932 return 0;
4933 }
4934 }
4935 cond = PyObject_SetAttrString(state->TypeVar_type, "_field_types",
4936 TypeVar_annotations) == 0;
4937 if (!cond) {
4938 Py_DECREF(TypeVar_annotations);
4939 return 0;
4940 }
4941 cond = PyObject_SetAttrString(state->TypeVar_type, "__annotations__",
4942 TypeVar_annotations) == 0;
4943 if (!cond) {
4944 Py_DECREF(TypeVar_annotations);
4945 return 0;
4946 }
4947 Py_DECREF(TypeVar_annotations);
4948 PyObject *ParamSpec_annotations = PyDict_New();
4949 if (!ParamSpec_annotations) return 0;
4950 {
4951 PyObject *type = (PyObject *)&PyUnicode_Type;
4952 Py_INCREF(type);
4953 cond = PyDict_SetItemString(ParamSpec_annotations, "name", type) == 0;
4954 Py_DECREF(type);
4955 if (!cond) {
4956 Py_DECREF(ParamSpec_annotations);
4957 return 0;
4958 }
4959 }
4960 {
4961 PyObject *type = state->expr_type;
4962 type = _Py_union_type_or(type, Py_None);
4963 cond = type != NULL;
4964 if (!cond) {
4965 Py_DECREF(ParamSpec_annotations);
4966 return 0;
4967 }
4968 cond = PyDict_SetItemString(ParamSpec_annotations, "default_value",
4969 type) == 0;
4970 Py_DECREF(type);
4971 if (!cond) {
4972 Py_DECREF(ParamSpec_annotations);
4973 return 0;
4974 }
4975 }
4976 cond = PyObject_SetAttrString(state->ParamSpec_type, "_field_types",
4977 ParamSpec_annotations) == 0;
4978 if (!cond) {
4979 Py_DECREF(ParamSpec_annotations);
4980 return 0;
4981 }
4982 cond = PyObject_SetAttrString(state->ParamSpec_type, "__annotations__",
4983 ParamSpec_annotations) == 0;
4984 if (!cond) {
4985 Py_DECREF(ParamSpec_annotations);
4986 return 0;
4987 }
4988 Py_DECREF(ParamSpec_annotations);
4989 PyObject *TypeVarTuple_annotations = PyDict_New();
4990 if (!TypeVarTuple_annotations) return 0;
4991 {
4992 PyObject *type = (PyObject *)&PyUnicode_Type;
4993 Py_INCREF(type);
4994 cond = PyDict_SetItemString(TypeVarTuple_annotations, "name", type) ==
4995 0;
4996 Py_DECREF(type);
4997 if (!cond) {
4998 Py_DECREF(TypeVarTuple_annotations);
4999 return 0;
5000 }
5001 }
5002 {
5003 PyObject *type = state->expr_type;
5004 type = _Py_union_type_or(type, Py_None);
5005 cond = type != NULL;
5006 if (!cond) {
5007 Py_DECREF(TypeVarTuple_annotations);
5008 return 0;
5009 }
5010 cond = PyDict_SetItemString(TypeVarTuple_annotations, "default_value",
5011 type) == 0;
5012 Py_DECREF(type);
5013 if (!cond) {
5014 Py_DECREF(TypeVarTuple_annotations);
5015 return 0;
5016 }
5017 }
5018 cond = PyObject_SetAttrString(state->TypeVarTuple_type, "_field_types",
5019 TypeVarTuple_annotations) == 0;
5020 if (!cond) {
5021 Py_DECREF(TypeVarTuple_annotations);
5022 return 0;
5023 }
5024 cond = PyObject_SetAttrString(state->TypeVarTuple_type, "__annotations__",
5025 TypeVarTuple_annotations) == 0;
5026 if (!cond) {
5027 Py_DECREF(TypeVarTuple_annotations);
5028 return 0;
5029 }
5030 Py_DECREF(TypeVarTuple_annotations);
5031
5032 return 1;
5033 }
5034
5035
5036
5037 typedef struct {
5038 PyObject_HEAD
5039 PyObject *dict;
5040 } AST_object;
5041
5042 static void
ast_dealloc(AST_object * self)5043 ast_dealloc(AST_object *self)
5044 {
5045 /* bpo-31095: UnTrack is needed before calling any callbacks */
5046 PyTypeObject *tp = Py_TYPE(self);
5047 PyObject_GC_UnTrack(self);
5048 Py_CLEAR(self->dict);
5049 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
5050 assert(free_func != NULL);
5051 free_func(self);
5052 Py_DECREF(tp);
5053 }
5054
5055 static int
ast_traverse(AST_object * self,visitproc visit,void * arg)5056 ast_traverse(AST_object *self, visitproc visit, void *arg)
5057 {
5058 Py_VISIT(Py_TYPE(self));
5059 Py_VISIT(self->dict);
5060 return 0;
5061 }
5062
5063 static int
ast_clear(AST_object * self)5064 ast_clear(AST_object *self)
5065 {
5066 Py_CLEAR(self->dict);
5067 return 0;
5068 }
5069
5070 static int
ast_type_init(PyObject * self,PyObject * args,PyObject * kw)5071 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
5072 {
5073 struct ast_state *state = get_ast_state();
5074 if (state == NULL) {
5075 return -1;
5076 }
5077
5078 Py_ssize_t i, numfields = 0;
5079 int res = -1;
5080 PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL;
5081
5082 fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields);
5083 if (fields == NULL) {
5084 goto cleanup;
5085 }
5086
5087 numfields = PySequence_Size(fields);
5088 if (numfields == -1) {
5089 goto cleanup;
5090 }
5091 remaining_fields = PySet_New(fields);
5092 if (remaining_fields == NULL) {
5093 goto cleanup;
5094 }
5095
5096 res = 0; /* if no error occurs, this stays 0 to the end */
5097 if (numfields < PyTuple_GET_SIZE(args)) {
5098 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
5099 "%zd positional argument%s",
5100 _PyType_Name(Py_TYPE(self)),
5101 numfields, numfields == 1 ? "" : "s");
5102 res = -1;
5103 goto cleanup;
5104 }
5105 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
5106 /* cannot be reached when fields is NULL */
5107 PyObject *name = PySequence_GetItem(fields, i);
5108 if (!name) {
5109 res = -1;
5110 goto cleanup;
5111 }
5112 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
5113 if (PySet_Discard(remaining_fields, name) < 0) {
5114 res = -1;
5115 Py_DECREF(name);
5116 goto cleanup;
5117 }
5118 Py_DECREF(name);
5119 if (res < 0) {
5120 goto cleanup;
5121 }
5122 }
5123 if (kw) {
5124 i = 0; /* needed by PyDict_Next */
5125 while (PyDict_Next(kw, &i, &key, &value)) {
5126 int contains = PySequence_Contains(fields, key);
5127 if (contains == -1) {
5128 res = -1;
5129 goto cleanup;
5130 }
5131 else if (contains == 1) {
5132 int p = PySet_Discard(remaining_fields, key);
5133 if (p == -1) {
5134 res = -1;
5135 goto cleanup;
5136 }
5137 if (p == 0) {
5138 PyErr_Format(PyExc_TypeError,
5139 "%.400s got multiple values for argument '%U'",
5140 Py_TYPE(self)->tp_name, key);
5141 res = -1;
5142 goto cleanup;
5143 }
5144 }
5145 else {
5146 // Lazily initialize "attributes"
5147 if (attributes == NULL) {
5148 attributes = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_attributes);
5149 if (attributes == NULL) {
5150 res = -1;
5151 goto cleanup;
5152 }
5153 }
5154 int contains = PySequence_Contains(attributes, key);
5155 if (contains == -1) {
5156 res = -1;
5157 goto cleanup;
5158 }
5159 else if (contains == 0) {
5160 if (PyErr_WarnFormat(
5161 PyExc_DeprecationWarning, 1,
5162 "%.400s.__init__ got an unexpected keyword argument '%U'. "
5163 "Support for arbitrary keyword arguments is deprecated "
5164 "and will be removed in Python 3.15.",
5165 Py_TYPE(self)->tp_name, key
5166 ) < 0) {
5167 res = -1;
5168 goto cleanup;
5169 }
5170 }
5171 }
5172 res = PyObject_SetAttr(self, key, value);
5173 if (res < 0) {
5174 goto cleanup;
5175 }
5176 }
5177 }
5178 Py_ssize_t size = PySet_Size(remaining_fields);
5179 PyObject *field_types = NULL, *remaining_list = NULL;
5180 if (size > 0) {
5181 if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
5182 &field_types) < 0) {
5183 res = -1;
5184 goto cleanup;
5185 }
5186 if (field_types == NULL) {
5187 // Probably a user-defined subclass of AST that lacks _field_types.
5188 // This will continue to work as it did before 3.13; i.e., attributes
5189 // that are not passed in simply do not exist on the instance.
5190 goto cleanup;
5191 }
5192 remaining_list = PySequence_List(remaining_fields);
5193 if (!remaining_list) {
5194 goto set_remaining_cleanup;
5195 }
5196 for (Py_ssize_t i = 0; i < size; i++) {
5197 PyObject *name = PyList_GET_ITEM(remaining_list, i);
5198 PyObject *type = PyDict_GetItemWithError(field_types, name);
5199 if (!type) {
5200 if (PyErr_Occurred()) {
5201 goto set_remaining_cleanup;
5202 }
5203 else {
5204 if (PyErr_WarnFormat(
5205 PyExc_DeprecationWarning, 1,
5206 "Field '%U' is missing from %.400s._field_types. "
5207 "This will become an error in Python 3.15.",
5208 name, Py_TYPE(self)->tp_name
5209 ) < 0) {
5210 goto set_remaining_cleanup;
5211 }
5212 }
5213 }
5214 else if (_PyUnion_Check(type)) {
5215 // optional field
5216 // do nothing, we'll have set a None default on the class
5217 }
5218 else if (Py_IS_TYPE(type, &Py_GenericAliasType)) {
5219 // list field
5220 PyObject *empty = PyList_New(0);
5221 if (!empty) {
5222 goto set_remaining_cleanup;
5223 }
5224 res = PyObject_SetAttr(self, name, empty);
5225 Py_DECREF(empty);
5226 if (res < 0) {
5227 goto set_remaining_cleanup;
5228 }
5229 }
5230 else if (type == state->expr_context_type) {
5231 // special case for expr_context: default to Load()
5232 res = PyObject_SetAttr(self, name, state->Load_singleton);
5233 if (res < 0) {
5234 goto set_remaining_cleanup;
5235 }
5236 }
5237 else {
5238 // simple field (e.g., identifier)
5239 if (PyErr_WarnFormat(
5240 PyExc_DeprecationWarning, 1,
5241 "%.400s.__init__ missing 1 required positional argument: '%U'. "
5242 "This will become an error in Python 3.15.",
5243 Py_TYPE(self)->tp_name, name
5244 ) < 0) {
5245 goto set_remaining_cleanup;
5246 }
5247 }
5248 }
5249 Py_DECREF(remaining_list);
5250 Py_DECREF(field_types);
5251 }
5252 cleanup:
5253 Py_XDECREF(attributes);
5254 Py_XDECREF(fields);
5255 Py_XDECREF(remaining_fields);
5256 return res;
5257 set_remaining_cleanup:
5258 Py_XDECREF(remaining_list);
5259 Py_XDECREF(field_types);
5260 res = -1;
5261 goto cleanup;
5262 }
5263
5264 /* Pickling support */
5265 static PyObject *
ast_type_reduce(PyObject * self,PyObject * unused)5266 ast_type_reduce(PyObject *self, PyObject *unused)
5267 {
5268 struct ast_state *state = get_ast_state();
5269 if (state == NULL) {
5270 return NULL;
5271 }
5272
5273 PyObject *dict = NULL, *fields = NULL, *positional_args = NULL;
5274 if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
5275 return NULL;
5276 }
5277 PyObject *result = NULL;
5278 if (dict) {
5279 // Unpickling (or copying) works as follows:
5280 // - Construct the object with only positional arguments
5281 // - Set the fields from the dict
5282 // We have two constraints:
5283 // - We must set all the required fields in the initial constructor call,
5284 // or the unpickling or deepcopying of the object will trigger DeprecationWarnings.
5285 // - We must not include child nodes in the positional args, because
5286 // that may trigger runaway recursion during copying (gh-120108).
5287 // To satisfy both constraints, we set all the fields to None in the
5288 // initial list of positional args, and then set the fields from the dict.
5289 if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
5290 goto cleanup;
5291 }
5292 if (fields) {
5293 Py_ssize_t numfields = PySequence_Size(fields);
5294 if (numfields == -1) {
5295 Py_DECREF(dict);
5296 goto cleanup;
5297 }
5298 positional_args = PyList_New(0);
5299 if (!positional_args) {
5300 goto cleanup;
5301 }
5302 for (Py_ssize_t i = 0; i < numfields; i++) {
5303 PyObject *name = PySequence_GetItem(fields, i);
5304 if (!name) {
5305 goto cleanup;
5306 }
5307 PyObject *value;
5308 int rc = PyDict_GetItemRef(dict, name, &value);
5309 Py_DECREF(name);
5310 if (rc < 0) {
5311 goto cleanup;
5312 }
5313 if (!value) {
5314 break;
5315 }
5316 rc = PyList_Append(positional_args, Py_None);
5317 Py_DECREF(value);
5318 if (rc < 0) {
5319 goto cleanup;
5320 }
5321 }
5322 PyObject *args_tuple = PyList_AsTuple(positional_args);
5323 if (!args_tuple) {
5324 goto cleanup;
5325 }
5326 result = Py_BuildValue("ONN", Py_TYPE(self), args_tuple, dict);
5327 }
5328 else {
5329 result = Py_BuildValue("O()N", Py_TYPE(self), dict);
5330 }
5331 }
5332 else {
5333 result = Py_BuildValue("O()", Py_TYPE(self));
5334 }
5335 cleanup:
5336 Py_XDECREF(fields);
5337 Py_XDECREF(positional_args);
5338 return result;
5339 }
5340
5341 static PyMemberDef ast_type_members[] = {
5342 {"__dictoffset__", Py_T_PYSSIZET, offsetof(AST_object, dict), Py_READONLY},
5343 {NULL} /* Sentinel */
5344 };
5345
5346 static PyMethodDef ast_type_methods[] = {
5347 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
5348 {NULL}
5349 };
5350
5351 static PyGetSetDef ast_type_getsets[] = {
5352 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
5353 {NULL}
5354 };
5355
5356 static PyType_Slot AST_type_slots[] = {
5357 {Py_tp_dealloc, ast_dealloc},
5358 {Py_tp_getattro, PyObject_GenericGetAttr},
5359 {Py_tp_setattro, PyObject_GenericSetAttr},
5360 {Py_tp_traverse, ast_traverse},
5361 {Py_tp_clear, ast_clear},
5362 {Py_tp_members, ast_type_members},
5363 {Py_tp_methods, ast_type_methods},
5364 {Py_tp_getset, ast_type_getsets},
5365 {Py_tp_init, ast_type_init},
5366 {Py_tp_alloc, PyType_GenericAlloc},
5367 {Py_tp_new, PyType_GenericNew},
5368 {Py_tp_free, PyObject_GC_Del},
5369 {0, 0},
5370 };
5371
5372 static PyType_Spec AST_type_spec = {
5373 "ast.AST",
5374 sizeof(AST_object),
5375 0,
5376 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
5377 AST_type_slots
5378 };
5379
5380 static PyObject *
make_type(struct ast_state * state,const char * type,PyObject * base,const char * const * fields,int num_fields,const char * doc)5381 make_type(struct ast_state *state, const char *type, PyObject* base,
5382 const char* const* fields, int num_fields, const char *doc)
5383 {
5384 PyObject *fnames, *result;
5385 int i;
5386 fnames = PyTuple_New(num_fields);
5387 if (!fnames) return NULL;
5388 for (i = 0; i < num_fields; i++) {
5389 PyObject *field = PyUnicode_InternFromString(fields[i]);
5390 if (!field) {
5391 Py_DECREF(fnames);
5392 return NULL;
5393 }
5394 PyTuple_SET_ITEM(fnames, i, field);
5395 }
5396 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
5397 type, base,
5398 state->_fields, fnames,
5399 state->__match_args__, fnames,
5400 state->__module__,
5401 state->ast,
5402 state->__doc__, doc);
5403 Py_DECREF(fnames);
5404 return result;
5405 }
5406
5407 static int
add_attributes(struct ast_state * state,PyObject * type,const char * const * attrs,int num_fields)5408 add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
5409 {
5410 int i, result;
5411 PyObject *s, *l = PyTuple_New(num_fields);
5412 if (!l)
5413 return -1;
5414 for (i = 0; i < num_fields; i++) {
5415 s = PyUnicode_InternFromString(attrs[i]);
5416 if (!s) {
5417 Py_DECREF(l);
5418 return -1;
5419 }
5420 PyTuple_SET_ITEM(l, i, s);
5421 }
5422 result = PyObject_SetAttr(type, state->_attributes, l);
5423 Py_DECREF(l);
5424 return result;
5425 }
5426
5427 /* Conversion AST -> Python */
5428
ast2obj_list(struct ast_state * state,struct validator * vstate,asdl_seq * seq,PyObject * (* func)(struct ast_state * state,struct validator * vstate,void *))5429 static PyObject* ast2obj_list(struct ast_state *state, struct validator *vstate, asdl_seq *seq,
5430 PyObject* (*func)(struct ast_state *state, struct validator *vstate, void*))
5431 {
5432 Py_ssize_t i, n = asdl_seq_LEN(seq);
5433 PyObject *result = PyList_New(n);
5434 PyObject *value;
5435 if (!result)
5436 return NULL;
5437 for (i = 0; i < n; i++) {
5438 value = func(state, vstate, asdl_seq_GET_UNTYPED(seq, i));
5439 if (!value) {
5440 Py_DECREF(result);
5441 return NULL;
5442 }
5443 PyList_SET_ITEM(result, i, value);
5444 }
5445 return result;
5446 }
5447
ast2obj_object(struct ast_state * Py_UNUSED (state),struct validator * Py_UNUSED (vstate),void * o)5448 static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), void *o)
5449 {
5450 PyObject *op = (PyObject*)o;
5451 if (!op) {
5452 op = Py_None;
5453 }
5454 return Py_NewRef(op);
5455 }
5456 #define ast2obj_constant ast2obj_object
5457 #define ast2obj_identifier ast2obj_object
5458 #define ast2obj_string ast2obj_object
5459
ast2obj_int(struct ast_state * Py_UNUSED (state),struct validator * Py_UNUSED (vstate),long b)5460 static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), long b)
5461 {
5462 return PyLong_FromLong(b);
5463 }
5464
5465 /* Conversion Python -> AST */
5466
obj2ast_object(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)5467 static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
5468 {
5469 if (obj == Py_None)
5470 obj = NULL;
5471 if (obj) {
5472 if (_PyArena_AddPyObject(arena, obj) < 0) {
5473 *out = NULL;
5474 return -1;
5475 }
5476 *out = Py_NewRef(obj);
5477 }
5478 else {
5479 *out = NULL;
5480 }
5481 return 0;
5482 }
5483
obj2ast_constant(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)5484 static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
5485 {
5486 if (_PyArena_AddPyObject(arena, obj) < 0) {
5487 *out = NULL;
5488 return -1;
5489 }
5490 *out = Py_NewRef(obj);
5491 return 0;
5492 }
5493
obj2ast_identifier(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)5494 static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
5495 {
5496 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
5497 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
5498 return -1;
5499 }
5500 return obj2ast_object(state, obj, out, arena);
5501 }
5502
obj2ast_string(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)5503 static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
5504 {
5505 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
5506 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
5507 return -1;
5508 }
5509 return obj2ast_object(state, obj, out, arena);
5510 }
5511
obj2ast_int(struct ast_state * Py_UNUSED (state),PyObject * obj,int * out,PyArena * arena)5512 static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
5513 {
5514 int i;
5515 if (!PyLong_Check(obj)) {
5516 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
5517 return -1;
5518 }
5519
5520 i = PyLong_AsInt(obj);
5521 if (i == -1 && PyErr_Occurred())
5522 return -1;
5523 *out = i;
5524 return 0;
5525 }
5526
add_ast_fields(struct ast_state * state)5527 static int add_ast_fields(struct ast_state *state)
5528 {
5529 PyObject *empty_tuple;
5530 empty_tuple = PyTuple_New(0);
5531 if (!empty_tuple ||
5532 PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
5533 PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
5534 PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
5535 Py_XDECREF(empty_tuple);
5536 return -1;
5537 }
5538 Py_DECREF(empty_tuple);
5539 return 0;
5540 }
5541
5542
5543
5544 static int
init_types(struct ast_state * state)5545 init_types(struct ast_state *state)
5546 {
5547 if (init_identifiers(state) < 0) {
5548 return -1;
5549 }
5550 state->AST_type = PyType_FromSpec(&AST_type_spec);
5551 if (!state->AST_type) {
5552 return -1;
5553 }
5554 if (add_ast_fields(state) < 0) {
5555 return -1;
5556 }
5557 state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
5558 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
5559 " | Interactive(stmt* body)\n"
5560 " | Expression(expr body)\n"
5561 " | FunctionType(expr* argtypes, expr returns)");
5562 if (!state->mod_type) return -1;
5563 if (add_attributes(state, state->mod_type, NULL, 0) < 0) return -1;
5564 state->Module_type = make_type(state, "Module", state->mod_type,
5565 Module_fields, 2,
5566 "Module(stmt* body, type_ignore* type_ignores)");
5567 if (!state->Module_type) return -1;
5568 state->Interactive_type = make_type(state, "Interactive", state->mod_type,
5569 Interactive_fields, 1,
5570 "Interactive(stmt* body)");
5571 if (!state->Interactive_type) return -1;
5572 state->Expression_type = make_type(state, "Expression", state->mod_type,
5573 Expression_fields, 1,
5574 "Expression(expr body)");
5575 if (!state->Expression_type) return -1;
5576 state->FunctionType_type = make_type(state, "FunctionType",
5577 state->mod_type, FunctionType_fields,
5578 2,
5579 "FunctionType(expr* argtypes, expr returns)");
5580 if (!state->FunctionType_type) return -1;
5581 state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
5582 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
5583 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
5584 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
5585 " | Return(expr? value)\n"
5586 " | Delete(expr* targets)\n"
5587 " | Assign(expr* targets, expr value, string? type_comment)\n"
5588 " | TypeAlias(expr name, type_param* type_params, expr value)\n"
5589 " | AugAssign(expr target, operator op, expr value)\n"
5590 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
5591 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
5592 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
5593 " | While(expr test, stmt* body, stmt* orelse)\n"
5594 " | If(expr test, stmt* body, stmt* orelse)\n"
5595 " | With(withitem* items, stmt* body, string? type_comment)\n"
5596 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
5597 " | Match(expr subject, match_case* cases)\n"
5598 " | Raise(expr? exc, expr? cause)\n"
5599 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
5600 " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
5601 " | Assert(expr test, expr? msg)\n"
5602 " | Import(alias* names)\n"
5603 " | ImportFrom(identifier? module, alias* names, int? level)\n"
5604 " | Global(identifier* names)\n"
5605 " | Nonlocal(identifier* names)\n"
5606 " | Expr(expr value)\n"
5607 " | Pass\n"
5608 " | Break\n"
5609 " | Continue");
5610 if (!state->stmt_type) return -1;
5611 if (add_attributes(state, state->stmt_type, stmt_attributes, 4) < 0) return
5612 -1;
5613 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
5614 return -1;
5615 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
5616 -1)
5617 return -1;
5618 state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
5619 FunctionDef_fields, 7,
5620 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
5621 if (!state->FunctionDef_type) return -1;
5622 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
5623 -1)
5624 return -1;
5625 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
5626 == -1)
5627 return -1;
5628 state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
5629 state->stmt_type,
5630 AsyncFunctionDef_fields, 7,
5631 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
5632 if (!state->AsyncFunctionDef_type) return -1;
5633 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
5634 == -1)
5635 return -1;
5636 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
5637 Py_None) == -1)
5638 return -1;
5639 state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
5640 ClassDef_fields, 6,
5641 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
5642 if (!state->ClassDef_type) return -1;
5643 state->Return_type = make_type(state, "Return", state->stmt_type,
5644 Return_fields, 1,
5645 "Return(expr? value)");
5646 if (!state->Return_type) return -1;
5647 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
5648 return -1;
5649 state->Delete_type = make_type(state, "Delete", state->stmt_type,
5650 Delete_fields, 1,
5651 "Delete(expr* targets)");
5652 if (!state->Delete_type) return -1;
5653 state->Assign_type = make_type(state, "Assign", state->stmt_type,
5654 Assign_fields, 3,
5655 "Assign(expr* targets, expr value, string? type_comment)");
5656 if (!state->Assign_type) return -1;
5657 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
5658 -1)
5659 return -1;
5660 state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
5661 TypeAlias_fields, 3,
5662 "TypeAlias(expr name, type_param* type_params, expr value)");
5663 if (!state->TypeAlias_type) return -1;
5664 state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
5665 AugAssign_fields, 3,
5666 "AugAssign(expr target, operator op, expr value)");
5667 if (!state->AugAssign_type) return -1;
5668 state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
5669 AnnAssign_fields, 4,
5670 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
5671 if (!state->AnnAssign_type) return -1;
5672 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
5673 return -1;
5674 state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
5675 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
5676 if (!state->For_type) return -1;
5677 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
5678 return -1;
5679 state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
5680 AsyncFor_fields, 5,
5681 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
5682 if (!state->AsyncFor_type) return -1;
5683 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
5684 -1)
5685 return -1;
5686 state->While_type = make_type(state, "While", state->stmt_type,
5687 While_fields, 3,
5688 "While(expr test, stmt* body, stmt* orelse)");
5689 if (!state->While_type) return -1;
5690 state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
5691 "If(expr test, stmt* body, stmt* orelse)");
5692 if (!state->If_type) return -1;
5693 state->With_type = make_type(state, "With", state->stmt_type, With_fields,
5694 3,
5695 "With(withitem* items, stmt* body, string? type_comment)");
5696 if (!state->With_type) return -1;
5697 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
5698 return -1;
5699 state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
5700 AsyncWith_fields, 3,
5701 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
5702 if (!state->AsyncWith_type) return -1;
5703 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
5704 == -1)
5705 return -1;
5706 state->Match_type = make_type(state, "Match", state->stmt_type,
5707 Match_fields, 2,
5708 "Match(expr subject, match_case* cases)");
5709 if (!state->Match_type) return -1;
5710 state->Raise_type = make_type(state, "Raise", state->stmt_type,
5711 Raise_fields, 2,
5712 "Raise(expr? exc, expr? cause)");
5713 if (!state->Raise_type) return -1;
5714 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
5715 return -1;
5716 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
5717 return -1;
5718 state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
5719 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
5720 if (!state->Try_type) return -1;
5721 state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
5722 TryStar_fields, 4,
5723 "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
5724 if (!state->TryStar_type) return -1;
5725 state->Assert_type = make_type(state, "Assert", state->stmt_type,
5726 Assert_fields, 2,
5727 "Assert(expr test, expr? msg)");
5728 if (!state->Assert_type) return -1;
5729 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
5730 return -1;
5731 state->Import_type = make_type(state, "Import", state->stmt_type,
5732 Import_fields, 1,
5733 "Import(alias* names)");
5734 if (!state->Import_type) return -1;
5735 state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
5736 ImportFrom_fields, 3,
5737 "ImportFrom(identifier? module, alias* names, int? level)");
5738 if (!state->ImportFrom_type) return -1;
5739 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
5740 return -1;
5741 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
5742 return -1;
5743 state->Global_type = make_type(state, "Global", state->stmt_type,
5744 Global_fields, 1,
5745 "Global(identifier* names)");
5746 if (!state->Global_type) return -1;
5747 state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
5748 Nonlocal_fields, 1,
5749 "Nonlocal(identifier* names)");
5750 if (!state->Nonlocal_type) return -1;
5751 state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
5752 1,
5753 "Expr(expr value)");
5754 if (!state->Expr_type) return -1;
5755 state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
5756 "Pass");
5757 if (!state->Pass_type) return -1;
5758 state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
5759 "Break");
5760 if (!state->Break_type) return -1;
5761 state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
5762 0,
5763 "Continue");
5764 if (!state->Continue_type) return -1;
5765 state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
5766 "expr = BoolOp(boolop op, expr* values)\n"
5767 " | NamedExpr(expr target, expr value)\n"
5768 " | BinOp(expr left, operator op, expr right)\n"
5769 " | UnaryOp(unaryop op, expr operand)\n"
5770 " | Lambda(arguments args, expr body)\n"
5771 " | IfExp(expr test, expr body, expr orelse)\n"
5772 " | Dict(expr* keys, expr* values)\n"
5773 " | Set(expr* elts)\n"
5774 " | ListComp(expr elt, comprehension* generators)\n"
5775 " | SetComp(expr elt, comprehension* generators)\n"
5776 " | DictComp(expr key, expr value, comprehension* generators)\n"
5777 " | GeneratorExp(expr elt, comprehension* generators)\n"
5778 " | Await(expr value)\n"
5779 " | Yield(expr? value)\n"
5780 " | YieldFrom(expr value)\n"
5781 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
5782 " | Call(expr func, expr* args, keyword* keywords)\n"
5783 " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
5784 " | JoinedStr(expr* values)\n"
5785 " | Constant(constant value, string? kind)\n"
5786 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
5787 " | Subscript(expr value, expr slice, expr_context ctx)\n"
5788 " | Starred(expr value, expr_context ctx)\n"
5789 " | Name(identifier id, expr_context ctx)\n"
5790 " | List(expr* elts, expr_context ctx)\n"
5791 " | Tuple(expr* elts, expr_context ctx)\n"
5792 " | Slice(expr? lower, expr? upper, expr? step)");
5793 if (!state->expr_type) return -1;
5794 if (add_attributes(state, state->expr_type, expr_attributes, 4) < 0) return
5795 -1;
5796 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
5797 return -1;
5798 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
5799 -1)
5800 return -1;
5801 state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
5802 BoolOp_fields, 2,
5803 "BoolOp(boolop op, expr* values)");
5804 if (!state->BoolOp_type) return -1;
5805 state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
5806 NamedExpr_fields, 2,
5807 "NamedExpr(expr target, expr value)");
5808 if (!state->NamedExpr_type) return -1;
5809 state->BinOp_type = make_type(state, "BinOp", state->expr_type,
5810 BinOp_fields, 3,
5811 "BinOp(expr left, operator op, expr right)");
5812 if (!state->BinOp_type) return -1;
5813 state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
5814 UnaryOp_fields, 2,
5815 "UnaryOp(unaryop op, expr operand)");
5816 if (!state->UnaryOp_type) return -1;
5817 state->Lambda_type = make_type(state, "Lambda", state->expr_type,
5818 Lambda_fields, 2,
5819 "Lambda(arguments args, expr body)");
5820 if (!state->Lambda_type) return -1;
5821 state->IfExp_type = make_type(state, "IfExp", state->expr_type,
5822 IfExp_fields, 3,
5823 "IfExp(expr test, expr body, expr orelse)");
5824 if (!state->IfExp_type) return -1;
5825 state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
5826 2,
5827 "Dict(expr* keys, expr* values)");
5828 if (!state->Dict_type) return -1;
5829 state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
5830 "Set(expr* elts)");
5831 if (!state->Set_type) return -1;
5832 state->ListComp_type = make_type(state, "ListComp", state->expr_type,
5833 ListComp_fields, 2,
5834 "ListComp(expr elt, comprehension* generators)");
5835 if (!state->ListComp_type) return -1;
5836 state->SetComp_type = make_type(state, "SetComp", state->expr_type,
5837 SetComp_fields, 2,
5838 "SetComp(expr elt, comprehension* generators)");
5839 if (!state->SetComp_type) return -1;
5840 state->DictComp_type = make_type(state, "DictComp", state->expr_type,
5841 DictComp_fields, 3,
5842 "DictComp(expr key, expr value, comprehension* generators)");
5843 if (!state->DictComp_type) return -1;
5844 state->GeneratorExp_type = make_type(state, "GeneratorExp",
5845 state->expr_type, GeneratorExp_fields,
5846 2,
5847 "GeneratorExp(expr elt, comprehension* generators)");
5848 if (!state->GeneratorExp_type) return -1;
5849 state->Await_type = make_type(state, "Await", state->expr_type,
5850 Await_fields, 1,
5851 "Await(expr value)");
5852 if (!state->Await_type) return -1;
5853 state->Yield_type = make_type(state, "Yield", state->expr_type,
5854 Yield_fields, 1,
5855 "Yield(expr? value)");
5856 if (!state->Yield_type) return -1;
5857 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
5858 return -1;
5859 state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
5860 YieldFrom_fields, 1,
5861 "YieldFrom(expr value)");
5862 if (!state->YieldFrom_type) return -1;
5863 state->Compare_type = make_type(state, "Compare", state->expr_type,
5864 Compare_fields, 3,
5865 "Compare(expr left, cmpop* ops, expr* comparators)");
5866 if (!state->Compare_type) return -1;
5867 state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
5868 3,
5869 "Call(expr func, expr* args, keyword* keywords)");
5870 if (!state->Call_type) return -1;
5871 state->FormattedValue_type = make_type(state, "FormattedValue",
5872 state->expr_type,
5873 FormattedValue_fields, 3,
5874 "FormattedValue(expr value, int conversion, expr? format_spec)");
5875 if (!state->FormattedValue_type) return -1;
5876 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
5877 Py_None) == -1)
5878 return -1;
5879 state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
5880 JoinedStr_fields, 1,
5881 "JoinedStr(expr* values)");
5882 if (!state->JoinedStr_type) return -1;
5883 state->Constant_type = make_type(state, "Constant", state->expr_type,
5884 Constant_fields, 2,
5885 "Constant(constant value, string? kind)");
5886 if (!state->Constant_type) return -1;
5887 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
5888 return -1;
5889 state->Attribute_type = make_type(state, "Attribute", state->expr_type,
5890 Attribute_fields, 3,
5891 "Attribute(expr value, identifier attr, expr_context ctx)");
5892 if (!state->Attribute_type) return -1;
5893 state->Subscript_type = make_type(state, "Subscript", state->expr_type,
5894 Subscript_fields, 3,
5895 "Subscript(expr value, expr slice, expr_context ctx)");
5896 if (!state->Subscript_type) return -1;
5897 state->Starred_type = make_type(state, "Starred", state->expr_type,
5898 Starred_fields, 2,
5899 "Starred(expr value, expr_context ctx)");
5900 if (!state->Starred_type) return -1;
5901 state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
5902 2,
5903 "Name(identifier id, expr_context ctx)");
5904 if (!state->Name_type) return -1;
5905 state->List_type = make_type(state, "List", state->expr_type, List_fields,
5906 2,
5907 "List(expr* elts, expr_context ctx)");
5908 if (!state->List_type) return -1;
5909 state->Tuple_type = make_type(state, "Tuple", state->expr_type,
5910 Tuple_fields, 2,
5911 "Tuple(expr* elts, expr_context ctx)");
5912 if (!state->Tuple_type) return -1;
5913 state->Slice_type = make_type(state, "Slice", state->expr_type,
5914 Slice_fields, 3,
5915 "Slice(expr? lower, expr? upper, expr? step)");
5916 if (!state->Slice_type) return -1;
5917 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
5918 return -1;
5919 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
5920 return -1;
5921 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
5922 return -1;
5923 state->expr_context_type = make_type(state, "expr_context",
5924 state->AST_type, NULL, 0,
5925 "expr_context = Load | Store | Del");
5926 if (!state->expr_context_type) return -1;
5927 if (add_attributes(state, state->expr_context_type, NULL, 0) < 0) return -1;
5928 state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
5929 0,
5930 "Load");
5931 if (!state->Load_type) return -1;
5932 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
5933 NULL, NULL);
5934 if (!state->Load_singleton) return -1;
5935 state->Store_type = make_type(state, "Store", state->expr_context_type,
5936 NULL, 0,
5937 "Store");
5938 if (!state->Store_type) return -1;
5939 state->Store_singleton = PyType_GenericNew((PyTypeObject
5940 *)state->Store_type, NULL, NULL);
5941 if (!state->Store_singleton) return -1;
5942 state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
5943 "Del");
5944 if (!state->Del_type) return -1;
5945 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
5946 NULL, NULL);
5947 if (!state->Del_singleton) return -1;
5948 state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
5949 "boolop = And | Or");
5950 if (!state->boolop_type) return -1;
5951 if (add_attributes(state, state->boolop_type, NULL, 0) < 0) return -1;
5952 state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
5953 "And");
5954 if (!state->And_type) return -1;
5955 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
5956 NULL, NULL);
5957 if (!state->And_singleton) return -1;
5958 state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
5959 "Or");
5960 if (!state->Or_type) return -1;
5961 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
5962 NULL, NULL);
5963 if (!state->Or_singleton) return -1;
5964 state->operator_type = make_type(state, "operator", state->AST_type, NULL,
5965 0,
5966 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
5967 if (!state->operator_type) return -1;
5968 if (add_attributes(state, state->operator_type, NULL, 0) < 0) return -1;
5969 state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
5970 "Add");
5971 if (!state->Add_type) return -1;
5972 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
5973 NULL, NULL);
5974 if (!state->Add_singleton) return -1;
5975 state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
5976 "Sub");
5977 if (!state->Sub_type) return -1;
5978 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
5979 NULL, NULL);
5980 if (!state->Sub_singleton) return -1;
5981 state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
5982 "Mult");
5983 if (!state->Mult_type) return -1;
5984 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
5985 NULL, NULL);
5986 if (!state->Mult_singleton) return -1;
5987 state->MatMult_type = make_type(state, "MatMult", state->operator_type,
5988 NULL, 0,
5989 "MatMult");
5990 if (!state->MatMult_type) return -1;
5991 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
5992 *)state->MatMult_type, NULL,
5993 NULL);
5994 if (!state->MatMult_singleton) return -1;
5995 state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
5996 "Div");
5997 if (!state->Div_type) return -1;
5998 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
5999 NULL, NULL);
6000 if (!state->Div_singleton) return -1;
6001 state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
6002 "Mod");
6003 if (!state->Mod_type) return -1;
6004 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
6005 NULL, NULL);
6006 if (!state->Mod_singleton) return -1;
6007 state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
6008 "Pow");
6009 if (!state->Pow_type) return -1;
6010 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
6011 NULL, NULL);
6012 if (!state->Pow_singleton) return -1;
6013 state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
6014 0,
6015 "LShift");
6016 if (!state->LShift_type) return -1;
6017 state->LShift_singleton = PyType_GenericNew((PyTypeObject
6018 *)state->LShift_type, NULL,
6019 NULL);
6020 if (!state->LShift_singleton) return -1;
6021 state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
6022 0,
6023 "RShift");
6024 if (!state->RShift_type) return -1;
6025 state->RShift_singleton = PyType_GenericNew((PyTypeObject
6026 *)state->RShift_type, NULL,
6027 NULL);
6028 if (!state->RShift_singleton) return -1;
6029 state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
6030 "BitOr");
6031 if (!state->BitOr_type) return -1;
6032 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
6033 *)state->BitOr_type, NULL, NULL);
6034 if (!state->BitOr_singleton) return -1;
6035 state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
6036 0,
6037 "BitXor");
6038 if (!state->BitXor_type) return -1;
6039 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
6040 *)state->BitXor_type, NULL,
6041 NULL);
6042 if (!state->BitXor_singleton) return -1;
6043 state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
6044 0,
6045 "BitAnd");
6046 if (!state->BitAnd_type) return -1;
6047 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
6048 *)state->BitAnd_type, NULL,
6049 NULL);
6050 if (!state->BitAnd_singleton) return -1;
6051 state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
6052 NULL, 0,
6053 "FloorDiv");
6054 if (!state->FloorDiv_type) return -1;
6055 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
6056 *)state->FloorDiv_type, NULL,
6057 NULL);
6058 if (!state->FloorDiv_singleton) return -1;
6059 state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
6060 "unaryop = Invert | Not | UAdd | USub");
6061 if (!state->unaryop_type) return -1;
6062 if (add_attributes(state, state->unaryop_type, NULL, 0) < 0) return -1;
6063 state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
6064 0,
6065 "Invert");
6066 if (!state->Invert_type) return -1;
6067 state->Invert_singleton = PyType_GenericNew((PyTypeObject
6068 *)state->Invert_type, NULL,
6069 NULL);
6070 if (!state->Invert_singleton) return -1;
6071 state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
6072 "Not");
6073 if (!state->Not_type) return -1;
6074 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
6075 NULL, NULL);
6076 if (!state->Not_singleton) return -1;
6077 state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
6078 "UAdd");
6079 if (!state->UAdd_type) return -1;
6080 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
6081 NULL, NULL);
6082 if (!state->UAdd_singleton) return -1;
6083 state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
6084 "USub");
6085 if (!state->USub_type) return -1;
6086 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
6087 NULL, NULL);
6088 if (!state->USub_singleton) return -1;
6089 state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
6090 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
6091 if (!state->cmpop_type) return -1;
6092 if (add_attributes(state, state->cmpop_type, NULL, 0) < 0) return -1;
6093 state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
6094 "Eq");
6095 if (!state->Eq_type) return -1;
6096 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
6097 NULL, NULL);
6098 if (!state->Eq_singleton) return -1;
6099 state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
6100 "NotEq");
6101 if (!state->NotEq_type) return -1;
6102 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
6103 *)state->NotEq_type, NULL, NULL);
6104 if (!state->NotEq_singleton) return -1;
6105 state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
6106 "Lt");
6107 if (!state->Lt_type) return -1;
6108 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
6109 NULL, NULL);
6110 if (!state->Lt_singleton) return -1;
6111 state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
6112 "LtE");
6113 if (!state->LtE_type) return -1;
6114 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
6115 NULL, NULL);
6116 if (!state->LtE_singleton) return -1;
6117 state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
6118 "Gt");
6119 if (!state->Gt_type) return -1;
6120 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
6121 NULL, NULL);
6122 if (!state->Gt_singleton) return -1;
6123 state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
6124 "GtE");
6125 if (!state->GtE_type) return -1;
6126 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
6127 NULL, NULL);
6128 if (!state->GtE_singleton) return -1;
6129 state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
6130 "Is");
6131 if (!state->Is_type) return -1;
6132 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
6133 NULL, NULL);
6134 if (!state->Is_singleton) return -1;
6135 state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
6136 "IsNot");
6137 if (!state->IsNot_type) return -1;
6138 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
6139 *)state->IsNot_type, NULL, NULL);
6140 if (!state->IsNot_singleton) return -1;
6141 state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
6142 "In");
6143 if (!state->In_type) return -1;
6144 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
6145 NULL, NULL);
6146 if (!state->In_singleton) return -1;
6147 state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
6148 "NotIn");
6149 if (!state->NotIn_type) return -1;
6150 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
6151 *)state->NotIn_type, NULL, NULL);
6152 if (!state->NotIn_singleton) return -1;
6153 state->comprehension_type = make_type(state, "comprehension",
6154 state->AST_type,
6155 comprehension_fields, 4,
6156 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
6157 if (!state->comprehension_type) return -1;
6158 if (add_attributes(state, state->comprehension_type, NULL, 0) < 0) return
6159 -1;
6160 state->excepthandler_type = make_type(state, "excepthandler",
6161 state->AST_type, NULL, 0,
6162 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
6163 if (!state->excepthandler_type) return -1;
6164 if (add_attributes(state, state->excepthandler_type,
6165 excepthandler_attributes, 4) < 0) return -1;
6166 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
6167 == -1)
6168 return -1;
6169 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
6170 Py_None) == -1)
6171 return -1;
6172 state->ExceptHandler_type = make_type(state, "ExceptHandler",
6173 state->excepthandler_type,
6174 ExceptHandler_fields, 3,
6175 "ExceptHandler(expr? type, identifier? name, stmt* body)");
6176 if (!state->ExceptHandler_type) return -1;
6177 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
6178 return -1;
6179 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
6180 return -1;
6181 state->arguments_type = make_type(state, "arguments", state->AST_type,
6182 arguments_fields, 7,
6183 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
6184 if (!state->arguments_type) return -1;
6185 if (add_attributes(state, state->arguments_type, NULL, 0) < 0) return -1;
6186 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
6187 return -1;
6188 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
6189 return -1;
6190 state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
6191 "arg(identifier arg, expr? annotation, string? type_comment)");
6192 if (!state->arg_type) return -1;
6193 if (add_attributes(state, state->arg_type, arg_attributes, 4) < 0) return
6194 -1;
6195 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
6196 return -1;
6197 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
6198 return -1;
6199 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
6200 return -1;
6201 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
6202 return -1;
6203 state->keyword_type = make_type(state, "keyword", state->AST_type,
6204 keyword_fields, 2,
6205 "keyword(identifier? arg, expr value)");
6206 if (!state->keyword_type) return -1;
6207 if (add_attributes(state, state->keyword_type, keyword_attributes, 4) < 0)
6208 return -1;
6209 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
6210 return -1;
6211 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
6212 return -1;
6213 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
6214 == -1)
6215 return -1;
6216 state->alias_type = make_type(state, "alias", state->AST_type,
6217 alias_fields, 2,
6218 "alias(identifier name, identifier? asname)");
6219 if (!state->alias_type) return -1;
6220 if (add_attributes(state, state->alias_type, alias_attributes, 4) < 0)
6221 return -1;
6222 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
6223 return -1;
6224 if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
6225 return -1;
6226 if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
6227 -1)
6228 return -1;
6229 state->withitem_type = make_type(state, "withitem", state->AST_type,
6230 withitem_fields, 2,
6231 "withitem(expr context_expr, expr? optional_vars)");
6232 if (!state->withitem_type) return -1;
6233 if (add_attributes(state, state->withitem_type, NULL, 0) < 0) return -1;
6234 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
6235 == -1)
6236 return -1;
6237 state->match_case_type = make_type(state, "match_case", state->AST_type,
6238 match_case_fields, 3,
6239 "match_case(pattern pattern, expr? guard, stmt* body)");
6240 if (!state->match_case_type) return -1;
6241 if (add_attributes(state, state->match_case_type, NULL, 0) < 0) return -1;
6242 if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
6243 return -1;
6244 state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
6245 "pattern = MatchValue(expr value)\n"
6246 " | MatchSingleton(constant value)\n"
6247 " | MatchSequence(pattern* patterns)\n"
6248 " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
6249 " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
6250 " | MatchStar(identifier? name)\n"
6251 " | MatchAs(pattern? pattern, identifier? name)\n"
6252 " | MatchOr(pattern* patterns)");
6253 if (!state->pattern_type) return -1;
6254 if (add_attributes(state, state->pattern_type, pattern_attributes, 4) < 0)
6255 return -1;
6256 state->MatchValue_type = make_type(state, "MatchValue",
6257 state->pattern_type, MatchValue_fields,
6258 1,
6259 "MatchValue(expr value)");
6260 if (!state->MatchValue_type) return -1;
6261 state->MatchSingleton_type = make_type(state, "MatchSingleton",
6262 state->pattern_type,
6263 MatchSingleton_fields, 1,
6264 "MatchSingleton(constant value)");
6265 if (!state->MatchSingleton_type) return -1;
6266 state->MatchSequence_type = make_type(state, "MatchSequence",
6267 state->pattern_type,
6268 MatchSequence_fields, 1,
6269 "MatchSequence(pattern* patterns)");
6270 if (!state->MatchSequence_type) return -1;
6271 state->MatchMapping_type = make_type(state, "MatchMapping",
6272 state->pattern_type,
6273 MatchMapping_fields, 3,
6274 "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
6275 if (!state->MatchMapping_type) return -1;
6276 if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
6277 return -1;
6278 state->MatchClass_type = make_type(state, "MatchClass",
6279 state->pattern_type, MatchClass_fields,
6280 4,
6281 "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
6282 if (!state->MatchClass_type) return -1;
6283 state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
6284 MatchStar_fields, 1,
6285 "MatchStar(identifier? name)");
6286 if (!state->MatchStar_type) return -1;
6287 if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
6288 return -1;
6289 state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
6290 MatchAs_fields, 2,
6291 "MatchAs(pattern? pattern, identifier? name)");
6292 if (!state->MatchAs_type) return -1;
6293 if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
6294 return -1;
6295 if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
6296 return -1;
6297 state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
6298 MatchOr_fields, 1,
6299 "MatchOr(pattern* patterns)");
6300 if (!state->MatchOr_type) return -1;
6301 state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
6302 NULL, 0,
6303 "type_ignore = TypeIgnore(int lineno, string tag)");
6304 if (!state->type_ignore_type) return -1;
6305 if (add_attributes(state, state->type_ignore_type, NULL, 0) < 0) return -1;
6306 state->TypeIgnore_type = make_type(state, "TypeIgnore",
6307 state->type_ignore_type,
6308 TypeIgnore_fields, 2,
6309 "TypeIgnore(int lineno, string tag)");
6310 if (!state->TypeIgnore_type) return -1;
6311 state->type_param_type = make_type(state, "type_param", state->AST_type,
6312 NULL, 0,
6313 "type_param = TypeVar(identifier name, expr? bound, expr? default_value)\n"
6314 " | ParamSpec(identifier name, expr? default_value)\n"
6315 " | TypeVarTuple(identifier name, expr? default_value)");
6316 if (!state->type_param_type) return -1;
6317 if (add_attributes(state, state->type_param_type, type_param_attributes, 4)
6318 < 0) return -1;
6319 state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
6320 TypeVar_fields, 3,
6321 "TypeVar(identifier name, expr? bound, expr? default_value)");
6322 if (!state->TypeVar_type) return -1;
6323 if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
6324 return -1;
6325 if (PyObject_SetAttr(state->TypeVar_type, state->default_value, Py_None) ==
6326 -1)
6327 return -1;
6328 state->ParamSpec_type = make_type(state, "ParamSpec",
6329 state->type_param_type, ParamSpec_fields,
6330 2,
6331 "ParamSpec(identifier name, expr? default_value)");
6332 if (!state->ParamSpec_type) return -1;
6333 if (PyObject_SetAttr(state->ParamSpec_type, state->default_value, Py_None)
6334 == -1)
6335 return -1;
6336 state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
6337 state->type_param_type,
6338 TypeVarTuple_fields, 2,
6339 "TypeVarTuple(identifier name, expr? default_value)");
6340 if (!state->TypeVarTuple_type) return -1;
6341 if (PyObject_SetAttr(state->TypeVarTuple_type, state->default_value,
6342 Py_None) == -1)
6343 return -1;
6344
6345 if (!add_ast_annotations(state)) {
6346 return -1;
6347 }
6348 return 0;
6349 }
6350
6351 static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
6352 PyArena* arena);
6353 static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
6354 PyArena* arena);
6355 static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
6356 PyArena* arena);
6357 static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
6358 expr_context_ty* out, PyArena* arena);
6359 static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
6360 out, PyArena* arena);
6361 static int obj2ast_operator(struct ast_state *state, PyObject* obj,
6362 operator_ty* out, PyArena* arena);
6363 static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
6364 out, PyArena* arena);
6365 static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
6366 PyArena* arena);
6367 static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
6368 comprehension_ty* out, PyArena* arena);
6369 static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
6370 excepthandler_ty* out, PyArena* arena);
6371 static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
6372 arguments_ty* out, PyArena* arena);
6373 static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
6374 PyArena* arena);
6375 static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
6376 out, PyArena* arena);
6377 static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
6378 PyArena* arena);
6379 static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
6380 withitem_ty* out, PyArena* arena);
6381 static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
6382 match_case_ty* out, PyArena* arena);
6383 static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
6384 out, PyArena* arena);
6385 static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
6386 type_ignore_ty* out, PyArena* arena);
6387 static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
6388 type_param_ty* out, PyArena* arena);
6389
6390 mod_ty
_PyAST_Module(asdl_stmt_seq * body,asdl_type_ignore_seq * type_ignores,PyArena * arena)6391 _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
6392 PyArena *arena)
6393 {
6394 mod_ty p;
6395 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
6396 if (!p)
6397 return NULL;
6398 p->kind = Module_kind;
6399 p->v.Module.body = body;
6400 p->v.Module.type_ignores = type_ignores;
6401 return p;
6402 }
6403
6404 mod_ty
_PyAST_Interactive(asdl_stmt_seq * body,PyArena * arena)6405 _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
6406 {
6407 mod_ty p;
6408 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
6409 if (!p)
6410 return NULL;
6411 p->kind = Interactive_kind;
6412 p->v.Interactive.body = body;
6413 return p;
6414 }
6415
6416 mod_ty
_PyAST_Expression(expr_ty body,PyArena * arena)6417 _PyAST_Expression(expr_ty body, PyArena *arena)
6418 {
6419 mod_ty p;
6420 if (!body) {
6421 PyErr_SetString(PyExc_ValueError,
6422 "field 'body' is required for Expression");
6423 return NULL;
6424 }
6425 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
6426 if (!p)
6427 return NULL;
6428 p->kind = Expression_kind;
6429 p->v.Expression.body = body;
6430 return p;
6431 }
6432
6433 mod_ty
_PyAST_FunctionType(asdl_expr_seq * argtypes,expr_ty returns,PyArena * arena)6434 _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
6435 {
6436 mod_ty p;
6437 if (!returns) {
6438 PyErr_SetString(PyExc_ValueError,
6439 "field 'returns' is required for FunctionType");
6440 return NULL;
6441 }
6442 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
6443 if (!p)
6444 return NULL;
6445 p->kind = FunctionType_kind;
6446 p->v.FunctionType.argtypes = argtypes;
6447 p->v.FunctionType.returns = returns;
6448 return p;
6449 }
6450
6451 stmt_ty
_PyAST_FunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,asdl_type_param_seq * type_params,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6452 _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
6453 asdl_expr_seq * decorator_list, expr_ty returns, string
6454 type_comment, asdl_type_param_seq * type_params, int lineno,
6455 int col_offset, int end_lineno, int end_col_offset, PyArena
6456 *arena)
6457 {
6458 stmt_ty p;
6459 if (!name) {
6460 PyErr_SetString(PyExc_ValueError,
6461 "field 'name' is required for FunctionDef");
6462 return NULL;
6463 }
6464 if (!args) {
6465 PyErr_SetString(PyExc_ValueError,
6466 "field 'args' is required for FunctionDef");
6467 return NULL;
6468 }
6469 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6470 if (!p)
6471 return NULL;
6472 p->kind = FunctionDef_kind;
6473 p->v.FunctionDef.name = name;
6474 p->v.FunctionDef.args = args;
6475 p->v.FunctionDef.body = body;
6476 p->v.FunctionDef.decorator_list = decorator_list;
6477 p->v.FunctionDef.returns = returns;
6478 p->v.FunctionDef.type_comment = type_comment;
6479 p->v.FunctionDef.type_params = type_params;
6480 p->lineno = lineno;
6481 p->col_offset = col_offset;
6482 p->end_lineno = end_lineno;
6483 p->end_col_offset = end_col_offset;
6484 return p;
6485 }
6486
6487 stmt_ty
_PyAST_AsyncFunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,asdl_type_param_seq * type_params,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6488 _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
6489 body, asdl_expr_seq * decorator_list, expr_ty returns,
6490 string type_comment, asdl_type_param_seq * type_params,
6491 int lineno, int col_offset, int end_lineno, int
6492 end_col_offset, PyArena *arena)
6493 {
6494 stmt_ty p;
6495 if (!name) {
6496 PyErr_SetString(PyExc_ValueError,
6497 "field 'name' is required for AsyncFunctionDef");
6498 return NULL;
6499 }
6500 if (!args) {
6501 PyErr_SetString(PyExc_ValueError,
6502 "field 'args' is required for AsyncFunctionDef");
6503 return NULL;
6504 }
6505 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6506 if (!p)
6507 return NULL;
6508 p->kind = AsyncFunctionDef_kind;
6509 p->v.AsyncFunctionDef.name = name;
6510 p->v.AsyncFunctionDef.args = args;
6511 p->v.AsyncFunctionDef.body = body;
6512 p->v.AsyncFunctionDef.decorator_list = decorator_list;
6513 p->v.AsyncFunctionDef.returns = returns;
6514 p->v.AsyncFunctionDef.type_comment = type_comment;
6515 p->v.AsyncFunctionDef.type_params = type_params;
6516 p->lineno = lineno;
6517 p->col_offset = col_offset;
6518 p->end_lineno = end_lineno;
6519 p->end_col_offset = end_col_offset;
6520 return p;
6521 }
6522
6523 stmt_ty
_PyAST_ClassDef(identifier name,asdl_expr_seq * bases,asdl_keyword_seq * keywords,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,asdl_type_param_seq * type_params,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6524 _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
6525 keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
6526 asdl_type_param_seq * type_params, int lineno, int col_offset,
6527 int end_lineno, int end_col_offset, PyArena *arena)
6528 {
6529 stmt_ty p;
6530 if (!name) {
6531 PyErr_SetString(PyExc_ValueError,
6532 "field 'name' is required for ClassDef");
6533 return NULL;
6534 }
6535 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6536 if (!p)
6537 return NULL;
6538 p->kind = ClassDef_kind;
6539 p->v.ClassDef.name = name;
6540 p->v.ClassDef.bases = bases;
6541 p->v.ClassDef.keywords = keywords;
6542 p->v.ClassDef.body = body;
6543 p->v.ClassDef.decorator_list = decorator_list;
6544 p->v.ClassDef.type_params = type_params;
6545 p->lineno = lineno;
6546 p->col_offset = col_offset;
6547 p->end_lineno = end_lineno;
6548 p->end_col_offset = end_col_offset;
6549 return p;
6550 }
6551
6552 stmt_ty
_PyAST_Return(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6553 _PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
6554 end_col_offset, PyArena *arena)
6555 {
6556 stmt_ty p;
6557 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6558 if (!p)
6559 return NULL;
6560 p->kind = Return_kind;
6561 p->v.Return.value = value;
6562 p->lineno = lineno;
6563 p->col_offset = col_offset;
6564 p->end_lineno = end_lineno;
6565 p->end_col_offset = end_col_offset;
6566 return p;
6567 }
6568
6569 stmt_ty
_PyAST_Delete(asdl_expr_seq * targets,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6570 _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
6571 end_lineno, int end_col_offset, PyArena *arena)
6572 {
6573 stmt_ty p;
6574 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6575 if (!p)
6576 return NULL;
6577 p->kind = Delete_kind;
6578 p->v.Delete.targets = targets;
6579 p->lineno = lineno;
6580 p->col_offset = col_offset;
6581 p->end_lineno = end_lineno;
6582 p->end_col_offset = end_col_offset;
6583 return p;
6584 }
6585
6586 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)6587 _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
6588 lineno, int col_offset, int end_lineno, int end_col_offset,
6589 PyArena *arena)
6590 {
6591 stmt_ty p;
6592 if (!value) {
6593 PyErr_SetString(PyExc_ValueError,
6594 "field 'value' is required for Assign");
6595 return NULL;
6596 }
6597 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6598 if (!p)
6599 return NULL;
6600 p->kind = Assign_kind;
6601 p->v.Assign.targets = targets;
6602 p->v.Assign.value = value;
6603 p->v.Assign.type_comment = type_comment;
6604 p->lineno = lineno;
6605 p->col_offset = col_offset;
6606 p->end_lineno = end_lineno;
6607 p->end_col_offset = end_col_offset;
6608 return p;
6609 }
6610
6611 stmt_ty
_PyAST_TypeAlias(expr_ty name,asdl_type_param_seq * type_params,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6612 _PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
6613 value, int lineno, int col_offset, int end_lineno, int
6614 end_col_offset, PyArena *arena)
6615 {
6616 stmt_ty p;
6617 if (!name) {
6618 PyErr_SetString(PyExc_ValueError,
6619 "field 'name' is required for TypeAlias");
6620 return NULL;
6621 }
6622 if (!value) {
6623 PyErr_SetString(PyExc_ValueError,
6624 "field 'value' is required for TypeAlias");
6625 return NULL;
6626 }
6627 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6628 if (!p)
6629 return NULL;
6630 p->kind = TypeAlias_kind;
6631 p->v.TypeAlias.name = name;
6632 p->v.TypeAlias.type_params = type_params;
6633 p->v.TypeAlias.value = value;
6634 p->lineno = lineno;
6635 p->col_offset = col_offset;
6636 p->end_lineno = end_lineno;
6637 p->end_col_offset = end_col_offset;
6638 return p;
6639 }
6640
6641 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)6642 _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
6643 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
6644 {
6645 stmt_ty p;
6646 if (!target) {
6647 PyErr_SetString(PyExc_ValueError,
6648 "field 'target' is required for AugAssign");
6649 return NULL;
6650 }
6651 if (!op) {
6652 PyErr_SetString(PyExc_ValueError,
6653 "field 'op' is required for AugAssign");
6654 return NULL;
6655 }
6656 if (!value) {
6657 PyErr_SetString(PyExc_ValueError,
6658 "field 'value' is required for AugAssign");
6659 return NULL;
6660 }
6661 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6662 if (!p)
6663 return NULL;
6664 p->kind = AugAssign_kind;
6665 p->v.AugAssign.target = target;
6666 p->v.AugAssign.op = op;
6667 p->v.AugAssign.value = value;
6668 p->lineno = lineno;
6669 p->col_offset = col_offset;
6670 p->end_lineno = end_lineno;
6671 p->end_col_offset = end_col_offset;
6672 return p;
6673 }
6674
6675 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)6676 _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
6677 int lineno, int col_offset, int end_lineno, int
6678 end_col_offset, PyArena *arena)
6679 {
6680 stmt_ty p;
6681 if (!target) {
6682 PyErr_SetString(PyExc_ValueError,
6683 "field 'target' is required for AnnAssign");
6684 return NULL;
6685 }
6686 if (!annotation) {
6687 PyErr_SetString(PyExc_ValueError,
6688 "field 'annotation' is required for AnnAssign");
6689 return NULL;
6690 }
6691 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6692 if (!p)
6693 return NULL;
6694 p->kind = AnnAssign_kind;
6695 p->v.AnnAssign.target = target;
6696 p->v.AnnAssign.annotation = annotation;
6697 p->v.AnnAssign.value = value;
6698 p->v.AnnAssign.simple = simple;
6699 p->lineno = lineno;
6700 p->col_offset = col_offset;
6701 p->end_lineno = end_lineno;
6702 p->end_col_offset = end_col_offset;
6703 return p;
6704 }
6705
6706 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)6707 _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
6708 orelse, string type_comment, int lineno, int col_offset, int
6709 end_lineno, int end_col_offset, PyArena *arena)
6710 {
6711 stmt_ty p;
6712 if (!target) {
6713 PyErr_SetString(PyExc_ValueError,
6714 "field 'target' is required for For");
6715 return NULL;
6716 }
6717 if (!iter) {
6718 PyErr_SetString(PyExc_ValueError,
6719 "field 'iter' is required for For");
6720 return NULL;
6721 }
6722 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6723 if (!p)
6724 return NULL;
6725 p->kind = For_kind;
6726 p->v.For.target = target;
6727 p->v.For.iter = iter;
6728 p->v.For.body = body;
6729 p->v.For.orelse = orelse;
6730 p->v.For.type_comment = type_comment;
6731 p->lineno = lineno;
6732 p->col_offset = col_offset;
6733 p->end_lineno = end_lineno;
6734 p->end_col_offset = end_col_offset;
6735 return p;
6736 }
6737
6738 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)6739 _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
6740 asdl_stmt_seq * orelse, string type_comment, int lineno, int
6741 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
6742 {
6743 stmt_ty p;
6744 if (!target) {
6745 PyErr_SetString(PyExc_ValueError,
6746 "field 'target' is required for AsyncFor");
6747 return NULL;
6748 }
6749 if (!iter) {
6750 PyErr_SetString(PyExc_ValueError,
6751 "field 'iter' is required for AsyncFor");
6752 return NULL;
6753 }
6754 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6755 if (!p)
6756 return NULL;
6757 p->kind = AsyncFor_kind;
6758 p->v.AsyncFor.target = target;
6759 p->v.AsyncFor.iter = iter;
6760 p->v.AsyncFor.body = body;
6761 p->v.AsyncFor.orelse = orelse;
6762 p->v.AsyncFor.type_comment = type_comment;
6763 p->lineno = lineno;
6764 p->col_offset = col_offset;
6765 p->end_lineno = end_lineno;
6766 p->end_col_offset = end_col_offset;
6767 return p;
6768 }
6769
6770 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)6771 _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
6772 lineno, int col_offset, int end_lineno, int end_col_offset,
6773 PyArena *arena)
6774 {
6775 stmt_ty p;
6776 if (!test) {
6777 PyErr_SetString(PyExc_ValueError,
6778 "field 'test' is required for While");
6779 return NULL;
6780 }
6781 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6782 if (!p)
6783 return NULL;
6784 p->kind = While_kind;
6785 p->v.While.test = test;
6786 p->v.While.body = body;
6787 p->v.While.orelse = orelse;
6788 p->lineno = lineno;
6789 p->col_offset = col_offset;
6790 p->end_lineno = end_lineno;
6791 p->end_col_offset = end_col_offset;
6792 return p;
6793 }
6794
6795 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)6796 _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
6797 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
6798 *arena)
6799 {
6800 stmt_ty p;
6801 if (!test) {
6802 PyErr_SetString(PyExc_ValueError,
6803 "field 'test' is required for If");
6804 return NULL;
6805 }
6806 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6807 if (!p)
6808 return NULL;
6809 p->kind = If_kind;
6810 p->v.If.test = test;
6811 p->v.If.body = body;
6812 p->v.If.orelse = orelse;
6813 p->lineno = lineno;
6814 p->col_offset = col_offset;
6815 p->end_lineno = end_lineno;
6816 p->end_col_offset = end_col_offset;
6817 return p;
6818 }
6819
6820 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)6821 _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
6822 type_comment, int lineno, int col_offset, int end_lineno, int
6823 end_col_offset, PyArena *arena)
6824 {
6825 stmt_ty p;
6826 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6827 if (!p)
6828 return NULL;
6829 p->kind = With_kind;
6830 p->v.With.items = items;
6831 p->v.With.body = body;
6832 p->v.With.type_comment = type_comment;
6833 p->lineno = lineno;
6834 p->col_offset = col_offset;
6835 p->end_lineno = end_lineno;
6836 p->end_col_offset = end_col_offset;
6837 return p;
6838 }
6839
6840 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)6841 _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
6842 type_comment, int lineno, int col_offset, int end_lineno, int
6843 end_col_offset, PyArena *arena)
6844 {
6845 stmt_ty p;
6846 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6847 if (!p)
6848 return NULL;
6849 p->kind = AsyncWith_kind;
6850 p->v.AsyncWith.items = items;
6851 p->v.AsyncWith.body = body;
6852 p->v.AsyncWith.type_comment = type_comment;
6853 p->lineno = lineno;
6854 p->col_offset = col_offset;
6855 p->end_lineno = end_lineno;
6856 p->end_col_offset = end_col_offset;
6857 return p;
6858 }
6859
6860 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)6861 _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
6862 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
6863 {
6864 stmt_ty p;
6865 if (!subject) {
6866 PyErr_SetString(PyExc_ValueError,
6867 "field 'subject' is required for Match");
6868 return NULL;
6869 }
6870 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6871 if (!p)
6872 return NULL;
6873 p->kind = Match_kind;
6874 p->v.Match.subject = subject;
6875 p->v.Match.cases = cases;
6876 p->lineno = lineno;
6877 p->col_offset = col_offset;
6878 p->end_lineno = end_lineno;
6879 p->end_col_offset = end_col_offset;
6880 return p;
6881 }
6882
6883 stmt_ty
_PyAST_Raise(expr_ty exc,expr_ty cause,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6884 _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
6885 end_lineno, int end_col_offset, PyArena *arena)
6886 {
6887 stmt_ty p;
6888 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6889 if (!p)
6890 return NULL;
6891 p->kind = Raise_kind;
6892 p->v.Raise.exc = exc;
6893 p->v.Raise.cause = cause;
6894 p->lineno = lineno;
6895 p->col_offset = col_offset;
6896 p->end_lineno = end_lineno;
6897 p->end_col_offset = end_col_offset;
6898 return p;
6899 }
6900
6901 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)6902 _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
6903 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
6904 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
6905 {
6906 stmt_ty p;
6907 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6908 if (!p)
6909 return NULL;
6910 p->kind = Try_kind;
6911 p->v.Try.body = body;
6912 p->v.Try.handlers = handlers;
6913 p->v.Try.orelse = orelse;
6914 p->v.Try.finalbody = finalbody;
6915 p->lineno = lineno;
6916 p->col_offset = col_offset;
6917 p->end_lineno = end_lineno;
6918 p->end_col_offset = end_col_offset;
6919 return p;
6920 }
6921
6922 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)6923 _PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
6924 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
6925 int col_offset, int end_lineno, int end_col_offset, PyArena
6926 *arena)
6927 {
6928 stmt_ty p;
6929 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6930 if (!p)
6931 return NULL;
6932 p->kind = TryStar_kind;
6933 p->v.TryStar.body = body;
6934 p->v.TryStar.handlers = handlers;
6935 p->v.TryStar.orelse = orelse;
6936 p->v.TryStar.finalbody = finalbody;
6937 p->lineno = lineno;
6938 p->col_offset = col_offset;
6939 p->end_lineno = end_lineno;
6940 p->end_col_offset = end_col_offset;
6941 return p;
6942 }
6943
6944 stmt_ty
_PyAST_Assert(expr_ty test,expr_ty msg,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6945 _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
6946 end_lineno, int end_col_offset, PyArena *arena)
6947 {
6948 stmt_ty p;
6949 if (!test) {
6950 PyErr_SetString(PyExc_ValueError,
6951 "field 'test' is required for Assert");
6952 return NULL;
6953 }
6954 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6955 if (!p)
6956 return NULL;
6957 p->kind = Assert_kind;
6958 p->v.Assert.test = test;
6959 p->v.Assert.msg = msg;
6960 p->lineno = lineno;
6961 p->col_offset = col_offset;
6962 p->end_lineno = end_lineno;
6963 p->end_col_offset = end_col_offset;
6964 return p;
6965 }
6966
6967 stmt_ty
_PyAST_Import(asdl_alias_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)6968 _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
6969 end_lineno, int end_col_offset, PyArena *arena)
6970 {
6971 stmt_ty p;
6972 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6973 if (!p)
6974 return NULL;
6975 p->kind = Import_kind;
6976 p->v.Import.names = names;
6977 p->lineno = lineno;
6978 p->col_offset = col_offset;
6979 p->end_lineno = end_lineno;
6980 p->end_col_offset = end_col_offset;
6981 return p;
6982 }
6983
6984 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)6985 _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
6986 lineno, int col_offset, int end_lineno, int end_col_offset,
6987 PyArena *arena)
6988 {
6989 stmt_ty p;
6990 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
6991 if (!p)
6992 return NULL;
6993 p->kind = ImportFrom_kind;
6994 p->v.ImportFrom.module = module;
6995 p->v.ImportFrom.names = names;
6996 p->v.ImportFrom.level = level;
6997 p->lineno = lineno;
6998 p->col_offset = col_offset;
6999 p->end_lineno = end_lineno;
7000 p->end_col_offset = end_col_offset;
7001 return p;
7002 }
7003
7004 stmt_ty
_PyAST_Global(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7005 _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
7006 end_lineno, int end_col_offset, PyArena *arena)
7007 {
7008 stmt_ty p;
7009 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7010 if (!p)
7011 return NULL;
7012 p->kind = Global_kind;
7013 p->v.Global.names = names;
7014 p->lineno = lineno;
7015 p->col_offset = col_offset;
7016 p->end_lineno = end_lineno;
7017 p->end_col_offset = end_col_offset;
7018 return p;
7019 }
7020
7021 stmt_ty
_PyAST_Nonlocal(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7022 _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
7023 end_lineno, int end_col_offset, PyArena *arena)
7024 {
7025 stmt_ty p;
7026 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7027 if (!p)
7028 return NULL;
7029 p->kind = Nonlocal_kind;
7030 p->v.Nonlocal.names = names;
7031 p->lineno = lineno;
7032 p->col_offset = col_offset;
7033 p->end_lineno = end_lineno;
7034 p->end_col_offset = end_col_offset;
7035 return p;
7036 }
7037
7038 stmt_ty
_PyAST_Expr(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7039 _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
7040 end_col_offset, PyArena *arena)
7041 {
7042 stmt_ty p;
7043 if (!value) {
7044 PyErr_SetString(PyExc_ValueError,
7045 "field 'value' is required for Expr");
7046 return NULL;
7047 }
7048 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7049 if (!p)
7050 return NULL;
7051 p->kind = Expr_kind;
7052 p->v.Expr.value = value;
7053 p->lineno = lineno;
7054 p->col_offset = col_offset;
7055 p->end_lineno = end_lineno;
7056 p->end_col_offset = end_col_offset;
7057 return p;
7058 }
7059
7060 stmt_ty
_PyAST_Pass(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7061 _PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
7062 PyArena *arena)
7063 {
7064 stmt_ty p;
7065 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7066 if (!p)
7067 return NULL;
7068 p->kind = Pass_kind;
7069 p->lineno = lineno;
7070 p->col_offset = col_offset;
7071 p->end_lineno = end_lineno;
7072 p->end_col_offset = end_col_offset;
7073 return p;
7074 }
7075
7076 stmt_ty
_PyAST_Break(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7077 _PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
7078 PyArena *arena)
7079 {
7080 stmt_ty p;
7081 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7082 if (!p)
7083 return NULL;
7084 p->kind = Break_kind;
7085 p->lineno = lineno;
7086 p->col_offset = col_offset;
7087 p->end_lineno = end_lineno;
7088 p->end_col_offset = end_col_offset;
7089 return p;
7090 }
7091
7092 stmt_ty
_PyAST_Continue(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7093 _PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
7094 PyArena *arena)
7095 {
7096 stmt_ty p;
7097 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
7098 if (!p)
7099 return NULL;
7100 p->kind = Continue_kind;
7101 p->lineno = lineno;
7102 p->col_offset = col_offset;
7103 p->end_lineno = end_lineno;
7104 p->end_col_offset = end_col_offset;
7105 return p;
7106 }
7107
7108 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)7109 _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
7110 int end_lineno, int end_col_offset, PyArena *arena)
7111 {
7112 expr_ty p;
7113 if (!op) {
7114 PyErr_SetString(PyExc_ValueError,
7115 "field 'op' is required for BoolOp");
7116 return NULL;
7117 }
7118 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7119 if (!p)
7120 return NULL;
7121 p->kind = BoolOp_kind;
7122 p->v.BoolOp.op = op;
7123 p->v.BoolOp.values = values;
7124 p->lineno = lineno;
7125 p->col_offset = col_offset;
7126 p->end_lineno = end_lineno;
7127 p->end_col_offset = end_col_offset;
7128 return p;
7129 }
7130
7131 expr_ty
_PyAST_NamedExpr(expr_ty target,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7132 _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
7133 end_lineno, int end_col_offset, PyArena *arena)
7134 {
7135 expr_ty p;
7136 if (!target) {
7137 PyErr_SetString(PyExc_ValueError,
7138 "field 'target' is required for NamedExpr");
7139 return NULL;
7140 }
7141 if (!value) {
7142 PyErr_SetString(PyExc_ValueError,
7143 "field 'value' is required for NamedExpr");
7144 return NULL;
7145 }
7146 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7147 if (!p)
7148 return NULL;
7149 p->kind = NamedExpr_kind;
7150 p->v.NamedExpr.target = target;
7151 p->v.NamedExpr.value = value;
7152 p->lineno = lineno;
7153 p->col_offset = col_offset;
7154 p->end_lineno = end_lineno;
7155 p->end_col_offset = end_col_offset;
7156 return p;
7157 }
7158
7159 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)7160 _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
7161 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7162 {
7163 expr_ty p;
7164 if (!left) {
7165 PyErr_SetString(PyExc_ValueError,
7166 "field 'left' is required for BinOp");
7167 return NULL;
7168 }
7169 if (!op) {
7170 PyErr_SetString(PyExc_ValueError,
7171 "field 'op' is required for BinOp");
7172 return NULL;
7173 }
7174 if (!right) {
7175 PyErr_SetString(PyExc_ValueError,
7176 "field 'right' is required for BinOp");
7177 return NULL;
7178 }
7179 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7180 if (!p)
7181 return NULL;
7182 p->kind = BinOp_kind;
7183 p->v.BinOp.left = left;
7184 p->v.BinOp.op = op;
7185 p->v.BinOp.right = right;
7186 p->lineno = lineno;
7187 p->col_offset = col_offset;
7188 p->end_lineno = end_lineno;
7189 p->end_col_offset = end_col_offset;
7190 return p;
7191 }
7192
7193 expr_ty
_PyAST_UnaryOp(unaryop_ty op,expr_ty operand,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7194 _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
7195 end_lineno, int end_col_offset, PyArena *arena)
7196 {
7197 expr_ty p;
7198 if (!op) {
7199 PyErr_SetString(PyExc_ValueError,
7200 "field 'op' is required for UnaryOp");
7201 return NULL;
7202 }
7203 if (!operand) {
7204 PyErr_SetString(PyExc_ValueError,
7205 "field 'operand' is required for UnaryOp");
7206 return NULL;
7207 }
7208 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7209 if (!p)
7210 return NULL;
7211 p->kind = UnaryOp_kind;
7212 p->v.UnaryOp.op = op;
7213 p->v.UnaryOp.operand = operand;
7214 p->lineno = lineno;
7215 p->col_offset = col_offset;
7216 p->end_lineno = end_lineno;
7217 p->end_col_offset = end_col_offset;
7218 return p;
7219 }
7220
7221 expr_ty
_PyAST_Lambda(arguments_ty args,expr_ty body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7222 _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
7223 end_lineno, int end_col_offset, PyArena *arena)
7224 {
7225 expr_ty p;
7226 if (!args) {
7227 PyErr_SetString(PyExc_ValueError,
7228 "field 'args' is required for Lambda");
7229 return NULL;
7230 }
7231 if (!body) {
7232 PyErr_SetString(PyExc_ValueError,
7233 "field 'body' is required for Lambda");
7234 return NULL;
7235 }
7236 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7237 if (!p)
7238 return NULL;
7239 p->kind = Lambda_kind;
7240 p->v.Lambda.args = args;
7241 p->v.Lambda.body = body;
7242 p->lineno = lineno;
7243 p->col_offset = col_offset;
7244 p->end_lineno = end_lineno;
7245 p->end_col_offset = end_col_offset;
7246 return p;
7247 }
7248
7249 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)7250 _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
7251 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7252 {
7253 expr_ty p;
7254 if (!test) {
7255 PyErr_SetString(PyExc_ValueError,
7256 "field 'test' is required for IfExp");
7257 return NULL;
7258 }
7259 if (!body) {
7260 PyErr_SetString(PyExc_ValueError,
7261 "field 'body' is required for IfExp");
7262 return NULL;
7263 }
7264 if (!orelse) {
7265 PyErr_SetString(PyExc_ValueError,
7266 "field 'orelse' is required for IfExp");
7267 return NULL;
7268 }
7269 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7270 if (!p)
7271 return NULL;
7272 p->kind = IfExp_kind;
7273 p->v.IfExp.test = test;
7274 p->v.IfExp.body = body;
7275 p->v.IfExp.orelse = orelse;
7276 p->lineno = lineno;
7277 p->col_offset = col_offset;
7278 p->end_lineno = end_lineno;
7279 p->end_col_offset = end_col_offset;
7280 return p;
7281 }
7282
7283 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)7284 _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
7285 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7286 {
7287 expr_ty p;
7288 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7289 if (!p)
7290 return NULL;
7291 p->kind = Dict_kind;
7292 p->v.Dict.keys = keys;
7293 p->v.Dict.values = values;
7294 p->lineno = lineno;
7295 p->col_offset = col_offset;
7296 p->end_lineno = end_lineno;
7297 p->end_col_offset = end_col_offset;
7298 return p;
7299 }
7300
7301 expr_ty
_PyAST_Set(asdl_expr_seq * elts,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7302 _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
7303 int end_col_offset, PyArena *arena)
7304 {
7305 expr_ty p;
7306 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7307 if (!p)
7308 return NULL;
7309 p->kind = Set_kind;
7310 p->v.Set.elts = elts;
7311 p->lineno = lineno;
7312 p->col_offset = col_offset;
7313 p->end_lineno = end_lineno;
7314 p->end_col_offset = end_col_offset;
7315 return p;
7316 }
7317
7318 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)7319 _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
7320 int col_offset, int end_lineno, int end_col_offset, PyArena
7321 *arena)
7322 {
7323 expr_ty p;
7324 if (!elt) {
7325 PyErr_SetString(PyExc_ValueError,
7326 "field 'elt' is required for ListComp");
7327 return NULL;
7328 }
7329 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7330 if (!p)
7331 return NULL;
7332 p->kind = ListComp_kind;
7333 p->v.ListComp.elt = elt;
7334 p->v.ListComp.generators = generators;
7335 p->lineno = lineno;
7336 p->col_offset = col_offset;
7337 p->end_lineno = end_lineno;
7338 p->end_col_offset = end_col_offset;
7339 return p;
7340 }
7341
7342 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)7343 _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
7344 int col_offset, int end_lineno, int end_col_offset, PyArena
7345 *arena)
7346 {
7347 expr_ty p;
7348 if (!elt) {
7349 PyErr_SetString(PyExc_ValueError,
7350 "field 'elt' is required for SetComp");
7351 return NULL;
7352 }
7353 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7354 if (!p)
7355 return NULL;
7356 p->kind = SetComp_kind;
7357 p->v.SetComp.elt = elt;
7358 p->v.SetComp.generators = generators;
7359 p->lineno = lineno;
7360 p->col_offset = col_offset;
7361 p->end_lineno = end_lineno;
7362 p->end_col_offset = end_col_offset;
7363 return p;
7364 }
7365
7366 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)7367 _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
7368 generators, int lineno, int col_offset, int end_lineno, int
7369 end_col_offset, PyArena *arena)
7370 {
7371 expr_ty p;
7372 if (!key) {
7373 PyErr_SetString(PyExc_ValueError,
7374 "field 'key' is required for DictComp");
7375 return NULL;
7376 }
7377 if (!value) {
7378 PyErr_SetString(PyExc_ValueError,
7379 "field 'value' is required for DictComp");
7380 return NULL;
7381 }
7382 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7383 if (!p)
7384 return NULL;
7385 p->kind = DictComp_kind;
7386 p->v.DictComp.key = key;
7387 p->v.DictComp.value = value;
7388 p->v.DictComp.generators = generators;
7389 p->lineno = lineno;
7390 p->col_offset = col_offset;
7391 p->end_lineno = end_lineno;
7392 p->end_col_offset = end_col_offset;
7393 return p;
7394 }
7395
7396 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)7397 _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
7398 lineno, int col_offset, int end_lineno, int end_col_offset,
7399 PyArena *arena)
7400 {
7401 expr_ty p;
7402 if (!elt) {
7403 PyErr_SetString(PyExc_ValueError,
7404 "field 'elt' is required for GeneratorExp");
7405 return NULL;
7406 }
7407 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7408 if (!p)
7409 return NULL;
7410 p->kind = GeneratorExp_kind;
7411 p->v.GeneratorExp.elt = elt;
7412 p->v.GeneratorExp.generators = generators;
7413 p->lineno = lineno;
7414 p->col_offset = col_offset;
7415 p->end_lineno = end_lineno;
7416 p->end_col_offset = end_col_offset;
7417 return p;
7418 }
7419
7420 expr_ty
_PyAST_Await(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7421 _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
7422 end_col_offset, PyArena *arena)
7423 {
7424 expr_ty p;
7425 if (!value) {
7426 PyErr_SetString(PyExc_ValueError,
7427 "field 'value' is required for Await");
7428 return NULL;
7429 }
7430 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7431 if (!p)
7432 return NULL;
7433 p->kind = Await_kind;
7434 p->v.Await.value = value;
7435 p->lineno = lineno;
7436 p->col_offset = col_offset;
7437 p->end_lineno = end_lineno;
7438 p->end_col_offset = end_col_offset;
7439 return p;
7440 }
7441
7442 expr_ty
_PyAST_Yield(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7443 _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
7444 end_col_offset, PyArena *arena)
7445 {
7446 expr_ty p;
7447 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7448 if (!p)
7449 return NULL;
7450 p->kind = Yield_kind;
7451 p->v.Yield.value = value;
7452 p->lineno = lineno;
7453 p->col_offset = col_offset;
7454 p->end_lineno = end_lineno;
7455 p->end_col_offset = end_col_offset;
7456 return p;
7457 }
7458
7459 expr_ty
_PyAST_YieldFrom(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7460 _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
7461 end_col_offset, PyArena *arena)
7462 {
7463 expr_ty p;
7464 if (!value) {
7465 PyErr_SetString(PyExc_ValueError,
7466 "field 'value' is required for YieldFrom");
7467 return NULL;
7468 }
7469 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7470 if (!p)
7471 return NULL;
7472 p->kind = YieldFrom_kind;
7473 p->v.YieldFrom.value = value;
7474 p->lineno = lineno;
7475 p->col_offset = col_offset;
7476 p->end_lineno = end_lineno;
7477 p->end_col_offset = end_col_offset;
7478 return p;
7479 }
7480
7481 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)7482 _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
7483 int lineno, int col_offset, int end_lineno, int end_col_offset,
7484 PyArena *arena)
7485 {
7486 expr_ty p;
7487 if (!left) {
7488 PyErr_SetString(PyExc_ValueError,
7489 "field 'left' is required for Compare");
7490 return NULL;
7491 }
7492 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7493 if (!p)
7494 return NULL;
7495 p->kind = Compare_kind;
7496 p->v.Compare.left = left;
7497 p->v.Compare.ops = ops;
7498 p->v.Compare.comparators = comparators;
7499 p->lineno = lineno;
7500 p->col_offset = col_offset;
7501 p->end_lineno = end_lineno;
7502 p->end_col_offset = end_col_offset;
7503 return p;
7504 }
7505
7506 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)7507 _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
7508 int lineno, int col_offset, int end_lineno, int end_col_offset,
7509 PyArena *arena)
7510 {
7511 expr_ty p;
7512 if (!func) {
7513 PyErr_SetString(PyExc_ValueError,
7514 "field 'func' is required for Call");
7515 return NULL;
7516 }
7517 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7518 if (!p)
7519 return NULL;
7520 p->kind = Call_kind;
7521 p->v.Call.func = func;
7522 p->v.Call.args = args;
7523 p->v.Call.keywords = keywords;
7524 p->lineno = lineno;
7525 p->col_offset = col_offset;
7526 p->end_lineno = end_lineno;
7527 p->end_col_offset = end_col_offset;
7528 return p;
7529 }
7530
7531 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)7532 _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
7533 lineno, int col_offset, int end_lineno, int
7534 end_col_offset, PyArena *arena)
7535 {
7536 expr_ty p;
7537 if (!value) {
7538 PyErr_SetString(PyExc_ValueError,
7539 "field 'value' is required for FormattedValue");
7540 return NULL;
7541 }
7542 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7543 if (!p)
7544 return NULL;
7545 p->kind = FormattedValue_kind;
7546 p->v.FormattedValue.value = value;
7547 p->v.FormattedValue.conversion = conversion;
7548 p->v.FormattedValue.format_spec = format_spec;
7549 p->lineno = lineno;
7550 p->col_offset = col_offset;
7551 p->end_lineno = end_lineno;
7552 p->end_col_offset = end_col_offset;
7553 return p;
7554 }
7555
7556 expr_ty
_PyAST_JoinedStr(asdl_expr_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7557 _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
7558 end_lineno, int end_col_offset, PyArena *arena)
7559 {
7560 expr_ty p;
7561 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7562 if (!p)
7563 return NULL;
7564 p->kind = JoinedStr_kind;
7565 p->v.JoinedStr.values = values;
7566 p->lineno = lineno;
7567 p->col_offset = col_offset;
7568 p->end_lineno = end_lineno;
7569 p->end_col_offset = end_col_offset;
7570 return p;
7571 }
7572
7573 expr_ty
_PyAST_Constant(constant value,string kind,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7574 _PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
7575 end_lineno, int end_col_offset, PyArena *arena)
7576 {
7577 expr_ty p;
7578 if (!value) {
7579 PyErr_SetString(PyExc_ValueError,
7580 "field 'value' is required for Constant");
7581 return NULL;
7582 }
7583 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7584 if (!p)
7585 return NULL;
7586 p->kind = Constant_kind;
7587 p->v.Constant.value = value;
7588 p->v.Constant.kind = kind;
7589 p->lineno = lineno;
7590 p->col_offset = col_offset;
7591 p->end_lineno = end_lineno;
7592 p->end_col_offset = end_col_offset;
7593 return p;
7594 }
7595
7596 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)7597 _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
7598 lineno, int col_offset, int end_lineno, int end_col_offset,
7599 PyArena *arena)
7600 {
7601 expr_ty p;
7602 if (!value) {
7603 PyErr_SetString(PyExc_ValueError,
7604 "field 'value' is required for Attribute");
7605 return NULL;
7606 }
7607 if (!attr) {
7608 PyErr_SetString(PyExc_ValueError,
7609 "field 'attr' is required for Attribute");
7610 return NULL;
7611 }
7612 if (!ctx) {
7613 PyErr_SetString(PyExc_ValueError,
7614 "field 'ctx' is required for Attribute");
7615 return NULL;
7616 }
7617 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7618 if (!p)
7619 return NULL;
7620 p->kind = Attribute_kind;
7621 p->v.Attribute.value = value;
7622 p->v.Attribute.attr = attr;
7623 p->v.Attribute.ctx = ctx;
7624 p->lineno = lineno;
7625 p->col_offset = col_offset;
7626 p->end_lineno = end_lineno;
7627 p->end_col_offset = end_col_offset;
7628 return p;
7629 }
7630
7631 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)7632 _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
7633 int col_offset, int end_lineno, int end_col_offset, PyArena
7634 *arena)
7635 {
7636 expr_ty p;
7637 if (!value) {
7638 PyErr_SetString(PyExc_ValueError,
7639 "field 'value' is required for Subscript");
7640 return NULL;
7641 }
7642 if (!slice) {
7643 PyErr_SetString(PyExc_ValueError,
7644 "field 'slice' is required for Subscript");
7645 return NULL;
7646 }
7647 if (!ctx) {
7648 PyErr_SetString(PyExc_ValueError,
7649 "field 'ctx' is required for Subscript");
7650 return NULL;
7651 }
7652 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7653 if (!p)
7654 return NULL;
7655 p->kind = Subscript_kind;
7656 p->v.Subscript.value = value;
7657 p->v.Subscript.slice = slice;
7658 p->v.Subscript.ctx = ctx;
7659 p->lineno = lineno;
7660 p->col_offset = col_offset;
7661 p->end_lineno = end_lineno;
7662 p->end_col_offset = end_col_offset;
7663 return p;
7664 }
7665
7666 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)7667 _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
7668 int end_lineno, int end_col_offset, PyArena *arena)
7669 {
7670 expr_ty p;
7671 if (!value) {
7672 PyErr_SetString(PyExc_ValueError,
7673 "field 'value' is required for Starred");
7674 return NULL;
7675 }
7676 if (!ctx) {
7677 PyErr_SetString(PyExc_ValueError,
7678 "field 'ctx' is required for Starred");
7679 return NULL;
7680 }
7681 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7682 if (!p)
7683 return NULL;
7684 p->kind = Starred_kind;
7685 p->v.Starred.value = value;
7686 p->v.Starred.ctx = ctx;
7687 p->lineno = lineno;
7688 p->col_offset = col_offset;
7689 p->end_lineno = end_lineno;
7690 p->end_col_offset = end_col_offset;
7691 return p;
7692 }
7693
7694 expr_ty
_PyAST_Name(identifier id,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7695 _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
7696 end_lineno, int end_col_offset, PyArena *arena)
7697 {
7698 expr_ty p;
7699 if (!id) {
7700 PyErr_SetString(PyExc_ValueError,
7701 "field 'id' is required for Name");
7702 return NULL;
7703 }
7704 if (!ctx) {
7705 PyErr_SetString(PyExc_ValueError,
7706 "field 'ctx' is required for Name");
7707 return NULL;
7708 }
7709 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7710 if (!p)
7711 return NULL;
7712 p->kind = Name_kind;
7713 p->v.Name.id = id;
7714 p->v.Name.ctx = ctx;
7715 p->lineno = lineno;
7716 p->col_offset = col_offset;
7717 p->end_lineno = end_lineno;
7718 p->end_col_offset = end_col_offset;
7719 return p;
7720 }
7721
7722 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)7723 _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
7724 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7725 {
7726 expr_ty p;
7727 if (!ctx) {
7728 PyErr_SetString(PyExc_ValueError,
7729 "field 'ctx' is required for List");
7730 return NULL;
7731 }
7732 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7733 if (!p)
7734 return NULL;
7735 p->kind = List_kind;
7736 p->v.List.elts = elts;
7737 p->v.List.ctx = ctx;
7738 p->lineno = lineno;
7739 p->col_offset = col_offset;
7740 p->end_lineno = end_lineno;
7741 p->end_col_offset = end_col_offset;
7742 return p;
7743 }
7744
7745 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)7746 _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
7747 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7748 {
7749 expr_ty p;
7750 if (!ctx) {
7751 PyErr_SetString(PyExc_ValueError,
7752 "field 'ctx' is required for Tuple");
7753 return NULL;
7754 }
7755 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7756 if (!p)
7757 return NULL;
7758 p->kind = Tuple_kind;
7759 p->v.Tuple.elts = elts;
7760 p->v.Tuple.ctx = ctx;
7761 p->lineno = lineno;
7762 p->col_offset = col_offset;
7763 p->end_lineno = end_lineno;
7764 p->end_col_offset = end_col_offset;
7765 return p;
7766 }
7767
7768 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)7769 _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
7770 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7771 {
7772 expr_ty p;
7773 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
7774 if (!p)
7775 return NULL;
7776 p->kind = Slice_kind;
7777 p->v.Slice.lower = lower;
7778 p->v.Slice.upper = upper;
7779 p->v.Slice.step = step;
7780 p->lineno = lineno;
7781 p->col_offset = col_offset;
7782 p->end_lineno = end_lineno;
7783 p->end_col_offset = end_col_offset;
7784 return p;
7785 }
7786
7787 comprehension_ty
_PyAST_comprehension(expr_ty target,expr_ty iter,asdl_expr_seq * ifs,int is_async,PyArena * arena)7788 _PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
7789 is_async, PyArena *arena)
7790 {
7791 comprehension_ty p;
7792 if (!target) {
7793 PyErr_SetString(PyExc_ValueError,
7794 "field 'target' is required for comprehension");
7795 return NULL;
7796 }
7797 if (!iter) {
7798 PyErr_SetString(PyExc_ValueError,
7799 "field 'iter' is required for comprehension");
7800 return NULL;
7801 }
7802 p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
7803 if (!p)
7804 return NULL;
7805 p->target = target;
7806 p->iter = iter;
7807 p->ifs = ifs;
7808 p->is_async = is_async;
7809 return p;
7810 }
7811
7812 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)7813 _PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
7814 lineno, int col_offset, int end_lineno, int
7815 end_col_offset, PyArena *arena)
7816 {
7817 excepthandler_ty p;
7818 p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
7819 if (!p)
7820 return NULL;
7821 p->kind = ExceptHandler_kind;
7822 p->v.ExceptHandler.type = type;
7823 p->v.ExceptHandler.name = name;
7824 p->v.ExceptHandler.body = body;
7825 p->lineno = lineno;
7826 p->col_offset = col_offset;
7827 p->end_lineno = end_lineno;
7828 p->end_col_offset = end_col_offset;
7829 return p;
7830 }
7831
7832 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)7833 _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
7834 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
7835 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
7836 *arena)
7837 {
7838 arguments_ty p;
7839 p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
7840 if (!p)
7841 return NULL;
7842 p->posonlyargs = posonlyargs;
7843 p->args = args;
7844 p->vararg = vararg;
7845 p->kwonlyargs = kwonlyargs;
7846 p->kw_defaults = kw_defaults;
7847 p->kwarg = kwarg;
7848 p->defaults = defaults;
7849 return p;
7850 }
7851
7852 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)7853 _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
7854 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
7855 {
7856 arg_ty p;
7857 if (!arg) {
7858 PyErr_SetString(PyExc_ValueError,
7859 "field 'arg' is required for arg");
7860 return NULL;
7861 }
7862 p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
7863 if (!p)
7864 return NULL;
7865 p->arg = arg;
7866 p->annotation = annotation;
7867 p->type_comment = type_comment;
7868 p->lineno = lineno;
7869 p->col_offset = col_offset;
7870 p->end_lineno = end_lineno;
7871 p->end_col_offset = end_col_offset;
7872 return p;
7873 }
7874
7875 keyword_ty
_PyAST_keyword(identifier arg,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7876 _PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
7877 end_lineno, int end_col_offset, PyArena *arena)
7878 {
7879 keyword_ty p;
7880 if (!value) {
7881 PyErr_SetString(PyExc_ValueError,
7882 "field 'value' is required for keyword");
7883 return NULL;
7884 }
7885 p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
7886 if (!p)
7887 return NULL;
7888 p->arg = arg;
7889 p->value = value;
7890 p->lineno = lineno;
7891 p->col_offset = col_offset;
7892 p->end_lineno = end_lineno;
7893 p->end_col_offset = end_col_offset;
7894 return p;
7895 }
7896
7897 alias_ty
_PyAST_alias(identifier name,identifier asname,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7898 _PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
7899 int end_lineno, int end_col_offset, PyArena *arena)
7900 {
7901 alias_ty p;
7902 if (!name) {
7903 PyErr_SetString(PyExc_ValueError,
7904 "field 'name' is required for alias");
7905 return NULL;
7906 }
7907 p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
7908 if (!p)
7909 return NULL;
7910 p->name = name;
7911 p->asname = asname;
7912 p->lineno = lineno;
7913 p->col_offset = col_offset;
7914 p->end_lineno = end_lineno;
7915 p->end_col_offset = end_col_offset;
7916 return p;
7917 }
7918
7919 withitem_ty
_PyAST_withitem(expr_ty context_expr,expr_ty optional_vars,PyArena * arena)7920 _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
7921 {
7922 withitem_ty p;
7923 if (!context_expr) {
7924 PyErr_SetString(PyExc_ValueError,
7925 "field 'context_expr' is required for withitem");
7926 return NULL;
7927 }
7928 p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
7929 if (!p)
7930 return NULL;
7931 p->context_expr = context_expr;
7932 p->optional_vars = optional_vars;
7933 return p;
7934 }
7935
7936 match_case_ty
_PyAST_match_case(pattern_ty pattern,expr_ty guard,asdl_stmt_seq * body,PyArena * arena)7937 _PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
7938 PyArena *arena)
7939 {
7940 match_case_ty p;
7941 if (!pattern) {
7942 PyErr_SetString(PyExc_ValueError,
7943 "field 'pattern' is required for match_case");
7944 return NULL;
7945 }
7946 p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
7947 if (!p)
7948 return NULL;
7949 p->pattern = pattern;
7950 p->guard = guard;
7951 p->body = body;
7952 return p;
7953 }
7954
7955 pattern_ty
_PyAST_MatchValue(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7956 _PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
7957 int end_col_offset, PyArena *arena)
7958 {
7959 pattern_ty p;
7960 if (!value) {
7961 PyErr_SetString(PyExc_ValueError,
7962 "field 'value' is required for MatchValue");
7963 return NULL;
7964 }
7965 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
7966 if (!p)
7967 return NULL;
7968 p->kind = MatchValue_kind;
7969 p->v.MatchValue.value = value;
7970 p->lineno = lineno;
7971 p->col_offset = col_offset;
7972 p->end_lineno = end_lineno;
7973 p->end_col_offset = end_col_offset;
7974 return p;
7975 }
7976
7977 pattern_ty
_PyAST_MatchSingleton(constant value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)7978 _PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
7979 end_lineno, int end_col_offset, PyArena *arena)
7980 {
7981 pattern_ty p;
7982 if (!value) {
7983 PyErr_SetString(PyExc_ValueError,
7984 "field 'value' is required for MatchSingleton");
7985 return NULL;
7986 }
7987 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
7988 if (!p)
7989 return NULL;
7990 p->kind = MatchSingleton_kind;
7991 p->v.MatchSingleton.value = value;
7992 p->lineno = lineno;
7993 p->col_offset = col_offset;
7994 p->end_lineno = end_lineno;
7995 p->end_col_offset = end_col_offset;
7996 return p;
7997 }
7998
7999 pattern_ty
_PyAST_MatchSequence(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8000 _PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
8001 int end_lineno, int end_col_offset, PyArena *arena)
8002 {
8003 pattern_ty p;
8004 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8005 if (!p)
8006 return NULL;
8007 p->kind = MatchSequence_kind;
8008 p->v.MatchSequence.patterns = patterns;
8009 p->lineno = lineno;
8010 p->col_offset = col_offset;
8011 p->end_lineno = end_lineno;
8012 p->end_col_offset = end_col_offset;
8013 return p;
8014 }
8015
8016 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)8017 _PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
8018 identifier rest, int lineno, int col_offset, int
8019 end_lineno, int end_col_offset, PyArena *arena)
8020 {
8021 pattern_ty p;
8022 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8023 if (!p)
8024 return NULL;
8025 p->kind = MatchMapping_kind;
8026 p->v.MatchMapping.keys = keys;
8027 p->v.MatchMapping.patterns = patterns;
8028 p->v.MatchMapping.rest = rest;
8029 p->lineno = lineno;
8030 p->col_offset = col_offset;
8031 p->end_lineno = end_lineno;
8032 p->end_col_offset = end_col_offset;
8033 return p;
8034 }
8035
8036 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)8037 _PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
8038 * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
8039 col_offset, int end_lineno, int end_col_offset, PyArena
8040 *arena)
8041 {
8042 pattern_ty p;
8043 if (!cls) {
8044 PyErr_SetString(PyExc_ValueError,
8045 "field 'cls' is required for MatchClass");
8046 return NULL;
8047 }
8048 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8049 if (!p)
8050 return NULL;
8051 p->kind = MatchClass_kind;
8052 p->v.MatchClass.cls = cls;
8053 p->v.MatchClass.patterns = patterns;
8054 p->v.MatchClass.kwd_attrs = kwd_attrs;
8055 p->v.MatchClass.kwd_patterns = kwd_patterns;
8056 p->lineno = lineno;
8057 p->col_offset = col_offset;
8058 p->end_lineno = end_lineno;
8059 p->end_col_offset = end_col_offset;
8060 return p;
8061 }
8062
8063 pattern_ty
_PyAST_MatchStar(identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8064 _PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
8065 int end_col_offset, PyArena *arena)
8066 {
8067 pattern_ty p;
8068 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8069 if (!p)
8070 return NULL;
8071 p->kind = MatchStar_kind;
8072 p->v.MatchStar.name = name;
8073 p->lineno = lineno;
8074 p->col_offset = col_offset;
8075 p->end_lineno = end_lineno;
8076 p->end_col_offset = end_col_offset;
8077 return p;
8078 }
8079
8080 pattern_ty
_PyAST_MatchAs(pattern_ty pattern,identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8081 _PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
8082 int end_lineno, int end_col_offset, PyArena *arena)
8083 {
8084 pattern_ty p;
8085 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8086 if (!p)
8087 return NULL;
8088 p->kind = MatchAs_kind;
8089 p->v.MatchAs.pattern = pattern;
8090 p->v.MatchAs.name = name;
8091 p->lineno = lineno;
8092 p->col_offset = col_offset;
8093 p->end_lineno = end_lineno;
8094 p->end_col_offset = end_col_offset;
8095 return p;
8096 }
8097
8098 pattern_ty
_PyAST_MatchOr(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8099 _PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
8100 end_lineno, int end_col_offset, PyArena *arena)
8101 {
8102 pattern_ty p;
8103 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
8104 if (!p)
8105 return NULL;
8106 p->kind = MatchOr_kind;
8107 p->v.MatchOr.patterns = patterns;
8108 p->lineno = lineno;
8109 p->col_offset = col_offset;
8110 p->end_lineno = end_lineno;
8111 p->end_col_offset = end_col_offset;
8112 return p;
8113 }
8114
8115 type_ignore_ty
_PyAST_TypeIgnore(int lineno,string tag,PyArena * arena)8116 _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
8117 {
8118 type_ignore_ty p;
8119 if (!tag) {
8120 PyErr_SetString(PyExc_ValueError,
8121 "field 'tag' is required for TypeIgnore");
8122 return NULL;
8123 }
8124 p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
8125 if (!p)
8126 return NULL;
8127 p->kind = TypeIgnore_kind;
8128 p->v.TypeIgnore.lineno = lineno;
8129 p->v.TypeIgnore.tag = tag;
8130 return p;
8131 }
8132
8133 type_param_ty
_PyAST_TypeVar(identifier name,expr_ty bound,expr_ty default_value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8134 _PyAST_TypeVar(identifier name, expr_ty bound, expr_ty default_value, int
8135 lineno, int col_offset, int end_lineno, int end_col_offset,
8136 PyArena *arena)
8137 {
8138 type_param_ty p;
8139 if (!name) {
8140 PyErr_SetString(PyExc_ValueError,
8141 "field 'name' is required for TypeVar");
8142 return NULL;
8143 }
8144 p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
8145 if (!p)
8146 return NULL;
8147 p->kind = TypeVar_kind;
8148 p->v.TypeVar.name = name;
8149 p->v.TypeVar.bound = bound;
8150 p->v.TypeVar.default_value = default_value;
8151 p->lineno = lineno;
8152 p->col_offset = col_offset;
8153 p->end_lineno = end_lineno;
8154 p->end_col_offset = end_col_offset;
8155 return p;
8156 }
8157
8158 type_param_ty
_PyAST_ParamSpec(identifier name,expr_ty default_value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8159 _PyAST_ParamSpec(identifier name, expr_ty default_value, int lineno, int
8160 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
8161 {
8162 type_param_ty p;
8163 if (!name) {
8164 PyErr_SetString(PyExc_ValueError,
8165 "field 'name' is required for ParamSpec");
8166 return NULL;
8167 }
8168 p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
8169 if (!p)
8170 return NULL;
8171 p->kind = ParamSpec_kind;
8172 p->v.ParamSpec.name = name;
8173 p->v.ParamSpec.default_value = default_value;
8174 p->lineno = lineno;
8175 p->col_offset = col_offset;
8176 p->end_lineno = end_lineno;
8177 p->end_col_offset = end_col_offset;
8178 return p;
8179 }
8180
8181 type_param_ty
_PyAST_TypeVarTuple(identifier name,expr_ty default_value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)8182 _PyAST_TypeVarTuple(identifier name, expr_ty default_value, int lineno, int
8183 col_offset, int end_lineno, int end_col_offset, PyArena
8184 *arena)
8185 {
8186 type_param_ty p;
8187 if (!name) {
8188 PyErr_SetString(PyExc_ValueError,
8189 "field 'name' is required for TypeVarTuple");
8190 return NULL;
8191 }
8192 p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
8193 if (!p)
8194 return NULL;
8195 p->kind = TypeVarTuple_kind;
8196 p->v.TypeVarTuple.name = name;
8197 p->v.TypeVarTuple.default_value = default_value;
8198 p->lineno = lineno;
8199 p->col_offset = col_offset;
8200 p->end_lineno = end_lineno;
8201 p->end_col_offset = end_col_offset;
8202 return p;
8203 }
8204
8205
8206 PyObject*
ast2obj_mod(struct ast_state * state,struct validator * vstate,void * _o)8207 ast2obj_mod(struct ast_state *state, struct validator *vstate, void* _o)
8208 {
8209 mod_ty o = (mod_ty)_o;
8210 PyObject *result = NULL, *value = NULL;
8211 PyTypeObject *tp;
8212 if (!o) {
8213 Py_RETURN_NONE;
8214 }
8215 if (++vstate->recursion_depth > vstate->recursion_limit) {
8216 PyErr_SetString(PyExc_RecursionError,
8217 "maximum recursion depth exceeded during ast construction");
8218 return NULL;
8219 }
8220 switch (o->kind) {
8221 case Module_kind:
8222 tp = (PyTypeObject *)state->Module_type;
8223 result = PyType_GenericNew(tp, NULL, NULL);
8224 if (!result) goto failed;
8225 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Module.body,
8226 ast2obj_stmt);
8227 if (!value) goto failed;
8228 if (PyObject_SetAttr(result, state->body, value) == -1)
8229 goto failed;
8230 Py_DECREF(value);
8231 value = ast2obj_list(state, vstate,
8232 (asdl_seq*)o->v.Module.type_ignores,
8233 ast2obj_type_ignore);
8234 if (!value) goto failed;
8235 if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
8236 goto failed;
8237 Py_DECREF(value);
8238 break;
8239 case Interactive_kind:
8240 tp = (PyTypeObject *)state->Interactive_type;
8241 result = PyType_GenericNew(tp, NULL, NULL);
8242 if (!result) goto failed;
8243 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Interactive.body,
8244 ast2obj_stmt);
8245 if (!value) goto failed;
8246 if (PyObject_SetAttr(result, state->body, value) == -1)
8247 goto failed;
8248 Py_DECREF(value);
8249 break;
8250 case Expression_kind:
8251 tp = (PyTypeObject *)state->Expression_type;
8252 result = PyType_GenericNew(tp, NULL, NULL);
8253 if (!result) goto failed;
8254 value = ast2obj_expr(state, vstate, o->v.Expression.body);
8255 if (!value) goto failed;
8256 if (PyObject_SetAttr(result, state->body, value) == -1)
8257 goto failed;
8258 Py_DECREF(value);
8259 break;
8260 case FunctionType_kind:
8261 tp = (PyTypeObject *)state->FunctionType_type;
8262 result = PyType_GenericNew(tp, NULL, NULL);
8263 if (!result) goto failed;
8264 value = ast2obj_list(state, vstate,
8265 (asdl_seq*)o->v.FunctionType.argtypes,
8266 ast2obj_expr);
8267 if (!value) goto failed;
8268 if (PyObject_SetAttr(result, state->argtypes, value) == -1)
8269 goto failed;
8270 Py_DECREF(value);
8271 value = ast2obj_expr(state, vstate, o->v.FunctionType.returns);
8272 if (!value) goto failed;
8273 if (PyObject_SetAttr(result, state->returns, value) == -1)
8274 goto failed;
8275 Py_DECREF(value);
8276 break;
8277 }
8278 vstate->recursion_depth--;
8279 return result;
8280 failed:
8281 vstate->recursion_depth--;
8282 Py_XDECREF(value);
8283 Py_XDECREF(result);
8284 return NULL;
8285 }
8286
8287 PyObject*
ast2obj_stmt(struct ast_state * state,struct validator * vstate,void * _o)8288 ast2obj_stmt(struct ast_state *state, struct validator *vstate, void* _o)
8289 {
8290 stmt_ty o = (stmt_ty)_o;
8291 PyObject *result = NULL, *value = NULL;
8292 PyTypeObject *tp;
8293 if (!o) {
8294 Py_RETURN_NONE;
8295 }
8296 if (++vstate->recursion_depth > vstate->recursion_limit) {
8297 PyErr_SetString(PyExc_RecursionError,
8298 "maximum recursion depth exceeded during ast construction");
8299 return NULL;
8300 }
8301 switch (o->kind) {
8302 case FunctionDef_kind:
8303 tp = (PyTypeObject *)state->FunctionDef_type;
8304 result = PyType_GenericNew(tp, NULL, NULL);
8305 if (!result) goto failed;
8306 value = ast2obj_identifier(state, vstate, o->v.FunctionDef.name);
8307 if (!value) goto failed;
8308 if (PyObject_SetAttr(result, state->name, value) == -1)
8309 goto failed;
8310 Py_DECREF(value);
8311 value = ast2obj_arguments(state, vstate, o->v.FunctionDef.args);
8312 if (!value) goto failed;
8313 if (PyObject_SetAttr(result, state->args, value) == -1)
8314 goto failed;
8315 Py_DECREF(value);
8316 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.FunctionDef.body,
8317 ast2obj_stmt);
8318 if (!value) goto failed;
8319 if (PyObject_SetAttr(result, state->body, value) == -1)
8320 goto failed;
8321 Py_DECREF(value);
8322 value = ast2obj_list(state, vstate,
8323 (asdl_seq*)o->v.FunctionDef.decorator_list,
8324 ast2obj_expr);
8325 if (!value) goto failed;
8326 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
8327 goto failed;
8328 Py_DECREF(value);
8329 value = ast2obj_expr(state, vstate, o->v.FunctionDef.returns);
8330 if (!value) goto failed;
8331 if (PyObject_SetAttr(result, state->returns, value) == -1)
8332 goto failed;
8333 Py_DECREF(value);
8334 value = ast2obj_string(state, vstate, o->v.FunctionDef.type_comment);
8335 if (!value) goto failed;
8336 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8337 goto failed;
8338 Py_DECREF(value);
8339 value = ast2obj_list(state, vstate,
8340 (asdl_seq*)o->v.FunctionDef.type_params,
8341 ast2obj_type_param);
8342 if (!value) goto failed;
8343 if (PyObject_SetAttr(result, state->type_params, value) == -1)
8344 goto failed;
8345 Py_DECREF(value);
8346 break;
8347 case AsyncFunctionDef_kind:
8348 tp = (PyTypeObject *)state->AsyncFunctionDef_type;
8349 result = PyType_GenericNew(tp, NULL, NULL);
8350 if (!result) goto failed;
8351 value = ast2obj_identifier(state, vstate, o->v.AsyncFunctionDef.name);
8352 if (!value) goto failed;
8353 if (PyObject_SetAttr(result, state->name, value) == -1)
8354 goto failed;
8355 Py_DECREF(value);
8356 value = ast2obj_arguments(state, vstate, o->v.AsyncFunctionDef.args);
8357 if (!value) goto failed;
8358 if (PyObject_SetAttr(result, state->args, value) == -1)
8359 goto failed;
8360 Py_DECREF(value);
8361 value = ast2obj_list(state, vstate,
8362 (asdl_seq*)o->v.AsyncFunctionDef.body,
8363 ast2obj_stmt);
8364 if (!value) goto failed;
8365 if (PyObject_SetAttr(result, state->body, value) == -1)
8366 goto failed;
8367 Py_DECREF(value);
8368 value = ast2obj_list(state, vstate,
8369 (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
8370 ast2obj_expr);
8371 if (!value) goto failed;
8372 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
8373 goto failed;
8374 Py_DECREF(value);
8375 value = ast2obj_expr(state, vstate, o->v.AsyncFunctionDef.returns);
8376 if (!value) goto failed;
8377 if (PyObject_SetAttr(result, state->returns, value) == -1)
8378 goto failed;
8379 Py_DECREF(value);
8380 value = ast2obj_string(state, vstate, o->v.AsyncFunctionDef.type_comment);
8381 if (!value) goto failed;
8382 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8383 goto failed;
8384 Py_DECREF(value);
8385 value = ast2obj_list(state, vstate,
8386 (asdl_seq*)o->v.AsyncFunctionDef.type_params,
8387 ast2obj_type_param);
8388 if (!value) goto failed;
8389 if (PyObject_SetAttr(result, state->type_params, value) == -1)
8390 goto failed;
8391 Py_DECREF(value);
8392 break;
8393 case ClassDef_kind:
8394 tp = (PyTypeObject *)state->ClassDef_type;
8395 result = PyType_GenericNew(tp, NULL, NULL);
8396 if (!result) goto failed;
8397 value = ast2obj_identifier(state, vstate, o->v.ClassDef.name);
8398 if (!value) goto failed;
8399 if (PyObject_SetAttr(result, state->name, value) == -1)
8400 goto failed;
8401 Py_DECREF(value);
8402 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.bases,
8403 ast2obj_expr);
8404 if (!value) goto failed;
8405 if (PyObject_SetAttr(result, state->bases, value) == -1)
8406 goto failed;
8407 Py_DECREF(value);
8408 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.keywords,
8409 ast2obj_keyword);
8410 if (!value) goto failed;
8411 if (PyObject_SetAttr(result, state->keywords, value) == -1)
8412 goto failed;
8413 Py_DECREF(value);
8414 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.body,
8415 ast2obj_stmt);
8416 if (!value) goto failed;
8417 if (PyObject_SetAttr(result, state->body, value) == -1)
8418 goto failed;
8419 Py_DECREF(value);
8420 value = ast2obj_list(state, vstate,
8421 (asdl_seq*)o->v.ClassDef.decorator_list,
8422 ast2obj_expr);
8423 if (!value) goto failed;
8424 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
8425 goto failed;
8426 Py_DECREF(value);
8427 value = ast2obj_list(state, vstate,
8428 (asdl_seq*)o->v.ClassDef.type_params,
8429 ast2obj_type_param);
8430 if (!value) goto failed;
8431 if (PyObject_SetAttr(result, state->type_params, value) == -1)
8432 goto failed;
8433 Py_DECREF(value);
8434 break;
8435 case Return_kind:
8436 tp = (PyTypeObject *)state->Return_type;
8437 result = PyType_GenericNew(tp, NULL, NULL);
8438 if (!result) goto failed;
8439 value = ast2obj_expr(state, vstate, o->v.Return.value);
8440 if (!value) goto failed;
8441 if (PyObject_SetAttr(result, state->value, value) == -1)
8442 goto failed;
8443 Py_DECREF(value);
8444 break;
8445 case Delete_kind:
8446 tp = (PyTypeObject *)state->Delete_type;
8447 result = PyType_GenericNew(tp, NULL, NULL);
8448 if (!result) goto failed;
8449 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Delete.targets,
8450 ast2obj_expr);
8451 if (!value) goto failed;
8452 if (PyObject_SetAttr(result, state->targets, value) == -1)
8453 goto failed;
8454 Py_DECREF(value);
8455 break;
8456 case Assign_kind:
8457 tp = (PyTypeObject *)state->Assign_type;
8458 result = PyType_GenericNew(tp, NULL, NULL);
8459 if (!result) goto failed;
8460 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Assign.targets,
8461 ast2obj_expr);
8462 if (!value) goto failed;
8463 if (PyObject_SetAttr(result, state->targets, value) == -1)
8464 goto failed;
8465 Py_DECREF(value);
8466 value = ast2obj_expr(state, vstate, o->v.Assign.value);
8467 if (!value) goto failed;
8468 if (PyObject_SetAttr(result, state->value, value) == -1)
8469 goto failed;
8470 Py_DECREF(value);
8471 value = ast2obj_string(state, vstate, o->v.Assign.type_comment);
8472 if (!value) goto failed;
8473 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8474 goto failed;
8475 Py_DECREF(value);
8476 break;
8477 case TypeAlias_kind:
8478 tp = (PyTypeObject *)state->TypeAlias_type;
8479 result = PyType_GenericNew(tp, NULL, NULL);
8480 if (!result) goto failed;
8481 value = ast2obj_expr(state, vstate, o->v.TypeAlias.name);
8482 if (!value) goto failed;
8483 if (PyObject_SetAttr(result, state->name, value) == -1)
8484 goto failed;
8485 Py_DECREF(value);
8486 value = ast2obj_list(state, vstate,
8487 (asdl_seq*)o->v.TypeAlias.type_params,
8488 ast2obj_type_param);
8489 if (!value) goto failed;
8490 if (PyObject_SetAttr(result, state->type_params, value) == -1)
8491 goto failed;
8492 Py_DECREF(value);
8493 value = ast2obj_expr(state, vstate, o->v.TypeAlias.value);
8494 if (!value) goto failed;
8495 if (PyObject_SetAttr(result, state->value, value) == -1)
8496 goto failed;
8497 Py_DECREF(value);
8498 break;
8499 case AugAssign_kind:
8500 tp = (PyTypeObject *)state->AugAssign_type;
8501 result = PyType_GenericNew(tp, NULL, NULL);
8502 if (!result) goto failed;
8503 value = ast2obj_expr(state, vstate, o->v.AugAssign.target);
8504 if (!value) goto failed;
8505 if (PyObject_SetAttr(result, state->target, value) == -1)
8506 goto failed;
8507 Py_DECREF(value);
8508 value = ast2obj_operator(state, vstate, o->v.AugAssign.op);
8509 if (!value) goto failed;
8510 if (PyObject_SetAttr(result, state->op, value) == -1)
8511 goto failed;
8512 Py_DECREF(value);
8513 value = ast2obj_expr(state, vstate, o->v.AugAssign.value);
8514 if (!value) goto failed;
8515 if (PyObject_SetAttr(result, state->value, value) == -1)
8516 goto failed;
8517 Py_DECREF(value);
8518 break;
8519 case AnnAssign_kind:
8520 tp = (PyTypeObject *)state->AnnAssign_type;
8521 result = PyType_GenericNew(tp, NULL, NULL);
8522 if (!result) goto failed;
8523 value = ast2obj_expr(state, vstate, o->v.AnnAssign.target);
8524 if (!value) goto failed;
8525 if (PyObject_SetAttr(result, state->target, value) == -1)
8526 goto failed;
8527 Py_DECREF(value);
8528 value = ast2obj_expr(state, vstate, o->v.AnnAssign.annotation);
8529 if (!value) goto failed;
8530 if (PyObject_SetAttr(result, state->annotation, value) == -1)
8531 goto failed;
8532 Py_DECREF(value);
8533 value = ast2obj_expr(state, vstate, o->v.AnnAssign.value);
8534 if (!value) goto failed;
8535 if (PyObject_SetAttr(result, state->value, value) == -1)
8536 goto failed;
8537 Py_DECREF(value);
8538 value = ast2obj_int(state, vstate, o->v.AnnAssign.simple);
8539 if (!value) goto failed;
8540 if (PyObject_SetAttr(result, state->simple, value) == -1)
8541 goto failed;
8542 Py_DECREF(value);
8543 break;
8544 case For_kind:
8545 tp = (PyTypeObject *)state->For_type;
8546 result = PyType_GenericNew(tp, NULL, NULL);
8547 if (!result) goto failed;
8548 value = ast2obj_expr(state, vstate, o->v.For.target);
8549 if (!value) goto failed;
8550 if (PyObject_SetAttr(result, state->target, value) == -1)
8551 goto failed;
8552 Py_DECREF(value);
8553 value = ast2obj_expr(state, vstate, o->v.For.iter);
8554 if (!value) goto failed;
8555 if (PyObject_SetAttr(result, state->iter, value) == -1)
8556 goto failed;
8557 Py_DECREF(value);
8558 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.body,
8559 ast2obj_stmt);
8560 if (!value) goto failed;
8561 if (PyObject_SetAttr(result, state->body, value) == -1)
8562 goto failed;
8563 Py_DECREF(value);
8564 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.orelse,
8565 ast2obj_stmt);
8566 if (!value) goto failed;
8567 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8568 goto failed;
8569 Py_DECREF(value);
8570 value = ast2obj_string(state, vstate, o->v.For.type_comment);
8571 if (!value) goto failed;
8572 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8573 goto failed;
8574 Py_DECREF(value);
8575 break;
8576 case AsyncFor_kind:
8577 tp = (PyTypeObject *)state->AsyncFor_type;
8578 result = PyType_GenericNew(tp, NULL, NULL);
8579 if (!result) goto failed;
8580 value = ast2obj_expr(state, vstate, o->v.AsyncFor.target);
8581 if (!value) goto failed;
8582 if (PyObject_SetAttr(result, state->target, value) == -1)
8583 goto failed;
8584 Py_DECREF(value);
8585 value = ast2obj_expr(state, vstate, o->v.AsyncFor.iter);
8586 if (!value) goto failed;
8587 if (PyObject_SetAttr(result, state->iter, value) == -1)
8588 goto failed;
8589 Py_DECREF(value);
8590 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.body,
8591 ast2obj_stmt);
8592 if (!value) goto failed;
8593 if (PyObject_SetAttr(result, state->body, value) == -1)
8594 goto failed;
8595 Py_DECREF(value);
8596 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.orelse,
8597 ast2obj_stmt);
8598 if (!value) goto failed;
8599 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8600 goto failed;
8601 Py_DECREF(value);
8602 value = ast2obj_string(state, vstate, o->v.AsyncFor.type_comment);
8603 if (!value) goto failed;
8604 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8605 goto failed;
8606 Py_DECREF(value);
8607 break;
8608 case While_kind:
8609 tp = (PyTypeObject *)state->While_type;
8610 result = PyType_GenericNew(tp, NULL, NULL);
8611 if (!result) goto failed;
8612 value = ast2obj_expr(state, vstate, o->v.While.test);
8613 if (!value) goto failed;
8614 if (PyObject_SetAttr(result, state->test, value) == -1)
8615 goto failed;
8616 Py_DECREF(value);
8617 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.body,
8618 ast2obj_stmt);
8619 if (!value) goto failed;
8620 if (PyObject_SetAttr(result, state->body, value) == -1)
8621 goto failed;
8622 Py_DECREF(value);
8623 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.orelse,
8624 ast2obj_stmt);
8625 if (!value) goto failed;
8626 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8627 goto failed;
8628 Py_DECREF(value);
8629 break;
8630 case If_kind:
8631 tp = (PyTypeObject *)state->If_type;
8632 result = PyType_GenericNew(tp, NULL, NULL);
8633 if (!result) goto failed;
8634 value = ast2obj_expr(state, vstate, o->v.If.test);
8635 if (!value) goto failed;
8636 if (PyObject_SetAttr(result, state->test, value) == -1)
8637 goto failed;
8638 Py_DECREF(value);
8639 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.body,
8640 ast2obj_stmt);
8641 if (!value) goto failed;
8642 if (PyObject_SetAttr(result, state->body, value) == -1)
8643 goto failed;
8644 Py_DECREF(value);
8645 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.orelse,
8646 ast2obj_stmt);
8647 if (!value) goto failed;
8648 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8649 goto failed;
8650 Py_DECREF(value);
8651 break;
8652 case With_kind:
8653 tp = (PyTypeObject *)state->With_type;
8654 result = PyType_GenericNew(tp, NULL, NULL);
8655 if (!result) goto failed;
8656 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.items,
8657 ast2obj_withitem);
8658 if (!value) goto failed;
8659 if (PyObject_SetAttr(result, state->items, value) == -1)
8660 goto failed;
8661 Py_DECREF(value);
8662 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.body,
8663 ast2obj_stmt);
8664 if (!value) goto failed;
8665 if (PyObject_SetAttr(result, state->body, value) == -1)
8666 goto failed;
8667 Py_DECREF(value);
8668 value = ast2obj_string(state, vstate, o->v.With.type_comment);
8669 if (!value) goto failed;
8670 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8671 goto failed;
8672 Py_DECREF(value);
8673 break;
8674 case AsyncWith_kind:
8675 tp = (PyTypeObject *)state->AsyncWith_type;
8676 result = PyType_GenericNew(tp, NULL, NULL);
8677 if (!result) goto failed;
8678 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.items,
8679 ast2obj_withitem);
8680 if (!value) goto failed;
8681 if (PyObject_SetAttr(result, state->items, value) == -1)
8682 goto failed;
8683 Py_DECREF(value);
8684 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.body,
8685 ast2obj_stmt);
8686 if (!value) goto failed;
8687 if (PyObject_SetAttr(result, state->body, value) == -1)
8688 goto failed;
8689 Py_DECREF(value);
8690 value = ast2obj_string(state, vstate, o->v.AsyncWith.type_comment);
8691 if (!value) goto failed;
8692 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
8693 goto failed;
8694 Py_DECREF(value);
8695 break;
8696 case Match_kind:
8697 tp = (PyTypeObject *)state->Match_type;
8698 result = PyType_GenericNew(tp, NULL, NULL);
8699 if (!result) goto failed;
8700 value = ast2obj_expr(state, vstate, o->v.Match.subject);
8701 if (!value) goto failed;
8702 if (PyObject_SetAttr(result, state->subject, value) == -1)
8703 goto failed;
8704 Py_DECREF(value);
8705 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Match.cases,
8706 ast2obj_match_case);
8707 if (!value) goto failed;
8708 if (PyObject_SetAttr(result, state->cases, value) == -1)
8709 goto failed;
8710 Py_DECREF(value);
8711 break;
8712 case Raise_kind:
8713 tp = (PyTypeObject *)state->Raise_type;
8714 result = PyType_GenericNew(tp, NULL, NULL);
8715 if (!result) goto failed;
8716 value = ast2obj_expr(state, vstate, o->v.Raise.exc);
8717 if (!value) goto failed;
8718 if (PyObject_SetAttr(result, state->exc, value) == -1)
8719 goto failed;
8720 Py_DECREF(value);
8721 value = ast2obj_expr(state, vstate, o->v.Raise.cause);
8722 if (!value) goto failed;
8723 if (PyObject_SetAttr(result, state->cause, value) == -1)
8724 goto failed;
8725 Py_DECREF(value);
8726 break;
8727 case Try_kind:
8728 tp = (PyTypeObject *)state->Try_type;
8729 result = PyType_GenericNew(tp, NULL, NULL);
8730 if (!result) goto failed;
8731 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.body,
8732 ast2obj_stmt);
8733 if (!value) goto failed;
8734 if (PyObject_SetAttr(result, state->body, value) == -1)
8735 goto failed;
8736 Py_DECREF(value);
8737 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.handlers,
8738 ast2obj_excepthandler);
8739 if (!value) goto failed;
8740 if (PyObject_SetAttr(result, state->handlers, value) == -1)
8741 goto failed;
8742 Py_DECREF(value);
8743 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.orelse,
8744 ast2obj_stmt);
8745 if (!value) goto failed;
8746 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8747 goto failed;
8748 Py_DECREF(value);
8749 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.finalbody,
8750 ast2obj_stmt);
8751 if (!value) goto failed;
8752 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
8753 goto failed;
8754 Py_DECREF(value);
8755 break;
8756 case TryStar_kind:
8757 tp = (PyTypeObject *)state->TryStar_type;
8758 result = PyType_GenericNew(tp, NULL, NULL);
8759 if (!result) goto failed;
8760 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.body,
8761 ast2obj_stmt);
8762 if (!value) goto failed;
8763 if (PyObject_SetAttr(result, state->body, value) == -1)
8764 goto failed;
8765 Py_DECREF(value);
8766 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.handlers,
8767 ast2obj_excepthandler);
8768 if (!value) goto failed;
8769 if (PyObject_SetAttr(result, state->handlers, value) == -1)
8770 goto failed;
8771 Py_DECREF(value);
8772 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.orelse,
8773 ast2obj_stmt);
8774 if (!value) goto failed;
8775 if (PyObject_SetAttr(result, state->orelse, value) == -1)
8776 goto failed;
8777 Py_DECREF(value);
8778 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.finalbody,
8779 ast2obj_stmt);
8780 if (!value) goto failed;
8781 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
8782 goto failed;
8783 Py_DECREF(value);
8784 break;
8785 case Assert_kind:
8786 tp = (PyTypeObject *)state->Assert_type;
8787 result = PyType_GenericNew(tp, NULL, NULL);
8788 if (!result) goto failed;
8789 value = ast2obj_expr(state, vstate, o->v.Assert.test);
8790 if (!value) goto failed;
8791 if (PyObject_SetAttr(result, state->test, value) == -1)
8792 goto failed;
8793 Py_DECREF(value);
8794 value = ast2obj_expr(state, vstate, o->v.Assert.msg);
8795 if (!value) goto failed;
8796 if (PyObject_SetAttr(result, state->msg, value) == -1)
8797 goto failed;
8798 Py_DECREF(value);
8799 break;
8800 case Import_kind:
8801 tp = (PyTypeObject *)state->Import_type;
8802 result = PyType_GenericNew(tp, NULL, NULL);
8803 if (!result) goto failed;
8804 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Import.names,
8805 ast2obj_alias);
8806 if (!value) goto failed;
8807 if (PyObject_SetAttr(result, state->names, value) == -1)
8808 goto failed;
8809 Py_DECREF(value);
8810 break;
8811 case ImportFrom_kind:
8812 tp = (PyTypeObject *)state->ImportFrom_type;
8813 result = PyType_GenericNew(tp, NULL, NULL);
8814 if (!result) goto failed;
8815 value = ast2obj_identifier(state, vstate, o->v.ImportFrom.module);
8816 if (!value) goto failed;
8817 if (PyObject_SetAttr(result, state->module, value) == -1)
8818 goto failed;
8819 Py_DECREF(value);
8820 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ImportFrom.names,
8821 ast2obj_alias);
8822 if (!value) goto failed;
8823 if (PyObject_SetAttr(result, state->names, value) == -1)
8824 goto failed;
8825 Py_DECREF(value);
8826 value = ast2obj_int(state, vstate, o->v.ImportFrom.level);
8827 if (!value) goto failed;
8828 if (PyObject_SetAttr(result, state->level, value) == -1)
8829 goto failed;
8830 Py_DECREF(value);
8831 break;
8832 case Global_kind:
8833 tp = (PyTypeObject *)state->Global_type;
8834 result = PyType_GenericNew(tp, NULL, NULL);
8835 if (!result) goto failed;
8836 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Global.names,
8837 ast2obj_identifier);
8838 if (!value) goto failed;
8839 if (PyObject_SetAttr(result, state->names, value) == -1)
8840 goto failed;
8841 Py_DECREF(value);
8842 break;
8843 case Nonlocal_kind:
8844 tp = (PyTypeObject *)state->Nonlocal_type;
8845 result = PyType_GenericNew(tp, NULL, NULL);
8846 if (!result) goto failed;
8847 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Nonlocal.names,
8848 ast2obj_identifier);
8849 if (!value) goto failed;
8850 if (PyObject_SetAttr(result, state->names, value) == -1)
8851 goto failed;
8852 Py_DECREF(value);
8853 break;
8854 case Expr_kind:
8855 tp = (PyTypeObject *)state->Expr_type;
8856 result = PyType_GenericNew(tp, NULL, NULL);
8857 if (!result) goto failed;
8858 value = ast2obj_expr(state, vstate, o->v.Expr.value);
8859 if (!value) goto failed;
8860 if (PyObject_SetAttr(result, state->value, value) == -1)
8861 goto failed;
8862 Py_DECREF(value);
8863 break;
8864 case Pass_kind:
8865 tp = (PyTypeObject *)state->Pass_type;
8866 result = PyType_GenericNew(tp, NULL, NULL);
8867 if (!result) goto failed;
8868 break;
8869 case Break_kind:
8870 tp = (PyTypeObject *)state->Break_type;
8871 result = PyType_GenericNew(tp, NULL, NULL);
8872 if (!result) goto failed;
8873 break;
8874 case Continue_kind:
8875 tp = (PyTypeObject *)state->Continue_type;
8876 result = PyType_GenericNew(tp, NULL, NULL);
8877 if (!result) goto failed;
8878 break;
8879 }
8880 value = ast2obj_int(state, vstate, o->lineno);
8881 if (!value) goto failed;
8882 if (PyObject_SetAttr(result, state->lineno, value) < 0)
8883 goto failed;
8884 Py_DECREF(value);
8885 value = ast2obj_int(state, vstate, o->col_offset);
8886 if (!value) goto failed;
8887 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
8888 goto failed;
8889 Py_DECREF(value);
8890 value = ast2obj_int(state, vstate, o->end_lineno);
8891 if (!value) goto failed;
8892 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
8893 goto failed;
8894 Py_DECREF(value);
8895 value = ast2obj_int(state, vstate, o->end_col_offset);
8896 if (!value) goto failed;
8897 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
8898 goto failed;
8899 Py_DECREF(value);
8900 vstate->recursion_depth--;
8901 return result;
8902 failed:
8903 vstate->recursion_depth--;
8904 Py_XDECREF(value);
8905 Py_XDECREF(result);
8906 return NULL;
8907 }
8908
8909 PyObject*
ast2obj_expr(struct ast_state * state,struct validator * vstate,void * _o)8910 ast2obj_expr(struct ast_state *state, struct validator *vstate, void* _o)
8911 {
8912 expr_ty o = (expr_ty)_o;
8913 PyObject *result = NULL, *value = NULL;
8914 PyTypeObject *tp;
8915 if (!o) {
8916 Py_RETURN_NONE;
8917 }
8918 if (++vstate->recursion_depth > vstate->recursion_limit) {
8919 PyErr_SetString(PyExc_RecursionError,
8920 "maximum recursion depth exceeded during ast construction");
8921 return NULL;
8922 }
8923 switch (o->kind) {
8924 case BoolOp_kind:
8925 tp = (PyTypeObject *)state->BoolOp_type;
8926 result = PyType_GenericNew(tp, NULL, NULL);
8927 if (!result) goto failed;
8928 value = ast2obj_boolop(state, vstate, o->v.BoolOp.op);
8929 if (!value) goto failed;
8930 if (PyObject_SetAttr(result, state->op, value) == -1)
8931 goto failed;
8932 Py_DECREF(value);
8933 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.BoolOp.values,
8934 ast2obj_expr);
8935 if (!value) goto failed;
8936 if (PyObject_SetAttr(result, state->values, value) == -1)
8937 goto failed;
8938 Py_DECREF(value);
8939 break;
8940 case NamedExpr_kind:
8941 tp = (PyTypeObject *)state->NamedExpr_type;
8942 result = PyType_GenericNew(tp, NULL, NULL);
8943 if (!result) goto failed;
8944 value = ast2obj_expr(state, vstate, o->v.NamedExpr.target);
8945 if (!value) goto failed;
8946 if (PyObject_SetAttr(result, state->target, value) == -1)
8947 goto failed;
8948 Py_DECREF(value);
8949 value = ast2obj_expr(state, vstate, o->v.NamedExpr.value);
8950 if (!value) goto failed;
8951 if (PyObject_SetAttr(result, state->value, value) == -1)
8952 goto failed;
8953 Py_DECREF(value);
8954 break;
8955 case BinOp_kind:
8956 tp = (PyTypeObject *)state->BinOp_type;
8957 result = PyType_GenericNew(tp, NULL, NULL);
8958 if (!result) goto failed;
8959 value = ast2obj_expr(state, vstate, o->v.BinOp.left);
8960 if (!value) goto failed;
8961 if (PyObject_SetAttr(result, state->left, value) == -1)
8962 goto failed;
8963 Py_DECREF(value);
8964 value = ast2obj_operator(state, vstate, o->v.BinOp.op);
8965 if (!value) goto failed;
8966 if (PyObject_SetAttr(result, state->op, value) == -1)
8967 goto failed;
8968 Py_DECREF(value);
8969 value = ast2obj_expr(state, vstate, o->v.BinOp.right);
8970 if (!value) goto failed;
8971 if (PyObject_SetAttr(result, state->right, value) == -1)
8972 goto failed;
8973 Py_DECREF(value);
8974 break;
8975 case UnaryOp_kind:
8976 tp = (PyTypeObject *)state->UnaryOp_type;
8977 result = PyType_GenericNew(tp, NULL, NULL);
8978 if (!result) goto failed;
8979 value = ast2obj_unaryop(state, vstate, o->v.UnaryOp.op);
8980 if (!value) goto failed;
8981 if (PyObject_SetAttr(result, state->op, value) == -1)
8982 goto failed;
8983 Py_DECREF(value);
8984 value = ast2obj_expr(state, vstate, o->v.UnaryOp.operand);
8985 if (!value) goto failed;
8986 if (PyObject_SetAttr(result, state->operand, value) == -1)
8987 goto failed;
8988 Py_DECREF(value);
8989 break;
8990 case Lambda_kind:
8991 tp = (PyTypeObject *)state->Lambda_type;
8992 result = PyType_GenericNew(tp, NULL, NULL);
8993 if (!result) goto failed;
8994 value = ast2obj_arguments(state, vstate, o->v.Lambda.args);
8995 if (!value) goto failed;
8996 if (PyObject_SetAttr(result, state->args, value) == -1)
8997 goto failed;
8998 Py_DECREF(value);
8999 value = ast2obj_expr(state, vstate, o->v.Lambda.body);
9000 if (!value) goto failed;
9001 if (PyObject_SetAttr(result, state->body, value) == -1)
9002 goto failed;
9003 Py_DECREF(value);
9004 break;
9005 case IfExp_kind:
9006 tp = (PyTypeObject *)state->IfExp_type;
9007 result = PyType_GenericNew(tp, NULL, NULL);
9008 if (!result) goto failed;
9009 value = ast2obj_expr(state, vstate, o->v.IfExp.test);
9010 if (!value) goto failed;
9011 if (PyObject_SetAttr(result, state->test, value) == -1)
9012 goto failed;
9013 Py_DECREF(value);
9014 value = ast2obj_expr(state, vstate, o->v.IfExp.body);
9015 if (!value) goto failed;
9016 if (PyObject_SetAttr(result, state->body, value) == -1)
9017 goto failed;
9018 Py_DECREF(value);
9019 value = ast2obj_expr(state, vstate, o->v.IfExp.orelse);
9020 if (!value) goto failed;
9021 if (PyObject_SetAttr(result, state->orelse, value) == -1)
9022 goto failed;
9023 Py_DECREF(value);
9024 break;
9025 case Dict_kind:
9026 tp = (PyTypeObject *)state->Dict_type;
9027 result = PyType_GenericNew(tp, NULL, NULL);
9028 if (!result) goto failed;
9029 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.keys,
9030 ast2obj_expr);
9031 if (!value) goto failed;
9032 if (PyObject_SetAttr(result, state->keys, value) == -1)
9033 goto failed;
9034 Py_DECREF(value);
9035 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.values,
9036 ast2obj_expr);
9037 if (!value) goto failed;
9038 if (PyObject_SetAttr(result, state->values, value) == -1)
9039 goto failed;
9040 Py_DECREF(value);
9041 break;
9042 case Set_kind:
9043 tp = (PyTypeObject *)state->Set_type;
9044 result = PyType_GenericNew(tp, NULL, NULL);
9045 if (!result) goto failed;
9046 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Set.elts,
9047 ast2obj_expr);
9048 if (!value) goto failed;
9049 if (PyObject_SetAttr(result, state->elts, value) == -1)
9050 goto failed;
9051 Py_DECREF(value);
9052 break;
9053 case ListComp_kind:
9054 tp = (PyTypeObject *)state->ListComp_type;
9055 result = PyType_GenericNew(tp, NULL, NULL);
9056 if (!result) goto failed;
9057 value = ast2obj_expr(state, vstate, o->v.ListComp.elt);
9058 if (!value) goto failed;
9059 if (PyObject_SetAttr(result, state->elt, value) == -1)
9060 goto failed;
9061 Py_DECREF(value);
9062 value = ast2obj_list(state, vstate,
9063 (asdl_seq*)o->v.ListComp.generators,
9064 ast2obj_comprehension);
9065 if (!value) goto failed;
9066 if (PyObject_SetAttr(result, state->generators, value) == -1)
9067 goto failed;
9068 Py_DECREF(value);
9069 break;
9070 case SetComp_kind:
9071 tp = (PyTypeObject *)state->SetComp_type;
9072 result = PyType_GenericNew(tp, NULL, NULL);
9073 if (!result) goto failed;
9074 value = ast2obj_expr(state, vstate, o->v.SetComp.elt);
9075 if (!value) goto failed;
9076 if (PyObject_SetAttr(result, state->elt, value) == -1)
9077 goto failed;
9078 Py_DECREF(value);
9079 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.SetComp.generators,
9080 ast2obj_comprehension);
9081 if (!value) goto failed;
9082 if (PyObject_SetAttr(result, state->generators, value) == -1)
9083 goto failed;
9084 Py_DECREF(value);
9085 break;
9086 case DictComp_kind:
9087 tp = (PyTypeObject *)state->DictComp_type;
9088 result = PyType_GenericNew(tp, NULL, NULL);
9089 if (!result) goto failed;
9090 value = ast2obj_expr(state, vstate, o->v.DictComp.key);
9091 if (!value) goto failed;
9092 if (PyObject_SetAttr(result, state->key, value) == -1)
9093 goto failed;
9094 Py_DECREF(value);
9095 value = ast2obj_expr(state, vstate, o->v.DictComp.value);
9096 if (!value) goto failed;
9097 if (PyObject_SetAttr(result, state->value, value) == -1)
9098 goto failed;
9099 Py_DECREF(value);
9100 value = ast2obj_list(state, vstate,
9101 (asdl_seq*)o->v.DictComp.generators,
9102 ast2obj_comprehension);
9103 if (!value) goto failed;
9104 if (PyObject_SetAttr(result, state->generators, value) == -1)
9105 goto failed;
9106 Py_DECREF(value);
9107 break;
9108 case GeneratorExp_kind:
9109 tp = (PyTypeObject *)state->GeneratorExp_type;
9110 result = PyType_GenericNew(tp, NULL, NULL);
9111 if (!result) goto failed;
9112 value = ast2obj_expr(state, vstate, o->v.GeneratorExp.elt);
9113 if (!value) goto failed;
9114 if (PyObject_SetAttr(result, state->elt, value) == -1)
9115 goto failed;
9116 Py_DECREF(value);
9117 value = ast2obj_list(state, vstate,
9118 (asdl_seq*)o->v.GeneratorExp.generators,
9119 ast2obj_comprehension);
9120 if (!value) goto failed;
9121 if (PyObject_SetAttr(result, state->generators, value) == -1)
9122 goto failed;
9123 Py_DECREF(value);
9124 break;
9125 case Await_kind:
9126 tp = (PyTypeObject *)state->Await_type;
9127 result = PyType_GenericNew(tp, NULL, NULL);
9128 if (!result) goto failed;
9129 value = ast2obj_expr(state, vstate, o->v.Await.value);
9130 if (!value) goto failed;
9131 if (PyObject_SetAttr(result, state->value, value) == -1)
9132 goto failed;
9133 Py_DECREF(value);
9134 break;
9135 case Yield_kind:
9136 tp = (PyTypeObject *)state->Yield_type;
9137 result = PyType_GenericNew(tp, NULL, NULL);
9138 if (!result) goto failed;
9139 value = ast2obj_expr(state, vstate, o->v.Yield.value);
9140 if (!value) goto failed;
9141 if (PyObject_SetAttr(result, state->value, value) == -1)
9142 goto failed;
9143 Py_DECREF(value);
9144 break;
9145 case YieldFrom_kind:
9146 tp = (PyTypeObject *)state->YieldFrom_type;
9147 result = PyType_GenericNew(tp, NULL, NULL);
9148 if (!result) goto failed;
9149 value = ast2obj_expr(state, vstate, o->v.YieldFrom.value);
9150 if (!value) goto failed;
9151 if (PyObject_SetAttr(result, state->value, value) == -1)
9152 goto failed;
9153 Py_DECREF(value);
9154 break;
9155 case Compare_kind:
9156 tp = (PyTypeObject *)state->Compare_type;
9157 result = PyType_GenericNew(tp, NULL, NULL);
9158 if (!result) goto failed;
9159 value = ast2obj_expr(state, vstate, o->v.Compare.left);
9160 if (!value) goto failed;
9161 if (PyObject_SetAttr(result, state->left, value) == -1)
9162 goto failed;
9163 Py_DECREF(value);
9164 {
9165 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
9166 value = PyList_New(n);
9167 if (!value) goto failed;
9168 for(i = 0; i < n; i++)
9169 PyList_SET_ITEM(value, i, ast2obj_cmpop(state, vstate, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
9170 }
9171 if (!value) goto failed;
9172 if (PyObject_SetAttr(result, state->ops, value) == -1)
9173 goto failed;
9174 Py_DECREF(value);
9175 value = ast2obj_list(state, vstate,
9176 (asdl_seq*)o->v.Compare.comparators, ast2obj_expr);
9177 if (!value) goto failed;
9178 if (PyObject_SetAttr(result, state->comparators, value) == -1)
9179 goto failed;
9180 Py_DECREF(value);
9181 break;
9182 case Call_kind:
9183 tp = (PyTypeObject *)state->Call_type;
9184 result = PyType_GenericNew(tp, NULL, NULL);
9185 if (!result) goto failed;
9186 value = ast2obj_expr(state, vstate, o->v.Call.func);
9187 if (!value) goto failed;
9188 if (PyObject_SetAttr(result, state->func, value) == -1)
9189 goto failed;
9190 Py_DECREF(value);
9191 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.args,
9192 ast2obj_expr);
9193 if (!value) goto failed;
9194 if (PyObject_SetAttr(result, state->args, value) == -1)
9195 goto failed;
9196 Py_DECREF(value);
9197 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.keywords,
9198 ast2obj_keyword);
9199 if (!value) goto failed;
9200 if (PyObject_SetAttr(result, state->keywords, value) == -1)
9201 goto failed;
9202 Py_DECREF(value);
9203 break;
9204 case FormattedValue_kind:
9205 tp = (PyTypeObject *)state->FormattedValue_type;
9206 result = PyType_GenericNew(tp, NULL, NULL);
9207 if (!result) goto failed;
9208 value = ast2obj_expr(state, vstate, o->v.FormattedValue.value);
9209 if (!value) goto failed;
9210 if (PyObject_SetAttr(result, state->value, value) == -1)
9211 goto failed;
9212 Py_DECREF(value);
9213 value = ast2obj_int(state, vstate, o->v.FormattedValue.conversion);
9214 if (!value) goto failed;
9215 if (PyObject_SetAttr(result, state->conversion, value) == -1)
9216 goto failed;
9217 Py_DECREF(value);
9218 value = ast2obj_expr(state, vstate, o->v.FormattedValue.format_spec);
9219 if (!value) goto failed;
9220 if (PyObject_SetAttr(result, state->format_spec, value) == -1)
9221 goto failed;
9222 Py_DECREF(value);
9223 break;
9224 case JoinedStr_kind:
9225 tp = (PyTypeObject *)state->JoinedStr_type;
9226 result = PyType_GenericNew(tp, NULL, NULL);
9227 if (!result) goto failed;
9228 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.JoinedStr.values,
9229 ast2obj_expr);
9230 if (!value) goto failed;
9231 if (PyObject_SetAttr(result, state->values, value) == -1)
9232 goto failed;
9233 Py_DECREF(value);
9234 break;
9235 case Constant_kind:
9236 tp = (PyTypeObject *)state->Constant_type;
9237 result = PyType_GenericNew(tp, NULL, NULL);
9238 if (!result) goto failed;
9239 value = ast2obj_constant(state, vstate, o->v.Constant.value);
9240 if (!value) goto failed;
9241 if (PyObject_SetAttr(result, state->value, value) == -1)
9242 goto failed;
9243 Py_DECREF(value);
9244 value = ast2obj_string(state, vstate, o->v.Constant.kind);
9245 if (!value) goto failed;
9246 if (PyObject_SetAttr(result, state->kind, value) == -1)
9247 goto failed;
9248 Py_DECREF(value);
9249 break;
9250 case Attribute_kind:
9251 tp = (PyTypeObject *)state->Attribute_type;
9252 result = PyType_GenericNew(tp, NULL, NULL);
9253 if (!result) goto failed;
9254 value = ast2obj_expr(state, vstate, o->v.Attribute.value);
9255 if (!value) goto failed;
9256 if (PyObject_SetAttr(result, state->value, value) == -1)
9257 goto failed;
9258 Py_DECREF(value);
9259 value = ast2obj_identifier(state, vstate, o->v.Attribute.attr);
9260 if (!value) goto failed;
9261 if (PyObject_SetAttr(result, state->attr, value) == -1)
9262 goto failed;
9263 Py_DECREF(value);
9264 value = ast2obj_expr_context(state, vstate, o->v.Attribute.ctx);
9265 if (!value) goto failed;
9266 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9267 goto failed;
9268 Py_DECREF(value);
9269 break;
9270 case Subscript_kind:
9271 tp = (PyTypeObject *)state->Subscript_type;
9272 result = PyType_GenericNew(tp, NULL, NULL);
9273 if (!result) goto failed;
9274 value = ast2obj_expr(state, vstate, o->v.Subscript.value);
9275 if (!value) goto failed;
9276 if (PyObject_SetAttr(result, state->value, value) == -1)
9277 goto failed;
9278 Py_DECREF(value);
9279 value = ast2obj_expr(state, vstate, o->v.Subscript.slice);
9280 if (!value) goto failed;
9281 if (PyObject_SetAttr(result, state->slice, value) == -1)
9282 goto failed;
9283 Py_DECREF(value);
9284 value = ast2obj_expr_context(state, vstate, o->v.Subscript.ctx);
9285 if (!value) goto failed;
9286 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9287 goto failed;
9288 Py_DECREF(value);
9289 break;
9290 case Starred_kind:
9291 tp = (PyTypeObject *)state->Starred_type;
9292 result = PyType_GenericNew(tp, NULL, NULL);
9293 if (!result) goto failed;
9294 value = ast2obj_expr(state, vstate, o->v.Starred.value);
9295 if (!value) goto failed;
9296 if (PyObject_SetAttr(result, state->value, value) == -1)
9297 goto failed;
9298 Py_DECREF(value);
9299 value = ast2obj_expr_context(state, vstate, o->v.Starred.ctx);
9300 if (!value) goto failed;
9301 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9302 goto failed;
9303 Py_DECREF(value);
9304 break;
9305 case Name_kind:
9306 tp = (PyTypeObject *)state->Name_type;
9307 result = PyType_GenericNew(tp, NULL, NULL);
9308 if (!result) goto failed;
9309 value = ast2obj_identifier(state, vstate, o->v.Name.id);
9310 if (!value) goto failed;
9311 if (PyObject_SetAttr(result, state->id, value) == -1)
9312 goto failed;
9313 Py_DECREF(value);
9314 value = ast2obj_expr_context(state, vstate, o->v.Name.ctx);
9315 if (!value) goto failed;
9316 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9317 goto failed;
9318 Py_DECREF(value);
9319 break;
9320 case List_kind:
9321 tp = (PyTypeObject *)state->List_type;
9322 result = PyType_GenericNew(tp, NULL, NULL);
9323 if (!result) goto failed;
9324 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.List.elts,
9325 ast2obj_expr);
9326 if (!value) goto failed;
9327 if (PyObject_SetAttr(result, state->elts, value) == -1)
9328 goto failed;
9329 Py_DECREF(value);
9330 value = ast2obj_expr_context(state, vstate, o->v.List.ctx);
9331 if (!value) goto failed;
9332 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9333 goto failed;
9334 Py_DECREF(value);
9335 break;
9336 case Tuple_kind:
9337 tp = (PyTypeObject *)state->Tuple_type;
9338 result = PyType_GenericNew(tp, NULL, NULL);
9339 if (!result) goto failed;
9340 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Tuple.elts,
9341 ast2obj_expr);
9342 if (!value) goto failed;
9343 if (PyObject_SetAttr(result, state->elts, value) == -1)
9344 goto failed;
9345 Py_DECREF(value);
9346 value = ast2obj_expr_context(state, vstate, o->v.Tuple.ctx);
9347 if (!value) goto failed;
9348 if (PyObject_SetAttr(result, state->ctx, value) == -1)
9349 goto failed;
9350 Py_DECREF(value);
9351 break;
9352 case Slice_kind:
9353 tp = (PyTypeObject *)state->Slice_type;
9354 result = PyType_GenericNew(tp, NULL, NULL);
9355 if (!result) goto failed;
9356 value = ast2obj_expr(state, vstate, o->v.Slice.lower);
9357 if (!value) goto failed;
9358 if (PyObject_SetAttr(result, state->lower, value) == -1)
9359 goto failed;
9360 Py_DECREF(value);
9361 value = ast2obj_expr(state, vstate, o->v.Slice.upper);
9362 if (!value) goto failed;
9363 if (PyObject_SetAttr(result, state->upper, value) == -1)
9364 goto failed;
9365 Py_DECREF(value);
9366 value = ast2obj_expr(state, vstate, o->v.Slice.step);
9367 if (!value) goto failed;
9368 if (PyObject_SetAttr(result, state->step, value) == -1)
9369 goto failed;
9370 Py_DECREF(value);
9371 break;
9372 }
9373 value = ast2obj_int(state, vstate, o->lineno);
9374 if (!value) goto failed;
9375 if (PyObject_SetAttr(result, state->lineno, value) < 0)
9376 goto failed;
9377 Py_DECREF(value);
9378 value = ast2obj_int(state, vstate, o->col_offset);
9379 if (!value) goto failed;
9380 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
9381 goto failed;
9382 Py_DECREF(value);
9383 value = ast2obj_int(state, vstate, o->end_lineno);
9384 if (!value) goto failed;
9385 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
9386 goto failed;
9387 Py_DECREF(value);
9388 value = ast2obj_int(state, vstate, o->end_col_offset);
9389 if (!value) goto failed;
9390 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
9391 goto failed;
9392 Py_DECREF(value);
9393 vstate->recursion_depth--;
9394 return result;
9395 failed:
9396 vstate->recursion_depth--;
9397 Py_XDECREF(value);
9398 Py_XDECREF(result);
9399 return NULL;
9400 }
9401
ast2obj_expr_context(struct ast_state * state,struct validator * vstate,expr_context_ty o)9402 PyObject* ast2obj_expr_context(struct ast_state *state, struct validator
9403 *vstate, expr_context_ty o)
9404 {
9405 switch(o) {
9406 case Load:
9407 return Py_NewRef(state->Load_singleton);
9408 case Store:
9409 return Py_NewRef(state->Store_singleton);
9410 case Del:
9411 return Py_NewRef(state->Del_singleton);
9412 }
9413 Py_UNREACHABLE();
9414 }
ast2obj_boolop(struct ast_state * state,struct validator * vstate,boolop_ty o)9415 PyObject* ast2obj_boolop(struct ast_state *state, struct validator *vstate,
9416 boolop_ty o)
9417 {
9418 switch(o) {
9419 case And:
9420 return Py_NewRef(state->And_singleton);
9421 case Or:
9422 return Py_NewRef(state->Or_singleton);
9423 }
9424 Py_UNREACHABLE();
9425 }
ast2obj_operator(struct ast_state * state,struct validator * vstate,operator_ty o)9426 PyObject* ast2obj_operator(struct ast_state *state, struct validator *vstate,
9427 operator_ty o)
9428 {
9429 switch(o) {
9430 case Add:
9431 return Py_NewRef(state->Add_singleton);
9432 case Sub:
9433 return Py_NewRef(state->Sub_singleton);
9434 case Mult:
9435 return Py_NewRef(state->Mult_singleton);
9436 case MatMult:
9437 return Py_NewRef(state->MatMult_singleton);
9438 case Div:
9439 return Py_NewRef(state->Div_singleton);
9440 case Mod:
9441 return Py_NewRef(state->Mod_singleton);
9442 case Pow:
9443 return Py_NewRef(state->Pow_singleton);
9444 case LShift:
9445 return Py_NewRef(state->LShift_singleton);
9446 case RShift:
9447 return Py_NewRef(state->RShift_singleton);
9448 case BitOr:
9449 return Py_NewRef(state->BitOr_singleton);
9450 case BitXor:
9451 return Py_NewRef(state->BitXor_singleton);
9452 case BitAnd:
9453 return Py_NewRef(state->BitAnd_singleton);
9454 case FloorDiv:
9455 return Py_NewRef(state->FloorDiv_singleton);
9456 }
9457 Py_UNREACHABLE();
9458 }
ast2obj_unaryop(struct ast_state * state,struct validator * vstate,unaryop_ty o)9459 PyObject* ast2obj_unaryop(struct ast_state *state, struct validator *vstate,
9460 unaryop_ty o)
9461 {
9462 switch(o) {
9463 case Invert:
9464 return Py_NewRef(state->Invert_singleton);
9465 case Not:
9466 return Py_NewRef(state->Not_singleton);
9467 case UAdd:
9468 return Py_NewRef(state->UAdd_singleton);
9469 case USub:
9470 return Py_NewRef(state->USub_singleton);
9471 }
9472 Py_UNREACHABLE();
9473 }
ast2obj_cmpop(struct ast_state * state,struct validator * vstate,cmpop_ty o)9474 PyObject* ast2obj_cmpop(struct ast_state *state, struct validator *vstate,
9475 cmpop_ty o)
9476 {
9477 switch(o) {
9478 case Eq:
9479 return Py_NewRef(state->Eq_singleton);
9480 case NotEq:
9481 return Py_NewRef(state->NotEq_singleton);
9482 case Lt:
9483 return Py_NewRef(state->Lt_singleton);
9484 case LtE:
9485 return Py_NewRef(state->LtE_singleton);
9486 case Gt:
9487 return Py_NewRef(state->Gt_singleton);
9488 case GtE:
9489 return Py_NewRef(state->GtE_singleton);
9490 case Is:
9491 return Py_NewRef(state->Is_singleton);
9492 case IsNot:
9493 return Py_NewRef(state->IsNot_singleton);
9494 case In:
9495 return Py_NewRef(state->In_singleton);
9496 case NotIn:
9497 return Py_NewRef(state->NotIn_singleton);
9498 }
9499 Py_UNREACHABLE();
9500 }
9501 PyObject*
ast2obj_comprehension(struct ast_state * state,struct validator * vstate,void * _o)9502 ast2obj_comprehension(struct ast_state *state, struct validator *vstate, void*
9503 _o)
9504 {
9505 comprehension_ty o = (comprehension_ty)_o;
9506 PyObject *result = NULL, *value = NULL;
9507 PyTypeObject *tp;
9508 if (!o) {
9509 Py_RETURN_NONE;
9510 }
9511 if (++vstate->recursion_depth > vstate->recursion_limit) {
9512 PyErr_SetString(PyExc_RecursionError,
9513 "maximum recursion depth exceeded during ast construction");
9514 return NULL;
9515 }
9516 tp = (PyTypeObject *)state->comprehension_type;
9517 result = PyType_GenericNew(tp, NULL, NULL);
9518 if (!result) return NULL;
9519 value = ast2obj_expr(state, vstate, o->target);
9520 if (!value) goto failed;
9521 if (PyObject_SetAttr(result, state->target, value) == -1)
9522 goto failed;
9523 Py_DECREF(value);
9524 value = ast2obj_expr(state, vstate, o->iter);
9525 if (!value) goto failed;
9526 if (PyObject_SetAttr(result, state->iter, value) == -1)
9527 goto failed;
9528 Py_DECREF(value);
9529 value = ast2obj_list(state, vstate, (asdl_seq*)o->ifs, ast2obj_expr);
9530 if (!value) goto failed;
9531 if (PyObject_SetAttr(result, state->ifs, value) == -1)
9532 goto failed;
9533 Py_DECREF(value);
9534 value = ast2obj_int(state, vstate, o->is_async);
9535 if (!value) goto failed;
9536 if (PyObject_SetAttr(result, state->is_async, value) == -1)
9537 goto failed;
9538 Py_DECREF(value);
9539 vstate->recursion_depth--;
9540 return result;
9541 failed:
9542 vstate->recursion_depth--;
9543 Py_XDECREF(value);
9544 Py_XDECREF(result);
9545 return NULL;
9546 }
9547
9548 PyObject*
ast2obj_excepthandler(struct ast_state * state,struct validator * vstate,void * _o)9549 ast2obj_excepthandler(struct ast_state *state, struct validator *vstate, void*
9550 _o)
9551 {
9552 excepthandler_ty o = (excepthandler_ty)_o;
9553 PyObject *result = NULL, *value = NULL;
9554 PyTypeObject *tp;
9555 if (!o) {
9556 Py_RETURN_NONE;
9557 }
9558 if (++vstate->recursion_depth > vstate->recursion_limit) {
9559 PyErr_SetString(PyExc_RecursionError,
9560 "maximum recursion depth exceeded during ast construction");
9561 return NULL;
9562 }
9563 switch (o->kind) {
9564 case ExceptHandler_kind:
9565 tp = (PyTypeObject *)state->ExceptHandler_type;
9566 result = PyType_GenericNew(tp, NULL, NULL);
9567 if (!result) goto failed;
9568 value = ast2obj_expr(state, vstate, o->v.ExceptHandler.type);
9569 if (!value) goto failed;
9570 if (PyObject_SetAttr(result, state->type, value) == -1)
9571 goto failed;
9572 Py_DECREF(value);
9573 value = ast2obj_identifier(state, vstate, o->v.ExceptHandler.name);
9574 if (!value) goto failed;
9575 if (PyObject_SetAttr(result, state->name, value) == -1)
9576 goto failed;
9577 Py_DECREF(value);
9578 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ExceptHandler.body,
9579 ast2obj_stmt);
9580 if (!value) goto failed;
9581 if (PyObject_SetAttr(result, state->body, value) == -1)
9582 goto failed;
9583 Py_DECREF(value);
9584 break;
9585 }
9586 value = ast2obj_int(state, vstate, o->lineno);
9587 if (!value) goto failed;
9588 if (PyObject_SetAttr(result, state->lineno, value) < 0)
9589 goto failed;
9590 Py_DECREF(value);
9591 value = ast2obj_int(state, vstate, o->col_offset);
9592 if (!value) goto failed;
9593 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
9594 goto failed;
9595 Py_DECREF(value);
9596 value = ast2obj_int(state, vstate, o->end_lineno);
9597 if (!value) goto failed;
9598 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
9599 goto failed;
9600 Py_DECREF(value);
9601 value = ast2obj_int(state, vstate, o->end_col_offset);
9602 if (!value) goto failed;
9603 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
9604 goto failed;
9605 Py_DECREF(value);
9606 vstate->recursion_depth--;
9607 return result;
9608 failed:
9609 vstate->recursion_depth--;
9610 Py_XDECREF(value);
9611 Py_XDECREF(result);
9612 return NULL;
9613 }
9614
9615 PyObject*
ast2obj_arguments(struct ast_state * state,struct validator * vstate,void * _o)9616 ast2obj_arguments(struct ast_state *state, struct validator *vstate, void* _o)
9617 {
9618 arguments_ty o = (arguments_ty)_o;
9619 PyObject *result = NULL, *value = NULL;
9620 PyTypeObject *tp;
9621 if (!o) {
9622 Py_RETURN_NONE;
9623 }
9624 if (++vstate->recursion_depth > vstate->recursion_limit) {
9625 PyErr_SetString(PyExc_RecursionError,
9626 "maximum recursion depth exceeded during ast construction");
9627 return NULL;
9628 }
9629 tp = (PyTypeObject *)state->arguments_type;
9630 result = PyType_GenericNew(tp, NULL, NULL);
9631 if (!result) return NULL;
9632 value = ast2obj_list(state, vstate, (asdl_seq*)o->posonlyargs, ast2obj_arg);
9633 if (!value) goto failed;
9634 if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
9635 goto failed;
9636 Py_DECREF(value);
9637 value = ast2obj_list(state, vstate, (asdl_seq*)o->args, ast2obj_arg);
9638 if (!value) goto failed;
9639 if (PyObject_SetAttr(result, state->args, value) == -1)
9640 goto failed;
9641 Py_DECREF(value);
9642 value = ast2obj_arg(state, vstate, o->vararg);
9643 if (!value) goto failed;
9644 if (PyObject_SetAttr(result, state->vararg, value) == -1)
9645 goto failed;
9646 Py_DECREF(value);
9647 value = ast2obj_list(state, vstate, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
9648 if (!value) goto failed;
9649 if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
9650 goto failed;
9651 Py_DECREF(value);
9652 value = ast2obj_list(state, vstate, (asdl_seq*)o->kw_defaults,
9653 ast2obj_expr);
9654 if (!value) goto failed;
9655 if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
9656 goto failed;
9657 Py_DECREF(value);
9658 value = ast2obj_arg(state, vstate, o->kwarg);
9659 if (!value) goto failed;
9660 if (PyObject_SetAttr(result, state->kwarg, value) == -1)
9661 goto failed;
9662 Py_DECREF(value);
9663 value = ast2obj_list(state, vstate, (asdl_seq*)o->defaults, ast2obj_expr);
9664 if (!value) goto failed;
9665 if (PyObject_SetAttr(result, state->defaults, value) == -1)
9666 goto failed;
9667 Py_DECREF(value);
9668 vstate->recursion_depth--;
9669 return result;
9670 failed:
9671 vstate->recursion_depth--;
9672 Py_XDECREF(value);
9673 Py_XDECREF(result);
9674 return NULL;
9675 }
9676
9677 PyObject*
ast2obj_arg(struct ast_state * state,struct validator * vstate,void * _o)9678 ast2obj_arg(struct ast_state *state, struct validator *vstate, void* _o)
9679 {
9680 arg_ty o = (arg_ty)_o;
9681 PyObject *result = NULL, *value = NULL;
9682 PyTypeObject *tp;
9683 if (!o) {
9684 Py_RETURN_NONE;
9685 }
9686 if (++vstate->recursion_depth > vstate->recursion_limit) {
9687 PyErr_SetString(PyExc_RecursionError,
9688 "maximum recursion depth exceeded during ast construction");
9689 return NULL;
9690 }
9691 tp = (PyTypeObject *)state->arg_type;
9692 result = PyType_GenericNew(tp, NULL, NULL);
9693 if (!result) return NULL;
9694 value = ast2obj_identifier(state, vstate, o->arg);
9695 if (!value) goto failed;
9696 if (PyObject_SetAttr(result, state->arg, value) == -1)
9697 goto failed;
9698 Py_DECREF(value);
9699 value = ast2obj_expr(state, vstate, o->annotation);
9700 if (!value) goto failed;
9701 if (PyObject_SetAttr(result, state->annotation, value) == -1)
9702 goto failed;
9703 Py_DECREF(value);
9704 value = ast2obj_string(state, vstate, o->type_comment);
9705 if (!value) goto failed;
9706 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
9707 goto failed;
9708 Py_DECREF(value);
9709 value = ast2obj_int(state, vstate, o->lineno);
9710 if (!value) goto failed;
9711 if (PyObject_SetAttr(result, state->lineno, value) < 0)
9712 goto failed;
9713 Py_DECREF(value);
9714 value = ast2obj_int(state, vstate, o->col_offset);
9715 if (!value) goto failed;
9716 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
9717 goto failed;
9718 Py_DECREF(value);
9719 value = ast2obj_int(state, vstate, o->end_lineno);
9720 if (!value) goto failed;
9721 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
9722 goto failed;
9723 Py_DECREF(value);
9724 value = ast2obj_int(state, vstate, o->end_col_offset);
9725 if (!value) goto failed;
9726 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
9727 goto failed;
9728 Py_DECREF(value);
9729 vstate->recursion_depth--;
9730 return result;
9731 failed:
9732 vstate->recursion_depth--;
9733 Py_XDECREF(value);
9734 Py_XDECREF(result);
9735 return NULL;
9736 }
9737
9738 PyObject*
ast2obj_keyword(struct ast_state * state,struct validator * vstate,void * _o)9739 ast2obj_keyword(struct ast_state *state, struct validator *vstate, void* _o)
9740 {
9741 keyword_ty o = (keyword_ty)_o;
9742 PyObject *result = NULL, *value = NULL;
9743 PyTypeObject *tp;
9744 if (!o) {
9745 Py_RETURN_NONE;
9746 }
9747 if (++vstate->recursion_depth > vstate->recursion_limit) {
9748 PyErr_SetString(PyExc_RecursionError,
9749 "maximum recursion depth exceeded during ast construction");
9750 return NULL;
9751 }
9752 tp = (PyTypeObject *)state->keyword_type;
9753 result = PyType_GenericNew(tp, NULL, NULL);
9754 if (!result) return NULL;
9755 value = ast2obj_identifier(state, vstate, o->arg);
9756 if (!value) goto failed;
9757 if (PyObject_SetAttr(result, state->arg, value) == -1)
9758 goto failed;
9759 Py_DECREF(value);
9760 value = ast2obj_expr(state, vstate, o->value);
9761 if (!value) goto failed;
9762 if (PyObject_SetAttr(result, state->value, value) == -1)
9763 goto failed;
9764 Py_DECREF(value);
9765 value = ast2obj_int(state, vstate, o->lineno);
9766 if (!value) goto failed;
9767 if (PyObject_SetAttr(result, state->lineno, value) < 0)
9768 goto failed;
9769 Py_DECREF(value);
9770 value = ast2obj_int(state, vstate, o->col_offset);
9771 if (!value) goto failed;
9772 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
9773 goto failed;
9774 Py_DECREF(value);
9775 value = ast2obj_int(state, vstate, o->end_lineno);
9776 if (!value) goto failed;
9777 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
9778 goto failed;
9779 Py_DECREF(value);
9780 value = ast2obj_int(state, vstate, o->end_col_offset);
9781 if (!value) goto failed;
9782 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
9783 goto failed;
9784 Py_DECREF(value);
9785 vstate->recursion_depth--;
9786 return result;
9787 failed:
9788 vstate->recursion_depth--;
9789 Py_XDECREF(value);
9790 Py_XDECREF(result);
9791 return NULL;
9792 }
9793
9794 PyObject*
ast2obj_alias(struct ast_state * state,struct validator * vstate,void * _o)9795 ast2obj_alias(struct ast_state *state, struct validator *vstate, void* _o)
9796 {
9797 alias_ty o = (alias_ty)_o;
9798 PyObject *result = NULL, *value = NULL;
9799 PyTypeObject *tp;
9800 if (!o) {
9801 Py_RETURN_NONE;
9802 }
9803 if (++vstate->recursion_depth > vstate->recursion_limit) {
9804 PyErr_SetString(PyExc_RecursionError,
9805 "maximum recursion depth exceeded during ast construction");
9806 return NULL;
9807 }
9808 tp = (PyTypeObject *)state->alias_type;
9809 result = PyType_GenericNew(tp, NULL, NULL);
9810 if (!result) return NULL;
9811 value = ast2obj_identifier(state, vstate, o->name);
9812 if (!value) goto failed;
9813 if (PyObject_SetAttr(result, state->name, value) == -1)
9814 goto failed;
9815 Py_DECREF(value);
9816 value = ast2obj_identifier(state, vstate, o->asname);
9817 if (!value) goto failed;
9818 if (PyObject_SetAttr(result, state->asname, value) == -1)
9819 goto failed;
9820 Py_DECREF(value);
9821 value = ast2obj_int(state, vstate, o->lineno);
9822 if (!value) goto failed;
9823 if (PyObject_SetAttr(result, state->lineno, value) < 0)
9824 goto failed;
9825 Py_DECREF(value);
9826 value = ast2obj_int(state, vstate, o->col_offset);
9827 if (!value) goto failed;
9828 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
9829 goto failed;
9830 Py_DECREF(value);
9831 value = ast2obj_int(state, vstate, o->end_lineno);
9832 if (!value) goto failed;
9833 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
9834 goto failed;
9835 Py_DECREF(value);
9836 value = ast2obj_int(state, vstate, o->end_col_offset);
9837 if (!value) goto failed;
9838 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
9839 goto failed;
9840 Py_DECREF(value);
9841 vstate->recursion_depth--;
9842 return result;
9843 failed:
9844 vstate->recursion_depth--;
9845 Py_XDECREF(value);
9846 Py_XDECREF(result);
9847 return NULL;
9848 }
9849
9850 PyObject*
ast2obj_withitem(struct ast_state * state,struct validator * vstate,void * _o)9851 ast2obj_withitem(struct ast_state *state, struct validator *vstate, void* _o)
9852 {
9853 withitem_ty o = (withitem_ty)_o;
9854 PyObject *result = NULL, *value = NULL;
9855 PyTypeObject *tp;
9856 if (!o) {
9857 Py_RETURN_NONE;
9858 }
9859 if (++vstate->recursion_depth > vstate->recursion_limit) {
9860 PyErr_SetString(PyExc_RecursionError,
9861 "maximum recursion depth exceeded during ast construction");
9862 return NULL;
9863 }
9864 tp = (PyTypeObject *)state->withitem_type;
9865 result = PyType_GenericNew(tp, NULL, NULL);
9866 if (!result) return NULL;
9867 value = ast2obj_expr(state, vstate, o->context_expr);
9868 if (!value) goto failed;
9869 if (PyObject_SetAttr(result, state->context_expr, value) == -1)
9870 goto failed;
9871 Py_DECREF(value);
9872 value = ast2obj_expr(state, vstate, o->optional_vars);
9873 if (!value) goto failed;
9874 if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
9875 goto failed;
9876 Py_DECREF(value);
9877 vstate->recursion_depth--;
9878 return result;
9879 failed:
9880 vstate->recursion_depth--;
9881 Py_XDECREF(value);
9882 Py_XDECREF(result);
9883 return NULL;
9884 }
9885
9886 PyObject*
ast2obj_match_case(struct ast_state * state,struct validator * vstate,void * _o)9887 ast2obj_match_case(struct ast_state *state, struct validator *vstate, void* _o)
9888 {
9889 match_case_ty o = (match_case_ty)_o;
9890 PyObject *result = NULL, *value = NULL;
9891 PyTypeObject *tp;
9892 if (!o) {
9893 Py_RETURN_NONE;
9894 }
9895 if (++vstate->recursion_depth > vstate->recursion_limit) {
9896 PyErr_SetString(PyExc_RecursionError,
9897 "maximum recursion depth exceeded during ast construction");
9898 return NULL;
9899 }
9900 tp = (PyTypeObject *)state->match_case_type;
9901 result = PyType_GenericNew(tp, NULL, NULL);
9902 if (!result) return NULL;
9903 value = ast2obj_pattern(state, vstate, o->pattern);
9904 if (!value) goto failed;
9905 if (PyObject_SetAttr(result, state->pattern, value) == -1)
9906 goto failed;
9907 Py_DECREF(value);
9908 value = ast2obj_expr(state, vstate, o->guard);
9909 if (!value) goto failed;
9910 if (PyObject_SetAttr(result, state->guard, value) == -1)
9911 goto failed;
9912 Py_DECREF(value);
9913 value = ast2obj_list(state, vstate, (asdl_seq*)o->body, ast2obj_stmt);
9914 if (!value) goto failed;
9915 if (PyObject_SetAttr(result, state->body, value) == -1)
9916 goto failed;
9917 Py_DECREF(value);
9918 vstate->recursion_depth--;
9919 return result;
9920 failed:
9921 vstate->recursion_depth--;
9922 Py_XDECREF(value);
9923 Py_XDECREF(result);
9924 return NULL;
9925 }
9926
9927 PyObject*
ast2obj_pattern(struct ast_state * state,struct validator * vstate,void * _o)9928 ast2obj_pattern(struct ast_state *state, struct validator *vstate, void* _o)
9929 {
9930 pattern_ty o = (pattern_ty)_o;
9931 PyObject *result = NULL, *value = NULL;
9932 PyTypeObject *tp;
9933 if (!o) {
9934 Py_RETURN_NONE;
9935 }
9936 if (++vstate->recursion_depth > vstate->recursion_limit) {
9937 PyErr_SetString(PyExc_RecursionError,
9938 "maximum recursion depth exceeded during ast construction");
9939 return NULL;
9940 }
9941 switch (o->kind) {
9942 case MatchValue_kind:
9943 tp = (PyTypeObject *)state->MatchValue_type;
9944 result = PyType_GenericNew(tp, NULL, NULL);
9945 if (!result) goto failed;
9946 value = ast2obj_expr(state, vstate, o->v.MatchValue.value);
9947 if (!value) goto failed;
9948 if (PyObject_SetAttr(result, state->value, value) == -1)
9949 goto failed;
9950 Py_DECREF(value);
9951 break;
9952 case MatchSingleton_kind:
9953 tp = (PyTypeObject *)state->MatchSingleton_type;
9954 result = PyType_GenericNew(tp, NULL, NULL);
9955 if (!result) goto failed;
9956 value = ast2obj_constant(state, vstate, o->v.MatchSingleton.value);
9957 if (!value) goto failed;
9958 if (PyObject_SetAttr(result, state->value, value) == -1)
9959 goto failed;
9960 Py_DECREF(value);
9961 break;
9962 case MatchSequence_kind:
9963 tp = (PyTypeObject *)state->MatchSequence_type;
9964 result = PyType_GenericNew(tp, NULL, NULL);
9965 if (!result) goto failed;
9966 value = ast2obj_list(state, vstate,
9967 (asdl_seq*)o->v.MatchSequence.patterns,
9968 ast2obj_pattern);
9969 if (!value) goto failed;
9970 if (PyObject_SetAttr(result, state->patterns, value) == -1)
9971 goto failed;
9972 Py_DECREF(value);
9973 break;
9974 case MatchMapping_kind:
9975 tp = (PyTypeObject *)state->MatchMapping_type;
9976 result = PyType_GenericNew(tp, NULL, NULL);
9977 if (!result) goto failed;
9978 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchMapping.keys,
9979 ast2obj_expr);
9980 if (!value) goto failed;
9981 if (PyObject_SetAttr(result, state->keys, value) == -1)
9982 goto failed;
9983 Py_DECREF(value);
9984 value = ast2obj_list(state, vstate,
9985 (asdl_seq*)o->v.MatchMapping.patterns,
9986 ast2obj_pattern);
9987 if (!value) goto failed;
9988 if (PyObject_SetAttr(result, state->patterns, value) == -1)
9989 goto failed;
9990 Py_DECREF(value);
9991 value = ast2obj_identifier(state, vstate, o->v.MatchMapping.rest);
9992 if (!value) goto failed;
9993 if (PyObject_SetAttr(result, state->rest, value) == -1)
9994 goto failed;
9995 Py_DECREF(value);
9996 break;
9997 case MatchClass_kind:
9998 tp = (PyTypeObject *)state->MatchClass_type;
9999 result = PyType_GenericNew(tp, NULL, NULL);
10000 if (!result) goto failed;
10001 value = ast2obj_expr(state, vstate, o->v.MatchClass.cls);
10002 if (!value) goto failed;
10003 if (PyObject_SetAttr(result, state->cls, value) == -1)
10004 goto failed;
10005 Py_DECREF(value);
10006 value = ast2obj_list(state, vstate,
10007 (asdl_seq*)o->v.MatchClass.patterns,
10008 ast2obj_pattern);
10009 if (!value) goto failed;
10010 if (PyObject_SetAttr(result, state->patterns, value) == -1)
10011 goto failed;
10012 Py_DECREF(value);
10013 value = ast2obj_list(state, vstate,
10014 (asdl_seq*)o->v.MatchClass.kwd_attrs,
10015 ast2obj_identifier);
10016 if (!value) goto failed;
10017 if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
10018 goto failed;
10019 Py_DECREF(value);
10020 value = ast2obj_list(state, vstate,
10021 (asdl_seq*)o->v.MatchClass.kwd_patterns,
10022 ast2obj_pattern);
10023 if (!value) goto failed;
10024 if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
10025 goto failed;
10026 Py_DECREF(value);
10027 break;
10028 case MatchStar_kind:
10029 tp = (PyTypeObject *)state->MatchStar_type;
10030 result = PyType_GenericNew(tp, NULL, NULL);
10031 if (!result) goto failed;
10032 value = ast2obj_identifier(state, vstate, o->v.MatchStar.name);
10033 if (!value) goto failed;
10034 if (PyObject_SetAttr(result, state->name, value) == -1)
10035 goto failed;
10036 Py_DECREF(value);
10037 break;
10038 case MatchAs_kind:
10039 tp = (PyTypeObject *)state->MatchAs_type;
10040 result = PyType_GenericNew(tp, NULL, NULL);
10041 if (!result) goto failed;
10042 value = ast2obj_pattern(state, vstate, o->v.MatchAs.pattern);
10043 if (!value) goto failed;
10044 if (PyObject_SetAttr(result, state->pattern, value) == -1)
10045 goto failed;
10046 Py_DECREF(value);
10047 value = ast2obj_identifier(state, vstate, o->v.MatchAs.name);
10048 if (!value) goto failed;
10049 if (PyObject_SetAttr(result, state->name, value) == -1)
10050 goto failed;
10051 Py_DECREF(value);
10052 break;
10053 case MatchOr_kind:
10054 tp = (PyTypeObject *)state->MatchOr_type;
10055 result = PyType_GenericNew(tp, NULL, NULL);
10056 if (!result) goto failed;
10057 value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchOr.patterns,
10058 ast2obj_pattern);
10059 if (!value) goto failed;
10060 if (PyObject_SetAttr(result, state->patterns, value) == -1)
10061 goto failed;
10062 Py_DECREF(value);
10063 break;
10064 }
10065 value = ast2obj_int(state, vstate, o->lineno);
10066 if (!value) goto failed;
10067 if (PyObject_SetAttr(result, state->lineno, value) < 0)
10068 goto failed;
10069 Py_DECREF(value);
10070 value = ast2obj_int(state, vstate, o->col_offset);
10071 if (!value) goto failed;
10072 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
10073 goto failed;
10074 Py_DECREF(value);
10075 value = ast2obj_int(state, vstate, o->end_lineno);
10076 if (!value) goto failed;
10077 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
10078 goto failed;
10079 Py_DECREF(value);
10080 value = ast2obj_int(state, vstate, o->end_col_offset);
10081 if (!value) goto failed;
10082 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
10083 goto failed;
10084 Py_DECREF(value);
10085 vstate->recursion_depth--;
10086 return result;
10087 failed:
10088 vstate->recursion_depth--;
10089 Py_XDECREF(value);
10090 Py_XDECREF(result);
10091 return NULL;
10092 }
10093
10094 PyObject*
ast2obj_type_ignore(struct ast_state * state,struct validator * vstate,void * _o)10095 ast2obj_type_ignore(struct ast_state *state, struct validator *vstate, void* _o)
10096 {
10097 type_ignore_ty o = (type_ignore_ty)_o;
10098 PyObject *result = NULL, *value = NULL;
10099 PyTypeObject *tp;
10100 if (!o) {
10101 Py_RETURN_NONE;
10102 }
10103 if (++vstate->recursion_depth > vstate->recursion_limit) {
10104 PyErr_SetString(PyExc_RecursionError,
10105 "maximum recursion depth exceeded during ast construction");
10106 return NULL;
10107 }
10108 switch (o->kind) {
10109 case TypeIgnore_kind:
10110 tp = (PyTypeObject *)state->TypeIgnore_type;
10111 result = PyType_GenericNew(tp, NULL, NULL);
10112 if (!result) goto failed;
10113 value = ast2obj_int(state, vstate, o->v.TypeIgnore.lineno);
10114 if (!value) goto failed;
10115 if (PyObject_SetAttr(result, state->lineno, value) == -1)
10116 goto failed;
10117 Py_DECREF(value);
10118 value = ast2obj_string(state, vstate, o->v.TypeIgnore.tag);
10119 if (!value) goto failed;
10120 if (PyObject_SetAttr(result, state->tag, value) == -1)
10121 goto failed;
10122 Py_DECREF(value);
10123 break;
10124 }
10125 vstate->recursion_depth--;
10126 return result;
10127 failed:
10128 vstate->recursion_depth--;
10129 Py_XDECREF(value);
10130 Py_XDECREF(result);
10131 return NULL;
10132 }
10133
10134 PyObject*
ast2obj_type_param(struct ast_state * state,struct validator * vstate,void * _o)10135 ast2obj_type_param(struct ast_state *state, struct validator *vstate, void* _o)
10136 {
10137 type_param_ty o = (type_param_ty)_o;
10138 PyObject *result = NULL, *value = NULL;
10139 PyTypeObject *tp;
10140 if (!o) {
10141 Py_RETURN_NONE;
10142 }
10143 if (++vstate->recursion_depth > vstate->recursion_limit) {
10144 PyErr_SetString(PyExc_RecursionError,
10145 "maximum recursion depth exceeded during ast construction");
10146 return NULL;
10147 }
10148 switch (o->kind) {
10149 case TypeVar_kind:
10150 tp = (PyTypeObject *)state->TypeVar_type;
10151 result = PyType_GenericNew(tp, NULL, NULL);
10152 if (!result) goto failed;
10153 value = ast2obj_identifier(state, vstate, o->v.TypeVar.name);
10154 if (!value) goto failed;
10155 if (PyObject_SetAttr(result, state->name, value) == -1)
10156 goto failed;
10157 Py_DECREF(value);
10158 value = ast2obj_expr(state, vstate, o->v.TypeVar.bound);
10159 if (!value) goto failed;
10160 if (PyObject_SetAttr(result, state->bound, value) == -1)
10161 goto failed;
10162 Py_DECREF(value);
10163 value = ast2obj_expr(state, vstate, o->v.TypeVar.default_value);
10164 if (!value) goto failed;
10165 if (PyObject_SetAttr(result, state->default_value, value) == -1)
10166 goto failed;
10167 Py_DECREF(value);
10168 break;
10169 case ParamSpec_kind:
10170 tp = (PyTypeObject *)state->ParamSpec_type;
10171 result = PyType_GenericNew(tp, NULL, NULL);
10172 if (!result) goto failed;
10173 value = ast2obj_identifier(state, vstate, o->v.ParamSpec.name);
10174 if (!value) goto failed;
10175 if (PyObject_SetAttr(result, state->name, value) == -1)
10176 goto failed;
10177 Py_DECREF(value);
10178 value = ast2obj_expr(state, vstate, o->v.ParamSpec.default_value);
10179 if (!value) goto failed;
10180 if (PyObject_SetAttr(result, state->default_value, value) == -1)
10181 goto failed;
10182 Py_DECREF(value);
10183 break;
10184 case TypeVarTuple_kind:
10185 tp = (PyTypeObject *)state->TypeVarTuple_type;
10186 result = PyType_GenericNew(tp, NULL, NULL);
10187 if (!result) goto failed;
10188 value = ast2obj_identifier(state, vstate, o->v.TypeVarTuple.name);
10189 if (!value) goto failed;
10190 if (PyObject_SetAttr(result, state->name, value) == -1)
10191 goto failed;
10192 Py_DECREF(value);
10193 value = ast2obj_expr(state, vstate, o->v.TypeVarTuple.default_value);
10194 if (!value) goto failed;
10195 if (PyObject_SetAttr(result, state->default_value, value) == -1)
10196 goto failed;
10197 Py_DECREF(value);
10198 break;
10199 }
10200 value = ast2obj_int(state, vstate, o->lineno);
10201 if (!value) goto failed;
10202 if (PyObject_SetAttr(result, state->lineno, value) < 0)
10203 goto failed;
10204 Py_DECREF(value);
10205 value = ast2obj_int(state, vstate, o->col_offset);
10206 if (!value) goto failed;
10207 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
10208 goto failed;
10209 Py_DECREF(value);
10210 value = ast2obj_int(state, vstate, o->end_lineno);
10211 if (!value) goto failed;
10212 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
10213 goto failed;
10214 Py_DECREF(value);
10215 value = ast2obj_int(state, vstate, o->end_col_offset);
10216 if (!value) goto failed;
10217 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
10218 goto failed;
10219 Py_DECREF(value);
10220 vstate->recursion_depth--;
10221 return result;
10222 failed:
10223 vstate->recursion_depth--;
10224 Py_XDECREF(value);
10225 Py_XDECREF(result);
10226 return NULL;
10227 }
10228
10229
10230 int
obj2ast_mod(struct ast_state * state,PyObject * obj,mod_ty * out,PyArena * arena)10231 obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
10232 {
10233 int isinstance;
10234
10235 PyObject *tmp = NULL;
10236 PyObject *tp;
10237
10238 if (obj == Py_None) {
10239 *out = NULL;
10240 return 0;
10241 }
10242 tp = state->Module_type;
10243 isinstance = PyObject_IsInstance(obj, tp);
10244 if (isinstance == -1) {
10245 return -1;
10246 }
10247 if (isinstance) {
10248 asdl_stmt_seq* body;
10249 asdl_type_ignore_seq* type_ignores;
10250
10251 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10252 return -1;
10253 }
10254 if (tmp == NULL) {
10255 tmp = PyList_New(0);
10256 if (tmp == NULL) {
10257 return -1;
10258 }
10259 }
10260 {
10261 int res;
10262 Py_ssize_t len;
10263 Py_ssize_t i;
10264 if (!PyList_Check(tmp)) {
10265 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10266 goto failed;
10267 }
10268 len = PyList_GET_SIZE(tmp);
10269 body = _Py_asdl_stmt_seq_new(len, arena);
10270 if (body == NULL) goto failed;
10271 for (i = 0; i < len; i++) {
10272 stmt_ty val;
10273 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10274 if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
10275 goto failed;
10276 }
10277 res = obj2ast_stmt(state, tmp2, &val, arena);
10278 _Py_LeaveRecursiveCall();
10279 Py_DECREF(tmp2);
10280 if (res != 0) goto failed;
10281 if (len != PyList_GET_SIZE(tmp)) {
10282 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
10283 goto failed;
10284 }
10285 asdl_seq_SET(body, i, val);
10286 }
10287 Py_CLEAR(tmp);
10288 }
10289 if (PyObject_GetOptionalAttr(obj, state->type_ignores, &tmp) < 0) {
10290 return -1;
10291 }
10292 if (tmp == NULL) {
10293 tmp = PyList_New(0);
10294 if (tmp == NULL) {
10295 return -1;
10296 }
10297 }
10298 {
10299 int res;
10300 Py_ssize_t len;
10301 Py_ssize_t i;
10302 if (!PyList_Check(tmp)) {
10303 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10304 goto failed;
10305 }
10306 len = PyList_GET_SIZE(tmp);
10307 type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
10308 if (type_ignores == NULL) goto failed;
10309 for (i = 0; i < len; i++) {
10310 type_ignore_ty val;
10311 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10312 if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
10313 goto failed;
10314 }
10315 res = obj2ast_type_ignore(state, tmp2, &val, arena);
10316 _Py_LeaveRecursiveCall();
10317 Py_DECREF(tmp2);
10318 if (res != 0) goto failed;
10319 if (len != PyList_GET_SIZE(tmp)) {
10320 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
10321 goto failed;
10322 }
10323 asdl_seq_SET(type_ignores, i, val);
10324 }
10325 Py_CLEAR(tmp);
10326 }
10327 *out = _PyAST_Module(body, type_ignores, arena);
10328 if (*out == NULL) goto failed;
10329 return 0;
10330 }
10331 tp = state->Interactive_type;
10332 isinstance = PyObject_IsInstance(obj, tp);
10333 if (isinstance == -1) {
10334 return -1;
10335 }
10336 if (isinstance) {
10337 asdl_stmt_seq* body;
10338
10339 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10340 return -1;
10341 }
10342 if (tmp == NULL) {
10343 tmp = PyList_New(0);
10344 if (tmp == NULL) {
10345 return -1;
10346 }
10347 }
10348 {
10349 int res;
10350 Py_ssize_t len;
10351 Py_ssize_t i;
10352 if (!PyList_Check(tmp)) {
10353 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10354 goto failed;
10355 }
10356 len = PyList_GET_SIZE(tmp);
10357 body = _Py_asdl_stmt_seq_new(len, arena);
10358 if (body == NULL) goto failed;
10359 for (i = 0; i < len; i++) {
10360 stmt_ty val;
10361 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10362 if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
10363 goto failed;
10364 }
10365 res = obj2ast_stmt(state, tmp2, &val, arena);
10366 _Py_LeaveRecursiveCall();
10367 Py_DECREF(tmp2);
10368 if (res != 0) goto failed;
10369 if (len != PyList_GET_SIZE(tmp)) {
10370 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
10371 goto failed;
10372 }
10373 asdl_seq_SET(body, i, val);
10374 }
10375 Py_CLEAR(tmp);
10376 }
10377 *out = _PyAST_Interactive(body, arena);
10378 if (*out == NULL) goto failed;
10379 return 0;
10380 }
10381 tp = state->Expression_type;
10382 isinstance = PyObject_IsInstance(obj, tp);
10383 if (isinstance == -1) {
10384 return -1;
10385 }
10386 if (isinstance) {
10387 expr_ty body;
10388
10389 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10390 return -1;
10391 }
10392 if (tmp == NULL) {
10393 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
10394 return -1;
10395 }
10396 else {
10397 int res;
10398 if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
10399 goto failed;
10400 }
10401 res = obj2ast_expr(state, tmp, &body, arena);
10402 _Py_LeaveRecursiveCall();
10403 if (res != 0) goto failed;
10404 Py_CLEAR(tmp);
10405 }
10406 *out = _PyAST_Expression(body, arena);
10407 if (*out == NULL) goto failed;
10408 return 0;
10409 }
10410 tp = state->FunctionType_type;
10411 isinstance = PyObject_IsInstance(obj, tp);
10412 if (isinstance == -1) {
10413 return -1;
10414 }
10415 if (isinstance) {
10416 asdl_expr_seq* argtypes;
10417 expr_ty returns;
10418
10419 if (PyObject_GetOptionalAttr(obj, state->argtypes, &tmp) < 0) {
10420 return -1;
10421 }
10422 if (tmp == NULL) {
10423 tmp = PyList_New(0);
10424 if (tmp == NULL) {
10425 return -1;
10426 }
10427 }
10428 {
10429 int res;
10430 Py_ssize_t len;
10431 Py_ssize_t i;
10432 if (!PyList_Check(tmp)) {
10433 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10434 goto failed;
10435 }
10436 len = PyList_GET_SIZE(tmp);
10437 argtypes = _Py_asdl_expr_seq_new(len, arena);
10438 if (argtypes == NULL) goto failed;
10439 for (i = 0; i < len; i++) {
10440 expr_ty val;
10441 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10442 if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
10443 goto failed;
10444 }
10445 res = obj2ast_expr(state, tmp2, &val, arena);
10446 _Py_LeaveRecursiveCall();
10447 Py_DECREF(tmp2);
10448 if (res != 0) goto failed;
10449 if (len != PyList_GET_SIZE(tmp)) {
10450 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
10451 goto failed;
10452 }
10453 asdl_seq_SET(argtypes, i, val);
10454 }
10455 Py_CLEAR(tmp);
10456 }
10457 if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
10458 return -1;
10459 }
10460 if (tmp == NULL) {
10461 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
10462 return -1;
10463 }
10464 else {
10465 int res;
10466 if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
10467 goto failed;
10468 }
10469 res = obj2ast_expr(state, tmp, &returns, arena);
10470 _Py_LeaveRecursiveCall();
10471 if (res != 0) goto failed;
10472 Py_CLEAR(tmp);
10473 }
10474 *out = _PyAST_FunctionType(argtypes, returns, arena);
10475 if (*out == NULL) goto failed;
10476 return 0;
10477 }
10478
10479 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
10480 failed:
10481 Py_XDECREF(tmp);
10482 return -1;
10483 }
10484
10485 int
obj2ast_stmt(struct ast_state * state,PyObject * obj,stmt_ty * out,PyArena * arena)10486 obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
10487 arena)
10488 {
10489 int isinstance;
10490
10491 PyObject *tmp = NULL;
10492 PyObject *tp;
10493 int lineno;
10494 int col_offset;
10495 int end_lineno;
10496 int end_col_offset;
10497
10498 if (obj == Py_None) {
10499 *out = NULL;
10500 return 0;
10501 }
10502 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
10503 return -1;
10504 }
10505 if (tmp == NULL) {
10506 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
10507 return -1;
10508 }
10509 else {
10510 int res;
10511 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
10512 goto failed;
10513 }
10514 res = obj2ast_int(state, tmp, &lineno, arena);
10515 _Py_LeaveRecursiveCall();
10516 if (res != 0) goto failed;
10517 Py_CLEAR(tmp);
10518 }
10519 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
10520 return -1;
10521 }
10522 if (tmp == NULL) {
10523 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
10524 return -1;
10525 }
10526 else {
10527 int res;
10528 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
10529 goto failed;
10530 }
10531 res = obj2ast_int(state, tmp, &col_offset, arena);
10532 _Py_LeaveRecursiveCall();
10533 if (res != 0) goto failed;
10534 Py_CLEAR(tmp);
10535 }
10536 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
10537 return -1;
10538 }
10539 if (tmp == NULL || tmp == Py_None) {
10540 Py_CLEAR(tmp);
10541 end_lineno = lineno;
10542 }
10543 else {
10544 int res;
10545 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
10546 goto failed;
10547 }
10548 res = obj2ast_int(state, tmp, &end_lineno, arena);
10549 _Py_LeaveRecursiveCall();
10550 if (res != 0) goto failed;
10551 Py_CLEAR(tmp);
10552 }
10553 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
10554 return -1;
10555 }
10556 if (tmp == NULL || tmp == Py_None) {
10557 Py_CLEAR(tmp);
10558 end_col_offset = col_offset;
10559 }
10560 else {
10561 int res;
10562 if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
10563 goto failed;
10564 }
10565 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10566 _Py_LeaveRecursiveCall();
10567 if (res != 0) goto failed;
10568 Py_CLEAR(tmp);
10569 }
10570 tp = state->FunctionDef_type;
10571 isinstance = PyObject_IsInstance(obj, tp);
10572 if (isinstance == -1) {
10573 return -1;
10574 }
10575 if (isinstance) {
10576 identifier name;
10577 arguments_ty args;
10578 asdl_stmt_seq* body;
10579 asdl_expr_seq* decorator_list;
10580 expr_ty returns;
10581 string type_comment;
10582 asdl_type_param_seq* type_params;
10583
10584 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
10585 return -1;
10586 }
10587 if (tmp == NULL) {
10588 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
10589 return -1;
10590 }
10591 else {
10592 int res;
10593 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10594 goto failed;
10595 }
10596 res = obj2ast_identifier(state, tmp, &name, arena);
10597 _Py_LeaveRecursiveCall();
10598 if (res != 0) goto failed;
10599 Py_CLEAR(tmp);
10600 }
10601 if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
10602 return -1;
10603 }
10604 if (tmp == NULL) {
10605 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
10606 return -1;
10607 }
10608 else {
10609 int res;
10610 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10611 goto failed;
10612 }
10613 res = obj2ast_arguments(state, tmp, &args, arena);
10614 _Py_LeaveRecursiveCall();
10615 if (res != 0) goto failed;
10616 Py_CLEAR(tmp);
10617 }
10618 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10619 return -1;
10620 }
10621 if (tmp == NULL) {
10622 tmp = PyList_New(0);
10623 if (tmp == NULL) {
10624 return -1;
10625 }
10626 }
10627 {
10628 int res;
10629 Py_ssize_t len;
10630 Py_ssize_t i;
10631 if (!PyList_Check(tmp)) {
10632 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10633 goto failed;
10634 }
10635 len = PyList_GET_SIZE(tmp);
10636 body = _Py_asdl_stmt_seq_new(len, arena);
10637 if (body == NULL) goto failed;
10638 for (i = 0; i < len; i++) {
10639 stmt_ty val;
10640 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10641 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10642 goto failed;
10643 }
10644 res = obj2ast_stmt(state, tmp2, &val, arena);
10645 _Py_LeaveRecursiveCall();
10646 Py_DECREF(tmp2);
10647 if (res != 0) goto failed;
10648 if (len != PyList_GET_SIZE(tmp)) {
10649 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
10650 goto failed;
10651 }
10652 asdl_seq_SET(body, i, val);
10653 }
10654 Py_CLEAR(tmp);
10655 }
10656 if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
10657 return -1;
10658 }
10659 if (tmp == NULL) {
10660 tmp = PyList_New(0);
10661 if (tmp == NULL) {
10662 return -1;
10663 }
10664 }
10665 {
10666 int res;
10667 Py_ssize_t len;
10668 Py_ssize_t i;
10669 if (!PyList_Check(tmp)) {
10670 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10671 goto failed;
10672 }
10673 len = PyList_GET_SIZE(tmp);
10674 decorator_list = _Py_asdl_expr_seq_new(len, arena);
10675 if (decorator_list == NULL) goto failed;
10676 for (i = 0; i < len; i++) {
10677 expr_ty val;
10678 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10679 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10680 goto failed;
10681 }
10682 res = obj2ast_expr(state, tmp2, &val, arena);
10683 _Py_LeaveRecursiveCall();
10684 Py_DECREF(tmp2);
10685 if (res != 0) goto failed;
10686 if (len != PyList_GET_SIZE(tmp)) {
10687 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
10688 goto failed;
10689 }
10690 asdl_seq_SET(decorator_list, i, val);
10691 }
10692 Py_CLEAR(tmp);
10693 }
10694 if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
10695 return -1;
10696 }
10697 if (tmp == NULL || tmp == Py_None) {
10698 Py_CLEAR(tmp);
10699 returns = NULL;
10700 }
10701 else {
10702 int res;
10703 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10704 goto failed;
10705 }
10706 res = obj2ast_expr(state, tmp, &returns, arena);
10707 _Py_LeaveRecursiveCall();
10708 if (res != 0) goto failed;
10709 Py_CLEAR(tmp);
10710 }
10711 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
10712 return -1;
10713 }
10714 if (tmp == NULL || tmp == Py_None) {
10715 Py_CLEAR(tmp);
10716 type_comment = NULL;
10717 }
10718 else {
10719 int res;
10720 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10721 goto failed;
10722 }
10723 res = obj2ast_string(state, tmp, &type_comment, arena);
10724 _Py_LeaveRecursiveCall();
10725 if (res != 0) goto failed;
10726 Py_CLEAR(tmp);
10727 }
10728 if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
10729 return -1;
10730 }
10731 if (tmp == NULL) {
10732 tmp = PyList_New(0);
10733 if (tmp == NULL) {
10734 return -1;
10735 }
10736 }
10737 {
10738 int res;
10739 Py_ssize_t len;
10740 Py_ssize_t i;
10741 if (!PyList_Check(tmp)) {
10742 PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10743 goto failed;
10744 }
10745 len = PyList_GET_SIZE(tmp);
10746 type_params = _Py_asdl_type_param_seq_new(len, arena);
10747 if (type_params == NULL) goto failed;
10748 for (i = 0; i < len; i++) {
10749 type_param_ty val;
10750 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10751 if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
10752 goto failed;
10753 }
10754 res = obj2ast_type_param(state, tmp2, &val, arena);
10755 _Py_LeaveRecursiveCall();
10756 Py_DECREF(tmp2);
10757 if (res != 0) goto failed;
10758 if (len != PyList_GET_SIZE(tmp)) {
10759 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
10760 goto failed;
10761 }
10762 asdl_seq_SET(type_params, i, val);
10763 }
10764 Py_CLEAR(tmp);
10765 }
10766 *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
10767 type_comment, type_params, lineno,
10768 col_offset, end_lineno, end_col_offset,
10769 arena);
10770 if (*out == NULL) goto failed;
10771 return 0;
10772 }
10773 tp = state->AsyncFunctionDef_type;
10774 isinstance = PyObject_IsInstance(obj, tp);
10775 if (isinstance == -1) {
10776 return -1;
10777 }
10778 if (isinstance) {
10779 identifier name;
10780 arguments_ty args;
10781 asdl_stmt_seq* body;
10782 asdl_expr_seq* decorator_list;
10783 expr_ty returns;
10784 string type_comment;
10785 asdl_type_param_seq* type_params;
10786
10787 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
10788 return -1;
10789 }
10790 if (tmp == NULL) {
10791 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
10792 return -1;
10793 }
10794 else {
10795 int res;
10796 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10797 goto failed;
10798 }
10799 res = obj2ast_identifier(state, tmp, &name, arena);
10800 _Py_LeaveRecursiveCall();
10801 if (res != 0) goto failed;
10802 Py_CLEAR(tmp);
10803 }
10804 if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
10805 return -1;
10806 }
10807 if (tmp == NULL) {
10808 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
10809 return -1;
10810 }
10811 else {
10812 int res;
10813 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10814 goto failed;
10815 }
10816 res = obj2ast_arguments(state, tmp, &args, arena);
10817 _Py_LeaveRecursiveCall();
10818 if (res != 0) goto failed;
10819 Py_CLEAR(tmp);
10820 }
10821 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
10822 return -1;
10823 }
10824 if (tmp == NULL) {
10825 tmp = PyList_New(0);
10826 if (tmp == NULL) {
10827 return -1;
10828 }
10829 }
10830 {
10831 int res;
10832 Py_ssize_t len;
10833 Py_ssize_t i;
10834 if (!PyList_Check(tmp)) {
10835 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10836 goto failed;
10837 }
10838 len = PyList_GET_SIZE(tmp);
10839 body = _Py_asdl_stmt_seq_new(len, arena);
10840 if (body == NULL) goto failed;
10841 for (i = 0; i < len; i++) {
10842 stmt_ty val;
10843 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10844 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10845 goto failed;
10846 }
10847 res = obj2ast_stmt(state, tmp2, &val, arena);
10848 _Py_LeaveRecursiveCall();
10849 Py_DECREF(tmp2);
10850 if (res != 0) goto failed;
10851 if (len != PyList_GET_SIZE(tmp)) {
10852 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
10853 goto failed;
10854 }
10855 asdl_seq_SET(body, i, val);
10856 }
10857 Py_CLEAR(tmp);
10858 }
10859 if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
10860 return -1;
10861 }
10862 if (tmp == NULL) {
10863 tmp = PyList_New(0);
10864 if (tmp == NULL) {
10865 return -1;
10866 }
10867 }
10868 {
10869 int res;
10870 Py_ssize_t len;
10871 Py_ssize_t i;
10872 if (!PyList_Check(tmp)) {
10873 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10874 goto failed;
10875 }
10876 len = PyList_GET_SIZE(tmp);
10877 decorator_list = _Py_asdl_expr_seq_new(len, arena);
10878 if (decorator_list == NULL) goto failed;
10879 for (i = 0; i < len; i++) {
10880 expr_ty val;
10881 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10882 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10883 goto failed;
10884 }
10885 res = obj2ast_expr(state, tmp2, &val, arena);
10886 _Py_LeaveRecursiveCall();
10887 Py_DECREF(tmp2);
10888 if (res != 0) goto failed;
10889 if (len != PyList_GET_SIZE(tmp)) {
10890 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
10891 goto failed;
10892 }
10893 asdl_seq_SET(decorator_list, i, val);
10894 }
10895 Py_CLEAR(tmp);
10896 }
10897 if (PyObject_GetOptionalAttr(obj, state->returns, &tmp) < 0) {
10898 return -1;
10899 }
10900 if (tmp == NULL || tmp == Py_None) {
10901 Py_CLEAR(tmp);
10902 returns = NULL;
10903 }
10904 else {
10905 int res;
10906 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10907 goto failed;
10908 }
10909 res = obj2ast_expr(state, tmp, &returns, arena);
10910 _Py_LeaveRecursiveCall();
10911 if (res != 0) goto failed;
10912 Py_CLEAR(tmp);
10913 }
10914 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
10915 return -1;
10916 }
10917 if (tmp == NULL || tmp == Py_None) {
10918 Py_CLEAR(tmp);
10919 type_comment = NULL;
10920 }
10921 else {
10922 int res;
10923 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10924 goto failed;
10925 }
10926 res = obj2ast_string(state, tmp, &type_comment, arena);
10927 _Py_LeaveRecursiveCall();
10928 if (res != 0) goto failed;
10929 Py_CLEAR(tmp);
10930 }
10931 if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
10932 return -1;
10933 }
10934 if (tmp == NULL) {
10935 tmp = PyList_New(0);
10936 if (tmp == NULL) {
10937 return -1;
10938 }
10939 }
10940 {
10941 int res;
10942 Py_ssize_t len;
10943 Py_ssize_t i;
10944 if (!PyList_Check(tmp)) {
10945 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10946 goto failed;
10947 }
10948 len = PyList_GET_SIZE(tmp);
10949 type_params = _Py_asdl_type_param_seq_new(len, arena);
10950 if (type_params == NULL) goto failed;
10951 for (i = 0; i < len; i++) {
10952 type_param_ty val;
10953 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
10954 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
10955 goto failed;
10956 }
10957 res = obj2ast_type_param(state, tmp2, &val, arena);
10958 _Py_LeaveRecursiveCall();
10959 Py_DECREF(tmp2);
10960 if (res != 0) goto failed;
10961 if (len != PyList_GET_SIZE(tmp)) {
10962 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
10963 goto failed;
10964 }
10965 asdl_seq_SET(type_params, i, val);
10966 }
10967 Py_CLEAR(tmp);
10968 }
10969 *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
10970 returns, type_comment, type_params,
10971 lineno, col_offset, end_lineno,
10972 end_col_offset, arena);
10973 if (*out == NULL) goto failed;
10974 return 0;
10975 }
10976 tp = state->ClassDef_type;
10977 isinstance = PyObject_IsInstance(obj, tp);
10978 if (isinstance == -1) {
10979 return -1;
10980 }
10981 if (isinstance) {
10982 identifier name;
10983 asdl_expr_seq* bases;
10984 asdl_keyword_seq* keywords;
10985 asdl_stmt_seq* body;
10986 asdl_expr_seq* decorator_list;
10987 asdl_type_param_seq* type_params;
10988
10989 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
10990 return -1;
10991 }
10992 if (tmp == NULL) {
10993 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
10994 return -1;
10995 }
10996 else {
10997 int res;
10998 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
10999 goto failed;
11000 }
11001 res = obj2ast_identifier(state, tmp, &name, arena);
11002 _Py_LeaveRecursiveCall();
11003 if (res != 0) goto failed;
11004 Py_CLEAR(tmp);
11005 }
11006 if (PyObject_GetOptionalAttr(obj, state->bases, &tmp) < 0) {
11007 return -1;
11008 }
11009 if (tmp == NULL) {
11010 tmp = PyList_New(0);
11011 if (tmp == NULL) {
11012 return -1;
11013 }
11014 }
11015 {
11016 int res;
11017 Py_ssize_t len;
11018 Py_ssize_t i;
11019 if (!PyList_Check(tmp)) {
11020 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11021 goto failed;
11022 }
11023 len = PyList_GET_SIZE(tmp);
11024 bases = _Py_asdl_expr_seq_new(len, arena);
11025 if (bases == NULL) goto failed;
11026 for (i = 0; i < len; i++) {
11027 expr_ty val;
11028 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11029 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
11030 goto failed;
11031 }
11032 res = obj2ast_expr(state, tmp2, &val, arena);
11033 _Py_LeaveRecursiveCall();
11034 Py_DECREF(tmp2);
11035 if (res != 0) goto failed;
11036 if (len != PyList_GET_SIZE(tmp)) {
11037 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
11038 goto failed;
11039 }
11040 asdl_seq_SET(bases, i, val);
11041 }
11042 Py_CLEAR(tmp);
11043 }
11044 if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
11045 return -1;
11046 }
11047 if (tmp == NULL) {
11048 tmp = PyList_New(0);
11049 if (tmp == NULL) {
11050 return -1;
11051 }
11052 }
11053 {
11054 int res;
11055 Py_ssize_t len;
11056 Py_ssize_t i;
11057 if (!PyList_Check(tmp)) {
11058 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11059 goto failed;
11060 }
11061 len = PyList_GET_SIZE(tmp);
11062 keywords = _Py_asdl_keyword_seq_new(len, arena);
11063 if (keywords == NULL) goto failed;
11064 for (i = 0; i < len; i++) {
11065 keyword_ty val;
11066 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11067 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
11068 goto failed;
11069 }
11070 res = obj2ast_keyword(state, tmp2, &val, arena);
11071 _Py_LeaveRecursiveCall();
11072 Py_DECREF(tmp2);
11073 if (res != 0) goto failed;
11074 if (len != PyList_GET_SIZE(tmp)) {
11075 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
11076 goto failed;
11077 }
11078 asdl_seq_SET(keywords, i, val);
11079 }
11080 Py_CLEAR(tmp);
11081 }
11082 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
11083 return -1;
11084 }
11085 if (tmp == NULL) {
11086 tmp = PyList_New(0);
11087 if (tmp == NULL) {
11088 return -1;
11089 }
11090 }
11091 {
11092 int res;
11093 Py_ssize_t len;
11094 Py_ssize_t i;
11095 if (!PyList_Check(tmp)) {
11096 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11097 goto failed;
11098 }
11099 len = PyList_GET_SIZE(tmp);
11100 body = _Py_asdl_stmt_seq_new(len, arena);
11101 if (body == NULL) goto failed;
11102 for (i = 0; i < len; i++) {
11103 stmt_ty val;
11104 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11105 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
11106 goto failed;
11107 }
11108 res = obj2ast_stmt(state, tmp2, &val, arena);
11109 _Py_LeaveRecursiveCall();
11110 Py_DECREF(tmp2);
11111 if (res != 0) goto failed;
11112 if (len != PyList_GET_SIZE(tmp)) {
11113 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
11114 goto failed;
11115 }
11116 asdl_seq_SET(body, i, val);
11117 }
11118 Py_CLEAR(tmp);
11119 }
11120 if (PyObject_GetOptionalAttr(obj, state->decorator_list, &tmp) < 0) {
11121 return -1;
11122 }
11123 if (tmp == NULL) {
11124 tmp = PyList_New(0);
11125 if (tmp == NULL) {
11126 return -1;
11127 }
11128 }
11129 {
11130 int res;
11131 Py_ssize_t len;
11132 Py_ssize_t i;
11133 if (!PyList_Check(tmp)) {
11134 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11135 goto failed;
11136 }
11137 len = PyList_GET_SIZE(tmp);
11138 decorator_list = _Py_asdl_expr_seq_new(len, arena);
11139 if (decorator_list == NULL) goto failed;
11140 for (i = 0; i < len; i++) {
11141 expr_ty val;
11142 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11143 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
11144 goto failed;
11145 }
11146 res = obj2ast_expr(state, tmp2, &val, arena);
11147 _Py_LeaveRecursiveCall();
11148 Py_DECREF(tmp2);
11149 if (res != 0) goto failed;
11150 if (len != PyList_GET_SIZE(tmp)) {
11151 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
11152 goto failed;
11153 }
11154 asdl_seq_SET(decorator_list, i, val);
11155 }
11156 Py_CLEAR(tmp);
11157 }
11158 if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
11159 return -1;
11160 }
11161 if (tmp == NULL) {
11162 tmp = PyList_New(0);
11163 if (tmp == NULL) {
11164 return -1;
11165 }
11166 }
11167 {
11168 int res;
11169 Py_ssize_t len;
11170 Py_ssize_t i;
11171 if (!PyList_Check(tmp)) {
11172 PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11173 goto failed;
11174 }
11175 len = PyList_GET_SIZE(tmp);
11176 type_params = _Py_asdl_type_param_seq_new(len, arena);
11177 if (type_params == NULL) goto failed;
11178 for (i = 0; i < len; i++) {
11179 type_param_ty val;
11180 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11181 if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
11182 goto failed;
11183 }
11184 res = obj2ast_type_param(state, tmp2, &val, arena);
11185 _Py_LeaveRecursiveCall();
11186 Py_DECREF(tmp2);
11187 if (res != 0) goto failed;
11188 if (len != PyList_GET_SIZE(tmp)) {
11189 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
11190 goto failed;
11191 }
11192 asdl_seq_SET(type_params, i, val);
11193 }
11194 Py_CLEAR(tmp);
11195 }
11196 *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
11197 type_params, lineno, col_offset, end_lineno,
11198 end_col_offset, arena);
11199 if (*out == NULL) goto failed;
11200 return 0;
11201 }
11202 tp = state->Return_type;
11203 isinstance = PyObject_IsInstance(obj, tp);
11204 if (isinstance == -1) {
11205 return -1;
11206 }
11207 if (isinstance) {
11208 expr_ty value;
11209
11210 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11211 return -1;
11212 }
11213 if (tmp == NULL || tmp == Py_None) {
11214 Py_CLEAR(tmp);
11215 value = NULL;
11216 }
11217 else {
11218 int res;
11219 if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
11220 goto failed;
11221 }
11222 res = obj2ast_expr(state, tmp, &value, arena);
11223 _Py_LeaveRecursiveCall();
11224 if (res != 0) goto failed;
11225 Py_CLEAR(tmp);
11226 }
11227 *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
11228 end_col_offset, arena);
11229 if (*out == NULL) goto failed;
11230 return 0;
11231 }
11232 tp = state->Delete_type;
11233 isinstance = PyObject_IsInstance(obj, tp);
11234 if (isinstance == -1) {
11235 return -1;
11236 }
11237 if (isinstance) {
11238 asdl_expr_seq* targets;
11239
11240 if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
11241 return -1;
11242 }
11243 if (tmp == NULL) {
11244 tmp = PyList_New(0);
11245 if (tmp == NULL) {
11246 return -1;
11247 }
11248 }
11249 {
11250 int res;
11251 Py_ssize_t len;
11252 Py_ssize_t i;
11253 if (!PyList_Check(tmp)) {
11254 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11255 goto failed;
11256 }
11257 len = PyList_GET_SIZE(tmp);
11258 targets = _Py_asdl_expr_seq_new(len, arena);
11259 if (targets == NULL) goto failed;
11260 for (i = 0; i < len; i++) {
11261 expr_ty val;
11262 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11263 if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
11264 goto failed;
11265 }
11266 res = obj2ast_expr(state, tmp2, &val, arena);
11267 _Py_LeaveRecursiveCall();
11268 Py_DECREF(tmp2);
11269 if (res != 0) goto failed;
11270 if (len != PyList_GET_SIZE(tmp)) {
11271 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
11272 goto failed;
11273 }
11274 asdl_seq_SET(targets, i, val);
11275 }
11276 Py_CLEAR(tmp);
11277 }
11278 *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
11279 end_col_offset, arena);
11280 if (*out == NULL) goto failed;
11281 return 0;
11282 }
11283 tp = state->Assign_type;
11284 isinstance = PyObject_IsInstance(obj, tp);
11285 if (isinstance == -1) {
11286 return -1;
11287 }
11288 if (isinstance) {
11289 asdl_expr_seq* targets;
11290 expr_ty value;
11291 string type_comment;
11292
11293 if (PyObject_GetOptionalAttr(obj, state->targets, &tmp) < 0) {
11294 return -1;
11295 }
11296 if (tmp == NULL) {
11297 tmp = PyList_New(0);
11298 if (tmp == NULL) {
11299 return -1;
11300 }
11301 }
11302 {
11303 int res;
11304 Py_ssize_t len;
11305 Py_ssize_t i;
11306 if (!PyList_Check(tmp)) {
11307 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11308 goto failed;
11309 }
11310 len = PyList_GET_SIZE(tmp);
11311 targets = _Py_asdl_expr_seq_new(len, arena);
11312 if (targets == NULL) goto failed;
11313 for (i = 0; i < len; i++) {
11314 expr_ty val;
11315 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11316 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
11317 goto failed;
11318 }
11319 res = obj2ast_expr(state, tmp2, &val, arena);
11320 _Py_LeaveRecursiveCall();
11321 Py_DECREF(tmp2);
11322 if (res != 0) goto failed;
11323 if (len != PyList_GET_SIZE(tmp)) {
11324 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
11325 goto failed;
11326 }
11327 asdl_seq_SET(targets, i, val);
11328 }
11329 Py_CLEAR(tmp);
11330 }
11331 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11332 return -1;
11333 }
11334 if (tmp == NULL) {
11335 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
11336 return -1;
11337 }
11338 else {
11339 int res;
11340 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
11341 goto failed;
11342 }
11343 res = obj2ast_expr(state, tmp, &value, arena);
11344 _Py_LeaveRecursiveCall();
11345 if (res != 0) goto failed;
11346 Py_CLEAR(tmp);
11347 }
11348 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
11349 return -1;
11350 }
11351 if (tmp == NULL || tmp == Py_None) {
11352 Py_CLEAR(tmp);
11353 type_comment = NULL;
11354 }
11355 else {
11356 int res;
11357 if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
11358 goto failed;
11359 }
11360 res = obj2ast_string(state, tmp, &type_comment, arena);
11361 _Py_LeaveRecursiveCall();
11362 if (res != 0) goto failed;
11363 Py_CLEAR(tmp);
11364 }
11365 *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
11366 end_lineno, end_col_offset, arena);
11367 if (*out == NULL) goto failed;
11368 return 0;
11369 }
11370 tp = state->TypeAlias_type;
11371 isinstance = PyObject_IsInstance(obj, tp);
11372 if (isinstance == -1) {
11373 return -1;
11374 }
11375 if (isinstance) {
11376 expr_ty name;
11377 asdl_type_param_seq* type_params;
11378 expr_ty value;
11379
11380 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
11381 return -1;
11382 }
11383 if (tmp == NULL) {
11384 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
11385 return -1;
11386 }
11387 else {
11388 int res;
11389 if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
11390 goto failed;
11391 }
11392 res = obj2ast_expr(state, tmp, &name, arena);
11393 _Py_LeaveRecursiveCall();
11394 if (res != 0) goto failed;
11395 Py_CLEAR(tmp);
11396 }
11397 if (PyObject_GetOptionalAttr(obj, state->type_params, &tmp) < 0) {
11398 return -1;
11399 }
11400 if (tmp == NULL) {
11401 tmp = PyList_New(0);
11402 if (tmp == NULL) {
11403 return -1;
11404 }
11405 }
11406 {
11407 int res;
11408 Py_ssize_t len;
11409 Py_ssize_t i;
11410 if (!PyList_Check(tmp)) {
11411 PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11412 goto failed;
11413 }
11414 len = PyList_GET_SIZE(tmp);
11415 type_params = _Py_asdl_type_param_seq_new(len, arena);
11416 if (type_params == NULL) goto failed;
11417 for (i = 0; i < len; i++) {
11418 type_param_ty val;
11419 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11420 if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
11421 goto failed;
11422 }
11423 res = obj2ast_type_param(state, tmp2, &val, arena);
11424 _Py_LeaveRecursiveCall();
11425 Py_DECREF(tmp2);
11426 if (res != 0) goto failed;
11427 if (len != PyList_GET_SIZE(tmp)) {
11428 PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
11429 goto failed;
11430 }
11431 asdl_seq_SET(type_params, i, val);
11432 }
11433 Py_CLEAR(tmp);
11434 }
11435 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11436 return -1;
11437 }
11438 if (tmp == NULL) {
11439 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
11440 return -1;
11441 }
11442 else {
11443 int res;
11444 if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
11445 goto failed;
11446 }
11447 res = obj2ast_expr(state, tmp, &value, arena);
11448 _Py_LeaveRecursiveCall();
11449 if (res != 0) goto failed;
11450 Py_CLEAR(tmp);
11451 }
11452 *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
11453 end_lineno, end_col_offset, arena);
11454 if (*out == NULL) goto failed;
11455 return 0;
11456 }
11457 tp = state->AugAssign_type;
11458 isinstance = PyObject_IsInstance(obj, tp);
11459 if (isinstance == -1) {
11460 return -1;
11461 }
11462 if (isinstance) {
11463 expr_ty target;
11464 operator_ty op;
11465 expr_ty value;
11466
11467 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
11468 return -1;
11469 }
11470 if (tmp == NULL) {
11471 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
11472 return -1;
11473 }
11474 else {
11475 int res;
11476 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
11477 goto failed;
11478 }
11479 res = obj2ast_expr(state, tmp, &target, arena);
11480 _Py_LeaveRecursiveCall();
11481 if (res != 0) goto failed;
11482 Py_CLEAR(tmp);
11483 }
11484 if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
11485 return -1;
11486 }
11487 if (tmp == NULL) {
11488 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
11489 return -1;
11490 }
11491 else {
11492 int res;
11493 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
11494 goto failed;
11495 }
11496 res = obj2ast_operator(state, tmp, &op, arena);
11497 _Py_LeaveRecursiveCall();
11498 if (res != 0) goto failed;
11499 Py_CLEAR(tmp);
11500 }
11501 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11502 return -1;
11503 }
11504 if (tmp == NULL) {
11505 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
11506 return -1;
11507 }
11508 else {
11509 int res;
11510 if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
11511 goto failed;
11512 }
11513 res = obj2ast_expr(state, tmp, &value, arena);
11514 _Py_LeaveRecursiveCall();
11515 if (res != 0) goto failed;
11516 Py_CLEAR(tmp);
11517 }
11518 *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
11519 end_lineno, end_col_offset, arena);
11520 if (*out == NULL) goto failed;
11521 return 0;
11522 }
11523 tp = state->AnnAssign_type;
11524 isinstance = PyObject_IsInstance(obj, tp);
11525 if (isinstance == -1) {
11526 return -1;
11527 }
11528 if (isinstance) {
11529 expr_ty target;
11530 expr_ty annotation;
11531 expr_ty value;
11532 int simple;
11533
11534 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
11535 return -1;
11536 }
11537 if (tmp == NULL) {
11538 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
11539 return -1;
11540 }
11541 else {
11542 int res;
11543 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
11544 goto failed;
11545 }
11546 res = obj2ast_expr(state, tmp, &target, arena);
11547 _Py_LeaveRecursiveCall();
11548 if (res != 0) goto failed;
11549 Py_CLEAR(tmp);
11550 }
11551 if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
11552 return -1;
11553 }
11554 if (tmp == NULL) {
11555 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
11556 return -1;
11557 }
11558 else {
11559 int res;
11560 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
11561 goto failed;
11562 }
11563 res = obj2ast_expr(state, tmp, &annotation, arena);
11564 _Py_LeaveRecursiveCall();
11565 if (res != 0) goto failed;
11566 Py_CLEAR(tmp);
11567 }
11568 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
11569 return -1;
11570 }
11571 if (tmp == NULL || tmp == Py_None) {
11572 Py_CLEAR(tmp);
11573 value = NULL;
11574 }
11575 else {
11576 int res;
11577 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
11578 goto failed;
11579 }
11580 res = obj2ast_expr(state, tmp, &value, arena);
11581 _Py_LeaveRecursiveCall();
11582 if (res != 0) goto failed;
11583 Py_CLEAR(tmp);
11584 }
11585 if (PyObject_GetOptionalAttr(obj, state->simple, &tmp) < 0) {
11586 return -1;
11587 }
11588 if (tmp == NULL) {
11589 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
11590 return -1;
11591 }
11592 else {
11593 int res;
11594 if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
11595 goto failed;
11596 }
11597 res = obj2ast_int(state, tmp, &simple, arena);
11598 _Py_LeaveRecursiveCall();
11599 if (res != 0) goto failed;
11600 Py_CLEAR(tmp);
11601 }
11602 *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
11603 col_offset, end_lineno, end_col_offset, arena);
11604 if (*out == NULL) goto failed;
11605 return 0;
11606 }
11607 tp = state->For_type;
11608 isinstance = PyObject_IsInstance(obj, tp);
11609 if (isinstance == -1) {
11610 return -1;
11611 }
11612 if (isinstance) {
11613 expr_ty target;
11614 expr_ty iter;
11615 asdl_stmt_seq* body;
11616 asdl_stmt_seq* orelse;
11617 string type_comment;
11618
11619 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
11620 return -1;
11621 }
11622 if (tmp == NULL) {
11623 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
11624 return -1;
11625 }
11626 else {
11627 int res;
11628 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
11629 goto failed;
11630 }
11631 res = obj2ast_expr(state, tmp, &target, arena);
11632 _Py_LeaveRecursiveCall();
11633 if (res != 0) goto failed;
11634 Py_CLEAR(tmp);
11635 }
11636 if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
11637 return -1;
11638 }
11639 if (tmp == NULL) {
11640 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
11641 return -1;
11642 }
11643 else {
11644 int res;
11645 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
11646 goto failed;
11647 }
11648 res = obj2ast_expr(state, tmp, &iter, arena);
11649 _Py_LeaveRecursiveCall();
11650 if (res != 0) goto failed;
11651 Py_CLEAR(tmp);
11652 }
11653 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
11654 return -1;
11655 }
11656 if (tmp == NULL) {
11657 tmp = PyList_New(0);
11658 if (tmp == NULL) {
11659 return -1;
11660 }
11661 }
11662 {
11663 int res;
11664 Py_ssize_t len;
11665 Py_ssize_t i;
11666 if (!PyList_Check(tmp)) {
11667 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11668 goto failed;
11669 }
11670 len = PyList_GET_SIZE(tmp);
11671 body = _Py_asdl_stmt_seq_new(len, arena);
11672 if (body == NULL) goto failed;
11673 for (i = 0; i < len; i++) {
11674 stmt_ty val;
11675 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11676 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
11677 goto failed;
11678 }
11679 res = obj2ast_stmt(state, tmp2, &val, arena);
11680 _Py_LeaveRecursiveCall();
11681 Py_DECREF(tmp2);
11682 if (res != 0) goto failed;
11683 if (len != PyList_GET_SIZE(tmp)) {
11684 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
11685 goto failed;
11686 }
11687 asdl_seq_SET(body, i, val);
11688 }
11689 Py_CLEAR(tmp);
11690 }
11691 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
11692 return -1;
11693 }
11694 if (tmp == NULL) {
11695 tmp = PyList_New(0);
11696 if (tmp == NULL) {
11697 return -1;
11698 }
11699 }
11700 {
11701 int res;
11702 Py_ssize_t len;
11703 Py_ssize_t i;
11704 if (!PyList_Check(tmp)) {
11705 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11706 goto failed;
11707 }
11708 len = PyList_GET_SIZE(tmp);
11709 orelse = _Py_asdl_stmt_seq_new(len, arena);
11710 if (orelse == NULL) goto failed;
11711 for (i = 0; i < len; i++) {
11712 stmt_ty val;
11713 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11714 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
11715 goto failed;
11716 }
11717 res = obj2ast_stmt(state, tmp2, &val, arena);
11718 _Py_LeaveRecursiveCall();
11719 Py_DECREF(tmp2);
11720 if (res != 0) goto failed;
11721 if (len != PyList_GET_SIZE(tmp)) {
11722 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
11723 goto failed;
11724 }
11725 asdl_seq_SET(orelse, i, val);
11726 }
11727 Py_CLEAR(tmp);
11728 }
11729 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
11730 return -1;
11731 }
11732 if (tmp == NULL || tmp == Py_None) {
11733 Py_CLEAR(tmp);
11734 type_comment = NULL;
11735 }
11736 else {
11737 int res;
11738 if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
11739 goto failed;
11740 }
11741 res = obj2ast_string(state, tmp, &type_comment, arena);
11742 _Py_LeaveRecursiveCall();
11743 if (res != 0) goto failed;
11744 Py_CLEAR(tmp);
11745 }
11746 *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
11747 col_offset, end_lineno, end_col_offset, arena);
11748 if (*out == NULL) goto failed;
11749 return 0;
11750 }
11751 tp = state->AsyncFor_type;
11752 isinstance = PyObject_IsInstance(obj, tp);
11753 if (isinstance == -1) {
11754 return -1;
11755 }
11756 if (isinstance) {
11757 expr_ty target;
11758 expr_ty iter;
11759 asdl_stmt_seq* body;
11760 asdl_stmt_seq* orelse;
11761 string type_comment;
11762
11763 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
11764 return -1;
11765 }
11766 if (tmp == NULL) {
11767 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
11768 return -1;
11769 }
11770 else {
11771 int res;
11772 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
11773 goto failed;
11774 }
11775 res = obj2ast_expr(state, tmp, &target, arena);
11776 _Py_LeaveRecursiveCall();
11777 if (res != 0) goto failed;
11778 Py_CLEAR(tmp);
11779 }
11780 if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
11781 return -1;
11782 }
11783 if (tmp == NULL) {
11784 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
11785 return -1;
11786 }
11787 else {
11788 int res;
11789 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
11790 goto failed;
11791 }
11792 res = obj2ast_expr(state, tmp, &iter, arena);
11793 _Py_LeaveRecursiveCall();
11794 if (res != 0) goto failed;
11795 Py_CLEAR(tmp);
11796 }
11797 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
11798 return -1;
11799 }
11800 if (tmp == NULL) {
11801 tmp = PyList_New(0);
11802 if (tmp == NULL) {
11803 return -1;
11804 }
11805 }
11806 {
11807 int res;
11808 Py_ssize_t len;
11809 Py_ssize_t i;
11810 if (!PyList_Check(tmp)) {
11811 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11812 goto failed;
11813 }
11814 len = PyList_GET_SIZE(tmp);
11815 body = _Py_asdl_stmt_seq_new(len, arena);
11816 if (body == NULL) goto failed;
11817 for (i = 0; i < len; i++) {
11818 stmt_ty val;
11819 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11820 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
11821 goto failed;
11822 }
11823 res = obj2ast_stmt(state, tmp2, &val, arena);
11824 _Py_LeaveRecursiveCall();
11825 Py_DECREF(tmp2);
11826 if (res != 0) goto failed;
11827 if (len != PyList_GET_SIZE(tmp)) {
11828 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
11829 goto failed;
11830 }
11831 asdl_seq_SET(body, i, val);
11832 }
11833 Py_CLEAR(tmp);
11834 }
11835 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
11836 return -1;
11837 }
11838 if (tmp == NULL) {
11839 tmp = PyList_New(0);
11840 if (tmp == NULL) {
11841 return -1;
11842 }
11843 }
11844 {
11845 int res;
11846 Py_ssize_t len;
11847 Py_ssize_t i;
11848 if (!PyList_Check(tmp)) {
11849 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11850 goto failed;
11851 }
11852 len = PyList_GET_SIZE(tmp);
11853 orelse = _Py_asdl_stmt_seq_new(len, arena);
11854 if (orelse == NULL) goto failed;
11855 for (i = 0; i < len; i++) {
11856 stmt_ty val;
11857 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11858 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
11859 goto failed;
11860 }
11861 res = obj2ast_stmt(state, tmp2, &val, arena);
11862 _Py_LeaveRecursiveCall();
11863 Py_DECREF(tmp2);
11864 if (res != 0) goto failed;
11865 if (len != PyList_GET_SIZE(tmp)) {
11866 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
11867 goto failed;
11868 }
11869 asdl_seq_SET(orelse, i, val);
11870 }
11871 Py_CLEAR(tmp);
11872 }
11873 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
11874 return -1;
11875 }
11876 if (tmp == NULL || tmp == Py_None) {
11877 Py_CLEAR(tmp);
11878 type_comment = NULL;
11879 }
11880 else {
11881 int res;
11882 if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
11883 goto failed;
11884 }
11885 res = obj2ast_string(state, tmp, &type_comment, arena);
11886 _Py_LeaveRecursiveCall();
11887 if (res != 0) goto failed;
11888 Py_CLEAR(tmp);
11889 }
11890 *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
11891 lineno, col_offset, end_lineno, end_col_offset,
11892 arena);
11893 if (*out == NULL) goto failed;
11894 return 0;
11895 }
11896 tp = state->While_type;
11897 isinstance = PyObject_IsInstance(obj, tp);
11898 if (isinstance == -1) {
11899 return -1;
11900 }
11901 if (isinstance) {
11902 expr_ty test;
11903 asdl_stmt_seq* body;
11904 asdl_stmt_seq* orelse;
11905
11906 if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
11907 return -1;
11908 }
11909 if (tmp == NULL) {
11910 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
11911 return -1;
11912 }
11913 else {
11914 int res;
11915 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
11916 goto failed;
11917 }
11918 res = obj2ast_expr(state, tmp, &test, arena);
11919 _Py_LeaveRecursiveCall();
11920 if (res != 0) goto failed;
11921 Py_CLEAR(tmp);
11922 }
11923 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
11924 return -1;
11925 }
11926 if (tmp == NULL) {
11927 tmp = PyList_New(0);
11928 if (tmp == NULL) {
11929 return -1;
11930 }
11931 }
11932 {
11933 int res;
11934 Py_ssize_t len;
11935 Py_ssize_t i;
11936 if (!PyList_Check(tmp)) {
11937 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11938 goto failed;
11939 }
11940 len = PyList_GET_SIZE(tmp);
11941 body = _Py_asdl_stmt_seq_new(len, arena);
11942 if (body == NULL) goto failed;
11943 for (i = 0; i < len; i++) {
11944 stmt_ty val;
11945 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11946 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
11947 goto failed;
11948 }
11949 res = obj2ast_stmt(state, tmp2, &val, arena);
11950 _Py_LeaveRecursiveCall();
11951 Py_DECREF(tmp2);
11952 if (res != 0) goto failed;
11953 if (len != PyList_GET_SIZE(tmp)) {
11954 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
11955 goto failed;
11956 }
11957 asdl_seq_SET(body, i, val);
11958 }
11959 Py_CLEAR(tmp);
11960 }
11961 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
11962 return -1;
11963 }
11964 if (tmp == NULL) {
11965 tmp = PyList_New(0);
11966 if (tmp == NULL) {
11967 return -1;
11968 }
11969 }
11970 {
11971 int res;
11972 Py_ssize_t len;
11973 Py_ssize_t i;
11974 if (!PyList_Check(tmp)) {
11975 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11976 goto failed;
11977 }
11978 len = PyList_GET_SIZE(tmp);
11979 orelse = _Py_asdl_stmt_seq_new(len, arena);
11980 if (orelse == NULL) goto failed;
11981 for (i = 0; i < len; i++) {
11982 stmt_ty val;
11983 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
11984 if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
11985 goto failed;
11986 }
11987 res = obj2ast_stmt(state, tmp2, &val, arena);
11988 _Py_LeaveRecursiveCall();
11989 Py_DECREF(tmp2);
11990 if (res != 0) goto failed;
11991 if (len != PyList_GET_SIZE(tmp)) {
11992 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
11993 goto failed;
11994 }
11995 asdl_seq_SET(orelse, i, val);
11996 }
11997 Py_CLEAR(tmp);
11998 }
11999 *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
12000 end_col_offset, arena);
12001 if (*out == NULL) goto failed;
12002 return 0;
12003 }
12004 tp = state->If_type;
12005 isinstance = PyObject_IsInstance(obj, tp);
12006 if (isinstance == -1) {
12007 return -1;
12008 }
12009 if (isinstance) {
12010 expr_ty test;
12011 asdl_stmt_seq* body;
12012 asdl_stmt_seq* orelse;
12013
12014 if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
12015 return -1;
12016 }
12017 if (tmp == NULL) {
12018 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
12019 return -1;
12020 }
12021 else {
12022 int res;
12023 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
12024 goto failed;
12025 }
12026 res = obj2ast_expr(state, tmp, &test, arena);
12027 _Py_LeaveRecursiveCall();
12028 if (res != 0) goto failed;
12029 Py_CLEAR(tmp);
12030 }
12031 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12032 return -1;
12033 }
12034 if (tmp == NULL) {
12035 tmp = PyList_New(0);
12036 if (tmp == NULL) {
12037 return -1;
12038 }
12039 }
12040 {
12041 int res;
12042 Py_ssize_t len;
12043 Py_ssize_t i;
12044 if (!PyList_Check(tmp)) {
12045 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12046 goto failed;
12047 }
12048 len = PyList_GET_SIZE(tmp);
12049 body = _Py_asdl_stmt_seq_new(len, arena);
12050 if (body == NULL) goto failed;
12051 for (i = 0; i < len; i++) {
12052 stmt_ty val;
12053 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12054 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
12055 goto failed;
12056 }
12057 res = obj2ast_stmt(state, tmp2, &val, arena);
12058 _Py_LeaveRecursiveCall();
12059 Py_DECREF(tmp2);
12060 if (res != 0) goto failed;
12061 if (len != PyList_GET_SIZE(tmp)) {
12062 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
12063 goto failed;
12064 }
12065 asdl_seq_SET(body, i, val);
12066 }
12067 Py_CLEAR(tmp);
12068 }
12069 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
12070 return -1;
12071 }
12072 if (tmp == NULL) {
12073 tmp = PyList_New(0);
12074 if (tmp == NULL) {
12075 return -1;
12076 }
12077 }
12078 {
12079 int res;
12080 Py_ssize_t len;
12081 Py_ssize_t i;
12082 if (!PyList_Check(tmp)) {
12083 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12084 goto failed;
12085 }
12086 len = PyList_GET_SIZE(tmp);
12087 orelse = _Py_asdl_stmt_seq_new(len, arena);
12088 if (orelse == NULL) goto failed;
12089 for (i = 0; i < len; i++) {
12090 stmt_ty val;
12091 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12092 if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
12093 goto failed;
12094 }
12095 res = obj2ast_stmt(state, tmp2, &val, arena);
12096 _Py_LeaveRecursiveCall();
12097 Py_DECREF(tmp2);
12098 if (res != 0) goto failed;
12099 if (len != PyList_GET_SIZE(tmp)) {
12100 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
12101 goto failed;
12102 }
12103 asdl_seq_SET(orelse, i, val);
12104 }
12105 Py_CLEAR(tmp);
12106 }
12107 *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
12108 end_col_offset, arena);
12109 if (*out == NULL) goto failed;
12110 return 0;
12111 }
12112 tp = state->With_type;
12113 isinstance = PyObject_IsInstance(obj, tp);
12114 if (isinstance == -1) {
12115 return -1;
12116 }
12117 if (isinstance) {
12118 asdl_withitem_seq* items;
12119 asdl_stmt_seq* body;
12120 string type_comment;
12121
12122 if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
12123 return -1;
12124 }
12125 if (tmp == NULL) {
12126 tmp = PyList_New(0);
12127 if (tmp == NULL) {
12128 return -1;
12129 }
12130 }
12131 {
12132 int res;
12133 Py_ssize_t len;
12134 Py_ssize_t i;
12135 if (!PyList_Check(tmp)) {
12136 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12137 goto failed;
12138 }
12139 len = PyList_GET_SIZE(tmp);
12140 items = _Py_asdl_withitem_seq_new(len, arena);
12141 if (items == NULL) goto failed;
12142 for (i = 0; i < len; i++) {
12143 withitem_ty val;
12144 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12145 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
12146 goto failed;
12147 }
12148 res = obj2ast_withitem(state, tmp2, &val, arena);
12149 _Py_LeaveRecursiveCall();
12150 Py_DECREF(tmp2);
12151 if (res != 0) goto failed;
12152 if (len != PyList_GET_SIZE(tmp)) {
12153 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
12154 goto failed;
12155 }
12156 asdl_seq_SET(items, i, val);
12157 }
12158 Py_CLEAR(tmp);
12159 }
12160 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12161 return -1;
12162 }
12163 if (tmp == NULL) {
12164 tmp = PyList_New(0);
12165 if (tmp == NULL) {
12166 return -1;
12167 }
12168 }
12169 {
12170 int res;
12171 Py_ssize_t len;
12172 Py_ssize_t i;
12173 if (!PyList_Check(tmp)) {
12174 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12175 goto failed;
12176 }
12177 len = PyList_GET_SIZE(tmp);
12178 body = _Py_asdl_stmt_seq_new(len, arena);
12179 if (body == NULL) goto failed;
12180 for (i = 0; i < len; i++) {
12181 stmt_ty val;
12182 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12183 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
12184 goto failed;
12185 }
12186 res = obj2ast_stmt(state, tmp2, &val, arena);
12187 _Py_LeaveRecursiveCall();
12188 Py_DECREF(tmp2);
12189 if (res != 0) goto failed;
12190 if (len != PyList_GET_SIZE(tmp)) {
12191 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
12192 goto failed;
12193 }
12194 asdl_seq_SET(body, i, val);
12195 }
12196 Py_CLEAR(tmp);
12197 }
12198 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
12199 return -1;
12200 }
12201 if (tmp == NULL || tmp == Py_None) {
12202 Py_CLEAR(tmp);
12203 type_comment = NULL;
12204 }
12205 else {
12206 int res;
12207 if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
12208 goto failed;
12209 }
12210 res = obj2ast_string(state, tmp, &type_comment, arena);
12211 _Py_LeaveRecursiveCall();
12212 if (res != 0) goto failed;
12213 Py_CLEAR(tmp);
12214 }
12215 *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
12216 end_lineno, end_col_offset, arena);
12217 if (*out == NULL) goto failed;
12218 return 0;
12219 }
12220 tp = state->AsyncWith_type;
12221 isinstance = PyObject_IsInstance(obj, tp);
12222 if (isinstance == -1) {
12223 return -1;
12224 }
12225 if (isinstance) {
12226 asdl_withitem_seq* items;
12227 asdl_stmt_seq* body;
12228 string type_comment;
12229
12230 if (PyObject_GetOptionalAttr(obj, state->items, &tmp) < 0) {
12231 return -1;
12232 }
12233 if (tmp == NULL) {
12234 tmp = PyList_New(0);
12235 if (tmp == NULL) {
12236 return -1;
12237 }
12238 }
12239 {
12240 int res;
12241 Py_ssize_t len;
12242 Py_ssize_t i;
12243 if (!PyList_Check(tmp)) {
12244 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12245 goto failed;
12246 }
12247 len = PyList_GET_SIZE(tmp);
12248 items = _Py_asdl_withitem_seq_new(len, arena);
12249 if (items == NULL) goto failed;
12250 for (i = 0; i < len; i++) {
12251 withitem_ty val;
12252 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12253 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
12254 goto failed;
12255 }
12256 res = obj2ast_withitem(state, tmp2, &val, arena);
12257 _Py_LeaveRecursiveCall();
12258 Py_DECREF(tmp2);
12259 if (res != 0) goto failed;
12260 if (len != PyList_GET_SIZE(tmp)) {
12261 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
12262 goto failed;
12263 }
12264 asdl_seq_SET(items, i, val);
12265 }
12266 Py_CLEAR(tmp);
12267 }
12268 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12269 return -1;
12270 }
12271 if (tmp == NULL) {
12272 tmp = PyList_New(0);
12273 if (tmp == NULL) {
12274 return -1;
12275 }
12276 }
12277 {
12278 int res;
12279 Py_ssize_t len;
12280 Py_ssize_t i;
12281 if (!PyList_Check(tmp)) {
12282 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12283 goto failed;
12284 }
12285 len = PyList_GET_SIZE(tmp);
12286 body = _Py_asdl_stmt_seq_new(len, arena);
12287 if (body == NULL) goto failed;
12288 for (i = 0; i < len; i++) {
12289 stmt_ty val;
12290 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12291 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
12292 goto failed;
12293 }
12294 res = obj2ast_stmt(state, tmp2, &val, arena);
12295 _Py_LeaveRecursiveCall();
12296 Py_DECREF(tmp2);
12297 if (res != 0) goto failed;
12298 if (len != PyList_GET_SIZE(tmp)) {
12299 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
12300 goto failed;
12301 }
12302 asdl_seq_SET(body, i, val);
12303 }
12304 Py_CLEAR(tmp);
12305 }
12306 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
12307 return -1;
12308 }
12309 if (tmp == NULL || tmp == Py_None) {
12310 Py_CLEAR(tmp);
12311 type_comment = NULL;
12312 }
12313 else {
12314 int res;
12315 if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
12316 goto failed;
12317 }
12318 res = obj2ast_string(state, tmp, &type_comment, arena);
12319 _Py_LeaveRecursiveCall();
12320 if (res != 0) goto failed;
12321 Py_CLEAR(tmp);
12322 }
12323 *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
12324 end_lineno, end_col_offset, arena);
12325 if (*out == NULL) goto failed;
12326 return 0;
12327 }
12328 tp = state->Match_type;
12329 isinstance = PyObject_IsInstance(obj, tp);
12330 if (isinstance == -1) {
12331 return -1;
12332 }
12333 if (isinstance) {
12334 expr_ty subject;
12335 asdl_match_case_seq* cases;
12336
12337 if (PyObject_GetOptionalAttr(obj, state->subject, &tmp) < 0) {
12338 return -1;
12339 }
12340 if (tmp == NULL) {
12341 PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
12342 return -1;
12343 }
12344 else {
12345 int res;
12346 if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
12347 goto failed;
12348 }
12349 res = obj2ast_expr(state, tmp, &subject, arena);
12350 _Py_LeaveRecursiveCall();
12351 if (res != 0) goto failed;
12352 Py_CLEAR(tmp);
12353 }
12354 if (PyObject_GetOptionalAttr(obj, state->cases, &tmp) < 0) {
12355 return -1;
12356 }
12357 if (tmp == NULL) {
12358 tmp = PyList_New(0);
12359 if (tmp == NULL) {
12360 return -1;
12361 }
12362 }
12363 {
12364 int res;
12365 Py_ssize_t len;
12366 Py_ssize_t i;
12367 if (!PyList_Check(tmp)) {
12368 PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12369 goto failed;
12370 }
12371 len = PyList_GET_SIZE(tmp);
12372 cases = _Py_asdl_match_case_seq_new(len, arena);
12373 if (cases == NULL) goto failed;
12374 for (i = 0; i < len; i++) {
12375 match_case_ty val;
12376 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12377 if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
12378 goto failed;
12379 }
12380 res = obj2ast_match_case(state, tmp2, &val, arena);
12381 _Py_LeaveRecursiveCall();
12382 Py_DECREF(tmp2);
12383 if (res != 0) goto failed;
12384 if (len != PyList_GET_SIZE(tmp)) {
12385 PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
12386 goto failed;
12387 }
12388 asdl_seq_SET(cases, i, val);
12389 }
12390 Py_CLEAR(tmp);
12391 }
12392 *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
12393 end_col_offset, arena);
12394 if (*out == NULL) goto failed;
12395 return 0;
12396 }
12397 tp = state->Raise_type;
12398 isinstance = PyObject_IsInstance(obj, tp);
12399 if (isinstance == -1) {
12400 return -1;
12401 }
12402 if (isinstance) {
12403 expr_ty exc;
12404 expr_ty cause;
12405
12406 if (PyObject_GetOptionalAttr(obj, state->exc, &tmp) < 0) {
12407 return -1;
12408 }
12409 if (tmp == NULL || tmp == Py_None) {
12410 Py_CLEAR(tmp);
12411 exc = NULL;
12412 }
12413 else {
12414 int res;
12415 if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
12416 goto failed;
12417 }
12418 res = obj2ast_expr(state, tmp, &exc, arena);
12419 _Py_LeaveRecursiveCall();
12420 if (res != 0) goto failed;
12421 Py_CLEAR(tmp);
12422 }
12423 if (PyObject_GetOptionalAttr(obj, state->cause, &tmp) < 0) {
12424 return -1;
12425 }
12426 if (tmp == NULL || tmp == Py_None) {
12427 Py_CLEAR(tmp);
12428 cause = NULL;
12429 }
12430 else {
12431 int res;
12432 if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
12433 goto failed;
12434 }
12435 res = obj2ast_expr(state, tmp, &cause, arena);
12436 _Py_LeaveRecursiveCall();
12437 if (res != 0) goto failed;
12438 Py_CLEAR(tmp);
12439 }
12440 *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
12441 end_col_offset, arena);
12442 if (*out == NULL) goto failed;
12443 return 0;
12444 }
12445 tp = state->Try_type;
12446 isinstance = PyObject_IsInstance(obj, tp);
12447 if (isinstance == -1) {
12448 return -1;
12449 }
12450 if (isinstance) {
12451 asdl_stmt_seq* body;
12452 asdl_excepthandler_seq* handlers;
12453 asdl_stmt_seq* orelse;
12454 asdl_stmt_seq* finalbody;
12455
12456 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12457 return -1;
12458 }
12459 if (tmp == NULL) {
12460 tmp = PyList_New(0);
12461 if (tmp == NULL) {
12462 return -1;
12463 }
12464 }
12465 {
12466 int res;
12467 Py_ssize_t len;
12468 Py_ssize_t i;
12469 if (!PyList_Check(tmp)) {
12470 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12471 goto failed;
12472 }
12473 len = PyList_GET_SIZE(tmp);
12474 body = _Py_asdl_stmt_seq_new(len, arena);
12475 if (body == NULL) goto failed;
12476 for (i = 0; i < len; i++) {
12477 stmt_ty val;
12478 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12479 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
12480 goto failed;
12481 }
12482 res = obj2ast_stmt(state, tmp2, &val, arena);
12483 _Py_LeaveRecursiveCall();
12484 Py_DECREF(tmp2);
12485 if (res != 0) goto failed;
12486 if (len != PyList_GET_SIZE(tmp)) {
12487 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
12488 goto failed;
12489 }
12490 asdl_seq_SET(body, i, val);
12491 }
12492 Py_CLEAR(tmp);
12493 }
12494 if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
12495 return -1;
12496 }
12497 if (tmp == NULL) {
12498 tmp = PyList_New(0);
12499 if (tmp == NULL) {
12500 return -1;
12501 }
12502 }
12503 {
12504 int res;
12505 Py_ssize_t len;
12506 Py_ssize_t i;
12507 if (!PyList_Check(tmp)) {
12508 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12509 goto failed;
12510 }
12511 len = PyList_GET_SIZE(tmp);
12512 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
12513 if (handlers == NULL) goto failed;
12514 for (i = 0; i < len; i++) {
12515 excepthandler_ty val;
12516 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12517 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
12518 goto failed;
12519 }
12520 res = obj2ast_excepthandler(state, tmp2, &val, arena);
12521 _Py_LeaveRecursiveCall();
12522 Py_DECREF(tmp2);
12523 if (res != 0) goto failed;
12524 if (len != PyList_GET_SIZE(tmp)) {
12525 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
12526 goto failed;
12527 }
12528 asdl_seq_SET(handlers, i, val);
12529 }
12530 Py_CLEAR(tmp);
12531 }
12532 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
12533 return -1;
12534 }
12535 if (tmp == NULL) {
12536 tmp = PyList_New(0);
12537 if (tmp == NULL) {
12538 return -1;
12539 }
12540 }
12541 {
12542 int res;
12543 Py_ssize_t len;
12544 Py_ssize_t i;
12545 if (!PyList_Check(tmp)) {
12546 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12547 goto failed;
12548 }
12549 len = PyList_GET_SIZE(tmp);
12550 orelse = _Py_asdl_stmt_seq_new(len, arena);
12551 if (orelse == NULL) goto failed;
12552 for (i = 0; i < len; i++) {
12553 stmt_ty val;
12554 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12555 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
12556 goto failed;
12557 }
12558 res = obj2ast_stmt(state, tmp2, &val, arena);
12559 _Py_LeaveRecursiveCall();
12560 Py_DECREF(tmp2);
12561 if (res != 0) goto failed;
12562 if (len != PyList_GET_SIZE(tmp)) {
12563 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
12564 goto failed;
12565 }
12566 asdl_seq_SET(orelse, i, val);
12567 }
12568 Py_CLEAR(tmp);
12569 }
12570 if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
12571 return -1;
12572 }
12573 if (tmp == NULL) {
12574 tmp = PyList_New(0);
12575 if (tmp == NULL) {
12576 return -1;
12577 }
12578 }
12579 {
12580 int res;
12581 Py_ssize_t len;
12582 Py_ssize_t i;
12583 if (!PyList_Check(tmp)) {
12584 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12585 goto failed;
12586 }
12587 len = PyList_GET_SIZE(tmp);
12588 finalbody = _Py_asdl_stmt_seq_new(len, arena);
12589 if (finalbody == NULL) goto failed;
12590 for (i = 0; i < len; i++) {
12591 stmt_ty val;
12592 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12593 if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
12594 goto failed;
12595 }
12596 res = obj2ast_stmt(state, tmp2, &val, arena);
12597 _Py_LeaveRecursiveCall();
12598 Py_DECREF(tmp2);
12599 if (res != 0) goto failed;
12600 if (len != PyList_GET_SIZE(tmp)) {
12601 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
12602 goto failed;
12603 }
12604 asdl_seq_SET(finalbody, i, val);
12605 }
12606 Py_CLEAR(tmp);
12607 }
12608 *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
12609 col_offset, end_lineno, end_col_offset, arena);
12610 if (*out == NULL) goto failed;
12611 return 0;
12612 }
12613 tp = state->TryStar_type;
12614 isinstance = PyObject_IsInstance(obj, tp);
12615 if (isinstance == -1) {
12616 return -1;
12617 }
12618 if (isinstance) {
12619 asdl_stmt_seq* body;
12620 asdl_excepthandler_seq* handlers;
12621 asdl_stmt_seq* orelse;
12622 asdl_stmt_seq* finalbody;
12623
12624 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
12625 return -1;
12626 }
12627 if (tmp == NULL) {
12628 tmp = PyList_New(0);
12629 if (tmp == NULL) {
12630 return -1;
12631 }
12632 }
12633 {
12634 int res;
12635 Py_ssize_t len;
12636 Py_ssize_t i;
12637 if (!PyList_Check(tmp)) {
12638 PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12639 goto failed;
12640 }
12641 len = PyList_GET_SIZE(tmp);
12642 body = _Py_asdl_stmt_seq_new(len, arena);
12643 if (body == NULL) goto failed;
12644 for (i = 0; i < len; i++) {
12645 stmt_ty val;
12646 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12647 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
12648 goto failed;
12649 }
12650 res = obj2ast_stmt(state, tmp2, &val, arena);
12651 _Py_LeaveRecursiveCall();
12652 Py_DECREF(tmp2);
12653 if (res != 0) goto failed;
12654 if (len != PyList_GET_SIZE(tmp)) {
12655 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
12656 goto failed;
12657 }
12658 asdl_seq_SET(body, i, val);
12659 }
12660 Py_CLEAR(tmp);
12661 }
12662 if (PyObject_GetOptionalAttr(obj, state->handlers, &tmp) < 0) {
12663 return -1;
12664 }
12665 if (tmp == NULL) {
12666 tmp = PyList_New(0);
12667 if (tmp == NULL) {
12668 return -1;
12669 }
12670 }
12671 {
12672 int res;
12673 Py_ssize_t len;
12674 Py_ssize_t i;
12675 if (!PyList_Check(tmp)) {
12676 PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12677 goto failed;
12678 }
12679 len = PyList_GET_SIZE(tmp);
12680 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
12681 if (handlers == NULL) goto failed;
12682 for (i = 0; i < len; i++) {
12683 excepthandler_ty val;
12684 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12685 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
12686 goto failed;
12687 }
12688 res = obj2ast_excepthandler(state, tmp2, &val, arena);
12689 _Py_LeaveRecursiveCall();
12690 Py_DECREF(tmp2);
12691 if (res != 0) goto failed;
12692 if (len != PyList_GET_SIZE(tmp)) {
12693 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
12694 goto failed;
12695 }
12696 asdl_seq_SET(handlers, i, val);
12697 }
12698 Py_CLEAR(tmp);
12699 }
12700 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
12701 return -1;
12702 }
12703 if (tmp == NULL) {
12704 tmp = PyList_New(0);
12705 if (tmp == NULL) {
12706 return -1;
12707 }
12708 }
12709 {
12710 int res;
12711 Py_ssize_t len;
12712 Py_ssize_t i;
12713 if (!PyList_Check(tmp)) {
12714 PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12715 goto failed;
12716 }
12717 len = PyList_GET_SIZE(tmp);
12718 orelse = _Py_asdl_stmt_seq_new(len, arena);
12719 if (orelse == NULL) goto failed;
12720 for (i = 0; i < len; i++) {
12721 stmt_ty val;
12722 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12723 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
12724 goto failed;
12725 }
12726 res = obj2ast_stmt(state, tmp2, &val, arena);
12727 _Py_LeaveRecursiveCall();
12728 Py_DECREF(tmp2);
12729 if (res != 0) goto failed;
12730 if (len != PyList_GET_SIZE(tmp)) {
12731 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
12732 goto failed;
12733 }
12734 asdl_seq_SET(orelse, i, val);
12735 }
12736 Py_CLEAR(tmp);
12737 }
12738 if (PyObject_GetOptionalAttr(obj, state->finalbody, &tmp) < 0) {
12739 return -1;
12740 }
12741 if (tmp == NULL) {
12742 tmp = PyList_New(0);
12743 if (tmp == NULL) {
12744 return -1;
12745 }
12746 }
12747 {
12748 int res;
12749 Py_ssize_t len;
12750 Py_ssize_t i;
12751 if (!PyList_Check(tmp)) {
12752 PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12753 goto failed;
12754 }
12755 len = PyList_GET_SIZE(tmp);
12756 finalbody = _Py_asdl_stmt_seq_new(len, arena);
12757 if (finalbody == NULL) goto failed;
12758 for (i = 0; i < len; i++) {
12759 stmt_ty val;
12760 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12761 if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
12762 goto failed;
12763 }
12764 res = obj2ast_stmt(state, tmp2, &val, arena);
12765 _Py_LeaveRecursiveCall();
12766 Py_DECREF(tmp2);
12767 if (res != 0) goto failed;
12768 if (len != PyList_GET_SIZE(tmp)) {
12769 PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
12770 goto failed;
12771 }
12772 asdl_seq_SET(finalbody, i, val);
12773 }
12774 Py_CLEAR(tmp);
12775 }
12776 *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
12777 col_offset, end_lineno, end_col_offset, arena);
12778 if (*out == NULL) goto failed;
12779 return 0;
12780 }
12781 tp = state->Assert_type;
12782 isinstance = PyObject_IsInstance(obj, tp);
12783 if (isinstance == -1) {
12784 return -1;
12785 }
12786 if (isinstance) {
12787 expr_ty test;
12788 expr_ty msg;
12789
12790 if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
12791 return -1;
12792 }
12793 if (tmp == NULL) {
12794 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
12795 return -1;
12796 }
12797 else {
12798 int res;
12799 if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
12800 goto failed;
12801 }
12802 res = obj2ast_expr(state, tmp, &test, arena);
12803 _Py_LeaveRecursiveCall();
12804 if (res != 0) goto failed;
12805 Py_CLEAR(tmp);
12806 }
12807 if (PyObject_GetOptionalAttr(obj, state->msg, &tmp) < 0) {
12808 return -1;
12809 }
12810 if (tmp == NULL || tmp == Py_None) {
12811 Py_CLEAR(tmp);
12812 msg = NULL;
12813 }
12814 else {
12815 int res;
12816 if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
12817 goto failed;
12818 }
12819 res = obj2ast_expr(state, tmp, &msg, arena);
12820 _Py_LeaveRecursiveCall();
12821 if (res != 0) goto failed;
12822 Py_CLEAR(tmp);
12823 }
12824 *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
12825 end_col_offset, arena);
12826 if (*out == NULL) goto failed;
12827 return 0;
12828 }
12829 tp = state->Import_type;
12830 isinstance = PyObject_IsInstance(obj, tp);
12831 if (isinstance == -1) {
12832 return -1;
12833 }
12834 if (isinstance) {
12835 asdl_alias_seq* names;
12836
12837 if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
12838 return -1;
12839 }
12840 if (tmp == NULL) {
12841 tmp = PyList_New(0);
12842 if (tmp == NULL) {
12843 return -1;
12844 }
12845 }
12846 {
12847 int res;
12848 Py_ssize_t len;
12849 Py_ssize_t i;
12850 if (!PyList_Check(tmp)) {
12851 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12852 goto failed;
12853 }
12854 len = PyList_GET_SIZE(tmp);
12855 names = _Py_asdl_alias_seq_new(len, arena);
12856 if (names == NULL) goto failed;
12857 for (i = 0; i < len; i++) {
12858 alias_ty val;
12859 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12860 if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
12861 goto failed;
12862 }
12863 res = obj2ast_alias(state, tmp2, &val, arena);
12864 _Py_LeaveRecursiveCall();
12865 Py_DECREF(tmp2);
12866 if (res != 0) goto failed;
12867 if (len != PyList_GET_SIZE(tmp)) {
12868 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
12869 goto failed;
12870 }
12871 asdl_seq_SET(names, i, val);
12872 }
12873 Py_CLEAR(tmp);
12874 }
12875 *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
12876 end_col_offset, arena);
12877 if (*out == NULL) goto failed;
12878 return 0;
12879 }
12880 tp = state->ImportFrom_type;
12881 isinstance = PyObject_IsInstance(obj, tp);
12882 if (isinstance == -1) {
12883 return -1;
12884 }
12885 if (isinstance) {
12886 identifier module;
12887 asdl_alias_seq* names;
12888 int level;
12889
12890 if (PyObject_GetOptionalAttr(obj, state->module, &tmp) < 0) {
12891 return -1;
12892 }
12893 if (tmp == NULL || tmp == Py_None) {
12894 Py_CLEAR(tmp);
12895 module = NULL;
12896 }
12897 else {
12898 int res;
12899 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
12900 goto failed;
12901 }
12902 res = obj2ast_identifier(state, tmp, &module, arena);
12903 _Py_LeaveRecursiveCall();
12904 if (res != 0) goto failed;
12905 Py_CLEAR(tmp);
12906 }
12907 if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
12908 return -1;
12909 }
12910 if (tmp == NULL) {
12911 tmp = PyList_New(0);
12912 if (tmp == NULL) {
12913 return -1;
12914 }
12915 }
12916 {
12917 int res;
12918 Py_ssize_t len;
12919 Py_ssize_t i;
12920 if (!PyList_Check(tmp)) {
12921 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12922 goto failed;
12923 }
12924 len = PyList_GET_SIZE(tmp);
12925 names = _Py_asdl_alias_seq_new(len, arena);
12926 if (names == NULL) goto failed;
12927 for (i = 0; i < len; i++) {
12928 alias_ty val;
12929 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12930 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
12931 goto failed;
12932 }
12933 res = obj2ast_alias(state, tmp2, &val, arena);
12934 _Py_LeaveRecursiveCall();
12935 Py_DECREF(tmp2);
12936 if (res != 0) goto failed;
12937 if (len != PyList_GET_SIZE(tmp)) {
12938 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
12939 goto failed;
12940 }
12941 asdl_seq_SET(names, i, val);
12942 }
12943 Py_CLEAR(tmp);
12944 }
12945 if (PyObject_GetOptionalAttr(obj, state->level, &tmp) < 0) {
12946 return -1;
12947 }
12948 if (tmp == NULL || tmp == Py_None) {
12949 Py_CLEAR(tmp);
12950 level = 0;
12951 }
12952 else {
12953 int res;
12954 if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
12955 goto failed;
12956 }
12957 res = obj2ast_int(state, tmp, &level, arena);
12958 _Py_LeaveRecursiveCall();
12959 if (res != 0) goto failed;
12960 Py_CLEAR(tmp);
12961 }
12962 *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
12963 end_lineno, end_col_offset, arena);
12964 if (*out == NULL) goto failed;
12965 return 0;
12966 }
12967 tp = state->Global_type;
12968 isinstance = PyObject_IsInstance(obj, tp);
12969 if (isinstance == -1) {
12970 return -1;
12971 }
12972 if (isinstance) {
12973 asdl_identifier_seq* names;
12974
12975 if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
12976 return -1;
12977 }
12978 if (tmp == NULL) {
12979 tmp = PyList_New(0);
12980 if (tmp == NULL) {
12981 return -1;
12982 }
12983 }
12984 {
12985 int res;
12986 Py_ssize_t len;
12987 Py_ssize_t i;
12988 if (!PyList_Check(tmp)) {
12989 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
12990 goto failed;
12991 }
12992 len = PyList_GET_SIZE(tmp);
12993 names = _Py_asdl_identifier_seq_new(len, arena);
12994 if (names == NULL) goto failed;
12995 for (i = 0; i < len; i++) {
12996 identifier val;
12997 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
12998 if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
12999 goto failed;
13000 }
13001 res = obj2ast_identifier(state, tmp2, &val, arena);
13002 _Py_LeaveRecursiveCall();
13003 Py_DECREF(tmp2);
13004 if (res != 0) goto failed;
13005 if (len != PyList_GET_SIZE(tmp)) {
13006 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
13007 goto failed;
13008 }
13009 asdl_seq_SET(names, i, val);
13010 }
13011 Py_CLEAR(tmp);
13012 }
13013 *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
13014 end_col_offset, arena);
13015 if (*out == NULL) goto failed;
13016 return 0;
13017 }
13018 tp = state->Nonlocal_type;
13019 isinstance = PyObject_IsInstance(obj, tp);
13020 if (isinstance == -1) {
13021 return -1;
13022 }
13023 if (isinstance) {
13024 asdl_identifier_seq* names;
13025
13026 if (PyObject_GetOptionalAttr(obj, state->names, &tmp) < 0) {
13027 return -1;
13028 }
13029 if (tmp == NULL) {
13030 tmp = PyList_New(0);
13031 if (tmp == NULL) {
13032 return -1;
13033 }
13034 }
13035 {
13036 int res;
13037 Py_ssize_t len;
13038 Py_ssize_t i;
13039 if (!PyList_Check(tmp)) {
13040 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13041 goto failed;
13042 }
13043 len = PyList_GET_SIZE(tmp);
13044 names = _Py_asdl_identifier_seq_new(len, arena);
13045 if (names == NULL) goto failed;
13046 for (i = 0; i < len; i++) {
13047 identifier val;
13048 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13049 if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
13050 goto failed;
13051 }
13052 res = obj2ast_identifier(state, tmp2, &val, arena);
13053 _Py_LeaveRecursiveCall();
13054 Py_DECREF(tmp2);
13055 if (res != 0) goto failed;
13056 if (len != PyList_GET_SIZE(tmp)) {
13057 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
13058 goto failed;
13059 }
13060 asdl_seq_SET(names, i, val);
13061 }
13062 Py_CLEAR(tmp);
13063 }
13064 *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
13065 end_col_offset, arena);
13066 if (*out == NULL) goto failed;
13067 return 0;
13068 }
13069 tp = state->Expr_type;
13070 isinstance = PyObject_IsInstance(obj, tp);
13071 if (isinstance == -1) {
13072 return -1;
13073 }
13074 if (isinstance) {
13075 expr_ty value;
13076
13077 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13078 return -1;
13079 }
13080 if (tmp == NULL) {
13081 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
13082 return -1;
13083 }
13084 else {
13085 int res;
13086 if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
13087 goto failed;
13088 }
13089 res = obj2ast_expr(state, tmp, &value, arena);
13090 _Py_LeaveRecursiveCall();
13091 if (res != 0) goto failed;
13092 Py_CLEAR(tmp);
13093 }
13094 *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
13095 end_col_offset, arena);
13096 if (*out == NULL) goto failed;
13097 return 0;
13098 }
13099 tp = state->Pass_type;
13100 isinstance = PyObject_IsInstance(obj, tp);
13101 if (isinstance == -1) {
13102 return -1;
13103 }
13104 if (isinstance) {
13105
13106 *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
13107 arena);
13108 if (*out == NULL) goto failed;
13109 return 0;
13110 }
13111 tp = state->Break_type;
13112 isinstance = PyObject_IsInstance(obj, tp);
13113 if (isinstance == -1) {
13114 return -1;
13115 }
13116 if (isinstance) {
13117
13118 *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
13119 arena);
13120 if (*out == NULL) goto failed;
13121 return 0;
13122 }
13123 tp = state->Continue_type;
13124 isinstance = PyObject_IsInstance(obj, tp);
13125 if (isinstance == -1) {
13126 return -1;
13127 }
13128 if (isinstance) {
13129
13130 *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
13131 arena);
13132 if (*out == NULL) goto failed;
13133 return 0;
13134 }
13135
13136 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
13137 failed:
13138 Py_XDECREF(tmp);
13139 return -1;
13140 }
13141
13142 int
obj2ast_expr(struct ast_state * state,PyObject * obj,expr_ty * out,PyArena * arena)13143 obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
13144 arena)
13145 {
13146 int isinstance;
13147
13148 PyObject *tmp = NULL;
13149 PyObject *tp;
13150 int lineno;
13151 int col_offset;
13152 int end_lineno;
13153 int end_col_offset;
13154
13155 if (obj == Py_None) {
13156 *out = NULL;
13157 return 0;
13158 }
13159 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
13160 return -1;
13161 }
13162 if (tmp == NULL) {
13163 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
13164 return -1;
13165 }
13166 else {
13167 int res;
13168 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
13169 goto failed;
13170 }
13171 res = obj2ast_int(state, tmp, &lineno, arena);
13172 _Py_LeaveRecursiveCall();
13173 if (res != 0) goto failed;
13174 Py_CLEAR(tmp);
13175 }
13176 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
13177 return -1;
13178 }
13179 if (tmp == NULL) {
13180 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
13181 return -1;
13182 }
13183 else {
13184 int res;
13185 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
13186 goto failed;
13187 }
13188 res = obj2ast_int(state, tmp, &col_offset, arena);
13189 _Py_LeaveRecursiveCall();
13190 if (res != 0) goto failed;
13191 Py_CLEAR(tmp);
13192 }
13193 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
13194 return -1;
13195 }
13196 if (tmp == NULL || tmp == Py_None) {
13197 Py_CLEAR(tmp);
13198 end_lineno = lineno;
13199 }
13200 else {
13201 int res;
13202 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
13203 goto failed;
13204 }
13205 res = obj2ast_int(state, tmp, &end_lineno, arena);
13206 _Py_LeaveRecursiveCall();
13207 if (res != 0) goto failed;
13208 Py_CLEAR(tmp);
13209 }
13210 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
13211 return -1;
13212 }
13213 if (tmp == NULL || tmp == Py_None) {
13214 Py_CLEAR(tmp);
13215 end_col_offset = col_offset;
13216 }
13217 else {
13218 int res;
13219 if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
13220 goto failed;
13221 }
13222 res = obj2ast_int(state, tmp, &end_col_offset, arena);
13223 _Py_LeaveRecursiveCall();
13224 if (res != 0) goto failed;
13225 Py_CLEAR(tmp);
13226 }
13227 tp = state->BoolOp_type;
13228 isinstance = PyObject_IsInstance(obj, tp);
13229 if (isinstance == -1) {
13230 return -1;
13231 }
13232 if (isinstance) {
13233 boolop_ty op;
13234 asdl_expr_seq* values;
13235
13236 if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
13237 return -1;
13238 }
13239 if (tmp == NULL) {
13240 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
13241 return -1;
13242 }
13243 else {
13244 int res;
13245 if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
13246 goto failed;
13247 }
13248 res = obj2ast_boolop(state, tmp, &op, arena);
13249 _Py_LeaveRecursiveCall();
13250 if (res != 0) goto failed;
13251 Py_CLEAR(tmp);
13252 }
13253 if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
13254 return -1;
13255 }
13256 if (tmp == NULL) {
13257 tmp = PyList_New(0);
13258 if (tmp == NULL) {
13259 return -1;
13260 }
13261 }
13262 {
13263 int res;
13264 Py_ssize_t len;
13265 Py_ssize_t i;
13266 if (!PyList_Check(tmp)) {
13267 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13268 goto failed;
13269 }
13270 len = PyList_GET_SIZE(tmp);
13271 values = _Py_asdl_expr_seq_new(len, arena);
13272 if (values == NULL) goto failed;
13273 for (i = 0; i < len; i++) {
13274 expr_ty val;
13275 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13276 if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
13277 goto failed;
13278 }
13279 res = obj2ast_expr(state, tmp2, &val, arena);
13280 _Py_LeaveRecursiveCall();
13281 Py_DECREF(tmp2);
13282 if (res != 0) goto failed;
13283 if (len != PyList_GET_SIZE(tmp)) {
13284 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
13285 goto failed;
13286 }
13287 asdl_seq_SET(values, i, val);
13288 }
13289 Py_CLEAR(tmp);
13290 }
13291 *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
13292 end_col_offset, arena);
13293 if (*out == NULL) goto failed;
13294 return 0;
13295 }
13296 tp = state->NamedExpr_type;
13297 isinstance = PyObject_IsInstance(obj, tp);
13298 if (isinstance == -1) {
13299 return -1;
13300 }
13301 if (isinstance) {
13302 expr_ty target;
13303 expr_ty value;
13304
13305 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
13306 return -1;
13307 }
13308 if (tmp == NULL) {
13309 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
13310 return -1;
13311 }
13312 else {
13313 int res;
13314 if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
13315 goto failed;
13316 }
13317 res = obj2ast_expr(state, tmp, &target, arena);
13318 _Py_LeaveRecursiveCall();
13319 if (res != 0) goto failed;
13320 Py_CLEAR(tmp);
13321 }
13322 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13323 return -1;
13324 }
13325 if (tmp == NULL) {
13326 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
13327 return -1;
13328 }
13329 else {
13330 int res;
13331 if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
13332 goto failed;
13333 }
13334 res = obj2ast_expr(state, tmp, &value, arena);
13335 _Py_LeaveRecursiveCall();
13336 if (res != 0) goto failed;
13337 Py_CLEAR(tmp);
13338 }
13339 *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
13340 end_col_offset, arena);
13341 if (*out == NULL) goto failed;
13342 return 0;
13343 }
13344 tp = state->BinOp_type;
13345 isinstance = PyObject_IsInstance(obj, tp);
13346 if (isinstance == -1) {
13347 return -1;
13348 }
13349 if (isinstance) {
13350 expr_ty left;
13351 operator_ty op;
13352 expr_ty right;
13353
13354 if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
13355 return -1;
13356 }
13357 if (tmp == NULL) {
13358 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
13359 return -1;
13360 }
13361 else {
13362 int res;
13363 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
13364 goto failed;
13365 }
13366 res = obj2ast_expr(state, tmp, &left, arena);
13367 _Py_LeaveRecursiveCall();
13368 if (res != 0) goto failed;
13369 Py_CLEAR(tmp);
13370 }
13371 if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
13372 return -1;
13373 }
13374 if (tmp == NULL) {
13375 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
13376 return -1;
13377 }
13378 else {
13379 int res;
13380 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
13381 goto failed;
13382 }
13383 res = obj2ast_operator(state, tmp, &op, arena);
13384 _Py_LeaveRecursiveCall();
13385 if (res != 0) goto failed;
13386 Py_CLEAR(tmp);
13387 }
13388 if (PyObject_GetOptionalAttr(obj, state->right, &tmp) < 0) {
13389 return -1;
13390 }
13391 if (tmp == NULL) {
13392 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
13393 return -1;
13394 }
13395 else {
13396 int res;
13397 if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
13398 goto failed;
13399 }
13400 res = obj2ast_expr(state, tmp, &right, arena);
13401 _Py_LeaveRecursiveCall();
13402 if (res != 0) goto failed;
13403 Py_CLEAR(tmp);
13404 }
13405 *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
13406 end_col_offset, arena);
13407 if (*out == NULL) goto failed;
13408 return 0;
13409 }
13410 tp = state->UnaryOp_type;
13411 isinstance = PyObject_IsInstance(obj, tp);
13412 if (isinstance == -1) {
13413 return -1;
13414 }
13415 if (isinstance) {
13416 unaryop_ty op;
13417 expr_ty operand;
13418
13419 if (PyObject_GetOptionalAttr(obj, state->op, &tmp) < 0) {
13420 return -1;
13421 }
13422 if (tmp == NULL) {
13423 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
13424 return -1;
13425 }
13426 else {
13427 int res;
13428 if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
13429 goto failed;
13430 }
13431 res = obj2ast_unaryop(state, tmp, &op, arena);
13432 _Py_LeaveRecursiveCall();
13433 if (res != 0) goto failed;
13434 Py_CLEAR(tmp);
13435 }
13436 if (PyObject_GetOptionalAttr(obj, state->operand, &tmp) < 0) {
13437 return -1;
13438 }
13439 if (tmp == NULL) {
13440 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
13441 return -1;
13442 }
13443 else {
13444 int res;
13445 if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
13446 goto failed;
13447 }
13448 res = obj2ast_expr(state, tmp, &operand, arena);
13449 _Py_LeaveRecursiveCall();
13450 if (res != 0) goto failed;
13451 Py_CLEAR(tmp);
13452 }
13453 *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
13454 end_col_offset, arena);
13455 if (*out == NULL) goto failed;
13456 return 0;
13457 }
13458 tp = state->Lambda_type;
13459 isinstance = PyObject_IsInstance(obj, tp);
13460 if (isinstance == -1) {
13461 return -1;
13462 }
13463 if (isinstance) {
13464 arguments_ty args;
13465 expr_ty body;
13466
13467 if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
13468 return -1;
13469 }
13470 if (tmp == NULL) {
13471 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
13472 return -1;
13473 }
13474 else {
13475 int res;
13476 if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
13477 goto failed;
13478 }
13479 res = obj2ast_arguments(state, tmp, &args, arena);
13480 _Py_LeaveRecursiveCall();
13481 if (res != 0) goto failed;
13482 Py_CLEAR(tmp);
13483 }
13484 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
13485 return -1;
13486 }
13487 if (tmp == NULL) {
13488 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
13489 return -1;
13490 }
13491 else {
13492 int res;
13493 if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
13494 goto failed;
13495 }
13496 res = obj2ast_expr(state, tmp, &body, arena);
13497 _Py_LeaveRecursiveCall();
13498 if (res != 0) goto failed;
13499 Py_CLEAR(tmp);
13500 }
13501 *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
13502 end_col_offset, arena);
13503 if (*out == NULL) goto failed;
13504 return 0;
13505 }
13506 tp = state->IfExp_type;
13507 isinstance = PyObject_IsInstance(obj, tp);
13508 if (isinstance == -1) {
13509 return -1;
13510 }
13511 if (isinstance) {
13512 expr_ty test;
13513 expr_ty body;
13514 expr_ty orelse;
13515
13516 if (PyObject_GetOptionalAttr(obj, state->test, &tmp) < 0) {
13517 return -1;
13518 }
13519 if (tmp == NULL) {
13520 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
13521 return -1;
13522 }
13523 else {
13524 int res;
13525 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
13526 goto failed;
13527 }
13528 res = obj2ast_expr(state, tmp, &test, arena);
13529 _Py_LeaveRecursiveCall();
13530 if (res != 0) goto failed;
13531 Py_CLEAR(tmp);
13532 }
13533 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
13534 return -1;
13535 }
13536 if (tmp == NULL) {
13537 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
13538 return -1;
13539 }
13540 else {
13541 int res;
13542 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
13543 goto failed;
13544 }
13545 res = obj2ast_expr(state, tmp, &body, arena);
13546 _Py_LeaveRecursiveCall();
13547 if (res != 0) goto failed;
13548 Py_CLEAR(tmp);
13549 }
13550 if (PyObject_GetOptionalAttr(obj, state->orelse, &tmp) < 0) {
13551 return -1;
13552 }
13553 if (tmp == NULL) {
13554 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
13555 return -1;
13556 }
13557 else {
13558 int res;
13559 if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
13560 goto failed;
13561 }
13562 res = obj2ast_expr(state, tmp, &orelse, arena);
13563 _Py_LeaveRecursiveCall();
13564 if (res != 0) goto failed;
13565 Py_CLEAR(tmp);
13566 }
13567 *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
13568 end_col_offset, arena);
13569 if (*out == NULL) goto failed;
13570 return 0;
13571 }
13572 tp = state->Dict_type;
13573 isinstance = PyObject_IsInstance(obj, tp);
13574 if (isinstance == -1) {
13575 return -1;
13576 }
13577 if (isinstance) {
13578 asdl_expr_seq* keys;
13579 asdl_expr_seq* values;
13580
13581 if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
13582 return -1;
13583 }
13584 if (tmp == NULL) {
13585 tmp = PyList_New(0);
13586 if (tmp == NULL) {
13587 return -1;
13588 }
13589 }
13590 {
13591 int res;
13592 Py_ssize_t len;
13593 Py_ssize_t i;
13594 if (!PyList_Check(tmp)) {
13595 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13596 goto failed;
13597 }
13598 len = PyList_GET_SIZE(tmp);
13599 keys = _Py_asdl_expr_seq_new(len, arena);
13600 if (keys == NULL) goto failed;
13601 for (i = 0; i < len; i++) {
13602 expr_ty val;
13603 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13604 if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
13605 goto failed;
13606 }
13607 res = obj2ast_expr(state, tmp2, &val, arena);
13608 _Py_LeaveRecursiveCall();
13609 Py_DECREF(tmp2);
13610 if (res != 0) goto failed;
13611 if (len != PyList_GET_SIZE(tmp)) {
13612 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
13613 goto failed;
13614 }
13615 asdl_seq_SET(keys, i, val);
13616 }
13617 Py_CLEAR(tmp);
13618 }
13619 if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
13620 return -1;
13621 }
13622 if (tmp == NULL) {
13623 tmp = PyList_New(0);
13624 if (tmp == NULL) {
13625 return -1;
13626 }
13627 }
13628 {
13629 int res;
13630 Py_ssize_t len;
13631 Py_ssize_t i;
13632 if (!PyList_Check(tmp)) {
13633 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13634 goto failed;
13635 }
13636 len = PyList_GET_SIZE(tmp);
13637 values = _Py_asdl_expr_seq_new(len, arena);
13638 if (values == NULL) goto failed;
13639 for (i = 0; i < len; i++) {
13640 expr_ty val;
13641 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13642 if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
13643 goto failed;
13644 }
13645 res = obj2ast_expr(state, tmp2, &val, arena);
13646 _Py_LeaveRecursiveCall();
13647 Py_DECREF(tmp2);
13648 if (res != 0) goto failed;
13649 if (len != PyList_GET_SIZE(tmp)) {
13650 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
13651 goto failed;
13652 }
13653 asdl_seq_SET(values, i, val);
13654 }
13655 Py_CLEAR(tmp);
13656 }
13657 *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
13658 end_col_offset, arena);
13659 if (*out == NULL) goto failed;
13660 return 0;
13661 }
13662 tp = state->Set_type;
13663 isinstance = PyObject_IsInstance(obj, tp);
13664 if (isinstance == -1) {
13665 return -1;
13666 }
13667 if (isinstance) {
13668 asdl_expr_seq* elts;
13669
13670 if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
13671 return -1;
13672 }
13673 if (tmp == NULL) {
13674 tmp = PyList_New(0);
13675 if (tmp == NULL) {
13676 return -1;
13677 }
13678 }
13679 {
13680 int res;
13681 Py_ssize_t len;
13682 Py_ssize_t i;
13683 if (!PyList_Check(tmp)) {
13684 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13685 goto failed;
13686 }
13687 len = PyList_GET_SIZE(tmp);
13688 elts = _Py_asdl_expr_seq_new(len, arena);
13689 if (elts == NULL) goto failed;
13690 for (i = 0; i < len; i++) {
13691 expr_ty val;
13692 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13693 if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
13694 goto failed;
13695 }
13696 res = obj2ast_expr(state, tmp2, &val, arena);
13697 _Py_LeaveRecursiveCall();
13698 Py_DECREF(tmp2);
13699 if (res != 0) goto failed;
13700 if (len != PyList_GET_SIZE(tmp)) {
13701 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
13702 goto failed;
13703 }
13704 asdl_seq_SET(elts, i, val);
13705 }
13706 Py_CLEAR(tmp);
13707 }
13708 *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
13709 arena);
13710 if (*out == NULL) goto failed;
13711 return 0;
13712 }
13713 tp = state->ListComp_type;
13714 isinstance = PyObject_IsInstance(obj, tp);
13715 if (isinstance == -1) {
13716 return -1;
13717 }
13718 if (isinstance) {
13719 expr_ty elt;
13720 asdl_comprehension_seq* generators;
13721
13722 if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
13723 return -1;
13724 }
13725 if (tmp == NULL) {
13726 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
13727 return -1;
13728 }
13729 else {
13730 int res;
13731 if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
13732 goto failed;
13733 }
13734 res = obj2ast_expr(state, tmp, &elt, arena);
13735 _Py_LeaveRecursiveCall();
13736 if (res != 0) goto failed;
13737 Py_CLEAR(tmp);
13738 }
13739 if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
13740 return -1;
13741 }
13742 if (tmp == NULL) {
13743 tmp = PyList_New(0);
13744 if (tmp == NULL) {
13745 return -1;
13746 }
13747 }
13748 {
13749 int res;
13750 Py_ssize_t len;
13751 Py_ssize_t i;
13752 if (!PyList_Check(tmp)) {
13753 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13754 goto failed;
13755 }
13756 len = PyList_GET_SIZE(tmp);
13757 generators = _Py_asdl_comprehension_seq_new(len, arena);
13758 if (generators == NULL) goto failed;
13759 for (i = 0; i < len; i++) {
13760 comprehension_ty val;
13761 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13762 if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
13763 goto failed;
13764 }
13765 res = obj2ast_comprehension(state, tmp2, &val, arena);
13766 _Py_LeaveRecursiveCall();
13767 Py_DECREF(tmp2);
13768 if (res != 0) goto failed;
13769 if (len != PyList_GET_SIZE(tmp)) {
13770 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
13771 goto failed;
13772 }
13773 asdl_seq_SET(generators, i, val);
13774 }
13775 Py_CLEAR(tmp);
13776 }
13777 *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
13778 end_col_offset, arena);
13779 if (*out == NULL) goto failed;
13780 return 0;
13781 }
13782 tp = state->SetComp_type;
13783 isinstance = PyObject_IsInstance(obj, tp);
13784 if (isinstance == -1) {
13785 return -1;
13786 }
13787 if (isinstance) {
13788 expr_ty elt;
13789 asdl_comprehension_seq* generators;
13790
13791 if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
13792 return -1;
13793 }
13794 if (tmp == NULL) {
13795 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
13796 return -1;
13797 }
13798 else {
13799 int res;
13800 if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
13801 goto failed;
13802 }
13803 res = obj2ast_expr(state, tmp, &elt, arena);
13804 _Py_LeaveRecursiveCall();
13805 if (res != 0) goto failed;
13806 Py_CLEAR(tmp);
13807 }
13808 if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
13809 return -1;
13810 }
13811 if (tmp == NULL) {
13812 tmp = PyList_New(0);
13813 if (tmp == NULL) {
13814 return -1;
13815 }
13816 }
13817 {
13818 int res;
13819 Py_ssize_t len;
13820 Py_ssize_t i;
13821 if (!PyList_Check(tmp)) {
13822 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13823 goto failed;
13824 }
13825 len = PyList_GET_SIZE(tmp);
13826 generators = _Py_asdl_comprehension_seq_new(len, arena);
13827 if (generators == NULL) goto failed;
13828 for (i = 0; i < len; i++) {
13829 comprehension_ty val;
13830 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13831 if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
13832 goto failed;
13833 }
13834 res = obj2ast_comprehension(state, tmp2, &val, arena);
13835 _Py_LeaveRecursiveCall();
13836 Py_DECREF(tmp2);
13837 if (res != 0) goto failed;
13838 if (len != PyList_GET_SIZE(tmp)) {
13839 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
13840 goto failed;
13841 }
13842 asdl_seq_SET(generators, i, val);
13843 }
13844 Py_CLEAR(tmp);
13845 }
13846 *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
13847 end_col_offset, arena);
13848 if (*out == NULL) goto failed;
13849 return 0;
13850 }
13851 tp = state->DictComp_type;
13852 isinstance = PyObject_IsInstance(obj, tp);
13853 if (isinstance == -1) {
13854 return -1;
13855 }
13856 if (isinstance) {
13857 expr_ty key;
13858 expr_ty value;
13859 asdl_comprehension_seq* generators;
13860
13861 if (PyObject_GetOptionalAttr(obj, state->key, &tmp) < 0) {
13862 return -1;
13863 }
13864 if (tmp == NULL) {
13865 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
13866 return -1;
13867 }
13868 else {
13869 int res;
13870 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
13871 goto failed;
13872 }
13873 res = obj2ast_expr(state, tmp, &key, arena);
13874 _Py_LeaveRecursiveCall();
13875 if (res != 0) goto failed;
13876 Py_CLEAR(tmp);
13877 }
13878 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
13879 return -1;
13880 }
13881 if (tmp == NULL) {
13882 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
13883 return -1;
13884 }
13885 else {
13886 int res;
13887 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
13888 goto failed;
13889 }
13890 res = obj2ast_expr(state, tmp, &value, arena);
13891 _Py_LeaveRecursiveCall();
13892 if (res != 0) goto failed;
13893 Py_CLEAR(tmp);
13894 }
13895 if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
13896 return -1;
13897 }
13898 if (tmp == NULL) {
13899 tmp = PyList_New(0);
13900 if (tmp == NULL) {
13901 return -1;
13902 }
13903 }
13904 {
13905 int res;
13906 Py_ssize_t len;
13907 Py_ssize_t i;
13908 if (!PyList_Check(tmp)) {
13909 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13910 goto failed;
13911 }
13912 len = PyList_GET_SIZE(tmp);
13913 generators = _Py_asdl_comprehension_seq_new(len, arena);
13914 if (generators == NULL) goto failed;
13915 for (i = 0; i < len; i++) {
13916 comprehension_ty val;
13917 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13918 if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
13919 goto failed;
13920 }
13921 res = obj2ast_comprehension(state, tmp2, &val, arena);
13922 _Py_LeaveRecursiveCall();
13923 Py_DECREF(tmp2);
13924 if (res != 0) goto failed;
13925 if (len != PyList_GET_SIZE(tmp)) {
13926 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
13927 goto failed;
13928 }
13929 asdl_seq_SET(generators, i, val);
13930 }
13931 Py_CLEAR(tmp);
13932 }
13933 *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
13934 end_lineno, end_col_offset, arena);
13935 if (*out == NULL) goto failed;
13936 return 0;
13937 }
13938 tp = state->GeneratorExp_type;
13939 isinstance = PyObject_IsInstance(obj, tp);
13940 if (isinstance == -1) {
13941 return -1;
13942 }
13943 if (isinstance) {
13944 expr_ty elt;
13945 asdl_comprehension_seq* generators;
13946
13947 if (PyObject_GetOptionalAttr(obj, state->elt, &tmp) < 0) {
13948 return -1;
13949 }
13950 if (tmp == NULL) {
13951 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
13952 return -1;
13953 }
13954 else {
13955 int res;
13956 if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
13957 goto failed;
13958 }
13959 res = obj2ast_expr(state, tmp, &elt, arena);
13960 _Py_LeaveRecursiveCall();
13961 if (res != 0) goto failed;
13962 Py_CLEAR(tmp);
13963 }
13964 if (PyObject_GetOptionalAttr(obj, state->generators, &tmp) < 0) {
13965 return -1;
13966 }
13967 if (tmp == NULL) {
13968 tmp = PyList_New(0);
13969 if (tmp == NULL) {
13970 return -1;
13971 }
13972 }
13973 {
13974 int res;
13975 Py_ssize_t len;
13976 Py_ssize_t i;
13977 if (!PyList_Check(tmp)) {
13978 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
13979 goto failed;
13980 }
13981 len = PyList_GET_SIZE(tmp);
13982 generators = _Py_asdl_comprehension_seq_new(len, arena);
13983 if (generators == NULL) goto failed;
13984 for (i = 0; i < len; i++) {
13985 comprehension_ty val;
13986 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
13987 if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
13988 goto failed;
13989 }
13990 res = obj2ast_comprehension(state, tmp2, &val, arena);
13991 _Py_LeaveRecursiveCall();
13992 Py_DECREF(tmp2);
13993 if (res != 0) goto failed;
13994 if (len != PyList_GET_SIZE(tmp)) {
13995 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
13996 goto failed;
13997 }
13998 asdl_seq_SET(generators, i, val);
13999 }
14000 Py_CLEAR(tmp);
14001 }
14002 *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
14003 end_lineno, end_col_offset, arena);
14004 if (*out == NULL) goto failed;
14005 return 0;
14006 }
14007 tp = state->Await_type;
14008 isinstance = PyObject_IsInstance(obj, tp);
14009 if (isinstance == -1) {
14010 return -1;
14011 }
14012 if (isinstance) {
14013 expr_ty value;
14014
14015 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14016 return -1;
14017 }
14018 if (tmp == NULL) {
14019 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
14020 return -1;
14021 }
14022 else {
14023 int res;
14024 if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
14025 goto failed;
14026 }
14027 res = obj2ast_expr(state, tmp, &value, arena);
14028 _Py_LeaveRecursiveCall();
14029 if (res != 0) goto failed;
14030 Py_CLEAR(tmp);
14031 }
14032 *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
14033 end_col_offset, arena);
14034 if (*out == NULL) goto failed;
14035 return 0;
14036 }
14037 tp = state->Yield_type;
14038 isinstance = PyObject_IsInstance(obj, tp);
14039 if (isinstance == -1) {
14040 return -1;
14041 }
14042 if (isinstance) {
14043 expr_ty value;
14044
14045 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14046 return -1;
14047 }
14048 if (tmp == NULL || tmp == Py_None) {
14049 Py_CLEAR(tmp);
14050 value = NULL;
14051 }
14052 else {
14053 int res;
14054 if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
14055 goto failed;
14056 }
14057 res = obj2ast_expr(state, tmp, &value, arena);
14058 _Py_LeaveRecursiveCall();
14059 if (res != 0) goto failed;
14060 Py_CLEAR(tmp);
14061 }
14062 *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
14063 end_col_offset, arena);
14064 if (*out == NULL) goto failed;
14065 return 0;
14066 }
14067 tp = state->YieldFrom_type;
14068 isinstance = PyObject_IsInstance(obj, tp);
14069 if (isinstance == -1) {
14070 return -1;
14071 }
14072 if (isinstance) {
14073 expr_ty value;
14074
14075 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14076 return -1;
14077 }
14078 if (tmp == NULL) {
14079 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
14080 return -1;
14081 }
14082 else {
14083 int res;
14084 if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
14085 goto failed;
14086 }
14087 res = obj2ast_expr(state, tmp, &value, arena);
14088 _Py_LeaveRecursiveCall();
14089 if (res != 0) goto failed;
14090 Py_CLEAR(tmp);
14091 }
14092 *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
14093 end_col_offset, arena);
14094 if (*out == NULL) goto failed;
14095 return 0;
14096 }
14097 tp = state->Compare_type;
14098 isinstance = PyObject_IsInstance(obj, tp);
14099 if (isinstance == -1) {
14100 return -1;
14101 }
14102 if (isinstance) {
14103 expr_ty left;
14104 asdl_int_seq* ops;
14105 asdl_expr_seq* comparators;
14106
14107 if (PyObject_GetOptionalAttr(obj, state->left, &tmp) < 0) {
14108 return -1;
14109 }
14110 if (tmp == NULL) {
14111 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
14112 return -1;
14113 }
14114 else {
14115 int res;
14116 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
14117 goto failed;
14118 }
14119 res = obj2ast_expr(state, tmp, &left, arena);
14120 _Py_LeaveRecursiveCall();
14121 if (res != 0) goto failed;
14122 Py_CLEAR(tmp);
14123 }
14124 if (PyObject_GetOptionalAttr(obj, state->ops, &tmp) < 0) {
14125 return -1;
14126 }
14127 if (tmp == NULL) {
14128 tmp = PyList_New(0);
14129 if (tmp == NULL) {
14130 return -1;
14131 }
14132 }
14133 {
14134 int res;
14135 Py_ssize_t len;
14136 Py_ssize_t i;
14137 if (!PyList_Check(tmp)) {
14138 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14139 goto failed;
14140 }
14141 len = PyList_GET_SIZE(tmp);
14142 ops = _Py_asdl_int_seq_new(len, arena);
14143 if (ops == NULL) goto failed;
14144 for (i = 0; i < len; i++) {
14145 cmpop_ty val;
14146 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14147 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
14148 goto failed;
14149 }
14150 res = obj2ast_cmpop(state, tmp2, &val, arena);
14151 _Py_LeaveRecursiveCall();
14152 Py_DECREF(tmp2);
14153 if (res != 0) goto failed;
14154 if (len != PyList_GET_SIZE(tmp)) {
14155 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
14156 goto failed;
14157 }
14158 asdl_seq_SET(ops, i, val);
14159 }
14160 Py_CLEAR(tmp);
14161 }
14162 if (PyObject_GetOptionalAttr(obj, state->comparators, &tmp) < 0) {
14163 return -1;
14164 }
14165 if (tmp == NULL) {
14166 tmp = PyList_New(0);
14167 if (tmp == NULL) {
14168 return -1;
14169 }
14170 }
14171 {
14172 int res;
14173 Py_ssize_t len;
14174 Py_ssize_t i;
14175 if (!PyList_Check(tmp)) {
14176 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14177 goto failed;
14178 }
14179 len = PyList_GET_SIZE(tmp);
14180 comparators = _Py_asdl_expr_seq_new(len, arena);
14181 if (comparators == NULL) goto failed;
14182 for (i = 0; i < len; i++) {
14183 expr_ty val;
14184 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14185 if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
14186 goto failed;
14187 }
14188 res = obj2ast_expr(state, tmp2, &val, arena);
14189 _Py_LeaveRecursiveCall();
14190 Py_DECREF(tmp2);
14191 if (res != 0) goto failed;
14192 if (len != PyList_GET_SIZE(tmp)) {
14193 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
14194 goto failed;
14195 }
14196 asdl_seq_SET(comparators, i, val);
14197 }
14198 Py_CLEAR(tmp);
14199 }
14200 *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
14201 end_lineno, end_col_offset, arena);
14202 if (*out == NULL) goto failed;
14203 return 0;
14204 }
14205 tp = state->Call_type;
14206 isinstance = PyObject_IsInstance(obj, tp);
14207 if (isinstance == -1) {
14208 return -1;
14209 }
14210 if (isinstance) {
14211 expr_ty func;
14212 asdl_expr_seq* args;
14213 asdl_keyword_seq* keywords;
14214
14215 if (PyObject_GetOptionalAttr(obj, state->func, &tmp) < 0) {
14216 return -1;
14217 }
14218 if (tmp == NULL) {
14219 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
14220 return -1;
14221 }
14222 else {
14223 int res;
14224 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
14225 goto failed;
14226 }
14227 res = obj2ast_expr(state, tmp, &func, arena);
14228 _Py_LeaveRecursiveCall();
14229 if (res != 0) goto failed;
14230 Py_CLEAR(tmp);
14231 }
14232 if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
14233 return -1;
14234 }
14235 if (tmp == NULL) {
14236 tmp = PyList_New(0);
14237 if (tmp == NULL) {
14238 return -1;
14239 }
14240 }
14241 {
14242 int res;
14243 Py_ssize_t len;
14244 Py_ssize_t i;
14245 if (!PyList_Check(tmp)) {
14246 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14247 goto failed;
14248 }
14249 len = PyList_GET_SIZE(tmp);
14250 args = _Py_asdl_expr_seq_new(len, arena);
14251 if (args == NULL) goto failed;
14252 for (i = 0; i < len; i++) {
14253 expr_ty val;
14254 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14255 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
14256 goto failed;
14257 }
14258 res = obj2ast_expr(state, tmp2, &val, arena);
14259 _Py_LeaveRecursiveCall();
14260 Py_DECREF(tmp2);
14261 if (res != 0) goto failed;
14262 if (len != PyList_GET_SIZE(tmp)) {
14263 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
14264 goto failed;
14265 }
14266 asdl_seq_SET(args, i, val);
14267 }
14268 Py_CLEAR(tmp);
14269 }
14270 if (PyObject_GetOptionalAttr(obj, state->keywords, &tmp) < 0) {
14271 return -1;
14272 }
14273 if (tmp == NULL) {
14274 tmp = PyList_New(0);
14275 if (tmp == NULL) {
14276 return -1;
14277 }
14278 }
14279 {
14280 int res;
14281 Py_ssize_t len;
14282 Py_ssize_t i;
14283 if (!PyList_Check(tmp)) {
14284 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14285 goto failed;
14286 }
14287 len = PyList_GET_SIZE(tmp);
14288 keywords = _Py_asdl_keyword_seq_new(len, arena);
14289 if (keywords == NULL) goto failed;
14290 for (i = 0; i < len; i++) {
14291 keyword_ty val;
14292 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14293 if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
14294 goto failed;
14295 }
14296 res = obj2ast_keyword(state, tmp2, &val, arena);
14297 _Py_LeaveRecursiveCall();
14298 Py_DECREF(tmp2);
14299 if (res != 0) goto failed;
14300 if (len != PyList_GET_SIZE(tmp)) {
14301 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
14302 goto failed;
14303 }
14304 asdl_seq_SET(keywords, i, val);
14305 }
14306 Py_CLEAR(tmp);
14307 }
14308 *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
14309 end_lineno, end_col_offset, arena);
14310 if (*out == NULL) goto failed;
14311 return 0;
14312 }
14313 tp = state->FormattedValue_type;
14314 isinstance = PyObject_IsInstance(obj, tp);
14315 if (isinstance == -1) {
14316 return -1;
14317 }
14318 if (isinstance) {
14319 expr_ty value;
14320 int conversion;
14321 expr_ty format_spec;
14322
14323 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14324 return -1;
14325 }
14326 if (tmp == NULL) {
14327 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
14328 return -1;
14329 }
14330 else {
14331 int res;
14332 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
14333 goto failed;
14334 }
14335 res = obj2ast_expr(state, tmp, &value, arena);
14336 _Py_LeaveRecursiveCall();
14337 if (res != 0) goto failed;
14338 Py_CLEAR(tmp);
14339 }
14340 if (PyObject_GetOptionalAttr(obj, state->conversion, &tmp) < 0) {
14341 return -1;
14342 }
14343 if (tmp == NULL) {
14344 PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
14345 return -1;
14346 }
14347 else {
14348 int res;
14349 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
14350 goto failed;
14351 }
14352 res = obj2ast_int(state, tmp, &conversion, arena);
14353 _Py_LeaveRecursiveCall();
14354 if (res != 0) goto failed;
14355 Py_CLEAR(tmp);
14356 }
14357 if (PyObject_GetOptionalAttr(obj, state->format_spec, &tmp) < 0) {
14358 return -1;
14359 }
14360 if (tmp == NULL || tmp == Py_None) {
14361 Py_CLEAR(tmp);
14362 format_spec = NULL;
14363 }
14364 else {
14365 int res;
14366 if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
14367 goto failed;
14368 }
14369 res = obj2ast_expr(state, tmp, &format_spec, arena);
14370 _Py_LeaveRecursiveCall();
14371 if (res != 0) goto failed;
14372 Py_CLEAR(tmp);
14373 }
14374 *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
14375 col_offset, end_lineno, end_col_offset,
14376 arena);
14377 if (*out == NULL) goto failed;
14378 return 0;
14379 }
14380 tp = state->JoinedStr_type;
14381 isinstance = PyObject_IsInstance(obj, tp);
14382 if (isinstance == -1) {
14383 return -1;
14384 }
14385 if (isinstance) {
14386 asdl_expr_seq* values;
14387
14388 if (PyObject_GetOptionalAttr(obj, state->values, &tmp) < 0) {
14389 return -1;
14390 }
14391 if (tmp == NULL) {
14392 tmp = PyList_New(0);
14393 if (tmp == NULL) {
14394 return -1;
14395 }
14396 }
14397 {
14398 int res;
14399 Py_ssize_t len;
14400 Py_ssize_t i;
14401 if (!PyList_Check(tmp)) {
14402 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14403 goto failed;
14404 }
14405 len = PyList_GET_SIZE(tmp);
14406 values = _Py_asdl_expr_seq_new(len, arena);
14407 if (values == NULL) goto failed;
14408 for (i = 0; i < len; i++) {
14409 expr_ty val;
14410 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14411 if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
14412 goto failed;
14413 }
14414 res = obj2ast_expr(state, tmp2, &val, arena);
14415 _Py_LeaveRecursiveCall();
14416 Py_DECREF(tmp2);
14417 if (res != 0) goto failed;
14418 if (len != PyList_GET_SIZE(tmp)) {
14419 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
14420 goto failed;
14421 }
14422 asdl_seq_SET(values, i, val);
14423 }
14424 Py_CLEAR(tmp);
14425 }
14426 *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
14427 end_col_offset, arena);
14428 if (*out == NULL) goto failed;
14429 return 0;
14430 }
14431 tp = state->Constant_type;
14432 isinstance = PyObject_IsInstance(obj, tp);
14433 if (isinstance == -1) {
14434 return -1;
14435 }
14436 if (isinstance) {
14437 constant value;
14438 string kind;
14439
14440 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14441 return -1;
14442 }
14443 if (tmp == NULL) {
14444 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
14445 return -1;
14446 }
14447 else {
14448 int res;
14449 if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
14450 goto failed;
14451 }
14452 res = obj2ast_constant(state, tmp, &value, arena);
14453 _Py_LeaveRecursiveCall();
14454 if (res != 0) goto failed;
14455 Py_CLEAR(tmp);
14456 }
14457 if (PyObject_GetOptionalAttr(obj, state->kind, &tmp) < 0) {
14458 return -1;
14459 }
14460 if (tmp == NULL || tmp == Py_None) {
14461 Py_CLEAR(tmp);
14462 kind = NULL;
14463 }
14464 else {
14465 int res;
14466 if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
14467 goto failed;
14468 }
14469 res = obj2ast_string(state, tmp, &kind, arena);
14470 _Py_LeaveRecursiveCall();
14471 if (res != 0) goto failed;
14472 Py_CLEAR(tmp);
14473 }
14474 *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
14475 end_col_offset, arena);
14476 if (*out == NULL) goto failed;
14477 return 0;
14478 }
14479 tp = state->Attribute_type;
14480 isinstance = PyObject_IsInstance(obj, tp);
14481 if (isinstance == -1) {
14482 return -1;
14483 }
14484 if (isinstance) {
14485 expr_ty value;
14486 identifier attr;
14487 expr_context_ty ctx;
14488
14489 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14490 return -1;
14491 }
14492 if (tmp == NULL) {
14493 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
14494 return -1;
14495 }
14496 else {
14497 int res;
14498 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
14499 goto failed;
14500 }
14501 res = obj2ast_expr(state, tmp, &value, arena);
14502 _Py_LeaveRecursiveCall();
14503 if (res != 0) goto failed;
14504 Py_CLEAR(tmp);
14505 }
14506 if (PyObject_GetOptionalAttr(obj, state->attr, &tmp) < 0) {
14507 return -1;
14508 }
14509 if (tmp == NULL) {
14510 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
14511 return -1;
14512 }
14513 else {
14514 int res;
14515 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
14516 goto failed;
14517 }
14518 res = obj2ast_identifier(state, tmp, &attr, arena);
14519 _Py_LeaveRecursiveCall();
14520 if (res != 0) goto failed;
14521 Py_CLEAR(tmp);
14522 }
14523 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14524 return -1;
14525 }
14526 if (tmp == NULL) {
14527 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
14528 return -1;
14529 }
14530 else {
14531 int res;
14532 if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
14533 goto failed;
14534 }
14535 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14536 _Py_LeaveRecursiveCall();
14537 if (res != 0) goto failed;
14538 Py_CLEAR(tmp);
14539 }
14540 *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
14541 end_lineno, end_col_offset, arena);
14542 if (*out == NULL) goto failed;
14543 return 0;
14544 }
14545 tp = state->Subscript_type;
14546 isinstance = PyObject_IsInstance(obj, tp);
14547 if (isinstance == -1) {
14548 return -1;
14549 }
14550 if (isinstance) {
14551 expr_ty value;
14552 expr_ty slice;
14553 expr_context_ty ctx;
14554
14555 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14556 return -1;
14557 }
14558 if (tmp == NULL) {
14559 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
14560 return -1;
14561 }
14562 else {
14563 int res;
14564 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
14565 goto failed;
14566 }
14567 res = obj2ast_expr(state, tmp, &value, arena);
14568 _Py_LeaveRecursiveCall();
14569 if (res != 0) goto failed;
14570 Py_CLEAR(tmp);
14571 }
14572 if (PyObject_GetOptionalAttr(obj, state->slice, &tmp) < 0) {
14573 return -1;
14574 }
14575 if (tmp == NULL) {
14576 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
14577 return -1;
14578 }
14579 else {
14580 int res;
14581 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
14582 goto failed;
14583 }
14584 res = obj2ast_expr(state, tmp, &slice, arena);
14585 _Py_LeaveRecursiveCall();
14586 if (res != 0) goto failed;
14587 Py_CLEAR(tmp);
14588 }
14589 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14590 return -1;
14591 }
14592 if (tmp == NULL) {
14593 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
14594 return -1;
14595 }
14596 else {
14597 int res;
14598 if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
14599 goto failed;
14600 }
14601 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14602 _Py_LeaveRecursiveCall();
14603 if (res != 0) goto failed;
14604 Py_CLEAR(tmp);
14605 }
14606 *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
14607 end_lineno, end_col_offset, arena);
14608 if (*out == NULL) goto failed;
14609 return 0;
14610 }
14611 tp = state->Starred_type;
14612 isinstance = PyObject_IsInstance(obj, tp);
14613 if (isinstance == -1) {
14614 return -1;
14615 }
14616 if (isinstance) {
14617 expr_ty value;
14618 expr_context_ty ctx;
14619
14620 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
14621 return -1;
14622 }
14623 if (tmp == NULL) {
14624 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
14625 return -1;
14626 }
14627 else {
14628 int res;
14629 if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
14630 goto failed;
14631 }
14632 res = obj2ast_expr(state, tmp, &value, arena);
14633 _Py_LeaveRecursiveCall();
14634 if (res != 0) goto failed;
14635 Py_CLEAR(tmp);
14636 }
14637 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14638 return -1;
14639 }
14640 if (tmp == NULL) {
14641 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
14642 return -1;
14643 }
14644 else {
14645 int res;
14646 if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
14647 goto failed;
14648 }
14649 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14650 _Py_LeaveRecursiveCall();
14651 if (res != 0) goto failed;
14652 Py_CLEAR(tmp);
14653 }
14654 *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
14655 end_col_offset, arena);
14656 if (*out == NULL) goto failed;
14657 return 0;
14658 }
14659 tp = state->Name_type;
14660 isinstance = PyObject_IsInstance(obj, tp);
14661 if (isinstance == -1) {
14662 return -1;
14663 }
14664 if (isinstance) {
14665 identifier id;
14666 expr_context_ty ctx;
14667
14668 if (PyObject_GetOptionalAttr(obj, state->id, &tmp) < 0) {
14669 return -1;
14670 }
14671 if (tmp == NULL) {
14672 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
14673 return -1;
14674 }
14675 else {
14676 int res;
14677 if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
14678 goto failed;
14679 }
14680 res = obj2ast_identifier(state, tmp, &id, arena);
14681 _Py_LeaveRecursiveCall();
14682 if (res != 0) goto failed;
14683 Py_CLEAR(tmp);
14684 }
14685 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14686 return -1;
14687 }
14688 if (tmp == NULL) {
14689 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
14690 return -1;
14691 }
14692 else {
14693 int res;
14694 if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
14695 goto failed;
14696 }
14697 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14698 _Py_LeaveRecursiveCall();
14699 if (res != 0) goto failed;
14700 Py_CLEAR(tmp);
14701 }
14702 *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
14703 end_col_offset, arena);
14704 if (*out == NULL) goto failed;
14705 return 0;
14706 }
14707 tp = state->List_type;
14708 isinstance = PyObject_IsInstance(obj, tp);
14709 if (isinstance == -1) {
14710 return -1;
14711 }
14712 if (isinstance) {
14713 asdl_expr_seq* elts;
14714 expr_context_ty ctx;
14715
14716 if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
14717 return -1;
14718 }
14719 if (tmp == NULL) {
14720 tmp = PyList_New(0);
14721 if (tmp == NULL) {
14722 return -1;
14723 }
14724 }
14725 {
14726 int res;
14727 Py_ssize_t len;
14728 Py_ssize_t i;
14729 if (!PyList_Check(tmp)) {
14730 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14731 goto failed;
14732 }
14733 len = PyList_GET_SIZE(tmp);
14734 elts = _Py_asdl_expr_seq_new(len, arena);
14735 if (elts == NULL) goto failed;
14736 for (i = 0; i < len; i++) {
14737 expr_ty val;
14738 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14739 if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
14740 goto failed;
14741 }
14742 res = obj2ast_expr(state, tmp2, &val, arena);
14743 _Py_LeaveRecursiveCall();
14744 Py_DECREF(tmp2);
14745 if (res != 0) goto failed;
14746 if (len != PyList_GET_SIZE(tmp)) {
14747 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
14748 goto failed;
14749 }
14750 asdl_seq_SET(elts, i, val);
14751 }
14752 Py_CLEAR(tmp);
14753 }
14754 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14755 return -1;
14756 }
14757 if (tmp == NULL) {
14758 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
14759 return -1;
14760 }
14761 else {
14762 int res;
14763 if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
14764 goto failed;
14765 }
14766 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14767 _Py_LeaveRecursiveCall();
14768 if (res != 0) goto failed;
14769 Py_CLEAR(tmp);
14770 }
14771 *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
14772 end_col_offset, arena);
14773 if (*out == NULL) goto failed;
14774 return 0;
14775 }
14776 tp = state->Tuple_type;
14777 isinstance = PyObject_IsInstance(obj, tp);
14778 if (isinstance == -1) {
14779 return -1;
14780 }
14781 if (isinstance) {
14782 asdl_expr_seq* elts;
14783 expr_context_ty ctx;
14784
14785 if (PyObject_GetOptionalAttr(obj, state->elts, &tmp) < 0) {
14786 return -1;
14787 }
14788 if (tmp == NULL) {
14789 tmp = PyList_New(0);
14790 if (tmp == NULL) {
14791 return -1;
14792 }
14793 }
14794 {
14795 int res;
14796 Py_ssize_t len;
14797 Py_ssize_t i;
14798 if (!PyList_Check(tmp)) {
14799 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
14800 goto failed;
14801 }
14802 len = PyList_GET_SIZE(tmp);
14803 elts = _Py_asdl_expr_seq_new(len, arena);
14804 if (elts == NULL) goto failed;
14805 for (i = 0; i < len; i++) {
14806 expr_ty val;
14807 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
14808 if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
14809 goto failed;
14810 }
14811 res = obj2ast_expr(state, tmp2, &val, arena);
14812 _Py_LeaveRecursiveCall();
14813 Py_DECREF(tmp2);
14814 if (res != 0) goto failed;
14815 if (len != PyList_GET_SIZE(tmp)) {
14816 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
14817 goto failed;
14818 }
14819 asdl_seq_SET(elts, i, val);
14820 }
14821 Py_CLEAR(tmp);
14822 }
14823 if (PyObject_GetOptionalAttr(obj, state->ctx, &tmp) < 0) {
14824 return -1;
14825 }
14826 if (tmp == NULL) {
14827 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
14828 return -1;
14829 }
14830 else {
14831 int res;
14832 if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
14833 goto failed;
14834 }
14835 res = obj2ast_expr_context(state, tmp, &ctx, arena);
14836 _Py_LeaveRecursiveCall();
14837 if (res != 0) goto failed;
14838 Py_CLEAR(tmp);
14839 }
14840 *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
14841 end_col_offset, arena);
14842 if (*out == NULL) goto failed;
14843 return 0;
14844 }
14845 tp = state->Slice_type;
14846 isinstance = PyObject_IsInstance(obj, tp);
14847 if (isinstance == -1) {
14848 return -1;
14849 }
14850 if (isinstance) {
14851 expr_ty lower;
14852 expr_ty upper;
14853 expr_ty step;
14854
14855 if (PyObject_GetOptionalAttr(obj, state->lower, &tmp) < 0) {
14856 return -1;
14857 }
14858 if (tmp == NULL || tmp == Py_None) {
14859 Py_CLEAR(tmp);
14860 lower = NULL;
14861 }
14862 else {
14863 int res;
14864 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
14865 goto failed;
14866 }
14867 res = obj2ast_expr(state, tmp, &lower, arena);
14868 _Py_LeaveRecursiveCall();
14869 if (res != 0) goto failed;
14870 Py_CLEAR(tmp);
14871 }
14872 if (PyObject_GetOptionalAttr(obj, state->upper, &tmp) < 0) {
14873 return -1;
14874 }
14875 if (tmp == NULL || tmp == Py_None) {
14876 Py_CLEAR(tmp);
14877 upper = NULL;
14878 }
14879 else {
14880 int res;
14881 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
14882 goto failed;
14883 }
14884 res = obj2ast_expr(state, tmp, &upper, arena);
14885 _Py_LeaveRecursiveCall();
14886 if (res != 0) goto failed;
14887 Py_CLEAR(tmp);
14888 }
14889 if (PyObject_GetOptionalAttr(obj, state->step, &tmp) < 0) {
14890 return -1;
14891 }
14892 if (tmp == NULL || tmp == Py_None) {
14893 Py_CLEAR(tmp);
14894 step = NULL;
14895 }
14896 else {
14897 int res;
14898 if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
14899 goto failed;
14900 }
14901 res = obj2ast_expr(state, tmp, &step, arena);
14902 _Py_LeaveRecursiveCall();
14903 if (res != 0) goto failed;
14904 Py_CLEAR(tmp);
14905 }
14906 *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
14907 end_col_offset, arena);
14908 if (*out == NULL) goto failed;
14909 return 0;
14910 }
14911
14912 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
14913 failed:
14914 Py_XDECREF(tmp);
14915 return -1;
14916 }
14917
14918 int
obj2ast_expr_context(struct ast_state * state,PyObject * obj,expr_context_ty * out,PyArena * arena)14919 obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
14920 out, PyArena* arena)
14921 {
14922 int isinstance;
14923
14924 isinstance = PyObject_IsInstance(obj, state->Load_type);
14925 if (isinstance == -1) {
14926 return -1;
14927 }
14928 if (isinstance) {
14929 *out = Load;
14930 return 0;
14931 }
14932 isinstance = PyObject_IsInstance(obj, state->Store_type);
14933 if (isinstance == -1) {
14934 return -1;
14935 }
14936 if (isinstance) {
14937 *out = Store;
14938 return 0;
14939 }
14940 isinstance = PyObject_IsInstance(obj, state->Del_type);
14941 if (isinstance == -1) {
14942 return -1;
14943 }
14944 if (isinstance) {
14945 *out = Del;
14946 return 0;
14947 }
14948
14949 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
14950 return -1;
14951 }
14952
14953 int
obj2ast_boolop(struct ast_state * state,PyObject * obj,boolop_ty * out,PyArena * arena)14954 obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
14955 arena)
14956 {
14957 int isinstance;
14958
14959 isinstance = PyObject_IsInstance(obj, state->And_type);
14960 if (isinstance == -1) {
14961 return -1;
14962 }
14963 if (isinstance) {
14964 *out = And;
14965 return 0;
14966 }
14967 isinstance = PyObject_IsInstance(obj, state->Or_type);
14968 if (isinstance == -1) {
14969 return -1;
14970 }
14971 if (isinstance) {
14972 *out = Or;
14973 return 0;
14974 }
14975
14976 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
14977 return -1;
14978 }
14979
14980 int
obj2ast_operator(struct ast_state * state,PyObject * obj,operator_ty * out,PyArena * arena)14981 obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
14982 PyArena* arena)
14983 {
14984 int isinstance;
14985
14986 isinstance = PyObject_IsInstance(obj, state->Add_type);
14987 if (isinstance == -1) {
14988 return -1;
14989 }
14990 if (isinstance) {
14991 *out = Add;
14992 return 0;
14993 }
14994 isinstance = PyObject_IsInstance(obj, state->Sub_type);
14995 if (isinstance == -1) {
14996 return -1;
14997 }
14998 if (isinstance) {
14999 *out = Sub;
15000 return 0;
15001 }
15002 isinstance = PyObject_IsInstance(obj, state->Mult_type);
15003 if (isinstance == -1) {
15004 return -1;
15005 }
15006 if (isinstance) {
15007 *out = Mult;
15008 return 0;
15009 }
15010 isinstance = PyObject_IsInstance(obj, state->MatMult_type);
15011 if (isinstance == -1) {
15012 return -1;
15013 }
15014 if (isinstance) {
15015 *out = MatMult;
15016 return 0;
15017 }
15018 isinstance = PyObject_IsInstance(obj, state->Div_type);
15019 if (isinstance == -1) {
15020 return -1;
15021 }
15022 if (isinstance) {
15023 *out = Div;
15024 return 0;
15025 }
15026 isinstance = PyObject_IsInstance(obj, state->Mod_type);
15027 if (isinstance == -1) {
15028 return -1;
15029 }
15030 if (isinstance) {
15031 *out = Mod;
15032 return 0;
15033 }
15034 isinstance = PyObject_IsInstance(obj, state->Pow_type);
15035 if (isinstance == -1) {
15036 return -1;
15037 }
15038 if (isinstance) {
15039 *out = Pow;
15040 return 0;
15041 }
15042 isinstance = PyObject_IsInstance(obj, state->LShift_type);
15043 if (isinstance == -1) {
15044 return -1;
15045 }
15046 if (isinstance) {
15047 *out = LShift;
15048 return 0;
15049 }
15050 isinstance = PyObject_IsInstance(obj, state->RShift_type);
15051 if (isinstance == -1) {
15052 return -1;
15053 }
15054 if (isinstance) {
15055 *out = RShift;
15056 return 0;
15057 }
15058 isinstance = PyObject_IsInstance(obj, state->BitOr_type);
15059 if (isinstance == -1) {
15060 return -1;
15061 }
15062 if (isinstance) {
15063 *out = BitOr;
15064 return 0;
15065 }
15066 isinstance = PyObject_IsInstance(obj, state->BitXor_type);
15067 if (isinstance == -1) {
15068 return -1;
15069 }
15070 if (isinstance) {
15071 *out = BitXor;
15072 return 0;
15073 }
15074 isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
15075 if (isinstance == -1) {
15076 return -1;
15077 }
15078 if (isinstance) {
15079 *out = BitAnd;
15080 return 0;
15081 }
15082 isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
15083 if (isinstance == -1) {
15084 return -1;
15085 }
15086 if (isinstance) {
15087 *out = FloorDiv;
15088 return 0;
15089 }
15090
15091 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
15092 return -1;
15093 }
15094
15095 int
obj2ast_unaryop(struct ast_state * state,PyObject * obj,unaryop_ty * out,PyArena * arena)15096 obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
15097 PyArena* arena)
15098 {
15099 int isinstance;
15100
15101 isinstance = PyObject_IsInstance(obj, state->Invert_type);
15102 if (isinstance == -1) {
15103 return -1;
15104 }
15105 if (isinstance) {
15106 *out = Invert;
15107 return 0;
15108 }
15109 isinstance = PyObject_IsInstance(obj, state->Not_type);
15110 if (isinstance == -1) {
15111 return -1;
15112 }
15113 if (isinstance) {
15114 *out = Not;
15115 return 0;
15116 }
15117 isinstance = PyObject_IsInstance(obj, state->UAdd_type);
15118 if (isinstance == -1) {
15119 return -1;
15120 }
15121 if (isinstance) {
15122 *out = UAdd;
15123 return 0;
15124 }
15125 isinstance = PyObject_IsInstance(obj, state->USub_type);
15126 if (isinstance == -1) {
15127 return -1;
15128 }
15129 if (isinstance) {
15130 *out = USub;
15131 return 0;
15132 }
15133
15134 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
15135 return -1;
15136 }
15137
15138 int
obj2ast_cmpop(struct ast_state * state,PyObject * obj,cmpop_ty * out,PyArena * arena)15139 obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
15140 arena)
15141 {
15142 int isinstance;
15143
15144 isinstance = PyObject_IsInstance(obj, state->Eq_type);
15145 if (isinstance == -1) {
15146 return -1;
15147 }
15148 if (isinstance) {
15149 *out = Eq;
15150 return 0;
15151 }
15152 isinstance = PyObject_IsInstance(obj, state->NotEq_type);
15153 if (isinstance == -1) {
15154 return -1;
15155 }
15156 if (isinstance) {
15157 *out = NotEq;
15158 return 0;
15159 }
15160 isinstance = PyObject_IsInstance(obj, state->Lt_type);
15161 if (isinstance == -1) {
15162 return -1;
15163 }
15164 if (isinstance) {
15165 *out = Lt;
15166 return 0;
15167 }
15168 isinstance = PyObject_IsInstance(obj, state->LtE_type);
15169 if (isinstance == -1) {
15170 return -1;
15171 }
15172 if (isinstance) {
15173 *out = LtE;
15174 return 0;
15175 }
15176 isinstance = PyObject_IsInstance(obj, state->Gt_type);
15177 if (isinstance == -1) {
15178 return -1;
15179 }
15180 if (isinstance) {
15181 *out = Gt;
15182 return 0;
15183 }
15184 isinstance = PyObject_IsInstance(obj, state->GtE_type);
15185 if (isinstance == -1) {
15186 return -1;
15187 }
15188 if (isinstance) {
15189 *out = GtE;
15190 return 0;
15191 }
15192 isinstance = PyObject_IsInstance(obj, state->Is_type);
15193 if (isinstance == -1) {
15194 return -1;
15195 }
15196 if (isinstance) {
15197 *out = Is;
15198 return 0;
15199 }
15200 isinstance = PyObject_IsInstance(obj, state->IsNot_type);
15201 if (isinstance == -1) {
15202 return -1;
15203 }
15204 if (isinstance) {
15205 *out = IsNot;
15206 return 0;
15207 }
15208 isinstance = PyObject_IsInstance(obj, state->In_type);
15209 if (isinstance == -1) {
15210 return -1;
15211 }
15212 if (isinstance) {
15213 *out = In;
15214 return 0;
15215 }
15216 isinstance = PyObject_IsInstance(obj, state->NotIn_type);
15217 if (isinstance == -1) {
15218 return -1;
15219 }
15220 if (isinstance) {
15221 *out = NotIn;
15222 return 0;
15223 }
15224
15225 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
15226 return -1;
15227 }
15228
15229 int
obj2ast_comprehension(struct ast_state * state,PyObject * obj,comprehension_ty * out,PyArena * arena)15230 obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
15231 out, PyArena* arena)
15232 {
15233 PyObject* tmp = NULL;
15234 expr_ty target;
15235 expr_ty iter;
15236 asdl_expr_seq* ifs;
15237 int is_async;
15238
15239 if (PyObject_GetOptionalAttr(obj, state->target, &tmp) < 0) {
15240 return -1;
15241 }
15242 if (tmp == NULL) {
15243 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
15244 return -1;
15245 }
15246 else {
15247 int res;
15248 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
15249 goto failed;
15250 }
15251 res = obj2ast_expr(state, tmp, &target, arena);
15252 _Py_LeaveRecursiveCall();
15253 if (res != 0) goto failed;
15254 Py_CLEAR(tmp);
15255 }
15256 if (PyObject_GetOptionalAttr(obj, state->iter, &tmp) < 0) {
15257 return -1;
15258 }
15259 if (tmp == NULL) {
15260 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
15261 return -1;
15262 }
15263 else {
15264 int res;
15265 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
15266 goto failed;
15267 }
15268 res = obj2ast_expr(state, tmp, &iter, arena);
15269 _Py_LeaveRecursiveCall();
15270 if (res != 0) goto failed;
15271 Py_CLEAR(tmp);
15272 }
15273 if (PyObject_GetOptionalAttr(obj, state->ifs, &tmp) < 0) {
15274 return -1;
15275 }
15276 if (tmp == NULL) {
15277 tmp = PyList_New(0);
15278 if (tmp == NULL) {
15279 return -1;
15280 }
15281 }
15282 {
15283 int res;
15284 Py_ssize_t len;
15285 Py_ssize_t i;
15286 if (!PyList_Check(tmp)) {
15287 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15288 goto failed;
15289 }
15290 len = PyList_GET_SIZE(tmp);
15291 ifs = _Py_asdl_expr_seq_new(len, arena);
15292 if (ifs == NULL) goto failed;
15293 for (i = 0; i < len; i++) {
15294 expr_ty val;
15295 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15296 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
15297 goto failed;
15298 }
15299 res = obj2ast_expr(state, tmp2, &val, arena);
15300 _Py_LeaveRecursiveCall();
15301 Py_DECREF(tmp2);
15302 if (res != 0) goto failed;
15303 if (len != PyList_GET_SIZE(tmp)) {
15304 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
15305 goto failed;
15306 }
15307 asdl_seq_SET(ifs, i, val);
15308 }
15309 Py_CLEAR(tmp);
15310 }
15311 if (PyObject_GetOptionalAttr(obj, state->is_async, &tmp) < 0) {
15312 return -1;
15313 }
15314 if (tmp == NULL) {
15315 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
15316 return -1;
15317 }
15318 else {
15319 int res;
15320 if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
15321 goto failed;
15322 }
15323 res = obj2ast_int(state, tmp, &is_async, arena);
15324 _Py_LeaveRecursiveCall();
15325 if (res != 0) goto failed;
15326 Py_CLEAR(tmp);
15327 }
15328 *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
15329 if (*out == NULL) goto failed;
15330 return 0;
15331 failed:
15332 Py_XDECREF(tmp);
15333 return -1;
15334 }
15335
15336 int
obj2ast_excepthandler(struct ast_state * state,PyObject * obj,excepthandler_ty * out,PyArena * arena)15337 obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
15338 out, PyArena* arena)
15339 {
15340 int isinstance;
15341
15342 PyObject *tmp = NULL;
15343 PyObject *tp;
15344 int lineno;
15345 int col_offset;
15346 int end_lineno;
15347 int end_col_offset;
15348
15349 if (obj == Py_None) {
15350 *out = NULL;
15351 return 0;
15352 }
15353 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
15354 return -1;
15355 }
15356 if (tmp == NULL) {
15357 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
15358 return -1;
15359 }
15360 else {
15361 int res;
15362 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
15363 goto failed;
15364 }
15365 res = obj2ast_int(state, tmp, &lineno, arena);
15366 _Py_LeaveRecursiveCall();
15367 if (res != 0) goto failed;
15368 Py_CLEAR(tmp);
15369 }
15370 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
15371 return -1;
15372 }
15373 if (tmp == NULL) {
15374 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
15375 return -1;
15376 }
15377 else {
15378 int res;
15379 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
15380 goto failed;
15381 }
15382 res = obj2ast_int(state, tmp, &col_offset, arena);
15383 _Py_LeaveRecursiveCall();
15384 if (res != 0) goto failed;
15385 Py_CLEAR(tmp);
15386 }
15387 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
15388 return -1;
15389 }
15390 if (tmp == NULL || tmp == Py_None) {
15391 Py_CLEAR(tmp);
15392 end_lineno = lineno;
15393 }
15394 else {
15395 int res;
15396 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
15397 goto failed;
15398 }
15399 res = obj2ast_int(state, tmp, &end_lineno, arena);
15400 _Py_LeaveRecursiveCall();
15401 if (res != 0) goto failed;
15402 Py_CLEAR(tmp);
15403 }
15404 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
15405 return -1;
15406 }
15407 if (tmp == NULL || tmp == Py_None) {
15408 Py_CLEAR(tmp);
15409 end_col_offset = col_offset;
15410 }
15411 else {
15412 int res;
15413 if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
15414 goto failed;
15415 }
15416 res = obj2ast_int(state, tmp, &end_col_offset, arena);
15417 _Py_LeaveRecursiveCall();
15418 if (res != 0) goto failed;
15419 Py_CLEAR(tmp);
15420 }
15421 tp = state->ExceptHandler_type;
15422 isinstance = PyObject_IsInstance(obj, tp);
15423 if (isinstance == -1) {
15424 return -1;
15425 }
15426 if (isinstance) {
15427 expr_ty type;
15428 identifier name;
15429 asdl_stmt_seq* body;
15430
15431 if (PyObject_GetOptionalAttr(obj, state->type, &tmp) < 0) {
15432 return -1;
15433 }
15434 if (tmp == NULL || tmp == Py_None) {
15435 Py_CLEAR(tmp);
15436 type = NULL;
15437 }
15438 else {
15439 int res;
15440 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
15441 goto failed;
15442 }
15443 res = obj2ast_expr(state, tmp, &type, arena);
15444 _Py_LeaveRecursiveCall();
15445 if (res != 0) goto failed;
15446 Py_CLEAR(tmp);
15447 }
15448 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
15449 return -1;
15450 }
15451 if (tmp == NULL || tmp == Py_None) {
15452 Py_CLEAR(tmp);
15453 name = NULL;
15454 }
15455 else {
15456 int res;
15457 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
15458 goto failed;
15459 }
15460 res = obj2ast_identifier(state, tmp, &name, arena);
15461 _Py_LeaveRecursiveCall();
15462 if (res != 0) goto failed;
15463 Py_CLEAR(tmp);
15464 }
15465 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
15466 return -1;
15467 }
15468 if (tmp == NULL) {
15469 tmp = PyList_New(0);
15470 if (tmp == NULL) {
15471 return -1;
15472 }
15473 }
15474 {
15475 int res;
15476 Py_ssize_t len;
15477 Py_ssize_t i;
15478 if (!PyList_Check(tmp)) {
15479 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15480 goto failed;
15481 }
15482 len = PyList_GET_SIZE(tmp);
15483 body = _Py_asdl_stmt_seq_new(len, arena);
15484 if (body == NULL) goto failed;
15485 for (i = 0; i < len; i++) {
15486 stmt_ty val;
15487 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15488 if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
15489 goto failed;
15490 }
15491 res = obj2ast_stmt(state, tmp2, &val, arena);
15492 _Py_LeaveRecursiveCall();
15493 Py_DECREF(tmp2);
15494 if (res != 0) goto failed;
15495 if (len != PyList_GET_SIZE(tmp)) {
15496 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
15497 goto failed;
15498 }
15499 asdl_seq_SET(body, i, val);
15500 }
15501 Py_CLEAR(tmp);
15502 }
15503 *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
15504 end_lineno, end_col_offset, arena);
15505 if (*out == NULL) goto failed;
15506 return 0;
15507 }
15508
15509 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
15510 failed:
15511 Py_XDECREF(tmp);
15512 return -1;
15513 }
15514
15515 int
obj2ast_arguments(struct ast_state * state,PyObject * obj,arguments_ty * out,PyArena * arena)15516 obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
15517 PyArena* arena)
15518 {
15519 PyObject* tmp = NULL;
15520 asdl_arg_seq* posonlyargs;
15521 asdl_arg_seq* args;
15522 arg_ty vararg;
15523 asdl_arg_seq* kwonlyargs;
15524 asdl_expr_seq* kw_defaults;
15525 arg_ty kwarg;
15526 asdl_expr_seq* defaults;
15527
15528 if (PyObject_GetOptionalAttr(obj, state->posonlyargs, &tmp) < 0) {
15529 return -1;
15530 }
15531 if (tmp == NULL) {
15532 tmp = PyList_New(0);
15533 if (tmp == NULL) {
15534 return -1;
15535 }
15536 }
15537 {
15538 int res;
15539 Py_ssize_t len;
15540 Py_ssize_t i;
15541 if (!PyList_Check(tmp)) {
15542 PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15543 goto failed;
15544 }
15545 len = PyList_GET_SIZE(tmp);
15546 posonlyargs = _Py_asdl_arg_seq_new(len, arena);
15547 if (posonlyargs == NULL) goto failed;
15548 for (i = 0; i < len; i++) {
15549 arg_ty val;
15550 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15551 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15552 goto failed;
15553 }
15554 res = obj2ast_arg(state, tmp2, &val, arena);
15555 _Py_LeaveRecursiveCall();
15556 Py_DECREF(tmp2);
15557 if (res != 0) goto failed;
15558 if (len != PyList_GET_SIZE(tmp)) {
15559 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
15560 goto failed;
15561 }
15562 asdl_seq_SET(posonlyargs, i, val);
15563 }
15564 Py_CLEAR(tmp);
15565 }
15566 if (PyObject_GetOptionalAttr(obj, state->args, &tmp) < 0) {
15567 return -1;
15568 }
15569 if (tmp == NULL) {
15570 tmp = PyList_New(0);
15571 if (tmp == NULL) {
15572 return -1;
15573 }
15574 }
15575 {
15576 int res;
15577 Py_ssize_t len;
15578 Py_ssize_t i;
15579 if (!PyList_Check(tmp)) {
15580 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15581 goto failed;
15582 }
15583 len = PyList_GET_SIZE(tmp);
15584 args = _Py_asdl_arg_seq_new(len, arena);
15585 if (args == NULL) goto failed;
15586 for (i = 0; i < len; i++) {
15587 arg_ty val;
15588 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15589 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15590 goto failed;
15591 }
15592 res = obj2ast_arg(state, tmp2, &val, arena);
15593 _Py_LeaveRecursiveCall();
15594 Py_DECREF(tmp2);
15595 if (res != 0) goto failed;
15596 if (len != PyList_GET_SIZE(tmp)) {
15597 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
15598 goto failed;
15599 }
15600 asdl_seq_SET(args, i, val);
15601 }
15602 Py_CLEAR(tmp);
15603 }
15604 if (PyObject_GetOptionalAttr(obj, state->vararg, &tmp) < 0) {
15605 return -1;
15606 }
15607 if (tmp == NULL || tmp == Py_None) {
15608 Py_CLEAR(tmp);
15609 vararg = NULL;
15610 }
15611 else {
15612 int res;
15613 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15614 goto failed;
15615 }
15616 res = obj2ast_arg(state, tmp, &vararg, arena);
15617 _Py_LeaveRecursiveCall();
15618 if (res != 0) goto failed;
15619 Py_CLEAR(tmp);
15620 }
15621 if (PyObject_GetOptionalAttr(obj, state->kwonlyargs, &tmp) < 0) {
15622 return -1;
15623 }
15624 if (tmp == NULL) {
15625 tmp = PyList_New(0);
15626 if (tmp == NULL) {
15627 return -1;
15628 }
15629 }
15630 {
15631 int res;
15632 Py_ssize_t len;
15633 Py_ssize_t i;
15634 if (!PyList_Check(tmp)) {
15635 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15636 goto failed;
15637 }
15638 len = PyList_GET_SIZE(tmp);
15639 kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
15640 if (kwonlyargs == NULL) goto failed;
15641 for (i = 0; i < len; i++) {
15642 arg_ty val;
15643 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15644 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15645 goto failed;
15646 }
15647 res = obj2ast_arg(state, tmp2, &val, arena);
15648 _Py_LeaveRecursiveCall();
15649 Py_DECREF(tmp2);
15650 if (res != 0) goto failed;
15651 if (len != PyList_GET_SIZE(tmp)) {
15652 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
15653 goto failed;
15654 }
15655 asdl_seq_SET(kwonlyargs, i, val);
15656 }
15657 Py_CLEAR(tmp);
15658 }
15659 if (PyObject_GetOptionalAttr(obj, state->kw_defaults, &tmp) < 0) {
15660 return -1;
15661 }
15662 if (tmp == NULL) {
15663 tmp = PyList_New(0);
15664 if (tmp == NULL) {
15665 return -1;
15666 }
15667 }
15668 {
15669 int res;
15670 Py_ssize_t len;
15671 Py_ssize_t i;
15672 if (!PyList_Check(tmp)) {
15673 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15674 goto failed;
15675 }
15676 len = PyList_GET_SIZE(tmp);
15677 kw_defaults = _Py_asdl_expr_seq_new(len, arena);
15678 if (kw_defaults == NULL) goto failed;
15679 for (i = 0; i < len; i++) {
15680 expr_ty val;
15681 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15682 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15683 goto failed;
15684 }
15685 res = obj2ast_expr(state, tmp2, &val, arena);
15686 _Py_LeaveRecursiveCall();
15687 Py_DECREF(tmp2);
15688 if (res != 0) goto failed;
15689 if (len != PyList_GET_SIZE(tmp)) {
15690 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
15691 goto failed;
15692 }
15693 asdl_seq_SET(kw_defaults, i, val);
15694 }
15695 Py_CLEAR(tmp);
15696 }
15697 if (PyObject_GetOptionalAttr(obj, state->kwarg, &tmp) < 0) {
15698 return -1;
15699 }
15700 if (tmp == NULL || tmp == Py_None) {
15701 Py_CLEAR(tmp);
15702 kwarg = NULL;
15703 }
15704 else {
15705 int res;
15706 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15707 goto failed;
15708 }
15709 res = obj2ast_arg(state, tmp, &kwarg, arena);
15710 _Py_LeaveRecursiveCall();
15711 if (res != 0) goto failed;
15712 Py_CLEAR(tmp);
15713 }
15714 if (PyObject_GetOptionalAttr(obj, state->defaults, &tmp) < 0) {
15715 return -1;
15716 }
15717 if (tmp == NULL) {
15718 tmp = PyList_New(0);
15719 if (tmp == NULL) {
15720 return -1;
15721 }
15722 }
15723 {
15724 int res;
15725 Py_ssize_t len;
15726 Py_ssize_t i;
15727 if (!PyList_Check(tmp)) {
15728 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
15729 goto failed;
15730 }
15731 len = PyList_GET_SIZE(tmp);
15732 defaults = _Py_asdl_expr_seq_new(len, arena);
15733 if (defaults == NULL) goto failed;
15734 for (i = 0; i < len; i++) {
15735 expr_ty val;
15736 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
15737 if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
15738 goto failed;
15739 }
15740 res = obj2ast_expr(state, tmp2, &val, arena);
15741 _Py_LeaveRecursiveCall();
15742 Py_DECREF(tmp2);
15743 if (res != 0) goto failed;
15744 if (len != PyList_GET_SIZE(tmp)) {
15745 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
15746 goto failed;
15747 }
15748 asdl_seq_SET(defaults, i, val);
15749 }
15750 Py_CLEAR(tmp);
15751 }
15752 *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
15753 kwarg, defaults, arena);
15754 if (*out == NULL) goto failed;
15755 return 0;
15756 failed:
15757 Py_XDECREF(tmp);
15758 return -1;
15759 }
15760
15761 int
obj2ast_arg(struct ast_state * state,PyObject * obj,arg_ty * out,PyArena * arena)15762 obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
15763 {
15764 PyObject* tmp = NULL;
15765 identifier arg;
15766 expr_ty annotation;
15767 string type_comment;
15768 int lineno;
15769 int col_offset;
15770 int end_lineno;
15771 int end_col_offset;
15772
15773 if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
15774 return -1;
15775 }
15776 if (tmp == NULL) {
15777 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
15778 return -1;
15779 }
15780 else {
15781 int res;
15782 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15783 goto failed;
15784 }
15785 res = obj2ast_identifier(state, tmp, &arg, arena);
15786 _Py_LeaveRecursiveCall();
15787 if (res != 0) goto failed;
15788 Py_CLEAR(tmp);
15789 }
15790 if (PyObject_GetOptionalAttr(obj, state->annotation, &tmp) < 0) {
15791 return -1;
15792 }
15793 if (tmp == NULL || tmp == Py_None) {
15794 Py_CLEAR(tmp);
15795 annotation = NULL;
15796 }
15797 else {
15798 int res;
15799 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15800 goto failed;
15801 }
15802 res = obj2ast_expr(state, tmp, &annotation, arena);
15803 _Py_LeaveRecursiveCall();
15804 if (res != 0) goto failed;
15805 Py_CLEAR(tmp);
15806 }
15807 if (PyObject_GetOptionalAttr(obj, state->type_comment, &tmp) < 0) {
15808 return -1;
15809 }
15810 if (tmp == NULL || tmp == Py_None) {
15811 Py_CLEAR(tmp);
15812 type_comment = NULL;
15813 }
15814 else {
15815 int res;
15816 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15817 goto failed;
15818 }
15819 res = obj2ast_string(state, tmp, &type_comment, arena);
15820 _Py_LeaveRecursiveCall();
15821 if (res != 0) goto failed;
15822 Py_CLEAR(tmp);
15823 }
15824 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
15825 return -1;
15826 }
15827 if (tmp == NULL) {
15828 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
15829 return -1;
15830 }
15831 else {
15832 int res;
15833 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15834 goto failed;
15835 }
15836 res = obj2ast_int(state, tmp, &lineno, arena);
15837 _Py_LeaveRecursiveCall();
15838 if (res != 0) goto failed;
15839 Py_CLEAR(tmp);
15840 }
15841 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
15842 return -1;
15843 }
15844 if (tmp == NULL) {
15845 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
15846 return -1;
15847 }
15848 else {
15849 int res;
15850 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15851 goto failed;
15852 }
15853 res = obj2ast_int(state, tmp, &col_offset, arena);
15854 _Py_LeaveRecursiveCall();
15855 if (res != 0) goto failed;
15856 Py_CLEAR(tmp);
15857 }
15858 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
15859 return -1;
15860 }
15861 if (tmp == NULL || tmp == Py_None) {
15862 Py_CLEAR(tmp);
15863 end_lineno = lineno;
15864 }
15865 else {
15866 int res;
15867 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15868 goto failed;
15869 }
15870 res = obj2ast_int(state, tmp, &end_lineno, arena);
15871 _Py_LeaveRecursiveCall();
15872 if (res != 0) goto failed;
15873 Py_CLEAR(tmp);
15874 }
15875 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
15876 return -1;
15877 }
15878 if (tmp == NULL || tmp == Py_None) {
15879 Py_CLEAR(tmp);
15880 end_col_offset = col_offset;
15881 }
15882 else {
15883 int res;
15884 if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
15885 goto failed;
15886 }
15887 res = obj2ast_int(state, tmp, &end_col_offset, arena);
15888 _Py_LeaveRecursiveCall();
15889 if (res != 0) goto failed;
15890 Py_CLEAR(tmp);
15891 }
15892 *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
15893 end_lineno, end_col_offset, arena);
15894 if (*out == NULL) goto failed;
15895 return 0;
15896 failed:
15897 Py_XDECREF(tmp);
15898 return -1;
15899 }
15900
15901 int
obj2ast_keyword(struct ast_state * state,PyObject * obj,keyword_ty * out,PyArena * arena)15902 obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
15903 PyArena* arena)
15904 {
15905 PyObject* tmp = NULL;
15906 identifier arg;
15907 expr_ty value;
15908 int lineno;
15909 int col_offset;
15910 int end_lineno;
15911 int end_col_offset;
15912
15913 if (PyObject_GetOptionalAttr(obj, state->arg, &tmp) < 0) {
15914 return -1;
15915 }
15916 if (tmp == NULL || tmp == Py_None) {
15917 Py_CLEAR(tmp);
15918 arg = NULL;
15919 }
15920 else {
15921 int res;
15922 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
15923 goto failed;
15924 }
15925 res = obj2ast_identifier(state, tmp, &arg, arena);
15926 _Py_LeaveRecursiveCall();
15927 if (res != 0) goto failed;
15928 Py_CLEAR(tmp);
15929 }
15930 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
15931 return -1;
15932 }
15933 if (tmp == NULL) {
15934 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
15935 return -1;
15936 }
15937 else {
15938 int res;
15939 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
15940 goto failed;
15941 }
15942 res = obj2ast_expr(state, tmp, &value, arena);
15943 _Py_LeaveRecursiveCall();
15944 if (res != 0) goto failed;
15945 Py_CLEAR(tmp);
15946 }
15947 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
15948 return -1;
15949 }
15950 if (tmp == NULL) {
15951 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
15952 return -1;
15953 }
15954 else {
15955 int res;
15956 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
15957 goto failed;
15958 }
15959 res = obj2ast_int(state, tmp, &lineno, arena);
15960 _Py_LeaveRecursiveCall();
15961 if (res != 0) goto failed;
15962 Py_CLEAR(tmp);
15963 }
15964 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
15965 return -1;
15966 }
15967 if (tmp == NULL) {
15968 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
15969 return -1;
15970 }
15971 else {
15972 int res;
15973 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
15974 goto failed;
15975 }
15976 res = obj2ast_int(state, tmp, &col_offset, arena);
15977 _Py_LeaveRecursiveCall();
15978 if (res != 0) goto failed;
15979 Py_CLEAR(tmp);
15980 }
15981 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
15982 return -1;
15983 }
15984 if (tmp == NULL || tmp == Py_None) {
15985 Py_CLEAR(tmp);
15986 end_lineno = lineno;
15987 }
15988 else {
15989 int res;
15990 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
15991 goto failed;
15992 }
15993 res = obj2ast_int(state, tmp, &end_lineno, arena);
15994 _Py_LeaveRecursiveCall();
15995 if (res != 0) goto failed;
15996 Py_CLEAR(tmp);
15997 }
15998 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
15999 return -1;
16000 }
16001 if (tmp == NULL || tmp == Py_None) {
16002 Py_CLEAR(tmp);
16003 end_col_offset = col_offset;
16004 }
16005 else {
16006 int res;
16007 if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
16008 goto failed;
16009 }
16010 res = obj2ast_int(state, tmp, &end_col_offset, arena);
16011 _Py_LeaveRecursiveCall();
16012 if (res != 0) goto failed;
16013 Py_CLEAR(tmp);
16014 }
16015 *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
16016 end_col_offset, arena);
16017 if (*out == NULL) goto failed;
16018 return 0;
16019 failed:
16020 Py_XDECREF(tmp);
16021 return -1;
16022 }
16023
16024 int
obj2ast_alias(struct ast_state * state,PyObject * obj,alias_ty * out,PyArena * arena)16025 obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
16026 arena)
16027 {
16028 PyObject* tmp = NULL;
16029 identifier name;
16030 identifier asname;
16031 int lineno;
16032 int col_offset;
16033 int end_lineno;
16034 int end_col_offset;
16035
16036 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
16037 return -1;
16038 }
16039 if (tmp == NULL) {
16040 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
16041 return -1;
16042 }
16043 else {
16044 int res;
16045 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16046 goto failed;
16047 }
16048 res = obj2ast_identifier(state, tmp, &name, arena);
16049 _Py_LeaveRecursiveCall();
16050 if (res != 0) goto failed;
16051 Py_CLEAR(tmp);
16052 }
16053 if (PyObject_GetOptionalAttr(obj, state->asname, &tmp) < 0) {
16054 return -1;
16055 }
16056 if (tmp == NULL || tmp == Py_None) {
16057 Py_CLEAR(tmp);
16058 asname = NULL;
16059 }
16060 else {
16061 int res;
16062 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16063 goto failed;
16064 }
16065 res = obj2ast_identifier(state, tmp, &asname, arena);
16066 _Py_LeaveRecursiveCall();
16067 if (res != 0) goto failed;
16068 Py_CLEAR(tmp);
16069 }
16070 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
16071 return -1;
16072 }
16073 if (tmp == NULL) {
16074 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
16075 return -1;
16076 }
16077 else {
16078 int res;
16079 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16080 goto failed;
16081 }
16082 res = obj2ast_int(state, tmp, &lineno, arena);
16083 _Py_LeaveRecursiveCall();
16084 if (res != 0) goto failed;
16085 Py_CLEAR(tmp);
16086 }
16087 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
16088 return -1;
16089 }
16090 if (tmp == NULL) {
16091 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
16092 return -1;
16093 }
16094 else {
16095 int res;
16096 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16097 goto failed;
16098 }
16099 res = obj2ast_int(state, tmp, &col_offset, arena);
16100 _Py_LeaveRecursiveCall();
16101 if (res != 0) goto failed;
16102 Py_CLEAR(tmp);
16103 }
16104 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
16105 return -1;
16106 }
16107 if (tmp == NULL || tmp == Py_None) {
16108 Py_CLEAR(tmp);
16109 end_lineno = lineno;
16110 }
16111 else {
16112 int res;
16113 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16114 goto failed;
16115 }
16116 res = obj2ast_int(state, tmp, &end_lineno, arena);
16117 _Py_LeaveRecursiveCall();
16118 if (res != 0) goto failed;
16119 Py_CLEAR(tmp);
16120 }
16121 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
16122 return -1;
16123 }
16124 if (tmp == NULL || tmp == Py_None) {
16125 Py_CLEAR(tmp);
16126 end_col_offset = col_offset;
16127 }
16128 else {
16129 int res;
16130 if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
16131 goto failed;
16132 }
16133 res = obj2ast_int(state, tmp, &end_col_offset, arena);
16134 _Py_LeaveRecursiveCall();
16135 if (res != 0) goto failed;
16136 Py_CLEAR(tmp);
16137 }
16138 *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
16139 end_col_offset, arena);
16140 if (*out == NULL) goto failed;
16141 return 0;
16142 failed:
16143 Py_XDECREF(tmp);
16144 return -1;
16145 }
16146
16147 int
obj2ast_withitem(struct ast_state * state,PyObject * obj,withitem_ty * out,PyArena * arena)16148 obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
16149 PyArena* arena)
16150 {
16151 PyObject* tmp = NULL;
16152 expr_ty context_expr;
16153 expr_ty optional_vars;
16154
16155 if (PyObject_GetOptionalAttr(obj, state->context_expr, &tmp) < 0) {
16156 return -1;
16157 }
16158 if (tmp == NULL) {
16159 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
16160 return -1;
16161 }
16162 else {
16163 int res;
16164 if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
16165 goto failed;
16166 }
16167 res = obj2ast_expr(state, tmp, &context_expr, arena);
16168 _Py_LeaveRecursiveCall();
16169 if (res != 0) goto failed;
16170 Py_CLEAR(tmp);
16171 }
16172 if (PyObject_GetOptionalAttr(obj, state->optional_vars, &tmp) < 0) {
16173 return -1;
16174 }
16175 if (tmp == NULL || tmp == Py_None) {
16176 Py_CLEAR(tmp);
16177 optional_vars = NULL;
16178 }
16179 else {
16180 int res;
16181 if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
16182 goto failed;
16183 }
16184 res = obj2ast_expr(state, tmp, &optional_vars, arena);
16185 _Py_LeaveRecursiveCall();
16186 if (res != 0) goto failed;
16187 Py_CLEAR(tmp);
16188 }
16189 *out = _PyAST_withitem(context_expr, optional_vars, arena);
16190 if (*out == NULL) goto failed;
16191 return 0;
16192 failed:
16193 Py_XDECREF(tmp);
16194 return -1;
16195 }
16196
16197 int
obj2ast_match_case(struct ast_state * state,PyObject * obj,match_case_ty * out,PyArena * arena)16198 obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
16199 PyArena* arena)
16200 {
16201 PyObject* tmp = NULL;
16202 pattern_ty pattern;
16203 expr_ty guard;
16204 asdl_stmt_seq* body;
16205
16206 if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
16207 return -1;
16208 }
16209 if (tmp == NULL) {
16210 PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
16211 return -1;
16212 }
16213 else {
16214 int res;
16215 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
16216 goto failed;
16217 }
16218 res = obj2ast_pattern(state, tmp, &pattern, arena);
16219 _Py_LeaveRecursiveCall();
16220 if (res != 0) goto failed;
16221 Py_CLEAR(tmp);
16222 }
16223 if (PyObject_GetOptionalAttr(obj, state->guard, &tmp) < 0) {
16224 return -1;
16225 }
16226 if (tmp == NULL || tmp == Py_None) {
16227 Py_CLEAR(tmp);
16228 guard = NULL;
16229 }
16230 else {
16231 int res;
16232 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
16233 goto failed;
16234 }
16235 res = obj2ast_expr(state, tmp, &guard, arena);
16236 _Py_LeaveRecursiveCall();
16237 if (res != 0) goto failed;
16238 Py_CLEAR(tmp);
16239 }
16240 if (PyObject_GetOptionalAttr(obj, state->body, &tmp) < 0) {
16241 return -1;
16242 }
16243 if (tmp == NULL) {
16244 tmp = PyList_New(0);
16245 if (tmp == NULL) {
16246 return -1;
16247 }
16248 }
16249 {
16250 int res;
16251 Py_ssize_t len;
16252 Py_ssize_t i;
16253 if (!PyList_Check(tmp)) {
16254 PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16255 goto failed;
16256 }
16257 len = PyList_GET_SIZE(tmp);
16258 body = _Py_asdl_stmt_seq_new(len, arena);
16259 if (body == NULL) goto failed;
16260 for (i = 0; i < len; i++) {
16261 stmt_ty val;
16262 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16263 if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
16264 goto failed;
16265 }
16266 res = obj2ast_stmt(state, tmp2, &val, arena);
16267 _Py_LeaveRecursiveCall();
16268 Py_DECREF(tmp2);
16269 if (res != 0) goto failed;
16270 if (len != PyList_GET_SIZE(tmp)) {
16271 PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
16272 goto failed;
16273 }
16274 asdl_seq_SET(body, i, val);
16275 }
16276 Py_CLEAR(tmp);
16277 }
16278 *out = _PyAST_match_case(pattern, guard, body, arena);
16279 if (*out == NULL) goto failed;
16280 return 0;
16281 failed:
16282 Py_XDECREF(tmp);
16283 return -1;
16284 }
16285
16286 int
obj2ast_pattern(struct ast_state * state,PyObject * obj,pattern_ty * out,PyArena * arena)16287 obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
16288 PyArena* arena)
16289 {
16290 int isinstance;
16291
16292 PyObject *tmp = NULL;
16293 PyObject *tp;
16294 int lineno;
16295 int col_offset;
16296 int end_lineno;
16297 int end_col_offset;
16298
16299 if (obj == Py_None) {
16300 *out = NULL;
16301 return 0;
16302 }
16303 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
16304 return -1;
16305 }
16306 if (tmp == NULL) {
16307 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
16308 return -1;
16309 }
16310 else {
16311 int res;
16312 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
16313 goto failed;
16314 }
16315 res = obj2ast_int(state, tmp, &lineno, arena);
16316 _Py_LeaveRecursiveCall();
16317 if (res != 0) goto failed;
16318 Py_CLEAR(tmp);
16319 }
16320 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
16321 return -1;
16322 }
16323 if (tmp == NULL) {
16324 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
16325 return -1;
16326 }
16327 else {
16328 int res;
16329 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
16330 goto failed;
16331 }
16332 res = obj2ast_int(state, tmp, &col_offset, arena);
16333 _Py_LeaveRecursiveCall();
16334 if (res != 0) goto failed;
16335 Py_CLEAR(tmp);
16336 }
16337 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
16338 return -1;
16339 }
16340 if (tmp == NULL) {
16341 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
16342 return -1;
16343 }
16344 else {
16345 int res;
16346 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
16347 goto failed;
16348 }
16349 res = obj2ast_int(state, tmp, &end_lineno, arena);
16350 _Py_LeaveRecursiveCall();
16351 if (res != 0) goto failed;
16352 Py_CLEAR(tmp);
16353 }
16354 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
16355 return -1;
16356 }
16357 if (tmp == NULL) {
16358 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
16359 return -1;
16360 }
16361 else {
16362 int res;
16363 if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
16364 goto failed;
16365 }
16366 res = obj2ast_int(state, tmp, &end_col_offset, arena);
16367 _Py_LeaveRecursiveCall();
16368 if (res != 0) goto failed;
16369 Py_CLEAR(tmp);
16370 }
16371 tp = state->MatchValue_type;
16372 isinstance = PyObject_IsInstance(obj, tp);
16373 if (isinstance == -1) {
16374 return -1;
16375 }
16376 if (isinstance) {
16377 expr_ty value;
16378
16379 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
16380 return -1;
16381 }
16382 if (tmp == NULL) {
16383 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
16384 return -1;
16385 }
16386 else {
16387 int res;
16388 if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
16389 goto failed;
16390 }
16391 res = obj2ast_expr(state, tmp, &value, arena);
16392 _Py_LeaveRecursiveCall();
16393 if (res != 0) goto failed;
16394 Py_CLEAR(tmp);
16395 }
16396 *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
16397 end_col_offset, arena);
16398 if (*out == NULL) goto failed;
16399 return 0;
16400 }
16401 tp = state->MatchSingleton_type;
16402 isinstance = PyObject_IsInstance(obj, tp);
16403 if (isinstance == -1) {
16404 return -1;
16405 }
16406 if (isinstance) {
16407 constant value;
16408
16409 if (PyObject_GetOptionalAttr(obj, state->value, &tmp) < 0) {
16410 return -1;
16411 }
16412 if (tmp == NULL) {
16413 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
16414 return -1;
16415 }
16416 else {
16417 int res;
16418 if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
16419 goto failed;
16420 }
16421 res = obj2ast_constant(state, tmp, &value, arena);
16422 _Py_LeaveRecursiveCall();
16423 if (res != 0) goto failed;
16424 Py_CLEAR(tmp);
16425 }
16426 *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
16427 end_col_offset, arena);
16428 if (*out == NULL) goto failed;
16429 return 0;
16430 }
16431 tp = state->MatchSequence_type;
16432 isinstance = PyObject_IsInstance(obj, tp);
16433 if (isinstance == -1) {
16434 return -1;
16435 }
16436 if (isinstance) {
16437 asdl_pattern_seq* patterns;
16438
16439 if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
16440 return -1;
16441 }
16442 if (tmp == NULL) {
16443 tmp = PyList_New(0);
16444 if (tmp == NULL) {
16445 return -1;
16446 }
16447 }
16448 {
16449 int res;
16450 Py_ssize_t len;
16451 Py_ssize_t i;
16452 if (!PyList_Check(tmp)) {
16453 PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16454 goto failed;
16455 }
16456 len = PyList_GET_SIZE(tmp);
16457 patterns = _Py_asdl_pattern_seq_new(len, arena);
16458 if (patterns == NULL) goto failed;
16459 for (i = 0; i < len; i++) {
16460 pattern_ty val;
16461 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16462 if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
16463 goto failed;
16464 }
16465 res = obj2ast_pattern(state, tmp2, &val, arena);
16466 _Py_LeaveRecursiveCall();
16467 Py_DECREF(tmp2);
16468 if (res != 0) goto failed;
16469 if (len != PyList_GET_SIZE(tmp)) {
16470 PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
16471 goto failed;
16472 }
16473 asdl_seq_SET(patterns, i, val);
16474 }
16475 Py_CLEAR(tmp);
16476 }
16477 *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
16478 end_col_offset, arena);
16479 if (*out == NULL) goto failed;
16480 return 0;
16481 }
16482 tp = state->MatchMapping_type;
16483 isinstance = PyObject_IsInstance(obj, tp);
16484 if (isinstance == -1) {
16485 return -1;
16486 }
16487 if (isinstance) {
16488 asdl_expr_seq* keys;
16489 asdl_pattern_seq* patterns;
16490 identifier rest;
16491
16492 if (PyObject_GetOptionalAttr(obj, state->keys, &tmp) < 0) {
16493 return -1;
16494 }
16495 if (tmp == NULL) {
16496 tmp = PyList_New(0);
16497 if (tmp == NULL) {
16498 return -1;
16499 }
16500 }
16501 {
16502 int res;
16503 Py_ssize_t len;
16504 Py_ssize_t i;
16505 if (!PyList_Check(tmp)) {
16506 PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16507 goto failed;
16508 }
16509 len = PyList_GET_SIZE(tmp);
16510 keys = _Py_asdl_expr_seq_new(len, arena);
16511 if (keys == NULL) goto failed;
16512 for (i = 0; i < len; i++) {
16513 expr_ty val;
16514 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16515 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
16516 goto failed;
16517 }
16518 res = obj2ast_expr(state, tmp2, &val, arena);
16519 _Py_LeaveRecursiveCall();
16520 Py_DECREF(tmp2);
16521 if (res != 0) goto failed;
16522 if (len != PyList_GET_SIZE(tmp)) {
16523 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
16524 goto failed;
16525 }
16526 asdl_seq_SET(keys, i, val);
16527 }
16528 Py_CLEAR(tmp);
16529 }
16530 if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
16531 return -1;
16532 }
16533 if (tmp == NULL) {
16534 tmp = PyList_New(0);
16535 if (tmp == NULL) {
16536 return -1;
16537 }
16538 }
16539 {
16540 int res;
16541 Py_ssize_t len;
16542 Py_ssize_t i;
16543 if (!PyList_Check(tmp)) {
16544 PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16545 goto failed;
16546 }
16547 len = PyList_GET_SIZE(tmp);
16548 patterns = _Py_asdl_pattern_seq_new(len, arena);
16549 if (patterns == NULL) goto failed;
16550 for (i = 0; i < len; i++) {
16551 pattern_ty val;
16552 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16553 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
16554 goto failed;
16555 }
16556 res = obj2ast_pattern(state, tmp2, &val, arena);
16557 _Py_LeaveRecursiveCall();
16558 Py_DECREF(tmp2);
16559 if (res != 0) goto failed;
16560 if (len != PyList_GET_SIZE(tmp)) {
16561 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
16562 goto failed;
16563 }
16564 asdl_seq_SET(patterns, i, val);
16565 }
16566 Py_CLEAR(tmp);
16567 }
16568 if (PyObject_GetOptionalAttr(obj, state->rest, &tmp) < 0) {
16569 return -1;
16570 }
16571 if (tmp == NULL || tmp == Py_None) {
16572 Py_CLEAR(tmp);
16573 rest = NULL;
16574 }
16575 else {
16576 int res;
16577 if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
16578 goto failed;
16579 }
16580 res = obj2ast_identifier(state, tmp, &rest, arena);
16581 _Py_LeaveRecursiveCall();
16582 if (res != 0) goto failed;
16583 Py_CLEAR(tmp);
16584 }
16585 *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
16586 end_lineno, end_col_offset, arena);
16587 if (*out == NULL) goto failed;
16588 return 0;
16589 }
16590 tp = state->MatchClass_type;
16591 isinstance = PyObject_IsInstance(obj, tp);
16592 if (isinstance == -1) {
16593 return -1;
16594 }
16595 if (isinstance) {
16596 expr_ty cls;
16597 asdl_pattern_seq* patterns;
16598 asdl_identifier_seq* kwd_attrs;
16599 asdl_pattern_seq* kwd_patterns;
16600
16601 if (PyObject_GetOptionalAttr(obj, state->cls, &tmp) < 0) {
16602 return -1;
16603 }
16604 if (tmp == NULL) {
16605 PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
16606 return -1;
16607 }
16608 else {
16609 int res;
16610 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
16611 goto failed;
16612 }
16613 res = obj2ast_expr(state, tmp, &cls, arena);
16614 _Py_LeaveRecursiveCall();
16615 if (res != 0) goto failed;
16616 Py_CLEAR(tmp);
16617 }
16618 if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
16619 return -1;
16620 }
16621 if (tmp == NULL) {
16622 tmp = PyList_New(0);
16623 if (tmp == NULL) {
16624 return -1;
16625 }
16626 }
16627 {
16628 int res;
16629 Py_ssize_t len;
16630 Py_ssize_t i;
16631 if (!PyList_Check(tmp)) {
16632 PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16633 goto failed;
16634 }
16635 len = PyList_GET_SIZE(tmp);
16636 patterns = _Py_asdl_pattern_seq_new(len, arena);
16637 if (patterns == NULL) goto failed;
16638 for (i = 0; i < len; i++) {
16639 pattern_ty val;
16640 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16641 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
16642 goto failed;
16643 }
16644 res = obj2ast_pattern(state, tmp2, &val, arena);
16645 _Py_LeaveRecursiveCall();
16646 Py_DECREF(tmp2);
16647 if (res != 0) goto failed;
16648 if (len != PyList_GET_SIZE(tmp)) {
16649 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
16650 goto failed;
16651 }
16652 asdl_seq_SET(patterns, i, val);
16653 }
16654 Py_CLEAR(tmp);
16655 }
16656 if (PyObject_GetOptionalAttr(obj, state->kwd_attrs, &tmp) < 0) {
16657 return -1;
16658 }
16659 if (tmp == NULL) {
16660 tmp = PyList_New(0);
16661 if (tmp == NULL) {
16662 return -1;
16663 }
16664 }
16665 {
16666 int res;
16667 Py_ssize_t len;
16668 Py_ssize_t i;
16669 if (!PyList_Check(tmp)) {
16670 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16671 goto failed;
16672 }
16673 len = PyList_GET_SIZE(tmp);
16674 kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
16675 if (kwd_attrs == NULL) goto failed;
16676 for (i = 0; i < len; i++) {
16677 identifier val;
16678 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16679 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
16680 goto failed;
16681 }
16682 res = obj2ast_identifier(state, tmp2, &val, arena);
16683 _Py_LeaveRecursiveCall();
16684 Py_DECREF(tmp2);
16685 if (res != 0) goto failed;
16686 if (len != PyList_GET_SIZE(tmp)) {
16687 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
16688 goto failed;
16689 }
16690 asdl_seq_SET(kwd_attrs, i, val);
16691 }
16692 Py_CLEAR(tmp);
16693 }
16694 if (PyObject_GetOptionalAttr(obj, state->kwd_patterns, &tmp) < 0) {
16695 return -1;
16696 }
16697 if (tmp == NULL) {
16698 tmp = PyList_New(0);
16699 if (tmp == NULL) {
16700 return -1;
16701 }
16702 }
16703 {
16704 int res;
16705 Py_ssize_t len;
16706 Py_ssize_t i;
16707 if (!PyList_Check(tmp)) {
16708 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16709 goto failed;
16710 }
16711 len = PyList_GET_SIZE(tmp);
16712 kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
16713 if (kwd_patterns == NULL) goto failed;
16714 for (i = 0; i < len; i++) {
16715 pattern_ty val;
16716 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16717 if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
16718 goto failed;
16719 }
16720 res = obj2ast_pattern(state, tmp2, &val, arena);
16721 _Py_LeaveRecursiveCall();
16722 Py_DECREF(tmp2);
16723 if (res != 0) goto failed;
16724 if (len != PyList_GET_SIZE(tmp)) {
16725 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
16726 goto failed;
16727 }
16728 asdl_seq_SET(kwd_patterns, i, val);
16729 }
16730 Py_CLEAR(tmp);
16731 }
16732 *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
16733 lineno, col_offset, end_lineno,
16734 end_col_offset, arena);
16735 if (*out == NULL) goto failed;
16736 return 0;
16737 }
16738 tp = state->MatchStar_type;
16739 isinstance = PyObject_IsInstance(obj, tp);
16740 if (isinstance == -1) {
16741 return -1;
16742 }
16743 if (isinstance) {
16744 identifier name;
16745
16746 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
16747 return -1;
16748 }
16749 if (tmp == NULL || tmp == Py_None) {
16750 Py_CLEAR(tmp);
16751 name = NULL;
16752 }
16753 else {
16754 int res;
16755 if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
16756 goto failed;
16757 }
16758 res = obj2ast_identifier(state, tmp, &name, arena);
16759 _Py_LeaveRecursiveCall();
16760 if (res != 0) goto failed;
16761 Py_CLEAR(tmp);
16762 }
16763 *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
16764 end_col_offset, arena);
16765 if (*out == NULL) goto failed;
16766 return 0;
16767 }
16768 tp = state->MatchAs_type;
16769 isinstance = PyObject_IsInstance(obj, tp);
16770 if (isinstance == -1) {
16771 return -1;
16772 }
16773 if (isinstance) {
16774 pattern_ty pattern;
16775 identifier name;
16776
16777 if (PyObject_GetOptionalAttr(obj, state->pattern, &tmp) < 0) {
16778 return -1;
16779 }
16780 if (tmp == NULL || tmp == Py_None) {
16781 Py_CLEAR(tmp);
16782 pattern = NULL;
16783 }
16784 else {
16785 int res;
16786 if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
16787 goto failed;
16788 }
16789 res = obj2ast_pattern(state, tmp, &pattern, arena);
16790 _Py_LeaveRecursiveCall();
16791 if (res != 0) goto failed;
16792 Py_CLEAR(tmp);
16793 }
16794 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
16795 return -1;
16796 }
16797 if (tmp == NULL || tmp == Py_None) {
16798 Py_CLEAR(tmp);
16799 name = NULL;
16800 }
16801 else {
16802 int res;
16803 if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
16804 goto failed;
16805 }
16806 res = obj2ast_identifier(state, tmp, &name, arena);
16807 _Py_LeaveRecursiveCall();
16808 if (res != 0) goto failed;
16809 Py_CLEAR(tmp);
16810 }
16811 *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
16812 end_col_offset, arena);
16813 if (*out == NULL) goto failed;
16814 return 0;
16815 }
16816 tp = state->MatchOr_type;
16817 isinstance = PyObject_IsInstance(obj, tp);
16818 if (isinstance == -1) {
16819 return -1;
16820 }
16821 if (isinstance) {
16822 asdl_pattern_seq* patterns;
16823
16824 if (PyObject_GetOptionalAttr(obj, state->patterns, &tmp) < 0) {
16825 return -1;
16826 }
16827 if (tmp == NULL) {
16828 tmp = PyList_New(0);
16829 if (tmp == NULL) {
16830 return -1;
16831 }
16832 }
16833 {
16834 int res;
16835 Py_ssize_t len;
16836 Py_ssize_t i;
16837 if (!PyList_Check(tmp)) {
16838 PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
16839 goto failed;
16840 }
16841 len = PyList_GET_SIZE(tmp);
16842 patterns = _Py_asdl_pattern_seq_new(len, arena);
16843 if (patterns == NULL) goto failed;
16844 for (i = 0; i < len; i++) {
16845 pattern_ty val;
16846 PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
16847 if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
16848 goto failed;
16849 }
16850 res = obj2ast_pattern(state, tmp2, &val, arena);
16851 _Py_LeaveRecursiveCall();
16852 Py_DECREF(tmp2);
16853 if (res != 0) goto failed;
16854 if (len != PyList_GET_SIZE(tmp)) {
16855 PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
16856 goto failed;
16857 }
16858 asdl_seq_SET(patterns, i, val);
16859 }
16860 Py_CLEAR(tmp);
16861 }
16862 *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
16863 end_col_offset, arena);
16864 if (*out == NULL) goto failed;
16865 return 0;
16866 }
16867
16868 PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
16869 failed:
16870 Py_XDECREF(tmp);
16871 return -1;
16872 }
16873
16874 int
obj2ast_type_ignore(struct ast_state * state,PyObject * obj,type_ignore_ty * out,PyArena * arena)16875 obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
16876 out, PyArena* arena)
16877 {
16878 int isinstance;
16879
16880 PyObject *tmp = NULL;
16881 PyObject *tp;
16882
16883 if (obj == Py_None) {
16884 *out = NULL;
16885 return 0;
16886 }
16887 tp = state->TypeIgnore_type;
16888 isinstance = PyObject_IsInstance(obj, tp);
16889 if (isinstance == -1) {
16890 return -1;
16891 }
16892 if (isinstance) {
16893 int lineno;
16894 string tag;
16895
16896 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
16897 return -1;
16898 }
16899 if (tmp == NULL) {
16900 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
16901 return -1;
16902 }
16903 else {
16904 int res;
16905 if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
16906 goto failed;
16907 }
16908 res = obj2ast_int(state, tmp, &lineno, arena);
16909 _Py_LeaveRecursiveCall();
16910 if (res != 0) goto failed;
16911 Py_CLEAR(tmp);
16912 }
16913 if (PyObject_GetOptionalAttr(obj, state->tag, &tmp) < 0) {
16914 return -1;
16915 }
16916 if (tmp == NULL) {
16917 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
16918 return -1;
16919 }
16920 else {
16921 int res;
16922 if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
16923 goto failed;
16924 }
16925 res = obj2ast_string(state, tmp, &tag, arena);
16926 _Py_LeaveRecursiveCall();
16927 if (res != 0) goto failed;
16928 Py_CLEAR(tmp);
16929 }
16930 *out = _PyAST_TypeIgnore(lineno, tag, arena);
16931 if (*out == NULL) goto failed;
16932 return 0;
16933 }
16934
16935 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
16936 failed:
16937 Py_XDECREF(tmp);
16938 return -1;
16939 }
16940
16941 int
obj2ast_type_param(struct ast_state * state,PyObject * obj,type_param_ty * out,PyArena * arena)16942 obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
16943 PyArena* arena)
16944 {
16945 int isinstance;
16946
16947 PyObject *tmp = NULL;
16948 PyObject *tp;
16949 int lineno;
16950 int col_offset;
16951 int end_lineno;
16952 int end_col_offset;
16953
16954 if (obj == Py_None) {
16955 *out = NULL;
16956 return 0;
16957 }
16958 if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
16959 return -1;
16960 }
16961 if (tmp == NULL) {
16962 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
16963 return -1;
16964 }
16965 else {
16966 int res;
16967 if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
16968 goto failed;
16969 }
16970 res = obj2ast_int(state, tmp, &lineno, arena);
16971 _Py_LeaveRecursiveCall();
16972 if (res != 0) goto failed;
16973 Py_CLEAR(tmp);
16974 }
16975 if (PyObject_GetOptionalAttr(obj, state->col_offset, &tmp) < 0) {
16976 return -1;
16977 }
16978 if (tmp == NULL) {
16979 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
16980 return -1;
16981 }
16982 else {
16983 int res;
16984 if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
16985 goto failed;
16986 }
16987 res = obj2ast_int(state, tmp, &col_offset, arena);
16988 _Py_LeaveRecursiveCall();
16989 if (res != 0) goto failed;
16990 Py_CLEAR(tmp);
16991 }
16992 if (PyObject_GetOptionalAttr(obj, state->end_lineno, &tmp) < 0) {
16993 return -1;
16994 }
16995 if (tmp == NULL) {
16996 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
16997 return -1;
16998 }
16999 else {
17000 int res;
17001 if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
17002 goto failed;
17003 }
17004 res = obj2ast_int(state, tmp, &end_lineno, arena);
17005 _Py_LeaveRecursiveCall();
17006 if (res != 0) goto failed;
17007 Py_CLEAR(tmp);
17008 }
17009 if (PyObject_GetOptionalAttr(obj, state->end_col_offset, &tmp) < 0) {
17010 return -1;
17011 }
17012 if (tmp == NULL) {
17013 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
17014 return -1;
17015 }
17016 else {
17017 int res;
17018 if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
17019 goto failed;
17020 }
17021 res = obj2ast_int(state, tmp, &end_col_offset, arena);
17022 _Py_LeaveRecursiveCall();
17023 if (res != 0) goto failed;
17024 Py_CLEAR(tmp);
17025 }
17026 tp = state->TypeVar_type;
17027 isinstance = PyObject_IsInstance(obj, tp);
17028 if (isinstance == -1) {
17029 return -1;
17030 }
17031 if (isinstance) {
17032 identifier name;
17033 expr_ty bound;
17034 expr_ty default_value;
17035
17036 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
17037 return -1;
17038 }
17039 if (tmp == NULL) {
17040 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
17041 return -1;
17042 }
17043 else {
17044 int res;
17045 if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
17046 goto failed;
17047 }
17048 res = obj2ast_identifier(state, tmp, &name, arena);
17049 _Py_LeaveRecursiveCall();
17050 if (res != 0) goto failed;
17051 Py_CLEAR(tmp);
17052 }
17053 if (PyObject_GetOptionalAttr(obj, state->bound, &tmp) < 0) {
17054 return -1;
17055 }
17056 if (tmp == NULL || tmp == Py_None) {
17057 Py_CLEAR(tmp);
17058 bound = NULL;
17059 }
17060 else {
17061 int res;
17062 if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
17063 goto failed;
17064 }
17065 res = obj2ast_expr(state, tmp, &bound, arena);
17066 _Py_LeaveRecursiveCall();
17067 if (res != 0) goto failed;
17068 Py_CLEAR(tmp);
17069 }
17070 if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
17071 return -1;
17072 }
17073 if (tmp == NULL || tmp == Py_None) {
17074 Py_CLEAR(tmp);
17075 default_value = NULL;
17076 }
17077 else {
17078 int res;
17079 if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
17080 goto failed;
17081 }
17082 res = obj2ast_expr(state, tmp, &default_value, arena);
17083 _Py_LeaveRecursiveCall();
17084 if (res != 0) goto failed;
17085 Py_CLEAR(tmp);
17086 }
17087 *out = _PyAST_TypeVar(name, bound, default_value, lineno, col_offset,
17088 end_lineno, end_col_offset, arena);
17089 if (*out == NULL) goto failed;
17090 return 0;
17091 }
17092 tp = state->ParamSpec_type;
17093 isinstance = PyObject_IsInstance(obj, tp);
17094 if (isinstance == -1) {
17095 return -1;
17096 }
17097 if (isinstance) {
17098 identifier name;
17099 expr_ty default_value;
17100
17101 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
17102 return -1;
17103 }
17104 if (tmp == NULL) {
17105 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
17106 return -1;
17107 }
17108 else {
17109 int res;
17110 if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
17111 goto failed;
17112 }
17113 res = obj2ast_identifier(state, tmp, &name, arena);
17114 _Py_LeaveRecursiveCall();
17115 if (res != 0) goto failed;
17116 Py_CLEAR(tmp);
17117 }
17118 if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
17119 return -1;
17120 }
17121 if (tmp == NULL || tmp == Py_None) {
17122 Py_CLEAR(tmp);
17123 default_value = NULL;
17124 }
17125 else {
17126 int res;
17127 if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
17128 goto failed;
17129 }
17130 res = obj2ast_expr(state, tmp, &default_value, arena);
17131 _Py_LeaveRecursiveCall();
17132 if (res != 0) goto failed;
17133 Py_CLEAR(tmp);
17134 }
17135 *out = _PyAST_ParamSpec(name, default_value, lineno, col_offset,
17136 end_lineno, end_col_offset, arena);
17137 if (*out == NULL) goto failed;
17138 return 0;
17139 }
17140 tp = state->TypeVarTuple_type;
17141 isinstance = PyObject_IsInstance(obj, tp);
17142 if (isinstance == -1) {
17143 return -1;
17144 }
17145 if (isinstance) {
17146 identifier name;
17147 expr_ty default_value;
17148
17149 if (PyObject_GetOptionalAttr(obj, state->name, &tmp) < 0) {
17150 return -1;
17151 }
17152 if (tmp == NULL) {
17153 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
17154 return -1;
17155 }
17156 else {
17157 int res;
17158 if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
17159 goto failed;
17160 }
17161 res = obj2ast_identifier(state, tmp, &name, arena);
17162 _Py_LeaveRecursiveCall();
17163 if (res != 0) goto failed;
17164 Py_CLEAR(tmp);
17165 }
17166 if (PyObject_GetOptionalAttr(obj, state->default_value, &tmp) < 0) {
17167 return -1;
17168 }
17169 if (tmp == NULL || tmp == Py_None) {
17170 Py_CLEAR(tmp);
17171 default_value = NULL;
17172 }
17173 else {
17174 int res;
17175 if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
17176 goto failed;
17177 }
17178 res = obj2ast_expr(state, tmp, &default_value, arena);
17179 _Py_LeaveRecursiveCall();
17180 if (res != 0) goto failed;
17181 Py_CLEAR(tmp);
17182 }
17183 *out = _PyAST_TypeVarTuple(name, default_value, lineno, col_offset,
17184 end_lineno, end_col_offset, arena);
17185 if (*out == NULL) goto failed;
17186 return 0;
17187 }
17188
17189 PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
17190 failed:
17191 Py_XDECREF(tmp);
17192 return -1;
17193 }
17194
17195
17196 static int
astmodule_exec(PyObject * m)17197 astmodule_exec(PyObject *m)
17198 {
17199 struct ast_state *state = get_ast_state();
17200 if (state == NULL) {
17201 return -1;
17202 }
17203 if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
17204 return -1;
17205 }
17206 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
17207 return -1;
17208 }
17209 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
17210 return -1;
17211 }
17212 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
17213 return -1;
17214 }
17215 if (PyModule_AddIntMacro(m, PyCF_OPTIMIZED_AST) < 0) {
17216 return -1;
17217 }
17218 if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
17219 return -1;
17220 }
17221 if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
17222 return -1;
17223 }
17224 if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
17225 return -1;
17226 }
17227 if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
17228 return -1;
17229 }
17230 if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
17231 {
17232 return -1;
17233 }
17234 if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
17235 return -1;
17236 }
17237 if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
17238 return -1;
17239 }
17240 if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
17241 state->AsyncFunctionDef_type) < 0) {
17242 return -1;
17243 }
17244 if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
17245 return -1;
17246 }
17247 if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
17248 return -1;
17249 }
17250 if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
17251 return -1;
17252 }
17253 if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
17254 return -1;
17255 }
17256 if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
17257 return -1;
17258 }
17259 if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
17260 return -1;
17261 }
17262 if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
17263 return -1;
17264 }
17265 if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
17266 return -1;
17267 }
17268 if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
17269 return -1;
17270 }
17271 if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
17272 return -1;
17273 }
17274 if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
17275 return -1;
17276 }
17277 if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
17278 return -1;
17279 }
17280 if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
17281 return -1;
17282 }
17283 if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
17284 return -1;
17285 }
17286 if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
17287 return -1;
17288 }
17289 if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
17290 return -1;
17291 }
17292 if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
17293 return -1;
17294 }
17295 if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
17296 return -1;
17297 }
17298 if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
17299 return -1;
17300 }
17301 if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
17302 return -1;
17303 }
17304 if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
17305 return -1;
17306 }
17307 if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
17308 return -1;
17309 }
17310 if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
17311 return -1;
17312 }
17313 if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
17314 return -1;
17315 }
17316 if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
17317 return -1;
17318 }
17319 if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
17320 return -1;
17321 }
17322 if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
17323 return -1;
17324 }
17325 if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
17326 return -1;
17327 }
17328 if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
17329 return -1;
17330 }
17331 if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
17332 return -1;
17333 }
17334 if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
17335 return -1;
17336 }
17337 if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
17338 return -1;
17339 }
17340 if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
17341 return -1;
17342 }
17343 if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
17344 return -1;
17345 }
17346 if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
17347 return -1;
17348 }
17349 if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
17350 return -1;
17351 }
17352 if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
17353 return -1;
17354 }
17355 if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
17356 return -1;
17357 }
17358 if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
17359 {
17360 return -1;
17361 }
17362 if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
17363 return -1;
17364 }
17365 if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
17366 return -1;
17367 }
17368 if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
17369 return -1;
17370 }
17371 if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
17372 return -1;
17373 }
17374 if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
17375 return -1;
17376 }
17377 if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
17378 < 0) {
17379 return -1;
17380 }
17381 if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
17382 return -1;
17383 }
17384 if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
17385 return -1;
17386 }
17387 if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
17388 return -1;
17389 }
17390 if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
17391 return -1;
17392 }
17393 if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
17394 return -1;
17395 }
17396 if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
17397 return -1;
17398 }
17399 if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
17400 return -1;
17401 }
17402 if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
17403 return -1;
17404 }
17405 if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
17406 return -1;
17407 }
17408 if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
17409 {
17410 return -1;
17411 }
17412 if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
17413 return -1;
17414 }
17415 if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
17416 return -1;
17417 }
17418 if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
17419 return -1;
17420 }
17421 if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
17422 return -1;
17423 }
17424 if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
17425 return -1;
17426 }
17427 if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
17428 return -1;
17429 }
17430 if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
17431 return -1;
17432 }
17433 if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
17434 return -1;
17435 }
17436 if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
17437 return -1;
17438 }
17439 if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
17440 return -1;
17441 }
17442 if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
17443 return -1;
17444 }
17445 if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
17446 return -1;
17447 }
17448 if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
17449 return -1;
17450 }
17451 if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
17452 return -1;
17453 }
17454 if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
17455 return -1;
17456 }
17457 if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
17458 return -1;
17459 }
17460 if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
17461 return -1;
17462 }
17463 if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
17464 return -1;
17465 }
17466 if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
17467 return -1;
17468 }
17469 if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
17470 return -1;
17471 }
17472 if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
17473 return -1;
17474 }
17475 if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
17476 return -1;
17477 }
17478 if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
17479 return -1;
17480 }
17481 if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
17482 return -1;
17483 }
17484 if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
17485 return -1;
17486 }
17487 if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
17488 return -1;
17489 }
17490 if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
17491 return -1;
17492 }
17493 if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
17494 return -1;
17495 }
17496 if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
17497 return -1;
17498 }
17499 if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
17500 return -1;
17501 }
17502 if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
17503 return -1;
17504 }
17505 if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
17506 return -1;
17507 }
17508 if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
17509 return -1;
17510 }
17511 if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
17512 return -1;
17513 }
17514 if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
17515 return -1;
17516 }
17517 if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
17518 return -1;
17519 }
17520 if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
17521 0) {
17522 return -1;
17523 }
17524 if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
17525 0) {
17526 return -1;
17527 }
17528 if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
17529 0) {
17530 return -1;
17531 }
17532 if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
17533 return -1;
17534 }
17535 if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
17536 return -1;
17537 }
17538 if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
17539 return -1;
17540 }
17541 if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
17542 return -1;
17543 }
17544 if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
17545 return -1;
17546 }
17547 if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
17548 return -1;
17549 }
17550 if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
17551 return -1;
17552 }
17553 if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
17554 return -1;
17555 }
17556 if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
17557 < 0) {
17558 return -1;
17559 }
17560 if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
17561 0) {
17562 return -1;
17563 }
17564 if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
17565 {
17566 return -1;
17567 }
17568 if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
17569 return -1;
17570 }
17571 if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
17572 return -1;
17573 }
17574 if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
17575 return -1;
17576 }
17577 if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
17578 return -1;
17579 }
17580 if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
17581 return -1;
17582 }
17583 if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
17584 return -1;
17585 }
17586 if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
17587 return -1;
17588 }
17589 if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
17590 return -1;
17591 }
17592 if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
17593 return -1;
17594 }
17595 if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
17596 {
17597 return -1;
17598 }
17599 return 0;
17600 }
17601
17602 static PyModuleDef_Slot astmodule_slots[] = {
17603 {Py_mod_exec, astmodule_exec},
17604 {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
17605 {Py_mod_gil, Py_MOD_GIL_NOT_USED},
17606 {0, NULL}
17607 };
17608
17609 static struct PyModuleDef _astmodule = {
17610 PyModuleDef_HEAD_INIT,
17611 .m_name = "_ast",
17612 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
17613 .m_size = 0,
17614 .m_slots = astmodule_slots,
17615 };
17616
17617 PyMODINIT_FUNC
PyInit__ast(void)17618 PyInit__ast(void)
17619 {
17620 return PyModuleDef_Init(&_astmodule);
17621 }
17622
17623
PyAST_mod2obj(mod_ty t)17624 PyObject* PyAST_mod2obj(mod_ty t)
17625 {
17626 struct ast_state *state = get_ast_state();
17627 if (state == NULL) {
17628 return NULL;
17629 }
17630
17631 int starting_recursion_depth;
17632 /* Be careful here to prevent overflow. */
17633 PyThreadState *tstate = _PyThreadState_GET();
17634 if (!tstate) {
17635 return NULL;
17636 }
17637 struct validator vstate;
17638 vstate.recursion_limit = Py_C_RECURSION_LIMIT;
17639 int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
17640 starting_recursion_depth = recursion_depth;
17641 vstate.recursion_depth = starting_recursion_depth;
17642
17643 PyObject *result = ast2obj_mod(state, &vstate, t);
17644
17645 /* Check that the recursion depth counting balanced correctly */
17646 if (result && vstate.recursion_depth != starting_recursion_depth) {
17647 PyErr_Format(PyExc_SystemError,
17648 "AST constructor recursion depth mismatch (before=%d, after=%d)",
17649 starting_recursion_depth, vstate.recursion_depth);
17650 return NULL;
17651 }
17652 return result;
17653 }
17654
17655 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
PyAST_obj2mod(PyObject * ast,PyArena * arena,int mode)17656 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
17657 {
17658 const char * const req_name[] = {"Module", "Expression", "Interactive"};
17659 int isinstance;
17660
17661 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
17662 return NULL;
17663 }
17664
17665 struct ast_state *state = get_ast_state();
17666 if (state == NULL) {
17667 return NULL;
17668 }
17669
17670 PyObject *req_type[3];
17671 req_type[0] = state->Module_type;
17672 req_type[1] = state->Expression_type;
17673 req_type[2] = state->Interactive_type;
17674
17675 assert(0 <= mode && mode <= 2);
17676
17677 isinstance = PyObject_IsInstance(ast, req_type[mode]);
17678 if (isinstance == -1)
17679 return NULL;
17680 if (!isinstance) {
17681 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
17682 req_name[mode], _PyType_Name(Py_TYPE(ast)));
17683 return NULL;
17684 }
17685
17686 mod_ty res = NULL;
17687 if (obj2ast_mod(state, ast, &res, arena) != 0)
17688 return NULL;
17689 else
17690 return res;
17691 }
17692
PyAST_Check(PyObject * obj)17693 int PyAST_Check(PyObject* obj)
17694 {
17695 struct ast_state *state = get_ast_state();
17696 if (state == NULL) {
17697 return -1;
17698 }
17699 return PyObject_IsInstance(obj, state->AST_type);
17700 }
17701
17702
17703