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_interp.h" // _PyInterpreterState.ast
7 #include "pycore_pystate.h" // _PyInterpreterState_GET()
8 #include "structmember.h"
9 #include <stddef.h>
10
11 // Forward declaration
12 static int init_types(struct ast_state *state);
13
14 static struct ast_state*
get_ast_state(void)15 get_ast_state(void)
16 {
17 PyInterpreterState *interp = _PyInterpreterState_GET();
18 struct ast_state *state = &interp->ast;
19 if (!init_types(state)) {
20 return NULL;
21 }
22 return state;
23 }
24
_PyAST_Fini(PyInterpreterState * interp)25 void _PyAST_Fini(PyInterpreterState *interp)
26 {
27 struct ast_state *state = &interp->ast;
28
29 Py_CLEAR(state->AST_type);
30 Py_CLEAR(state->Add_singleton);
31 Py_CLEAR(state->Add_type);
32 Py_CLEAR(state->And_singleton);
33 Py_CLEAR(state->And_type);
34 Py_CLEAR(state->AnnAssign_type);
35 Py_CLEAR(state->Assert_type);
36 Py_CLEAR(state->Assign_type);
37 Py_CLEAR(state->AsyncFor_type);
38 Py_CLEAR(state->AsyncFunctionDef_type);
39 Py_CLEAR(state->AsyncWith_type);
40 Py_CLEAR(state->Attribute_type);
41 Py_CLEAR(state->AugAssign_type);
42 Py_CLEAR(state->Await_type);
43 Py_CLEAR(state->BinOp_type);
44 Py_CLEAR(state->BitAnd_singleton);
45 Py_CLEAR(state->BitAnd_type);
46 Py_CLEAR(state->BitOr_singleton);
47 Py_CLEAR(state->BitOr_type);
48 Py_CLEAR(state->BitXor_singleton);
49 Py_CLEAR(state->BitXor_type);
50 Py_CLEAR(state->BoolOp_type);
51 Py_CLEAR(state->Break_type);
52 Py_CLEAR(state->Call_type);
53 Py_CLEAR(state->ClassDef_type);
54 Py_CLEAR(state->Compare_type);
55 Py_CLEAR(state->Constant_type);
56 Py_CLEAR(state->Continue_type);
57 Py_CLEAR(state->Del_singleton);
58 Py_CLEAR(state->Del_type);
59 Py_CLEAR(state->Delete_type);
60 Py_CLEAR(state->DictComp_type);
61 Py_CLEAR(state->Dict_type);
62 Py_CLEAR(state->Div_singleton);
63 Py_CLEAR(state->Div_type);
64 Py_CLEAR(state->Eq_singleton);
65 Py_CLEAR(state->Eq_type);
66 Py_CLEAR(state->ExceptHandler_type);
67 Py_CLEAR(state->Expr_type);
68 Py_CLEAR(state->Expression_type);
69 Py_CLEAR(state->FloorDiv_singleton);
70 Py_CLEAR(state->FloorDiv_type);
71 Py_CLEAR(state->For_type);
72 Py_CLEAR(state->FormattedValue_type);
73 Py_CLEAR(state->FunctionDef_type);
74 Py_CLEAR(state->FunctionType_type);
75 Py_CLEAR(state->GeneratorExp_type);
76 Py_CLEAR(state->Global_type);
77 Py_CLEAR(state->GtE_singleton);
78 Py_CLEAR(state->GtE_type);
79 Py_CLEAR(state->Gt_singleton);
80 Py_CLEAR(state->Gt_type);
81 Py_CLEAR(state->IfExp_type);
82 Py_CLEAR(state->If_type);
83 Py_CLEAR(state->ImportFrom_type);
84 Py_CLEAR(state->Import_type);
85 Py_CLEAR(state->In_singleton);
86 Py_CLEAR(state->In_type);
87 Py_CLEAR(state->Interactive_type);
88 Py_CLEAR(state->Invert_singleton);
89 Py_CLEAR(state->Invert_type);
90 Py_CLEAR(state->IsNot_singleton);
91 Py_CLEAR(state->IsNot_type);
92 Py_CLEAR(state->Is_singleton);
93 Py_CLEAR(state->Is_type);
94 Py_CLEAR(state->JoinedStr_type);
95 Py_CLEAR(state->LShift_singleton);
96 Py_CLEAR(state->LShift_type);
97 Py_CLEAR(state->Lambda_type);
98 Py_CLEAR(state->ListComp_type);
99 Py_CLEAR(state->List_type);
100 Py_CLEAR(state->Load_singleton);
101 Py_CLEAR(state->Load_type);
102 Py_CLEAR(state->LtE_singleton);
103 Py_CLEAR(state->LtE_type);
104 Py_CLEAR(state->Lt_singleton);
105 Py_CLEAR(state->Lt_type);
106 Py_CLEAR(state->MatMult_singleton);
107 Py_CLEAR(state->MatMult_type);
108 Py_CLEAR(state->MatchAs_type);
109 Py_CLEAR(state->MatchClass_type);
110 Py_CLEAR(state->MatchMapping_type);
111 Py_CLEAR(state->MatchOr_type);
112 Py_CLEAR(state->MatchSequence_type);
113 Py_CLEAR(state->MatchSingleton_type);
114 Py_CLEAR(state->MatchStar_type);
115 Py_CLEAR(state->MatchValue_type);
116 Py_CLEAR(state->Match_type);
117 Py_CLEAR(state->Mod_singleton);
118 Py_CLEAR(state->Mod_type);
119 Py_CLEAR(state->Module_type);
120 Py_CLEAR(state->Mult_singleton);
121 Py_CLEAR(state->Mult_type);
122 Py_CLEAR(state->Name_type);
123 Py_CLEAR(state->NamedExpr_type);
124 Py_CLEAR(state->Nonlocal_type);
125 Py_CLEAR(state->NotEq_singleton);
126 Py_CLEAR(state->NotEq_type);
127 Py_CLEAR(state->NotIn_singleton);
128 Py_CLEAR(state->NotIn_type);
129 Py_CLEAR(state->Not_singleton);
130 Py_CLEAR(state->Not_type);
131 Py_CLEAR(state->Or_singleton);
132 Py_CLEAR(state->Or_type);
133 Py_CLEAR(state->Pass_type);
134 Py_CLEAR(state->Pow_singleton);
135 Py_CLEAR(state->Pow_type);
136 Py_CLEAR(state->RShift_singleton);
137 Py_CLEAR(state->RShift_type);
138 Py_CLEAR(state->Raise_type);
139 Py_CLEAR(state->Return_type);
140 Py_CLEAR(state->SetComp_type);
141 Py_CLEAR(state->Set_type);
142 Py_CLEAR(state->Slice_type);
143 Py_CLEAR(state->Starred_type);
144 Py_CLEAR(state->Store_singleton);
145 Py_CLEAR(state->Store_type);
146 Py_CLEAR(state->Sub_singleton);
147 Py_CLEAR(state->Sub_type);
148 Py_CLEAR(state->Subscript_type);
149 Py_CLEAR(state->Try_type);
150 Py_CLEAR(state->Tuple_type);
151 Py_CLEAR(state->TypeIgnore_type);
152 Py_CLEAR(state->UAdd_singleton);
153 Py_CLEAR(state->UAdd_type);
154 Py_CLEAR(state->USub_singleton);
155 Py_CLEAR(state->USub_type);
156 Py_CLEAR(state->UnaryOp_type);
157 Py_CLEAR(state->While_type);
158 Py_CLEAR(state->With_type);
159 Py_CLEAR(state->YieldFrom_type);
160 Py_CLEAR(state->Yield_type);
161 Py_CLEAR(state->__dict__);
162 Py_CLEAR(state->__doc__);
163 Py_CLEAR(state->__match_args__);
164 Py_CLEAR(state->__module__);
165 Py_CLEAR(state->_attributes);
166 Py_CLEAR(state->_fields);
167 Py_CLEAR(state->alias_type);
168 Py_CLEAR(state->annotation);
169 Py_CLEAR(state->arg);
170 Py_CLEAR(state->arg_type);
171 Py_CLEAR(state->args);
172 Py_CLEAR(state->argtypes);
173 Py_CLEAR(state->arguments_type);
174 Py_CLEAR(state->asname);
175 Py_CLEAR(state->ast);
176 Py_CLEAR(state->attr);
177 Py_CLEAR(state->bases);
178 Py_CLEAR(state->body);
179 Py_CLEAR(state->boolop_type);
180 Py_CLEAR(state->cases);
181 Py_CLEAR(state->cause);
182 Py_CLEAR(state->cls);
183 Py_CLEAR(state->cmpop_type);
184 Py_CLEAR(state->col_offset);
185 Py_CLEAR(state->comparators);
186 Py_CLEAR(state->comprehension_type);
187 Py_CLEAR(state->context_expr);
188 Py_CLEAR(state->conversion);
189 Py_CLEAR(state->ctx);
190 Py_CLEAR(state->decorator_list);
191 Py_CLEAR(state->defaults);
192 Py_CLEAR(state->elt);
193 Py_CLEAR(state->elts);
194 Py_CLEAR(state->end_col_offset);
195 Py_CLEAR(state->end_lineno);
196 Py_CLEAR(state->exc);
197 Py_CLEAR(state->excepthandler_type);
198 Py_CLEAR(state->expr_context_type);
199 Py_CLEAR(state->expr_type);
200 Py_CLEAR(state->finalbody);
201 Py_CLEAR(state->format_spec);
202 Py_CLEAR(state->func);
203 Py_CLEAR(state->generators);
204 Py_CLEAR(state->guard);
205 Py_CLEAR(state->handlers);
206 Py_CLEAR(state->id);
207 Py_CLEAR(state->ifs);
208 Py_CLEAR(state->is_async);
209 Py_CLEAR(state->items);
210 Py_CLEAR(state->iter);
211 Py_CLEAR(state->key);
212 Py_CLEAR(state->keys);
213 Py_CLEAR(state->keyword_type);
214 Py_CLEAR(state->keywords);
215 Py_CLEAR(state->kind);
216 Py_CLEAR(state->kw_defaults);
217 Py_CLEAR(state->kwarg);
218 Py_CLEAR(state->kwd_attrs);
219 Py_CLEAR(state->kwd_patterns);
220 Py_CLEAR(state->kwonlyargs);
221 Py_CLEAR(state->left);
222 Py_CLEAR(state->level);
223 Py_CLEAR(state->lineno);
224 Py_CLEAR(state->lower);
225 Py_CLEAR(state->match_case_type);
226 Py_CLEAR(state->mod_type);
227 Py_CLEAR(state->module);
228 Py_CLEAR(state->msg);
229 Py_CLEAR(state->name);
230 Py_CLEAR(state->names);
231 Py_CLEAR(state->op);
232 Py_CLEAR(state->operand);
233 Py_CLEAR(state->operator_type);
234 Py_CLEAR(state->ops);
235 Py_CLEAR(state->optional_vars);
236 Py_CLEAR(state->orelse);
237 Py_CLEAR(state->pattern);
238 Py_CLEAR(state->pattern_type);
239 Py_CLEAR(state->patterns);
240 Py_CLEAR(state->posonlyargs);
241 Py_CLEAR(state->rest);
242 Py_CLEAR(state->returns);
243 Py_CLEAR(state->right);
244 Py_CLEAR(state->simple);
245 Py_CLEAR(state->slice);
246 Py_CLEAR(state->step);
247 Py_CLEAR(state->stmt_type);
248 Py_CLEAR(state->subject);
249 Py_CLEAR(state->tag);
250 Py_CLEAR(state->target);
251 Py_CLEAR(state->targets);
252 Py_CLEAR(state->test);
253 Py_CLEAR(state->type);
254 Py_CLEAR(state->type_comment);
255 Py_CLEAR(state->type_ignore_type);
256 Py_CLEAR(state->type_ignores);
257 Py_CLEAR(state->unaryop_type);
258 Py_CLEAR(state->upper);
259 Py_CLEAR(state->value);
260 Py_CLEAR(state->values);
261 Py_CLEAR(state->vararg);
262 Py_CLEAR(state->withitem_type);
263
264 #if !defined(NDEBUG)
265 state->initialized = -1;
266 #else
267 state->initialized = 0;
268 #endif
269 }
270
init_identifiers(struct ast_state * state)271 static int init_identifiers(struct ast_state *state)
272 {
273 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
274 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
275 if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return 0;
276 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
277 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
278 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
279 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
280 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
281 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
282 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
283 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
284 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
285 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
286 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
287 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
288 if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return 0;
289 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
290 if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return 0;
291 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
292 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
293 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
294 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
295 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
296 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
297 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
298 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
299 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
300 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
301 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
302 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
303 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
304 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
305 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
306 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
307 if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return 0;
308 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
309 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
310 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
311 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
312 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
313 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
314 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
315 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
316 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
317 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
318 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
319 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
320 if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return 0;
321 if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return 0;
322 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
323 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
324 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
325 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
326 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
327 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
328 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
329 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
330 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
331 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
332 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
333 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
334 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
335 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
336 if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return 0;
337 if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return 0;
338 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
339 if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return 0;
340 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
341 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
342 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
343 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
344 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
345 if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return 0;
346 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
347 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
348 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
349 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
350 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
351 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
352 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
353 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
354 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
355 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
356 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
357 return 1;
358 };
359
360 GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
361 GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
362 GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
363 GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
364 GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
365 GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
366 GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
367 GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
368 GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
369 GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
370 GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
371 GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
372 GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
373
374 static PyObject* ast2obj_mod(struct ast_state *state, void*);
375 static const char * const Module_fields[]={
376 "body",
377 "type_ignores",
378 };
379 static const char * const Interactive_fields[]={
380 "body",
381 };
382 static const char * const Expression_fields[]={
383 "body",
384 };
385 static const char * const FunctionType_fields[]={
386 "argtypes",
387 "returns",
388 };
389 static const char * const stmt_attributes[] = {
390 "lineno",
391 "col_offset",
392 "end_lineno",
393 "end_col_offset",
394 };
395 static PyObject* ast2obj_stmt(struct ast_state *state, void*);
396 static const char * const FunctionDef_fields[]={
397 "name",
398 "args",
399 "body",
400 "decorator_list",
401 "returns",
402 "type_comment",
403 };
404 static const char * const AsyncFunctionDef_fields[]={
405 "name",
406 "args",
407 "body",
408 "decorator_list",
409 "returns",
410 "type_comment",
411 };
412 static const char * const ClassDef_fields[]={
413 "name",
414 "bases",
415 "keywords",
416 "body",
417 "decorator_list",
418 };
419 static const char * const Return_fields[]={
420 "value",
421 };
422 static const char * const Delete_fields[]={
423 "targets",
424 };
425 static const char * const Assign_fields[]={
426 "targets",
427 "value",
428 "type_comment",
429 };
430 static const char * const AugAssign_fields[]={
431 "target",
432 "op",
433 "value",
434 };
435 static const char * const AnnAssign_fields[]={
436 "target",
437 "annotation",
438 "value",
439 "simple",
440 };
441 static const char * const For_fields[]={
442 "target",
443 "iter",
444 "body",
445 "orelse",
446 "type_comment",
447 };
448 static const char * const AsyncFor_fields[]={
449 "target",
450 "iter",
451 "body",
452 "orelse",
453 "type_comment",
454 };
455 static const char * const While_fields[]={
456 "test",
457 "body",
458 "orelse",
459 };
460 static const char * const If_fields[]={
461 "test",
462 "body",
463 "orelse",
464 };
465 static const char * const With_fields[]={
466 "items",
467 "body",
468 "type_comment",
469 };
470 static const char * const AsyncWith_fields[]={
471 "items",
472 "body",
473 "type_comment",
474 };
475 static const char * const Match_fields[]={
476 "subject",
477 "cases",
478 };
479 static const char * const Raise_fields[]={
480 "exc",
481 "cause",
482 };
483 static const char * const Try_fields[]={
484 "body",
485 "handlers",
486 "orelse",
487 "finalbody",
488 };
489 static const char * const Assert_fields[]={
490 "test",
491 "msg",
492 };
493 static const char * const Import_fields[]={
494 "names",
495 };
496 static const char * const ImportFrom_fields[]={
497 "module",
498 "names",
499 "level",
500 };
501 static const char * const Global_fields[]={
502 "names",
503 };
504 static const char * const Nonlocal_fields[]={
505 "names",
506 };
507 static const char * const Expr_fields[]={
508 "value",
509 };
510 static const char * const expr_attributes[] = {
511 "lineno",
512 "col_offset",
513 "end_lineno",
514 "end_col_offset",
515 };
516 static PyObject* ast2obj_expr(struct ast_state *state, void*);
517 static const char * const BoolOp_fields[]={
518 "op",
519 "values",
520 };
521 static const char * const NamedExpr_fields[]={
522 "target",
523 "value",
524 };
525 static const char * const BinOp_fields[]={
526 "left",
527 "op",
528 "right",
529 };
530 static const char * const UnaryOp_fields[]={
531 "op",
532 "operand",
533 };
534 static const char * const Lambda_fields[]={
535 "args",
536 "body",
537 };
538 static const char * const IfExp_fields[]={
539 "test",
540 "body",
541 "orelse",
542 };
543 static const char * const Dict_fields[]={
544 "keys",
545 "values",
546 };
547 static const char * const Set_fields[]={
548 "elts",
549 };
550 static const char * const ListComp_fields[]={
551 "elt",
552 "generators",
553 };
554 static const char * const SetComp_fields[]={
555 "elt",
556 "generators",
557 };
558 static const char * const DictComp_fields[]={
559 "key",
560 "value",
561 "generators",
562 };
563 static const char * const GeneratorExp_fields[]={
564 "elt",
565 "generators",
566 };
567 static const char * const Await_fields[]={
568 "value",
569 };
570 static const char * const Yield_fields[]={
571 "value",
572 };
573 static const char * const YieldFrom_fields[]={
574 "value",
575 };
576 static const char * const Compare_fields[]={
577 "left",
578 "ops",
579 "comparators",
580 };
581 static const char * const Call_fields[]={
582 "func",
583 "args",
584 "keywords",
585 };
586 static const char * const FormattedValue_fields[]={
587 "value",
588 "conversion",
589 "format_spec",
590 };
591 static const char * const JoinedStr_fields[]={
592 "values",
593 };
594 static const char * const Constant_fields[]={
595 "value",
596 "kind",
597 };
598 static const char * const Attribute_fields[]={
599 "value",
600 "attr",
601 "ctx",
602 };
603 static const char * const Subscript_fields[]={
604 "value",
605 "slice",
606 "ctx",
607 };
608 static const char * const Starred_fields[]={
609 "value",
610 "ctx",
611 };
612 static const char * const Name_fields[]={
613 "id",
614 "ctx",
615 };
616 static const char * const List_fields[]={
617 "elts",
618 "ctx",
619 };
620 static const char * const Tuple_fields[]={
621 "elts",
622 "ctx",
623 };
624 static const char * const Slice_fields[]={
625 "lower",
626 "upper",
627 "step",
628 };
629 static PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty);
630 static PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty);
631 static PyObject* ast2obj_operator(struct ast_state *state, operator_ty);
632 static PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty);
633 static PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty);
634 static PyObject* ast2obj_comprehension(struct ast_state *state, void*);
635 static const char * const comprehension_fields[]={
636 "target",
637 "iter",
638 "ifs",
639 "is_async",
640 };
641 static const char * const excepthandler_attributes[] = {
642 "lineno",
643 "col_offset",
644 "end_lineno",
645 "end_col_offset",
646 };
647 static PyObject* ast2obj_excepthandler(struct ast_state *state, void*);
648 static const char * const ExceptHandler_fields[]={
649 "type",
650 "name",
651 "body",
652 };
653 static PyObject* ast2obj_arguments(struct ast_state *state, void*);
654 static const char * const arguments_fields[]={
655 "posonlyargs",
656 "args",
657 "vararg",
658 "kwonlyargs",
659 "kw_defaults",
660 "kwarg",
661 "defaults",
662 };
663 static PyObject* ast2obj_arg(struct ast_state *state, void*);
664 static const char * const arg_attributes[] = {
665 "lineno",
666 "col_offset",
667 "end_lineno",
668 "end_col_offset",
669 };
670 static const char * const arg_fields[]={
671 "arg",
672 "annotation",
673 "type_comment",
674 };
675 static PyObject* ast2obj_keyword(struct ast_state *state, void*);
676 static const char * const keyword_attributes[] = {
677 "lineno",
678 "col_offset",
679 "end_lineno",
680 "end_col_offset",
681 };
682 static const char * const keyword_fields[]={
683 "arg",
684 "value",
685 };
686 static PyObject* ast2obj_alias(struct ast_state *state, void*);
687 static const char * const alias_attributes[] = {
688 "lineno",
689 "col_offset",
690 "end_lineno",
691 "end_col_offset",
692 };
693 static const char * const alias_fields[]={
694 "name",
695 "asname",
696 };
697 static PyObject* ast2obj_withitem(struct ast_state *state, void*);
698 static const char * const withitem_fields[]={
699 "context_expr",
700 "optional_vars",
701 };
702 static PyObject* ast2obj_match_case(struct ast_state *state, void*);
703 static const char * const match_case_fields[]={
704 "pattern",
705 "guard",
706 "body",
707 };
708 static const char * const pattern_attributes[] = {
709 "lineno",
710 "col_offset",
711 "end_lineno",
712 "end_col_offset",
713 };
714 static PyObject* ast2obj_pattern(struct ast_state *state, void*);
715 static const char * const MatchValue_fields[]={
716 "value",
717 };
718 static const char * const MatchSingleton_fields[]={
719 "value",
720 };
721 static const char * const MatchSequence_fields[]={
722 "patterns",
723 };
724 static const char * const MatchMapping_fields[]={
725 "keys",
726 "patterns",
727 "rest",
728 };
729 static const char * const MatchClass_fields[]={
730 "cls",
731 "patterns",
732 "kwd_attrs",
733 "kwd_patterns",
734 };
735 static const char * const MatchStar_fields[]={
736 "name",
737 };
738 static const char * const MatchAs_fields[]={
739 "pattern",
740 "name",
741 };
742 static const char * const MatchOr_fields[]={
743 "patterns",
744 };
745 static PyObject* ast2obj_type_ignore(struct ast_state *state, void*);
746 static const char * const TypeIgnore_fields[]={
747 "lineno",
748 "tag",
749 };
750
751
752
753 typedef struct {
754 PyObject_HEAD
755 PyObject *dict;
756 } AST_object;
757
758 static void
ast_dealloc(AST_object * self)759 ast_dealloc(AST_object *self)
760 {
761 /* bpo-31095: UnTrack is needed before calling any callbacks */
762 PyTypeObject *tp = Py_TYPE(self);
763 PyObject_GC_UnTrack(self);
764 Py_CLEAR(self->dict);
765 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
766 assert(free_func != NULL);
767 free_func(self);
768 Py_DECREF(tp);
769 }
770
771 static int
ast_traverse(AST_object * self,visitproc visit,void * arg)772 ast_traverse(AST_object *self, visitproc visit, void *arg)
773 {
774 Py_VISIT(Py_TYPE(self));
775 Py_VISIT(self->dict);
776 return 0;
777 }
778
779 static int
ast_clear(AST_object * self)780 ast_clear(AST_object *self)
781 {
782 Py_CLEAR(self->dict);
783 return 0;
784 }
785
786 static int
ast_type_init(PyObject * self,PyObject * args,PyObject * kw)787 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
788 {
789 struct ast_state *state = get_ast_state();
790 if (state == NULL) {
791 return -1;
792 }
793
794 Py_ssize_t i, numfields = 0;
795 int res = -1;
796 PyObject *key, *value, *fields;
797 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
798 goto cleanup;
799 }
800 if (fields) {
801 numfields = PySequence_Size(fields);
802 if (numfields == -1) {
803 goto cleanup;
804 }
805 }
806
807 res = 0; /* if no error occurs, this stays 0 to the end */
808 if (numfields < PyTuple_GET_SIZE(args)) {
809 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
810 "%zd positional argument%s",
811 _PyType_Name(Py_TYPE(self)),
812 numfields, numfields == 1 ? "" : "s");
813 res = -1;
814 goto cleanup;
815 }
816 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
817 /* cannot be reached when fields is NULL */
818 PyObject *name = PySequence_GetItem(fields, i);
819 if (!name) {
820 res = -1;
821 goto cleanup;
822 }
823 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
824 Py_DECREF(name);
825 if (res < 0) {
826 goto cleanup;
827 }
828 }
829 if (kw) {
830 i = 0; /* needed by PyDict_Next */
831 while (PyDict_Next(kw, &i, &key, &value)) {
832 int contains = PySequence_Contains(fields, key);
833 if (contains == -1) {
834 res = -1;
835 goto cleanup;
836 } else if (contains == 1) {
837 Py_ssize_t p = PySequence_Index(fields, key);
838 if (p == -1) {
839 res = -1;
840 goto cleanup;
841 }
842 if (p < PyTuple_GET_SIZE(args)) {
843 PyErr_Format(PyExc_TypeError,
844 "%.400s got multiple values for argument '%U'",
845 Py_TYPE(self)->tp_name, key);
846 res = -1;
847 goto cleanup;
848 }
849 }
850 res = PyObject_SetAttr(self, key, value);
851 if (res < 0) {
852 goto cleanup;
853 }
854 }
855 }
856 cleanup:
857 Py_XDECREF(fields);
858 return res;
859 }
860
861 /* Pickling support */
862 static PyObject *
ast_type_reduce(PyObject * self,PyObject * unused)863 ast_type_reduce(PyObject *self, PyObject *unused)
864 {
865 struct ast_state *state = get_ast_state();
866 if (state == NULL) {
867 return NULL;
868 }
869
870 PyObject *dict;
871 if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
872 return NULL;
873 }
874 if (dict) {
875 return Py_BuildValue("O()N", Py_TYPE(self), dict);
876 }
877 return Py_BuildValue("O()", Py_TYPE(self));
878 }
879
880 static PyMemberDef ast_type_members[] = {
881 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
882 {NULL} /* Sentinel */
883 };
884
885 static PyMethodDef ast_type_methods[] = {
886 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
887 {NULL}
888 };
889
890 static PyGetSetDef ast_type_getsets[] = {
891 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
892 {NULL}
893 };
894
895 static PyType_Slot AST_type_slots[] = {
896 {Py_tp_dealloc, ast_dealloc},
897 {Py_tp_getattro, PyObject_GenericGetAttr},
898 {Py_tp_setattro, PyObject_GenericSetAttr},
899 {Py_tp_traverse, ast_traverse},
900 {Py_tp_clear, ast_clear},
901 {Py_tp_members, ast_type_members},
902 {Py_tp_methods, ast_type_methods},
903 {Py_tp_getset, ast_type_getsets},
904 {Py_tp_init, ast_type_init},
905 {Py_tp_alloc, PyType_GenericAlloc},
906 {Py_tp_new, PyType_GenericNew},
907 {Py_tp_free, PyObject_GC_Del},
908 {0, 0},
909 };
910
911 static PyType_Spec AST_type_spec = {
912 "ast.AST",
913 sizeof(AST_object),
914 0,
915 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
916 AST_type_slots
917 };
918
919 static PyObject *
make_type(struct ast_state * state,const char * type,PyObject * base,const char * const * fields,int num_fields,const char * doc)920 make_type(struct ast_state *state, const char *type, PyObject* base,
921 const char* const* fields, int num_fields, const char *doc)
922 {
923 PyObject *fnames, *result;
924 int i;
925 fnames = PyTuple_New(num_fields);
926 if (!fnames) return NULL;
927 for (i = 0; i < num_fields; i++) {
928 PyObject *field = PyUnicode_InternFromString(fields[i]);
929 if (!field) {
930 Py_DECREF(fnames);
931 return NULL;
932 }
933 PyTuple_SET_ITEM(fnames, i, field);
934 }
935 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
936 type, base,
937 state->_fields, fnames,
938 state->__match_args__, fnames,
939 state->__module__,
940 state->ast,
941 state->__doc__, doc);
942 Py_DECREF(fnames);
943 return result;
944 }
945
946 static int
add_attributes(struct ast_state * state,PyObject * type,const char * const * attrs,int num_fields)947 add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
948 {
949 int i, result;
950 PyObject *s, *l = PyTuple_New(num_fields);
951 if (!l)
952 return 0;
953 for (i = 0; i < num_fields; i++) {
954 s = PyUnicode_InternFromString(attrs[i]);
955 if (!s) {
956 Py_DECREF(l);
957 return 0;
958 }
959 PyTuple_SET_ITEM(l, i, s);
960 }
961 result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
962 Py_DECREF(l);
963 return result;
964 }
965
966 /* Conversion AST -> Python */
967
ast2obj_list(struct ast_state * state,asdl_seq * seq,PyObject * (* func)(struct ast_state * state,void *))968 static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq, PyObject* (*func)(struct ast_state *state, void*))
969 {
970 Py_ssize_t i, n = asdl_seq_LEN(seq);
971 PyObject *result = PyList_New(n);
972 PyObject *value;
973 if (!result)
974 return NULL;
975 for (i = 0; i < n; i++) {
976 value = func(state, asdl_seq_GET_UNTYPED(seq, i));
977 if (!value) {
978 Py_DECREF(result);
979 return NULL;
980 }
981 PyList_SET_ITEM(result, i, value);
982 }
983 return result;
984 }
985
ast2obj_object(struct ast_state * Py_UNUSED (state),void * o)986 static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
987 {
988 if (!o)
989 o = Py_None;
990 Py_INCREF((PyObject*)o);
991 return (PyObject*)o;
992 }
993 #define ast2obj_constant ast2obj_object
994 #define ast2obj_identifier ast2obj_object
995 #define ast2obj_string ast2obj_object
996
ast2obj_int(struct ast_state * Py_UNUSED (state),long b)997 static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
998 {
999 return PyLong_FromLong(b);
1000 }
1001
1002 /* Conversion Python -> AST */
1003
obj2ast_object(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)1004 static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1005 {
1006 if (obj == Py_None)
1007 obj = NULL;
1008 if (obj) {
1009 if (_PyArena_AddPyObject(arena, obj) < 0) {
1010 *out = NULL;
1011 return -1;
1012 }
1013 Py_INCREF(obj);
1014 }
1015 *out = obj;
1016 return 0;
1017 }
1018
obj2ast_constant(struct ast_state * Py_UNUSED (state),PyObject * obj,PyObject ** out,PyArena * arena)1019 static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
1020 {
1021 if (_PyArena_AddPyObject(arena, obj) < 0) {
1022 *out = NULL;
1023 return -1;
1024 }
1025 Py_INCREF(obj);
1026 *out = obj;
1027 return 0;
1028 }
1029
obj2ast_identifier(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)1030 static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1031 {
1032 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1033 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
1034 return 1;
1035 }
1036 return obj2ast_object(state, obj, out, arena);
1037 }
1038
obj2ast_string(struct ast_state * state,PyObject * obj,PyObject ** out,PyArena * arena)1039 static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
1040 {
1041 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1042 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1043 return 1;
1044 }
1045 return obj2ast_object(state, obj, out, arena);
1046 }
1047
obj2ast_int(struct ast_state * Py_UNUSED (state),PyObject * obj,int * out,PyArena * arena)1048 static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
1049 {
1050 int i;
1051 if (!PyLong_Check(obj)) {
1052 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
1053 return 1;
1054 }
1055
1056 i = _PyLong_AsInt(obj);
1057 if (i == -1 && PyErr_Occurred())
1058 return 1;
1059 *out = i;
1060 return 0;
1061 }
1062
add_ast_fields(struct ast_state * state)1063 static int add_ast_fields(struct ast_state *state)
1064 {
1065 PyObject *empty_tuple;
1066 empty_tuple = PyTuple_New(0);
1067 if (!empty_tuple ||
1068 PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
1069 PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
1070 PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
1071 Py_XDECREF(empty_tuple);
1072 return -1;
1073 }
1074 Py_DECREF(empty_tuple);
1075 return 0;
1076 }
1077
1078
1079
1080 static int
init_types(struct ast_state * state)1081 init_types(struct ast_state *state)
1082 {
1083 // init_types() must not be called after _PyAST_Fini()
1084 // has been called
1085 assert(state->initialized >= 0);
1086
1087 if (state->initialized) {
1088 return 1;
1089 }
1090 if (init_identifiers(state) < 0) {
1091 return 0;
1092 }
1093 state->AST_type = PyType_FromSpec(&AST_type_spec);
1094 if (!state->AST_type) {
1095 return 0;
1096 }
1097 if (add_ast_fields(state) < 0) {
1098 return 0;
1099 }
1100 state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
1101 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1102 " | Interactive(stmt* body)\n"
1103 " | Expression(expr body)\n"
1104 " | FunctionType(expr* argtypes, expr returns)");
1105 if (!state->mod_type) return 0;
1106 if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
1107 state->Module_type = make_type(state, "Module", state->mod_type,
1108 Module_fields, 2,
1109 "Module(stmt* body, type_ignore* type_ignores)");
1110 if (!state->Module_type) return 0;
1111 state->Interactive_type = make_type(state, "Interactive", state->mod_type,
1112 Interactive_fields, 1,
1113 "Interactive(stmt* body)");
1114 if (!state->Interactive_type) return 0;
1115 state->Expression_type = make_type(state, "Expression", state->mod_type,
1116 Expression_fields, 1,
1117 "Expression(expr body)");
1118 if (!state->Expression_type) return 0;
1119 state->FunctionType_type = make_type(state, "FunctionType",
1120 state->mod_type, FunctionType_fields,
1121 2,
1122 "FunctionType(expr* argtypes, expr returns)");
1123 if (!state->FunctionType_type) return 0;
1124 state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
1125 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1126 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1127 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1128 " | Return(expr? value)\n"
1129 " | Delete(expr* targets)\n"
1130 " | Assign(expr* targets, expr value, string? type_comment)\n"
1131 " | AugAssign(expr target, operator op, expr value)\n"
1132 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1133 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1134 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1135 " | While(expr test, stmt* body, stmt* orelse)\n"
1136 " | If(expr test, stmt* body, stmt* orelse)\n"
1137 " | With(withitem* items, stmt* body, string? type_comment)\n"
1138 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1139 " | Match(expr subject, match_case* cases)\n"
1140 " | Raise(expr? exc, expr? cause)\n"
1141 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1142 " | Assert(expr test, expr? msg)\n"
1143 " | Import(alias* names)\n"
1144 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1145 " | Global(identifier* names)\n"
1146 " | Nonlocal(identifier* names)\n"
1147 " | Expr(expr value)\n"
1148 " | Pass\n"
1149 " | Break\n"
1150 " | Continue");
1151 if (!state->stmt_type) return 0;
1152 if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
1153 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1154 return 0;
1155 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1156 -1)
1157 return 0;
1158 state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
1159 FunctionDef_fields, 6,
1160 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
1161 if (!state->FunctionDef_type) return 0;
1162 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1163 -1)
1164 return 0;
1165 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1166 == -1)
1167 return 0;
1168 state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
1169 state->stmt_type,
1170 AsyncFunctionDef_fields, 6,
1171 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
1172 if (!state->AsyncFunctionDef_type) return 0;
1173 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1174 == -1)
1175 return 0;
1176 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1177 Py_None) == -1)
1178 return 0;
1179 state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
1180 ClassDef_fields, 5,
1181 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
1182 if (!state->ClassDef_type) return 0;
1183 state->Return_type = make_type(state, "Return", state->stmt_type,
1184 Return_fields, 1,
1185 "Return(expr? value)");
1186 if (!state->Return_type) return 0;
1187 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1188 return 0;
1189 state->Delete_type = make_type(state, "Delete", state->stmt_type,
1190 Delete_fields, 1,
1191 "Delete(expr* targets)");
1192 if (!state->Delete_type) return 0;
1193 state->Assign_type = make_type(state, "Assign", state->stmt_type,
1194 Assign_fields, 3,
1195 "Assign(expr* targets, expr value, string? type_comment)");
1196 if (!state->Assign_type) return 0;
1197 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1198 -1)
1199 return 0;
1200 state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
1201 AugAssign_fields, 3,
1202 "AugAssign(expr target, operator op, expr value)");
1203 if (!state->AugAssign_type) return 0;
1204 state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
1205 AnnAssign_fields, 4,
1206 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
1207 if (!state->AnnAssign_type) return 0;
1208 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1209 return 0;
1210 state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
1211 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1212 if (!state->For_type) return 0;
1213 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1214 return 0;
1215 state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
1216 AsyncFor_fields, 5,
1217 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
1218 if (!state->AsyncFor_type) return 0;
1219 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1220 -1)
1221 return 0;
1222 state->While_type = make_type(state, "While", state->stmt_type,
1223 While_fields, 3,
1224 "While(expr test, stmt* body, stmt* orelse)");
1225 if (!state->While_type) return 0;
1226 state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
1227 "If(expr test, stmt* body, stmt* orelse)");
1228 if (!state->If_type) return 0;
1229 state->With_type = make_type(state, "With", state->stmt_type, With_fields,
1230 3,
1231 "With(withitem* items, stmt* body, string? type_comment)");
1232 if (!state->With_type) return 0;
1233 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1234 return 0;
1235 state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
1236 AsyncWith_fields, 3,
1237 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
1238 if (!state->AsyncWith_type) return 0;
1239 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1240 == -1)
1241 return 0;
1242 state->Match_type = make_type(state, "Match", state->stmt_type,
1243 Match_fields, 2,
1244 "Match(expr subject, match_case* cases)");
1245 if (!state->Match_type) return 0;
1246 state->Raise_type = make_type(state, "Raise", state->stmt_type,
1247 Raise_fields, 2,
1248 "Raise(expr? exc, expr? cause)");
1249 if (!state->Raise_type) return 0;
1250 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1251 return 0;
1252 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1253 return 0;
1254 state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
1255 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
1256 if (!state->Try_type) return 0;
1257 state->Assert_type = make_type(state, "Assert", state->stmt_type,
1258 Assert_fields, 2,
1259 "Assert(expr test, expr? msg)");
1260 if (!state->Assert_type) return 0;
1261 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1262 return 0;
1263 state->Import_type = make_type(state, "Import", state->stmt_type,
1264 Import_fields, 1,
1265 "Import(alias* names)");
1266 if (!state->Import_type) return 0;
1267 state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
1268 ImportFrom_fields, 3,
1269 "ImportFrom(identifier? module, alias* names, int? level)");
1270 if (!state->ImportFrom_type) return 0;
1271 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1272 return 0;
1273 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1274 return 0;
1275 state->Global_type = make_type(state, "Global", state->stmt_type,
1276 Global_fields, 1,
1277 "Global(identifier* names)");
1278 if (!state->Global_type) return 0;
1279 state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
1280 Nonlocal_fields, 1,
1281 "Nonlocal(identifier* names)");
1282 if (!state->Nonlocal_type) return 0;
1283 state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
1284 1,
1285 "Expr(expr value)");
1286 if (!state->Expr_type) return 0;
1287 state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
1288 "Pass");
1289 if (!state->Pass_type) return 0;
1290 state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
1291 "Break");
1292 if (!state->Break_type) return 0;
1293 state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
1294 0,
1295 "Continue");
1296 if (!state->Continue_type) return 0;
1297 state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
1298 "expr = BoolOp(boolop op, expr* values)\n"
1299 " | NamedExpr(expr target, expr value)\n"
1300 " | BinOp(expr left, operator op, expr right)\n"
1301 " | UnaryOp(unaryop op, expr operand)\n"
1302 " | Lambda(arguments args, expr body)\n"
1303 " | IfExp(expr test, expr body, expr orelse)\n"
1304 " | Dict(expr* keys, expr* values)\n"
1305 " | Set(expr* elts)\n"
1306 " | ListComp(expr elt, comprehension* generators)\n"
1307 " | SetComp(expr elt, comprehension* generators)\n"
1308 " | DictComp(expr key, expr value, comprehension* generators)\n"
1309 " | GeneratorExp(expr elt, comprehension* generators)\n"
1310 " | Await(expr value)\n"
1311 " | Yield(expr? value)\n"
1312 " | YieldFrom(expr value)\n"
1313 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1314 " | Call(expr func, expr* args, keyword* keywords)\n"
1315 " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
1316 " | JoinedStr(expr* values)\n"
1317 " | Constant(constant value, string? kind)\n"
1318 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1319 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1320 " | Starred(expr value, expr_context ctx)\n"
1321 " | Name(identifier id, expr_context ctx)\n"
1322 " | List(expr* elts, expr_context ctx)\n"
1323 " | Tuple(expr* elts, expr_context ctx)\n"
1324 " | Slice(expr? lower, expr? upper, expr? step)");
1325 if (!state->expr_type) return 0;
1326 if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
1327 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1328 return 0;
1329 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1330 -1)
1331 return 0;
1332 state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
1333 BoolOp_fields, 2,
1334 "BoolOp(boolop op, expr* values)");
1335 if (!state->BoolOp_type) return 0;
1336 state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
1337 NamedExpr_fields, 2,
1338 "NamedExpr(expr target, expr value)");
1339 if (!state->NamedExpr_type) return 0;
1340 state->BinOp_type = make_type(state, "BinOp", state->expr_type,
1341 BinOp_fields, 3,
1342 "BinOp(expr left, operator op, expr right)");
1343 if (!state->BinOp_type) return 0;
1344 state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
1345 UnaryOp_fields, 2,
1346 "UnaryOp(unaryop op, expr operand)");
1347 if (!state->UnaryOp_type) return 0;
1348 state->Lambda_type = make_type(state, "Lambda", state->expr_type,
1349 Lambda_fields, 2,
1350 "Lambda(arguments args, expr body)");
1351 if (!state->Lambda_type) return 0;
1352 state->IfExp_type = make_type(state, "IfExp", state->expr_type,
1353 IfExp_fields, 3,
1354 "IfExp(expr test, expr body, expr orelse)");
1355 if (!state->IfExp_type) return 0;
1356 state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
1357 2,
1358 "Dict(expr* keys, expr* values)");
1359 if (!state->Dict_type) return 0;
1360 state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
1361 "Set(expr* elts)");
1362 if (!state->Set_type) return 0;
1363 state->ListComp_type = make_type(state, "ListComp", state->expr_type,
1364 ListComp_fields, 2,
1365 "ListComp(expr elt, comprehension* generators)");
1366 if (!state->ListComp_type) return 0;
1367 state->SetComp_type = make_type(state, "SetComp", state->expr_type,
1368 SetComp_fields, 2,
1369 "SetComp(expr elt, comprehension* generators)");
1370 if (!state->SetComp_type) return 0;
1371 state->DictComp_type = make_type(state, "DictComp", state->expr_type,
1372 DictComp_fields, 3,
1373 "DictComp(expr key, expr value, comprehension* generators)");
1374 if (!state->DictComp_type) return 0;
1375 state->GeneratorExp_type = make_type(state, "GeneratorExp",
1376 state->expr_type, GeneratorExp_fields,
1377 2,
1378 "GeneratorExp(expr elt, comprehension* generators)");
1379 if (!state->GeneratorExp_type) return 0;
1380 state->Await_type = make_type(state, "Await", state->expr_type,
1381 Await_fields, 1,
1382 "Await(expr value)");
1383 if (!state->Await_type) return 0;
1384 state->Yield_type = make_type(state, "Yield", state->expr_type,
1385 Yield_fields, 1,
1386 "Yield(expr? value)");
1387 if (!state->Yield_type) return 0;
1388 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1389 return 0;
1390 state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
1391 YieldFrom_fields, 1,
1392 "YieldFrom(expr value)");
1393 if (!state->YieldFrom_type) return 0;
1394 state->Compare_type = make_type(state, "Compare", state->expr_type,
1395 Compare_fields, 3,
1396 "Compare(expr left, cmpop* ops, expr* comparators)");
1397 if (!state->Compare_type) return 0;
1398 state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
1399 3,
1400 "Call(expr func, expr* args, keyword* keywords)");
1401 if (!state->Call_type) return 0;
1402 state->FormattedValue_type = make_type(state, "FormattedValue",
1403 state->expr_type,
1404 FormattedValue_fields, 3,
1405 "FormattedValue(expr value, int conversion, expr? format_spec)");
1406 if (!state->FormattedValue_type) return 0;
1407 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1408 Py_None) == -1)
1409 return 0;
1410 state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
1411 JoinedStr_fields, 1,
1412 "JoinedStr(expr* values)");
1413 if (!state->JoinedStr_type) return 0;
1414 state->Constant_type = make_type(state, "Constant", state->expr_type,
1415 Constant_fields, 2,
1416 "Constant(constant value, string? kind)");
1417 if (!state->Constant_type) return 0;
1418 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1419 return 0;
1420 state->Attribute_type = make_type(state, "Attribute", state->expr_type,
1421 Attribute_fields, 3,
1422 "Attribute(expr value, identifier attr, expr_context ctx)");
1423 if (!state->Attribute_type) return 0;
1424 state->Subscript_type = make_type(state, "Subscript", state->expr_type,
1425 Subscript_fields, 3,
1426 "Subscript(expr value, expr slice, expr_context ctx)");
1427 if (!state->Subscript_type) return 0;
1428 state->Starred_type = make_type(state, "Starred", state->expr_type,
1429 Starred_fields, 2,
1430 "Starred(expr value, expr_context ctx)");
1431 if (!state->Starred_type) return 0;
1432 state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
1433 2,
1434 "Name(identifier id, expr_context ctx)");
1435 if (!state->Name_type) return 0;
1436 state->List_type = make_type(state, "List", state->expr_type, List_fields,
1437 2,
1438 "List(expr* elts, expr_context ctx)");
1439 if (!state->List_type) return 0;
1440 state->Tuple_type = make_type(state, "Tuple", state->expr_type,
1441 Tuple_fields, 2,
1442 "Tuple(expr* elts, expr_context ctx)");
1443 if (!state->Tuple_type) return 0;
1444 state->Slice_type = make_type(state, "Slice", state->expr_type,
1445 Slice_fields, 3,
1446 "Slice(expr? lower, expr? upper, expr? step)");
1447 if (!state->Slice_type) return 0;
1448 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1449 return 0;
1450 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1451 return 0;
1452 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1453 return 0;
1454 state->expr_context_type = make_type(state, "expr_context",
1455 state->AST_type, NULL, 0,
1456 "expr_context = Load | Store | Del");
1457 if (!state->expr_context_type) return 0;
1458 if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
1459 state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
1460 0,
1461 "Load");
1462 if (!state->Load_type) return 0;
1463 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1464 NULL, NULL);
1465 if (!state->Load_singleton) return 0;
1466 state->Store_type = make_type(state, "Store", state->expr_context_type,
1467 NULL, 0,
1468 "Store");
1469 if (!state->Store_type) return 0;
1470 state->Store_singleton = PyType_GenericNew((PyTypeObject
1471 *)state->Store_type, NULL, NULL);
1472 if (!state->Store_singleton) return 0;
1473 state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
1474 "Del");
1475 if (!state->Del_type) return 0;
1476 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1477 NULL, NULL);
1478 if (!state->Del_singleton) return 0;
1479 state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
1480 "boolop = And | Or");
1481 if (!state->boolop_type) return 0;
1482 if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
1483 state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
1484 "And");
1485 if (!state->And_type) return 0;
1486 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1487 NULL, NULL);
1488 if (!state->And_singleton) return 0;
1489 state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
1490 "Or");
1491 if (!state->Or_type) return 0;
1492 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1493 NULL, NULL);
1494 if (!state->Or_singleton) return 0;
1495 state->operator_type = make_type(state, "operator", state->AST_type, NULL,
1496 0,
1497 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
1498 if (!state->operator_type) return 0;
1499 if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
1500 state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
1501 "Add");
1502 if (!state->Add_type) return 0;
1503 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1504 NULL, NULL);
1505 if (!state->Add_singleton) return 0;
1506 state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
1507 "Sub");
1508 if (!state->Sub_type) return 0;
1509 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1510 NULL, NULL);
1511 if (!state->Sub_singleton) return 0;
1512 state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
1513 "Mult");
1514 if (!state->Mult_type) return 0;
1515 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1516 NULL, NULL);
1517 if (!state->Mult_singleton) return 0;
1518 state->MatMult_type = make_type(state, "MatMult", state->operator_type,
1519 NULL, 0,
1520 "MatMult");
1521 if (!state->MatMult_type) return 0;
1522 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1523 *)state->MatMult_type, NULL,
1524 NULL);
1525 if (!state->MatMult_singleton) return 0;
1526 state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
1527 "Div");
1528 if (!state->Div_type) return 0;
1529 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1530 NULL, NULL);
1531 if (!state->Div_singleton) return 0;
1532 state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
1533 "Mod");
1534 if (!state->Mod_type) return 0;
1535 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1536 NULL, NULL);
1537 if (!state->Mod_singleton) return 0;
1538 state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
1539 "Pow");
1540 if (!state->Pow_type) return 0;
1541 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1542 NULL, NULL);
1543 if (!state->Pow_singleton) return 0;
1544 state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
1545 0,
1546 "LShift");
1547 if (!state->LShift_type) return 0;
1548 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1549 *)state->LShift_type, NULL,
1550 NULL);
1551 if (!state->LShift_singleton) return 0;
1552 state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
1553 0,
1554 "RShift");
1555 if (!state->RShift_type) return 0;
1556 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1557 *)state->RShift_type, NULL,
1558 NULL);
1559 if (!state->RShift_singleton) return 0;
1560 state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
1561 "BitOr");
1562 if (!state->BitOr_type) return 0;
1563 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1564 *)state->BitOr_type, NULL, NULL);
1565 if (!state->BitOr_singleton) return 0;
1566 state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
1567 0,
1568 "BitXor");
1569 if (!state->BitXor_type) return 0;
1570 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1571 *)state->BitXor_type, NULL,
1572 NULL);
1573 if (!state->BitXor_singleton) return 0;
1574 state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
1575 0,
1576 "BitAnd");
1577 if (!state->BitAnd_type) return 0;
1578 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1579 *)state->BitAnd_type, NULL,
1580 NULL);
1581 if (!state->BitAnd_singleton) return 0;
1582 state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
1583 NULL, 0,
1584 "FloorDiv");
1585 if (!state->FloorDiv_type) return 0;
1586 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1587 *)state->FloorDiv_type, NULL,
1588 NULL);
1589 if (!state->FloorDiv_singleton) return 0;
1590 state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
1591 "unaryop = Invert | Not | UAdd | USub");
1592 if (!state->unaryop_type) return 0;
1593 if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
1594 state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
1595 0,
1596 "Invert");
1597 if (!state->Invert_type) return 0;
1598 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1599 *)state->Invert_type, NULL,
1600 NULL);
1601 if (!state->Invert_singleton) return 0;
1602 state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
1603 "Not");
1604 if (!state->Not_type) return 0;
1605 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1606 NULL, NULL);
1607 if (!state->Not_singleton) return 0;
1608 state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
1609 "UAdd");
1610 if (!state->UAdd_type) return 0;
1611 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1612 NULL, NULL);
1613 if (!state->UAdd_singleton) return 0;
1614 state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
1615 "USub");
1616 if (!state->USub_type) return 0;
1617 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1618 NULL, NULL);
1619 if (!state->USub_singleton) return 0;
1620 state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
1621 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
1622 if (!state->cmpop_type) return 0;
1623 if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
1624 state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
1625 "Eq");
1626 if (!state->Eq_type) return 0;
1627 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1628 NULL, NULL);
1629 if (!state->Eq_singleton) return 0;
1630 state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
1631 "NotEq");
1632 if (!state->NotEq_type) return 0;
1633 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1634 *)state->NotEq_type, NULL, NULL);
1635 if (!state->NotEq_singleton) return 0;
1636 state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
1637 "Lt");
1638 if (!state->Lt_type) return 0;
1639 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1640 NULL, NULL);
1641 if (!state->Lt_singleton) return 0;
1642 state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
1643 "LtE");
1644 if (!state->LtE_type) return 0;
1645 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1646 NULL, NULL);
1647 if (!state->LtE_singleton) return 0;
1648 state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
1649 "Gt");
1650 if (!state->Gt_type) return 0;
1651 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1652 NULL, NULL);
1653 if (!state->Gt_singleton) return 0;
1654 state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
1655 "GtE");
1656 if (!state->GtE_type) return 0;
1657 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1658 NULL, NULL);
1659 if (!state->GtE_singleton) return 0;
1660 state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
1661 "Is");
1662 if (!state->Is_type) return 0;
1663 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1664 NULL, NULL);
1665 if (!state->Is_singleton) return 0;
1666 state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
1667 "IsNot");
1668 if (!state->IsNot_type) return 0;
1669 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1670 *)state->IsNot_type, NULL, NULL);
1671 if (!state->IsNot_singleton) return 0;
1672 state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
1673 "In");
1674 if (!state->In_type) return 0;
1675 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1676 NULL, NULL);
1677 if (!state->In_singleton) return 0;
1678 state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
1679 "NotIn");
1680 if (!state->NotIn_type) return 0;
1681 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1682 *)state->NotIn_type, NULL, NULL);
1683 if (!state->NotIn_singleton) return 0;
1684 state->comprehension_type = make_type(state, "comprehension",
1685 state->AST_type,
1686 comprehension_fields, 4,
1687 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
1688 if (!state->comprehension_type) return 0;
1689 if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
1690 state->excepthandler_type = make_type(state, "excepthandler",
1691 state->AST_type, NULL, 0,
1692 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
1693 if (!state->excepthandler_type) return 0;
1694 if (!add_attributes(state, state->excepthandler_type,
1695 excepthandler_attributes, 4)) return 0;
1696 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1697 == -1)
1698 return 0;
1699 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1700 Py_None) == -1)
1701 return 0;
1702 state->ExceptHandler_type = make_type(state, "ExceptHandler",
1703 state->excepthandler_type,
1704 ExceptHandler_fields, 3,
1705 "ExceptHandler(expr? type, identifier? name, stmt* body)");
1706 if (!state->ExceptHandler_type) return 0;
1707 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1708 return 0;
1709 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1710 return 0;
1711 state->arguments_type = make_type(state, "arguments", state->AST_type,
1712 arguments_fields, 7,
1713 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
1714 if (!state->arguments_type) return 0;
1715 if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
1716 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1717 return 0;
1718 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1719 return 0;
1720 state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
1721 "arg(identifier arg, expr? annotation, string? type_comment)");
1722 if (!state->arg_type) return 0;
1723 if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
1724 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1725 return 0;
1726 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1727 return 0;
1728 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1729 return 0;
1730 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1731 return 0;
1732 state->keyword_type = make_type(state, "keyword", state->AST_type,
1733 keyword_fields, 2,
1734 "keyword(identifier? arg, expr value)");
1735 if (!state->keyword_type) return 0;
1736 if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
1737 return 0;
1738 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1739 return 0;
1740 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1741 return 0;
1742 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1743 == -1)
1744 return 0;
1745 state->alias_type = make_type(state, "alias", state->AST_type,
1746 alias_fields, 2,
1747 "alias(identifier name, identifier? asname)");
1748 if (!state->alias_type) return 0;
1749 if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
1750 0;
1751 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1752 return 0;
1753 if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
1754 return 0;
1755 if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
1756 -1)
1757 return 0;
1758 state->withitem_type = make_type(state, "withitem", state->AST_type,
1759 withitem_fields, 2,
1760 "withitem(expr context_expr, expr? optional_vars)");
1761 if (!state->withitem_type) return 0;
1762 if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
1763 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1764 == -1)
1765 return 0;
1766 state->match_case_type = make_type(state, "match_case", state->AST_type,
1767 match_case_fields, 3,
1768 "match_case(pattern pattern, expr? guard, stmt* body)");
1769 if (!state->match_case_type) return 0;
1770 if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
1771 if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
1772 return 0;
1773 state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
1774 "pattern = MatchValue(expr value)\n"
1775 " | MatchSingleton(constant value)\n"
1776 " | MatchSequence(pattern* patterns)\n"
1777 " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
1778 " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
1779 " | MatchStar(identifier? name)\n"
1780 " | MatchAs(pattern? pattern, identifier? name)\n"
1781 " | MatchOr(pattern* patterns)");
1782 if (!state->pattern_type) return 0;
1783 if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
1784 return 0;
1785 state->MatchValue_type = make_type(state, "MatchValue",
1786 state->pattern_type, MatchValue_fields,
1787 1,
1788 "MatchValue(expr value)");
1789 if (!state->MatchValue_type) return 0;
1790 state->MatchSingleton_type = make_type(state, "MatchSingleton",
1791 state->pattern_type,
1792 MatchSingleton_fields, 1,
1793 "MatchSingleton(constant value)");
1794 if (!state->MatchSingleton_type) return 0;
1795 state->MatchSequence_type = make_type(state, "MatchSequence",
1796 state->pattern_type,
1797 MatchSequence_fields, 1,
1798 "MatchSequence(pattern* patterns)");
1799 if (!state->MatchSequence_type) return 0;
1800 state->MatchMapping_type = make_type(state, "MatchMapping",
1801 state->pattern_type,
1802 MatchMapping_fields, 3,
1803 "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
1804 if (!state->MatchMapping_type) return 0;
1805 if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
1806 return 0;
1807 state->MatchClass_type = make_type(state, "MatchClass",
1808 state->pattern_type, MatchClass_fields,
1809 4,
1810 "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
1811 if (!state->MatchClass_type) return 0;
1812 state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
1813 MatchStar_fields, 1,
1814 "MatchStar(identifier? name)");
1815 if (!state->MatchStar_type) return 0;
1816 if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
1817 return 0;
1818 state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
1819 MatchAs_fields, 2,
1820 "MatchAs(pattern? pattern, identifier? name)");
1821 if (!state->MatchAs_type) return 0;
1822 if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
1823 return 0;
1824 if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
1825 return 0;
1826 state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
1827 MatchOr_fields, 1,
1828 "MatchOr(pattern* patterns)");
1829 if (!state->MatchOr_type) return 0;
1830 state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
1831 NULL, 0,
1832 "type_ignore = TypeIgnore(int lineno, string tag)");
1833 if (!state->type_ignore_type) return 0;
1834 if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
1835 state->TypeIgnore_type = make_type(state, "TypeIgnore",
1836 state->type_ignore_type,
1837 TypeIgnore_fields, 2,
1838 "TypeIgnore(int lineno, string tag)");
1839 if (!state->TypeIgnore_type) return 0;
1840
1841 state->initialized = 1;
1842 return 1;
1843 }
1844
1845 static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
1846 PyArena* arena);
1847 static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
1848 PyArena* arena);
1849 static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
1850 PyArena* arena);
1851 static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
1852 expr_context_ty* out, PyArena* arena);
1853 static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
1854 out, PyArena* arena);
1855 static int obj2ast_operator(struct ast_state *state, PyObject* obj,
1856 operator_ty* out, PyArena* arena);
1857 static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
1858 out, PyArena* arena);
1859 static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
1860 PyArena* arena);
1861 static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
1862 comprehension_ty* out, PyArena* arena);
1863 static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
1864 excepthandler_ty* out, PyArena* arena);
1865 static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
1866 arguments_ty* out, PyArena* arena);
1867 static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
1868 PyArena* arena);
1869 static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
1870 out, PyArena* arena);
1871 static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
1872 PyArena* arena);
1873 static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
1874 withitem_ty* out, PyArena* arena);
1875 static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
1876 match_case_ty* out, PyArena* arena);
1877 static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
1878 out, PyArena* arena);
1879 static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
1880 type_ignore_ty* out, PyArena* arena);
1881
1882 mod_ty
_PyAST_Module(asdl_stmt_seq * body,asdl_type_ignore_seq * type_ignores,PyArena * arena)1883 _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
1884 PyArena *arena)
1885 {
1886 mod_ty p;
1887 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1888 if (!p)
1889 return NULL;
1890 p->kind = Module_kind;
1891 p->v.Module.body = body;
1892 p->v.Module.type_ignores = type_ignores;
1893 return p;
1894 }
1895
1896 mod_ty
_PyAST_Interactive(asdl_stmt_seq * body,PyArena * arena)1897 _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
1898 {
1899 mod_ty p;
1900 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1901 if (!p)
1902 return NULL;
1903 p->kind = Interactive_kind;
1904 p->v.Interactive.body = body;
1905 return p;
1906 }
1907
1908 mod_ty
_PyAST_Expression(expr_ty body,PyArena * arena)1909 _PyAST_Expression(expr_ty body, PyArena *arena)
1910 {
1911 mod_ty p;
1912 if (!body) {
1913 PyErr_SetString(PyExc_ValueError,
1914 "field 'body' is required for Expression");
1915 return NULL;
1916 }
1917 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1918 if (!p)
1919 return NULL;
1920 p->kind = Expression_kind;
1921 p->v.Expression.body = body;
1922 return p;
1923 }
1924
1925 mod_ty
_PyAST_FunctionType(asdl_expr_seq * argtypes,expr_ty returns,PyArena * arena)1926 _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
1927 {
1928 mod_ty p;
1929 if (!returns) {
1930 PyErr_SetString(PyExc_ValueError,
1931 "field 'returns' is required for FunctionType");
1932 return NULL;
1933 }
1934 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
1935 if (!p)
1936 return NULL;
1937 p->kind = FunctionType_kind;
1938 p->v.FunctionType.argtypes = argtypes;
1939 p->v.FunctionType.returns = returns;
1940 return p;
1941 }
1942
1943 stmt_ty
_PyAST_FunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1944 _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
1945 asdl_expr_seq * decorator_list, expr_ty returns, string
1946 type_comment, int lineno, int col_offset, int end_lineno,
1947 int end_col_offset, PyArena *arena)
1948 {
1949 stmt_ty p;
1950 if (!name) {
1951 PyErr_SetString(PyExc_ValueError,
1952 "field 'name' is required for FunctionDef");
1953 return NULL;
1954 }
1955 if (!args) {
1956 PyErr_SetString(PyExc_ValueError,
1957 "field 'args' is required for FunctionDef");
1958 return NULL;
1959 }
1960 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
1961 if (!p)
1962 return NULL;
1963 p->kind = FunctionDef_kind;
1964 p->v.FunctionDef.name = name;
1965 p->v.FunctionDef.args = args;
1966 p->v.FunctionDef.body = body;
1967 p->v.FunctionDef.decorator_list = decorator_list;
1968 p->v.FunctionDef.returns = returns;
1969 p->v.FunctionDef.type_comment = type_comment;
1970 p->lineno = lineno;
1971 p->col_offset = col_offset;
1972 p->end_lineno = end_lineno;
1973 p->end_col_offset = end_col_offset;
1974 return p;
1975 }
1976
1977 stmt_ty
_PyAST_AsyncFunctionDef(identifier name,arguments_ty args,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1978 _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
1979 body, asdl_expr_seq * decorator_list, expr_ty returns,
1980 string type_comment, int lineno, int col_offset, int
1981 end_lineno, int end_col_offset, PyArena *arena)
1982 {
1983 stmt_ty p;
1984 if (!name) {
1985 PyErr_SetString(PyExc_ValueError,
1986 "field 'name' is required for AsyncFunctionDef");
1987 return NULL;
1988 }
1989 if (!args) {
1990 PyErr_SetString(PyExc_ValueError,
1991 "field 'args' is required for AsyncFunctionDef");
1992 return NULL;
1993 }
1994 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
1995 if (!p)
1996 return NULL;
1997 p->kind = AsyncFunctionDef_kind;
1998 p->v.AsyncFunctionDef.name = name;
1999 p->v.AsyncFunctionDef.args = args;
2000 p->v.AsyncFunctionDef.body = body;
2001 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2002 p->v.AsyncFunctionDef.returns = returns;
2003 p->v.AsyncFunctionDef.type_comment = type_comment;
2004 p->lineno = lineno;
2005 p->col_offset = col_offset;
2006 p->end_lineno = end_lineno;
2007 p->end_col_offset = end_col_offset;
2008 return p;
2009 }
2010
2011 stmt_ty
_PyAST_ClassDef(identifier name,asdl_expr_seq * bases,asdl_keyword_seq * keywords,asdl_stmt_seq * body,asdl_expr_seq * decorator_list,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2012 _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
2013 keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
2014 int lineno, int col_offset, int end_lineno, int end_col_offset,
2015 PyArena *arena)
2016 {
2017 stmt_ty p;
2018 if (!name) {
2019 PyErr_SetString(PyExc_ValueError,
2020 "field 'name' is required for ClassDef");
2021 return NULL;
2022 }
2023 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2024 if (!p)
2025 return NULL;
2026 p->kind = ClassDef_kind;
2027 p->v.ClassDef.name = name;
2028 p->v.ClassDef.bases = bases;
2029 p->v.ClassDef.keywords = keywords;
2030 p->v.ClassDef.body = body;
2031 p->v.ClassDef.decorator_list = decorator_list;
2032 p->lineno = lineno;
2033 p->col_offset = col_offset;
2034 p->end_lineno = end_lineno;
2035 p->end_col_offset = end_col_offset;
2036 return p;
2037 }
2038
2039 stmt_ty
_PyAST_Return(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2040 _PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2041 end_col_offset, PyArena *arena)
2042 {
2043 stmt_ty p;
2044 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2045 if (!p)
2046 return NULL;
2047 p->kind = Return_kind;
2048 p->v.Return.value = value;
2049 p->lineno = lineno;
2050 p->col_offset = col_offset;
2051 p->end_lineno = end_lineno;
2052 p->end_col_offset = end_col_offset;
2053 return p;
2054 }
2055
2056 stmt_ty
_PyAST_Delete(asdl_expr_seq * targets,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2057 _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
2058 end_lineno, int end_col_offset, PyArena *arena)
2059 {
2060 stmt_ty p;
2061 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2062 if (!p)
2063 return NULL;
2064 p->kind = Delete_kind;
2065 p->v.Delete.targets = targets;
2066 p->lineno = lineno;
2067 p->col_offset = col_offset;
2068 p->end_lineno = end_lineno;
2069 p->end_col_offset = end_col_offset;
2070 return p;
2071 }
2072
2073 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)2074 _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
2075 lineno, int col_offset, int end_lineno, int end_col_offset,
2076 PyArena *arena)
2077 {
2078 stmt_ty p;
2079 if (!value) {
2080 PyErr_SetString(PyExc_ValueError,
2081 "field 'value' is required for Assign");
2082 return NULL;
2083 }
2084 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2085 if (!p)
2086 return NULL;
2087 p->kind = Assign_kind;
2088 p->v.Assign.targets = targets;
2089 p->v.Assign.value = value;
2090 p->v.Assign.type_comment = type_comment;
2091 p->lineno = lineno;
2092 p->col_offset = col_offset;
2093 p->end_lineno = end_lineno;
2094 p->end_col_offset = end_col_offset;
2095 return p;
2096 }
2097
2098 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)2099 _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
2100 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2101 {
2102 stmt_ty p;
2103 if (!target) {
2104 PyErr_SetString(PyExc_ValueError,
2105 "field 'target' is required for AugAssign");
2106 return NULL;
2107 }
2108 if (!op) {
2109 PyErr_SetString(PyExc_ValueError,
2110 "field 'op' is required for AugAssign");
2111 return NULL;
2112 }
2113 if (!value) {
2114 PyErr_SetString(PyExc_ValueError,
2115 "field 'value' is required for AugAssign");
2116 return NULL;
2117 }
2118 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2119 if (!p)
2120 return NULL;
2121 p->kind = AugAssign_kind;
2122 p->v.AugAssign.target = target;
2123 p->v.AugAssign.op = op;
2124 p->v.AugAssign.value = value;
2125 p->lineno = lineno;
2126 p->col_offset = col_offset;
2127 p->end_lineno = end_lineno;
2128 p->end_col_offset = end_col_offset;
2129 return p;
2130 }
2131
2132 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)2133 _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
2134 int lineno, int col_offset, int end_lineno, int
2135 end_col_offset, PyArena *arena)
2136 {
2137 stmt_ty p;
2138 if (!target) {
2139 PyErr_SetString(PyExc_ValueError,
2140 "field 'target' is required for AnnAssign");
2141 return NULL;
2142 }
2143 if (!annotation) {
2144 PyErr_SetString(PyExc_ValueError,
2145 "field 'annotation' is required for AnnAssign");
2146 return NULL;
2147 }
2148 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2149 if (!p)
2150 return NULL;
2151 p->kind = AnnAssign_kind;
2152 p->v.AnnAssign.target = target;
2153 p->v.AnnAssign.annotation = annotation;
2154 p->v.AnnAssign.value = value;
2155 p->v.AnnAssign.simple = simple;
2156 p->lineno = lineno;
2157 p->col_offset = col_offset;
2158 p->end_lineno = end_lineno;
2159 p->end_col_offset = end_col_offset;
2160 return p;
2161 }
2162
2163 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)2164 _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
2165 orelse, string type_comment, int lineno, int col_offset, int
2166 end_lineno, int end_col_offset, PyArena *arena)
2167 {
2168 stmt_ty p;
2169 if (!target) {
2170 PyErr_SetString(PyExc_ValueError,
2171 "field 'target' is required for For");
2172 return NULL;
2173 }
2174 if (!iter) {
2175 PyErr_SetString(PyExc_ValueError,
2176 "field 'iter' is required for For");
2177 return NULL;
2178 }
2179 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2180 if (!p)
2181 return NULL;
2182 p->kind = For_kind;
2183 p->v.For.target = target;
2184 p->v.For.iter = iter;
2185 p->v.For.body = body;
2186 p->v.For.orelse = orelse;
2187 p->v.For.type_comment = type_comment;
2188 p->lineno = lineno;
2189 p->col_offset = col_offset;
2190 p->end_lineno = end_lineno;
2191 p->end_col_offset = end_col_offset;
2192 return p;
2193 }
2194
2195 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)2196 _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
2197 asdl_stmt_seq * orelse, string type_comment, int lineno, int
2198 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2199 {
2200 stmt_ty p;
2201 if (!target) {
2202 PyErr_SetString(PyExc_ValueError,
2203 "field 'target' is required for AsyncFor");
2204 return NULL;
2205 }
2206 if (!iter) {
2207 PyErr_SetString(PyExc_ValueError,
2208 "field 'iter' is required for AsyncFor");
2209 return NULL;
2210 }
2211 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2212 if (!p)
2213 return NULL;
2214 p->kind = AsyncFor_kind;
2215 p->v.AsyncFor.target = target;
2216 p->v.AsyncFor.iter = iter;
2217 p->v.AsyncFor.body = body;
2218 p->v.AsyncFor.orelse = orelse;
2219 p->v.AsyncFor.type_comment = type_comment;
2220 p->lineno = lineno;
2221 p->col_offset = col_offset;
2222 p->end_lineno = end_lineno;
2223 p->end_col_offset = end_col_offset;
2224 return p;
2225 }
2226
2227 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)2228 _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2229 lineno, int col_offset, int end_lineno, int end_col_offset,
2230 PyArena *arena)
2231 {
2232 stmt_ty p;
2233 if (!test) {
2234 PyErr_SetString(PyExc_ValueError,
2235 "field 'test' is required for While");
2236 return NULL;
2237 }
2238 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2239 if (!p)
2240 return NULL;
2241 p->kind = While_kind;
2242 p->v.While.test = test;
2243 p->v.While.body = body;
2244 p->v.While.orelse = orelse;
2245 p->lineno = lineno;
2246 p->col_offset = col_offset;
2247 p->end_lineno = end_lineno;
2248 p->end_col_offset = end_col_offset;
2249 return p;
2250 }
2251
2252 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)2253 _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2254 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2255 *arena)
2256 {
2257 stmt_ty p;
2258 if (!test) {
2259 PyErr_SetString(PyExc_ValueError,
2260 "field 'test' is required for If");
2261 return NULL;
2262 }
2263 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2264 if (!p)
2265 return NULL;
2266 p->kind = If_kind;
2267 p->v.If.test = test;
2268 p->v.If.body = body;
2269 p->v.If.orelse = orelse;
2270 p->lineno = lineno;
2271 p->col_offset = col_offset;
2272 p->end_lineno = end_lineno;
2273 p->end_col_offset = end_col_offset;
2274 return p;
2275 }
2276
2277 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)2278 _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2279 type_comment, int lineno, int col_offset, int end_lineno, int
2280 end_col_offset, PyArena *arena)
2281 {
2282 stmt_ty p;
2283 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2284 if (!p)
2285 return NULL;
2286 p->kind = With_kind;
2287 p->v.With.items = items;
2288 p->v.With.body = body;
2289 p->v.With.type_comment = type_comment;
2290 p->lineno = lineno;
2291 p->col_offset = col_offset;
2292 p->end_lineno = end_lineno;
2293 p->end_col_offset = end_col_offset;
2294 return p;
2295 }
2296
2297 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)2298 _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2299 type_comment, int lineno, int col_offset, int end_lineno, int
2300 end_col_offset, PyArena *arena)
2301 {
2302 stmt_ty p;
2303 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2304 if (!p)
2305 return NULL;
2306 p->kind = AsyncWith_kind;
2307 p->v.AsyncWith.items = items;
2308 p->v.AsyncWith.body = body;
2309 p->v.AsyncWith.type_comment = type_comment;
2310 p->lineno = lineno;
2311 p->col_offset = col_offset;
2312 p->end_lineno = end_lineno;
2313 p->end_col_offset = end_col_offset;
2314 return p;
2315 }
2316
2317 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)2318 _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
2319 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2320 {
2321 stmt_ty p;
2322 if (!subject) {
2323 PyErr_SetString(PyExc_ValueError,
2324 "field 'subject' is required for Match");
2325 return NULL;
2326 }
2327 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2328 if (!p)
2329 return NULL;
2330 p->kind = Match_kind;
2331 p->v.Match.subject = subject;
2332 p->v.Match.cases = cases;
2333 p->lineno = lineno;
2334 p->col_offset = col_offset;
2335 p->end_lineno = end_lineno;
2336 p->end_col_offset = end_col_offset;
2337 return p;
2338 }
2339
2340 stmt_ty
_PyAST_Raise(expr_ty exc,expr_ty cause,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2341 _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
2342 end_lineno, int end_col_offset, PyArena *arena)
2343 {
2344 stmt_ty p;
2345 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2346 if (!p)
2347 return NULL;
2348 p->kind = Raise_kind;
2349 p->v.Raise.exc = exc;
2350 p->v.Raise.cause = cause;
2351 p->lineno = lineno;
2352 p->col_offset = col_offset;
2353 p->end_lineno = end_lineno;
2354 p->end_col_offset = end_col_offset;
2355 return p;
2356 }
2357
2358 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)2359 _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2360 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
2361 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2362 {
2363 stmt_ty p;
2364 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2365 if (!p)
2366 return NULL;
2367 p->kind = Try_kind;
2368 p->v.Try.body = body;
2369 p->v.Try.handlers = handlers;
2370 p->v.Try.orelse = orelse;
2371 p->v.Try.finalbody = finalbody;
2372 p->lineno = lineno;
2373 p->col_offset = col_offset;
2374 p->end_lineno = end_lineno;
2375 p->end_col_offset = end_col_offset;
2376 return p;
2377 }
2378
2379 stmt_ty
_PyAST_Assert(expr_ty test,expr_ty msg,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2380 _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
2381 end_lineno, int end_col_offset, PyArena *arena)
2382 {
2383 stmt_ty p;
2384 if (!test) {
2385 PyErr_SetString(PyExc_ValueError,
2386 "field 'test' is required for Assert");
2387 return NULL;
2388 }
2389 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2390 if (!p)
2391 return NULL;
2392 p->kind = Assert_kind;
2393 p->v.Assert.test = test;
2394 p->v.Assert.msg = msg;
2395 p->lineno = lineno;
2396 p->col_offset = col_offset;
2397 p->end_lineno = end_lineno;
2398 p->end_col_offset = end_col_offset;
2399 return p;
2400 }
2401
2402 stmt_ty
_PyAST_Import(asdl_alias_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2403 _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
2404 end_lineno, int end_col_offset, PyArena *arena)
2405 {
2406 stmt_ty p;
2407 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2408 if (!p)
2409 return NULL;
2410 p->kind = Import_kind;
2411 p->v.Import.names = names;
2412 p->lineno = lineno;
2413 p->col_offset = col_offset;
2414 p->end_lineno = end_lineno;
2415 p->end_col_offset = end_col_offset;
2416 return p;
2417 }
2418
2419 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)2420 _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
2421 lineno, int col_offset, int end_lineno, int end_col_offset,
2422 PyArena *arena)
2423 {
2424 stmt_ty p;
2425 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2426 if (!p)
2427 return NULL;
2428 p->kind = ImportFrom_kind;
2429 p->v.ImportFrom.module = module;
2430 p->v.ImportFrom.names = names;
2431 p->v.ImportFrom.level = level;
2432 p->lineno = lineno;
2433 p->col_offset = col_offset;
2434 p->end_lineno = end_lineno;
2435 p->end_col_offset = end_col_offset;
2436 return p;
2437 }
2438
2439 stmt_ty
_PyAST_Global(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2440 _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
2441 end_lineno, int end_col_offset, PyArena *arena)
2442 {
2443 stmt_ty p;
2444 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2445 if (!p)
2446 return NULL;
2447 p->kind = Global_kind;
2448 p->v.Global.names = names;
2449 p->lineno = lineno;
2450 p->col_offset = col_offset;
2451 p->end_lineno = end_lineno;
2452 p->end_col_offset = end_col_offset;
2453 return p;
2454 }
2455
2456 stmt_ty
_PyAST_Nonlocal(asdl_identifier_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2457 _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
2458 end_lineno, int end_col_offset, PyArena *arena)
2459 {
2460 stmt_ty p;
2461 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2462 if (!p)
2463 return NULL;
2464 p->kind = Nonlocal_kind;
2465 p->v.Nonlocal.names = names;
2466 p->lineno = lineno;
2467 p->col_offset = col_offset;
2468 p->end_lineno = end_lineno;
2469 p->end_col_offset = end_col_offset;
2470 return p;
2471 }
2472
2473 stmt_ty
_PyAST_Expr(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2474 _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2475 end_col_offset, PyArena *arena)
2476 {
2477 stmt_ty p;
2478 if (!value) {
2479 PyErr_SetString(PyExc_ValueError,
2480 "field 'value' is required for Expr");
2481 return NULL;
2482 }
2483 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2484 if (!p)
2485 return NULL;
2486 p->kind = Expr_kind;
2487 p->v.Expr.value = value;
2488 p->lineno = lineno;
2489 p->col_offset = col_offset;
2490 p->end_lineno = end_lineno;
2491 p->end_col_offset = end_col_offset;
2492 return p;
2493 }
2494
2495 stmt_ty
_PyAST_Pass(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2496 _PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
2497 PyArena *arena)
2498 {
2499 stmt_ty p;
2500 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2501 if (!p)
2502 return NULL;
2503 p->kind = Pass_kind;
2504 p->lineno = lineno;
2505 p->col_offset = col_offset;
2506 p->end_lineno = end_lineno;
2507 p->end_col_offset = end_col_offset;
2508 return p;
2509 }
2510
2511 stmt_ty
_PyAST_Break(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2512 _PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
2513 PyArena *arena)
2514 {
2515 stmt_ty p;
2516 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2517 if (!p)
2518 return NULL;
2519 p->kind = Break_kind;
2520 p->lineno = lineno;
2521 p->col_offset = col_offset;
2522 p->end_lineno = end_lineno;
2523 p->end_col_offset = end_col_offset;
2524 return p;
2525 }
2526
2527 stmt_ty
_PyAST_Continue(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2528 _PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2529 PyArena *arena)
2530 {
2531 stmt_ty p;
2532 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
2533 if (!p)
2534 return NULL;
2535 p->kind = Continue_kind;
2536 p->lineno = lineno;
2537 p->col_offset = col_offset;
2538 p->end_lineno = end_lineno;
2539 p->end_col_offset = end_col_offset;
2540 return p;
2541 }
2542
2543 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)2544 _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
2545 int end_lineno, int end_col_offset, PyArena *arena)
2546 {
2547 expr_ty p;
2548 if (!op) {
2549 PyErr_SetString(PyExc_ValueError,
2550 "field 'op' is required for BoolOp");
2551 return NULL;
2552 }
2553 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2554 if (!p)
2555 return NULL;
2556 p->kind = BoolOp_kind;
2557 p->v.BoolOp.op = op;
2558 p->v.BoolOp.values = values;
2559 p->lineno = lineno;
2560 p->col_offset = col_offset;
2561 p->end_lineno = end_lineno;
2562 p->end_col_offset = end_col_offset;
2563 return p;
2564 }
2565
2566 expr_ty
_PyAST_NamedExpr(expr_ty target,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2567 _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2568 end_lineno, int end_col_offset, PyArena *arena)
2569 {
2570 expr_ty p;
2571 if (!target) {
2572 PyErr_SetString(PyExc_ValueError,
2573 "field 'target' is required for NamedExpr");
2574 return NULL;
2575 }
2576 if (!value) {
2577 PyErr_SetString(PyExc_ValueError,
2578 "field 'value' is required for NamedExpr");
2579 return NULL;
2580 }
2581 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2582 if (!p)
2583 return NULL;
2584 p->kind = NamedExpr_kind;
2585 p->v.NamedExpr.target = target;
2586 p->v.NamedExpr.value = value;
2587 p->lineno = lineno;
2588 p->col_offset = col_offset;
2589 p->end_lineno = end_lineno;
2590 p->end_col_offset = end_col_offset;
2591 return p;
2592 }
2593
2594 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)2595 _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
2596 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2597 {
2598 expr_ty p;
2599 if (!left) {
2600 PyErr_SetString(PyExc_ValueError,
2601 "field 'left' is required for BinOp");
2602 return NULL;
2603 }
2604 if (!op) {
2605 PyErr_SetString(PyExc_ValueError,
2606 "field 'op' is required for BinOp");
2607 return NULL;
2608 }
2609 if (!right) {
2610 PyErr_SetString(PyExc_ValueError,
2611 "field 'right' is required for BinOp");
2612 return NULL;
2613 }
2614 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2615 if (!p)
2616 return NULL;
2617 p->kind = BinOp_kind;
2618 p->v.BinOp.left = left;
2619 p->v.BinOp.op = op;
2620 p->v.BinOp.right = right;
2621 p->lineno = lineno;
2622 p->col_offset = col_offset;
2623 p->end_lineno = end_lineno;
2624 p->end_col_offset = end_col_offset;
2625 return p;
2626 }
2627
2628 expr_ty
_PyAST_UnaryOp(unaryop_ty op,expr_ty operand,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2629 _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2630 end_lineno, int end_col_offset, PyArena *arena)
2631 {
2632 expr_ty p;
2633 if (!op) {
2634 PyErr_SetString(PyExc_ValueError,
2635 "field 'op' is required for UnaryOp");
2636 return NULL;
2637 }
2638 if (!operand) {
2639 PyErr_SetString(PyExc_ValueError,
2640 "field 'operand' is required for UnaryOp");
2641 return NULL;
2642 }
2643 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2644 if (!p)
2645 return NULL;
2646 p->kind = UnaryOp_kind;
2647 p->v.UnaryOp.op = op;
2648 p->v.UnaryOp.operand = operand;
2649 p->lineno = lineno;
2650 p->col_offset = col_offset;
2651 p->end_lineno = end_lineno;
2652 p->end_col_offset = end_col_offset;
2653 return p;
2654 }
2655
2656 expr_ty
_PyAST_Lambda(arguments_ty args,expr_ty body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2657 _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2658 end_lineno, int end_col_offset, PyArena *arena)
2659 {
2660 expr_ty p;
2661 if (!args) {
2662 PyErr_SetString(PyExc_ValueError,
2663 "field 'args' is required for Lambda");
2664 return NULL;
2665 }
2666 if (!body) {
2667 PyErr_SetString(PyExc_ValueError,
2668 "field 'body' is required for Lambda");
2669 return NULL;
2670 }
2671 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2672 if (!p)
2673 return NULL;
2674 p->kind = Lambda_kind;
2675 p->v.Lambda.args = args;
2676 p->v.Lambda.body = body;
2677 p->lineno = lineno;
2678 p->col_offset = col_offset;
2679 p->end_lineno = end_lineno;
2680 p->end_col_offset = end_col_offset;
2681 return p;
2682 }
2683
2684 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)2685 _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
2686 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2687 {
2688 expr_ty p;
2689 if (!test) {
2690 PyErr_SetString(PyExc_ValueError,
2691 "field 'test' is required for IfExp");
2692 return NULL;
2693 }
2694 if (!body) {
2695 PyErr_SetString(PyExc_ValueError,
2696 "field 'body' is required for IfExp");
2697 return NULL;
2698 }
2699 if (!orelse) {
2700 PyErr_SetString(PyExc_ValueError,
2701 "field 'orelse' is required for IfExp");
2702 return NULL;
2703 }
2704 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2705 if (!p)
2706 return NULL;
2707 p->kind = IfExp_kind;
2708 p->v.IfExp.test = test;
2709 p->v.IfExp.body = body;
2710 p->v.IfExp.orelse = orelse;
2711 p->lineno = lineno;
2712 p->col_offset = col_offset;
2713 p->end_lineno = end_lineno;
2714 p->end_col_offset = end_col_offset;
2715 return p;
2716 }
2717
2718 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)2719 _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
2720 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2721 {
2722 expr_ty p;
2723 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2724 if (!p)
2725 return NULL;
2726 p->kind = Dict_kind;
2727 p->v.Dict.keys = keys;
2728 p->v.Dict.values = values;
2729 p->lineno = lineno;
2730 p->col_offset = col_offset;
2731 p->end_lineno = end_lineno;
2732 p->end_col_offset = end_col_offset;
2733 return p;
2734 }
2735
2736 expr_ty
_PyAST_Set(asdl_expr_seq * elts,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2737 _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
2738 int end_col_offset, PyArena *arena)
2739 {
2740 expr_ty p;
2741 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2742 if (!p)
2743 return NULL;
2744 p->kind = Set_kind;
2745 p->v.Set.elts = elts;
2746 p->lineno = lineno;
2747 p->col_offset = col_offset;
2748 p->end_lineno = end_lineno;
2749 p->end_col_offset = end_col_offset;
2750 return p;
2751 }
2752
2753 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)2754 _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2755 int col_offset, int end_lineno, int end_col_offset, PyArena
2756 *arena)
2757 {
2758 expr_ty p;
2759 if (!elt) {
2760 PyErr_SetString(PyExc_ValueError,
2761 "field 'elt' is required for ListComp");
2762 return NULL;
2763 }
2764 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2765 if (!p)
2766 return NULL;
2767 p->kind = ListComp_kind;
2768 p->v.ListComp.elt = elt;
2769 p->v.ListComp.generators = generators;
2770 p->lineno = lineno;
2771 p->col_offset = col_offset;
2772 p->end_lineno = end_lineno;
2773 p->end_col_offset = end_col_offset;
2774 return p;
2775 }
2776
2777 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)2778 _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2779 int col_offset, int end_lineno, int end_col_offset, PyArena
2780 *arena)
2781 {
2782 expr_ty p;
2783 if (!elt) {
2784 PyErr_SetString(PyExc_ValueError,
2785 "field 'elt' is required for SetComp");
2786 return NULL;
2787 }
2788 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2789 if (!p)
2790 return NULL;
2791 p->kind = SetComp_kind;
2792 p->v.SetComp.elt = elt;
2793 p->v.SetComp.generators = generators;
2794 p->lineno = lineno;
2795 p->col_offset = col_offset;
2796 p->end_lineno = end_lineno;
2797 p->end_col_offset = end_col_offset;
2798 return p;
2799 }
2800
2801 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)2802 _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
2803 generators, int lineno, int col_offset, int end_lineno, int
2804 end_col_offset, PyArena *arena)
2805 {
2806 expr_ty p;
2807 if (!key) {
2808 PyErr_SetString(PyExc_ValueError,
2809 "field 'key' is required for DictComp");
2810 return NULL;
2811 }
2812 if (!value) {
2813 PyErr_SetString(PyExc_ValueError,
2814 "field 'value' is required for DictComp");
2815 return NULL;
2816 }
2817 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2818 if (!p)
2819 return NULL;
2820 p->kind = DictComp_kind;
2821 p->v.DictComp.key = key;
2822 p->v.DictComp.value = value;
2823 p->v.DictComp.generators = generators;
2824 p->lineno = lineno;
2825 p->col_offset = col_offset;
2826 p->end_lineno = end_lineno;
2827 p->end_col_offset = end_col_offset;
2828 return p;
2829 }
2830
2831 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)2832 _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
2833 lineno, int col_offset, int end_lineno, int end_col_offset,
2834 PyArena *arena)
2835 {
2836 expr_ty p;
2837 if (!elt) {
2838 PyErr_SetString(PyExc_ValueError,
2839 "field 'elt' is required for GeneratorExp");
2840 return NULL;
2841 }
2842 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2843 if (!p)
2844 return NULL;
2845 p->kind = GeneratorExp_kind;
2846 p->v.GeneratorExp.elt = elt;
2847 p->v.GeneratorExp.generators = generators;
2848 p->lineno = lineno;
2849 p->col_offset = col_offset;
2850 p->end_lineno = end_lineno;
2851 p->end_col_offset = end_col_offset;
2852 return p;
2853 }
2854
2855 expr_ty
_PyAST_Await(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2856 _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2857 end_col_offset, PyArena *arena)
2858 {
2859 expr_ty p;
2860 if (!value) {
2861 PyErr_SetString(PyExc_ValueError,
2862 "field 'value' is required for Await");
2863 return NULL;
2864 }
2865 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2866 if (!p)
2867 return NULL;
2868 p->kind = Await_kind;
2869 p->v.Await.value = value;
2870 p->lineno = lineno;
2871 p->col_offset = col_offset;
2872 p->end_lineno = end_lineno;
2873 p->end_col_offset = end_col_offset;
2874 return p;
2875 }
2876
2877 expr_ty
_PyAST_Yield(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2878 _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2879 end_col_offset, PyArena *arena)
2880 {
2881 expr_ty p;
2882 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2883 if (!p)
2884 return NULL;
2885 p->kind = Yield_kind;
2886 p->v.Yield.value = value;
2887 p->lineno = lineno;
2888 p->col_offset = col_offset;
2889 p->end_lineno = end_lineno;
2890 p->end_col_offset = end_col_offset;
2891 return p;
2892 }
2893
2894 expr_ty
_PyAST_YieldFrom(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2895 _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2896 end_col_offset, PyArena *arena)
2897 {
2898 expr_ty p;
2899 if (!value) {
2900 PyErr_SetString(PyExc_ValueError,
2901 "field 'value' is required for YieldFrom");
2902 return NULL;
2903 }
2904 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2905 if (!p)
2906 return NULL;
2907 p->kind = YieldFrom_kind;
2908 p->v.YieldFrom.value = value;
2909 p->lineno = lineno;
2910 p->col_offset = col_offset;
2911 p->end_lineno = end_lineno;
2912 p->end_col_offset = end_col_offset;
2913 return p;
2914 }
2915
2916 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)2917 _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
2918 int lineno, int col_offset, int end_lineno, int end_col_offset,
2919 PyArena *arena)
2920 {
2921 expr_ty p;
2922 if (!left) {
2923 PyErr_SetString(PyExc_ValueError,
2924 "field 'left' is required for Compare");
2925 return NULL;
2926 }
2927 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2928 if (!p)
2929 return NULL;
2930 p->kind = Compare_kind;
2931 p->v.Compare.left = left;
2932 p->v.Compare.ops = ops;
2933 p->v.Compare.comparators = comparators;
2934 p->lineno = lineno;
2935 p->col_offset = col_offset;
2936 p->end_lineno = end_lineno;
2937 p->end_col_offset = end_col_offset;
2938 return p;
2939 }
2940
2941 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)2942 _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
2943 int lineno, int col_offset, int end_lineno, int end_col_offset,
2944 PyArena *arena)
2945 {
2946 expr_ty p;
2947 if (!func) {
2948 PyErr_SetString(PyExc_ValueError,
2949 "field 'func' is required for Call");
2950 return NULL;
2951 }
2952 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2953 if (!p)
2954 return NULL;
2955 p->kind = Call_kind;
2956 p->v.Call.func = func;
2957 p->v.Call.args = args;
2958 p->v.Call.keywords = keywords;
2959 p->lineno = lineno;
2960 p->col_offset = col_offset;
2961 p->end_lineno = end_lineno;
2962 p->end_col_offset = end_col_offset;
2963 return p;
2964 }
2965
2966 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)2967 _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
2968 lineno, int col_offset, int end_lineno, int
2969 end_col_offset, PyArena *arena)
2970 {
2971 expr_ty p;
2972 if (!value) {
2973 PyErr_SetString(PyExc_ValueError,
2974 "field 'value' is required for FormattedValue");
2975 return NULL;
2976 }
2977 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2978 if (!p)
2979 return NULL;
2980 p->kind = FormattedValue_kind;
2981 p->v.FormattedValue.value = value;
2982 p->v.FormattedValue.conversion = conversion;
2983 p->v.FormattedValue.format_spec = format_spec;
2984 p->lineno = lineno;
2985 p->col_offset = col_offset;
2986 p->end_lineno = end_lineno;
2987 p->end_col_offset = end_col_offset;
2988 return p;
2989 }
2990
2991 expr_ty
_PyAST_JoinedStr(asdl_expr_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2992 _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
2993 end_lineno, int end_col_offset, PyArena *arena)
2994 {
2995 expr_ty p;
2996 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
2997 if (!p)
2998 return NULL;
2999 p->kind = JoinedStr_kind;
3000 p->v.JoinedStr.values = values;
3001 p->lineno = lineno;
3002 p->col_offset = col_offset;
3003 p->end_lineno = end_lineno;
3004 p->end_col_offset = end_col_offset;
3005 return p;
3006 }
3007
3008 expr_ty
_PyAST_Constant(constant value,string kind,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3009 _PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
3010 end_lineno, int end_col_offset, PyArena *arena)
3011 {
3012 expr_ty p;
3013 if (!value) {
3014 PyErr_SetString(PyExc_ValueError,
3015 "field 'value' is required for Constant");
3016 return NULL;
3017 }
3018 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3019 if (!p)
3020 return NULL;
3021 p->kind = Constant_kind;
3022 p->v.Constant.value = value;
3023 p->v.Constant.kind = kind;
3024 p->lineno = lineno;
3025 p->col_offset = col_offset;
3026 p->end_lineno = end_lineno;
3027 p->end_col_offset = end_col_offset;
3028 return p;
3029 }
3030
3031 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)3032 _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
3033 lineno, int col_offset, int end_lineno, int end_col_offset,
3034 PyArena *arena)
3035 {
3036 expr_ty p;
3037 if (!value) {
3038 PyErr_SetString(PyExc_ValueError,
3039 "field 'value' is required for Attribute");
3040 return NULL;
3041 }
3042 if (!attr) {
3043 PyErr_SetString(PyExc_ValueError,
3044 "field 'attr' is required for Attribute");
3045 return NULL;
3046 }
3047 if (!ctx) {
3048 PyErr_SetString(PyExc_ValueError,
3049 "field 'ctx' is required for Attribute");
3050 return NULL;
3051 }
3052 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3053 if (!p)
3054 return NULL;
3055 p->kind = Attribute_kind;
3056 p->v.Attribute.value = value;
3057 p->v.Attribute.attr = attr;
3058 p->v.Attribute.ctx = ctx;
3059 p->lineno = lineno;
3060 p->col_offset = col_offset;
3061 p->end_lineno = end_lineno;
3062 p->end_col_offset = end_col_offset;
3063 return p;
3064 }
3065
3066 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)3067 _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
3068 int col_offset, int end_lineno, int end_col_offset, PyArena
3069 *arena)
3070 {
3071 expr_ty p;
3072 if (!value) {
3073 PyErr_SetString(PyExc_ValueError,
3074 "field 'value' is required for Subscript");
3075 return NULL;
3076 }
3077 if (!slice) {
3078 PyErr_SetString(PyExc_ValueError,
3079 "field 'slice' is required for Subscript");
3080 return NULL;
3081 }
3082 if (!ctx) {
3083 PyErr_SetString(PyExc_ValueError,
3084 "field 'ctx' is required for Subscript");
3085 return NULL;
3086 }
3087 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3088 if (!p)
3089 return NULL;
3090 p->kind = Subscript_kind;
3091 p->v.Subscript.value = value;
3092 p->v.Subscript.slice = slice;
3093 p->v.Subscript.ctx = ctx;
3094 p->lineno = lineno;
3095 p->col_offset = col_offset;
3096 p->end_lineno = end_lineno;
3097 p->end_col_offset = end_col_offset;
3098 return p;
3099 }
3100
3101 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)3102 _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
3103 int end_lineno, int end_col_offset, PyArena *arena)
3104 {
3105 expr_ty p;
3106 if (!value) {
3107 PyErr_SetString(PyExc_ValueError,
3108 "field 'value' is required for Starred");
3109 return NULL;
3110 }
3111 if (!ctx) {
3112 PyErr_SetString(PyExc_ValueError,
3113 "field 'ctx' is required for Starred");
3114 return NULL;
3115 }
3116 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3117 if (!p)
3118 return NULL;
3119 p->kind = Starred_kind;
3120 p->v.Starred.value = value;
3121 p->v.Starred.ctx = ctx;
3122 p->lineno = lineno;
3123 p->col_offset = col_offset;
3124 p->end_lineno = end_lineno;
3125 p->end_col_offset = end_col_offset;
3126 return p;
3127 }
3128
3129 expr_ty
_PyAST_Name(identifier id,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3130 _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3131 end_lineno, int end_col_offset, PyArena *arena)
3132 {
3133 expr_ty p;
3134 if (!id) {
3135 PyErr_SetString(PyExc_ValueError,
3136 "field 'id' is required for Name");
3137 return NULL;
3138 }
3139 if (!ctx) {
3140 PyErr_SetString(PyExc_ValueError,
3141 "field 'ctx' is required for Name");
3142 return NULL;
3143 }
3144 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3145 if (!p)
3146 return NULL;
3147 p->kind = Name_kind;
3148 p->v.Name.id = id;
3149 p->v.Name.ctx = ctx;
3150 p->lineno = lineno;
3151 p->col_offset = col_offset;
3152 p->end_lineno = end_lineno;
3153 p->end_col_offset = end_col_offset;
3154 return p;
3155 }
3156
3157 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)3158 _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3159 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3160 {
3161 expr_ty p;
3162 if (!ctx) {
3163 PyErr_SetString(PyExc_ValueError,
3164 "field 'ctx' is required for List");
3165 return NULL;
3166 }
3167 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3168 if (!p)
3169 return NULL;
3170 p->kind = List_kind;
3171 p->v.List.elts = elts;
3172 p->v.List.ctx = ctx;
3173 p->lineno = lineno;
3174 p->col_offset = col_offset;
3175 p->end_lineno = end_lineno;
3176 p->end_col_offset = end_col_offset;
3177 return p;
3178 }
3179
3180 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)3181 _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3182 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3183 {
3184 expr_ty p;
3185 if (!ctx) {
3186 PyErr_SetString(PyExc_ValueError,
3187 "field 'ctx' is required for Tuple");
3188 return NULL;
3189 }
3190 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3191 if (!p)
3192 return NULL;
3193 p->kind = Tuple_kind;
3194 p->v.Tuple.elts = elts;
3195 p->v.Tuple.ctx = ctx;
3196 p->lineno = lineno;
3197 p->col_offset = col_offset;
3198 p->end_lineno = end_lineno;
3199 p->end_col_offset = end_col_offset;
3200 return p;
3201 }
3202
3203 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)3204 _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
3205 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3206 {
3207 expr_ty p;
3208 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
3209 if (!p)
3210 return NULL;
3211 p->kind = Slice_kind;
3212 p->v.Slice.lower = lower;
3213 p->v.Slice.upper = upper;
3214 p->v.Slice.step = step;
3215 p->lineno = lineno;
3216 p->col_offset = col_offset;
3217 p->end_lineno = end_lineno;
3218 p->end_col_offset = end_col_offset;
3219 return p;
3220 }
3221
3222 comprehension_ty
_PyAST_comprehension(expr_ty target,expr_ty iter,asdl_expr_seq * ifs,int is_async,PyArena * arena)3223 _PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
3224 is_async, PyArena *arena)
3225 {
3226 comprehension_ty p;
3227 if (!target) {
3228 PyErr_SetString(PyExc_ValueError,
3229 "field 'target' is required for comprehension");
3230 return NULL;
3231 }
3232 if (!iter) {
3233 PyErr_SetString(PyExc_ValueError,
3234 "field 'iter' is required for comprehension");
3235 return NULL;
3236 }
3237 p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
3238 if (!p)
3239 return NULL;
3240 p->target = target;
3241 p->iter = iter;
3242 p->ifs = ifs;
3243 p->is_async = is_async;
3244 return p;
3245 }
3246
3247 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)3248 _PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
3249 lineno, int col_offset, int end_lineno, int
3250 end_col_offset, PyArena *arena)
3251 {
3252 excepthandler_ty p;
3253 p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
3254 if (!p)
3255 return NULL;
3256 p->kind = ExceptHandler_kind;
3257 p->v.ExceptHandler.type = type;
3258 p->v.ExceptHandler.name = name;
3259 p->v.ExceptHandler.body = body;
3260 p->lineno = lineno;
3261 p->col_offset = col_offset;
3262 p->end_lineno = end_lineno;
3263 p->end_col_offset = end_col_offset;
3264 return p;
3265 }
3266
3267 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)3268 _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
3269 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
3270 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
3271 *arena)
3272 {
3273 arguments_ty p;
3274 p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
3275 if (!p)
3276 return NULL;
3277 p->posonlyargs = posonlyargs;
3278 p->args = args;
3279 p->vararg = vararg;
3280 p->kwonlyargs = kwonlyargs;
3281 p->kw_defaults = kw_defaults;
3282 p->kwarg = kwarg;
3283 p->defaults = defaults;
3284 return p;
3285 }
3286
3287 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)3288 _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
3289 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
3290 {
3291 arg_ty p;
3292 if (!arg) {
3293 PyErr_SetString(PyExc_ValueError,
3294 "field 'arg' is required for arg");
3295 return NULL;
3296 }
3297 p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
3298 if (!p)
3299 return NULL;
3300 p->arg = arg;
3301 p->annotation = annotation;
3302 p->type_comment = type_comment;
3303 p->lineno = lineno;
3304 p->col_offset = col_offset;
3305 p->end_lineno = end_lineno;
3306 p->end_col_offset = end_col_offset;
3307 return p;
3308 }
3309
3310 keyword_ty
_PyAST_keyword(identifier arg,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3311 _PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3312 end_lineno, int end_col_offset, PyArena *arena)
3313 {
3314 keyword_ty p;
3315 if (!value) {
3316 PyErr_SetString(PyExc_ValueError,
3317 "field 'value' is required for keyword");
3318 return NULL;
3319 }
3320 p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
3321 if (!p)
3322 return NULL;
3323 p->arg = arg;
3324 p->value = value;
3325 p->lineno = lineno;
3326 p->col_offset = col_offset;
3327 p->end_lineno = end_lineno;
3328 p->end_col_offset = end_col_offset;
3329 return p;
3330 }
3331
3332 alias_ty
_PyAST_alias(identifier name,identifier asname,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3333 _PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
3334 int end_lineno, int end_col_offset, PyArena *arena)
3335 {
3336 alias_ty p;
3337 if (!name) {
3338 PyErr_SetString(PyExc_ValueError,
3339 "field 'name' is required for alias");
3340 return NULL;
3341 }
3342 p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
3343 if (!p)
3344 return NULL;
3345 p->name = name;
3346 p->asname = asname;
3347 p->lineno = lineno;
3348 p->col_offset = col_offset;
3349 p->end_lineno = end_lineno;
3350 p->end_col_offset = end_col_offset;
3351 return p;
3352 }
3353
3354 withitem_ty
_PyAST_withitem(expr_ty context_expr,expr_ty optional_vars,PyArena * arena)3355 _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3356 {
3357 withitem_ty p;
3358 if (!context_expr) {
3359 PyErr_SetString(PyExc_ValueError,
3360 "field 'context_expr' is required for withitem");
3361 return NULL;
3362 }
3363 p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
3364 if (!p)
3365 return NULL;
3366 p->context_expr = context_expr;
3367 p->optional_vars = optional_vars;
3368 return p;
3369 }
3370
3371 match_case_ty
_PyAST_match_case(pattern_ty pattern,expr_ty guard,asdl_stmt_seq * body,PyArena * arena)3372 _PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
3373 PyArena *arena)
3374 {
3375 match_case_ty p;
3376 if (!pattern) {
3377 PyErr_SetString(PyExc_ValueError,
3378 "field 'pattern' is required for match_case");
3379 return NULL;
3380 }
3381 p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
3382 if (!p)
3383 return NULL;
3384 p->pattern = pattern;
3385 p->guard = guard;
3386 p->body = body;
3387 return p;
3388 }
3389
3390 pattern_ty
_PyAST_MatchValue(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3391 _PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
3392 int end_col_offset, PyArena *arena)
3393 {
3394 pattern_ty p;
3395 if (!value) {
3396 PyErr_SetString(PyExc_ValueError,
3397 "field 'value' is required for MatchValue");
3398 return NULL;
3399 }
3400 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3401 if (!p)
3402 return NULL;
3403 p->kind = MatchValue_kind;
3404 p->v.MatchValue.value = value;
3405 p->lineno = lineno;
3406 p->col_offset = col_offset;
3407 p->end_lineno = end_lineno;
3408 p->end_col_offset = end_col_offset;
3409 return p;
3410 }
3411
3412 pattern_ty
_PyAST_MatchSingleton(constant value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3413 _PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
3414 end_lineno, int end_col_offset, PyArena *arena)
3415 {
3416 pattern_ty p;
3417 if (!value) {
3418 PyErr_SetString(PyExc_ValueError,
3419 "field 'value' is required for MatchSingleton");
3420 return NULL;
3421 }
3422 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3423 if (!p)
3424 return NULL;
3425 p->kind = MatchSingleton_kind;
3426 p->v.MatchSingleton.value = value;
3427 p->lineno = lineno;
3428 p->col_offset = col_offset;
3429 p->end_lineno = end_lineno;
3430 p->end_col_offset = end_col_offset;
3431 return p;
3432 }
3433
3434 pattern_ty
_PyAST_MatchSequence(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3435 _PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
3436 int end_lineno, int end_col_offset, PyArena *arena)
3437 {
3438 pattern_ty p;
3439 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3440 if (!p)
3441 return NULL;
3442 p->kind = MatchSequence_kind;
3443 p->v.MatchSequence.patterns = patterns;
3444 p->lineno = lineno;
3445 p->col_offset = col_offset;
3446 p->end_lineno = end_lineno;
3447 p->end_col_offset = end_col_offset;
3448 return p;
3449 }
3450
3451 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)3452 _PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
3453 identifier rest, int lineno, int col_offset, int
3454 end_lineno, int end_col_offset, PyArena *arena)
3455 {
3456 pattern_ty p;
3457 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3458 if (!p)
3459 return NULL;
3460 p->kind = MatchMapping_kind;
3461 p->v.MatchMapping.keys = keys;
3462 p->v.MatchMapping.patterns = patterns;
3463 p->v.MatchMapping.rest = rest;
3464 p->lineno = lineno;
3465 p->col_offset = col_offset;
3466 p->end_lineno = end_lineno;
3467 p->end_col_offset = end_col_offset;
3468 return p;
3469 }
3470
3471 pattern_ty
_PyAST_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)3472 _PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
3473 * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
3474 col_offset, int end_lineno, int end_col_offset, PyArena
3475 *arena)
3476 {
3477 pattern_ty p;
3478 if (!cls) {
3479 PyErr_SetString(PyExc_ValueError,
3480 "field 'cls' is required for MatchClass");
3481 return NULL;
3482 }
3483 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3484 if (!p)
3485 return NULL;
3486 p->kind = MatchClass_kind;
3487 p->v.MatchClass.cls = cls;
3488 p->v.MatchClass.patterns = patterns;
3489 p->v.MatchClass.kwd_attrs = kwd_attrs;
3490 p->v.MatchClass.kwd_patterns = kwd_patterns;
3491 p->lineno = lineno;
3492 p->col_offset = col_offset;
3493 p->end_lineno = end_lineno;
3494 p->end_col_offset = end_col_offset;
3495 return p;
3496 }
3497
3498 pattern_ty
_PyAST_MatchStar(identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3499 _PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
3500 int end_col_offset, PyArena *arena)
3501 {
3502 pattern_ty p;
3503 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3504 if (!p)
3505 return NULL;
3506 p->kind = MatchStar_kind;
3507 p->v.MatchStar.name = name;
3508 p->lineno = lineno;
3509 p->col_offset = col_offset;
3510 p->end_lineno = end_lineno;
3511 p->end_col_offset = end_col_offset;
3512 return p;
3513 }
3514
3515 pattern_ty
_PyAST_MatchAs(pattern_ty pattern,identifier name,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3516 _PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
3517 int end_lineno, int end_col_offset, PyArena *arena)
3518 {
3519 pattern_ty p;
3520 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3521 if (!p)
3522 return NULL;
3523 p->kind = MatchAs_kind;
3524 p->v.MatchAs.pattern = pattern;
3525 p->v.MatchAs.name = name;
3526 p->lineno = lineno;
3527 p->col_offset = col_offset;
3528 p->end_lineno = end_lineno;
3529 p->end_col_offset = end_col_offset;
3530 return p;
3531 }
3532
3533 pattern_ty
_PyAST_MatchOr(asdl_pattern_seq * patterns,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)3534 _PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
3535 end_lineno, int end_col_offset, PyArena *arena)
3536 {
3537 pattern_ty p;
3538 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3539 if (!p)
3540 return NULL;
3541 p->kind = MatchOr_kind;
3542 p->v.MatchOr.patterns = patterns;
3543 p->lineno = lineno;
3544 p->col_offset = col_offset;
3545 p->end_lineno = end_lineno;
3546 p->end_col_offset = end_col_offset;
3547 return p;
3548 }
3549
3550 type_ignore_ty
_PyAST_TypeIgnore(int lineno,string tag,PyArena * arena)3551 _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
3552 {
3553 type_ignore_ty p;
3554 if (!tag) {
3555 PyErr_SetString(PyExc_ValueError,
3556 "field 'tag' is required for TypeIgnore");
3557 return NULL;
3558 }
3559 p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
3560 if (!p)
3561 return NULL;
3562 p->kind = TypeIgnore_kind;
3563 p->v.TypeIgnore.lineno = lineno;
3564 p->v.TypeIgnore.tag = tag;
3565 return p;
3566 }
3567
3568
3569 PyObject*
ast2obj_mod(struct ast_state * state,void * _o)3570 ast2obj_mod(struct ast_state *state, void* _o)
3571 {
3572 mod_ty o = (mod_ty)_o;
3573 PyObject *result = NULL, *value = NULL;
3574 PyTypeObject *tp;
3575 if (!o) {
3576 Py_RETURN_NONE;
3577 }
3578 switch (o->kind) {
3579 case Module_kind:
3580 tp = (PyTypeObject *)state->Module_type;
3581 result = PyType_GenericNew(tp, NULL, NULL);
3582 if (!result) goto failed;
3583 value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
3584 if (!value) goto failed;
3585 if (PyObject_SetAttr(result, state->body, value) == -1)
3586 goto failed;
3587 Py_DECREF(value);
3588 value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
3589 ast2obj_type_ignore);
3590 if (!value) goto failed;
3591 if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
3592 goto failed;
3593 Py_DECREF(value);
3594 break;
3595 case Interactive_kind:
3596 tp = (PyTypeObject *)state->Interactive_type;
3597 result = PyType_GenericNew(tp, NULL, NULL);
3598 if (!result) goto failed;
3599 value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
3600 ast2obj_stmt);
3601 if (!value) goto failed;
3602 if (PyObject_SetAttr(result, state->body, value) == -1)
3603 goto failed;
3604 Py_DECREF(value);
3605 break;
3606 case Expression_kind:
3607 tp = (PyTypeObject *)state->Expression_type;
3608 result = PyType_GenericNew(tp, NULL, NULL);
3609 if (!result) goto failed;
3610 value = ast2obj_expr(state, o->v.Expression.body);
3611 if (!value) goto failed;
3612 if (PyObject_SetAttr(result, state->body, value) == -1)
3613 goto failed;
3614 Py_DECREF(value);
3615 break;
3616 case FunctionType_kind:
3617 tp = (PyTypeObject *)state->FunctionType_type;
3618 result = PyType_GenericNew(tp, NULL, NULL);
3619 if (!result) goto failed;
3620 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
3621 ast2obj_expr);
3622 if (!value) goto failed;
3623 if (PyObject_SetAttr(result, state->argtypes, value) == -1)
3624 goto failed;
3625 Py_DECREF(value);
3626 value = ast2obj_expr(state, o->v.FunctionType.returns);
3627 if (!value) goto failed;
3628 if (PyObject_SetAttr(result, state->returns, value) == -1)
3629 goto failed;
3630 Py_DECREF(value);
3631 break;
3632 }
3633 return result;
3634 failed:
3635 Py_XDECREF(value);
3636 Py_XDECREF(result);
3637 return NULL;
3638 }
3639
3640 PyObject*
ast2obj_stmt(struct ast_state * state,void * _o)3641 ast2obj_stmt(struct ast_state *state, void* _o)
3642 {
3643 stmt_ty o = (stmt_ty)_o;
3644 PyObject *result = NULL, *value = NULL;
3645 PyTypeObject *tp;
3646 if (!o) {
3647 Py_RETURN_NONE;
3648 }
3649 switch (o->kind) {
3650 case FunctionDef_kind:
3651 tp = (PyTypeObject *)state->FunctionDef_type;
3652 result = PyType_GenericNew(tp, NULL, NULL);
3653 if (!result) goto failed;
3654 value = ast2obj_identifier(state, o->v.FunctionDef.name);
3655 if (!value) goto failed;
3656 if (PyObject_SetAttr(result, state->name, value) == -1)
3657 goto failed;
3658 Py_DECREF(value);
3659 value = ast2obj_arguments(state, o->v.FunctionDef.args);
3660 if (!value) goto failed;
3661 if (PyObject_SetAttr(result, state->args, value) == -1)
3662 goto failed;
3663 Py_DECREF(value);
3664 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
3665 ast2obj_stmt);
3666 if (!value) goto failed;
3667 if (PyObject_SetAttr(result, state->body, value) == -1)
3668 goto failed;
3669 Py_DECREF(value);
3670 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
3671 ast2obj_expr);
3672 if (!value) goto failed;
3673 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3674 goto failed;
3675 Py_DECREF(value);
3676 value = ast2obj_expr(state, o->v.FunctionDef.returns);
3677 if (!value) goto failed;
3678 if (PyObject_SetAttr(result, state->returns, value) == -1)
3679 goto failed;
3680 Py_DECREF(value);
3681 value = ast2obj_string(state, o->v.FunctionDef.type_comment);
3682 if (!value) goto failed;
3683 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3684 goto failed;
3685 Py_DECREF(value);
3686 break;
3687 case AsyncFunctionDef_kind:
3688 tp = (PyTypeObject *)state->AsyncFunctionDef_type;
3689 result = PyType_GenericNew(tp, NULL, NULL);
3690 if (!result) goto failed;
3691 value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
3692 if (!value) goto failed;
3693 if (PyObject_SetAttr(result, state->name, value) == -1)
3694 goto failed;
3695 Py_DECREF(value);
3696 value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
3697 if (!value) goto failed;
3698 if (PyObject_SetAttr(result, state->args, value) == -1)
3699 goto failed;
3700 Py_DECREF(value);
3701 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
3702 ast2obj_stmt);
3703 if (!value) goto failed;
3704 if (PyObject_SetAttr(result, state->body, value) == -1)
3705 goto failed;
3706 Py_DECREF(value);
3707 value = ast2obj_list(state,
3708 (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
3709 ast2obj_expr);
3710 if (!value) goto failed;
3711 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3712 goto failed;
3713 Py_DECREF(value);
3714 value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
3715 if (!value) goto failed;
3716 if (PyObject_SetAttr(result, state->returns, value) == -1)
3717 goto failed;
3718 Py_DECREF(value);
3719 value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
3720 if (!value) goto failed;
3721 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3722 goto failed;
3723 Py_DECREF(value);
3724 break;
3725 case ClassDef_kind:
3726 tp = (PyTypeObject *)state->ClassDef_type;
3727 result = PyType_GenericNew(tp, NULL, NULL);
3728 if (!result) goto failed;
3729 value = ast2obj_identifier(state, o->v.ClassDef.name);
3730 if (!value) goto failed;
3731 if (PyObject_SetAttr(result, state->name, value) == -1)
3732 goto failed;
3733 Py_DECREF(value);
3734 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
3735 ast2obj_expr);
3736 if (!value) goto failed;
3737 if (PyObject_SetAttr(result, state->bases, value) == -1)
3738 goto failed;
3739 Py_DECREF(value);
3740 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
3741 ast2obj_keyword);
3742 if (!value) goto failed;
3743 if (PyObject_SetAttr(result, state->keywords, value) == -1)
3744 goto failed;
3745 Py_DECREF(value);
3746 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
3747 ast2obj_stmt);
3748 if (!value) goto failed;
3749 if (PyObject_SetAttr(result, state->body, value) == -1)
3750 goto failed;
3751 Py_DECREF(value);
3752 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
3753 ast2obj_expr);
3754 if (!value) goto failed;
3755 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
3756 goto failed;
3757 Py_DECREF(value);
3758 break;
3759 case Return_kind:
3760 tp = (PyTypeObject *)state->Return_type;
3761 result = PyType_GenericNew(tp, NULL, NULL);
3762 if (!result) goto failed;
3763 value = ast2obj_expr(state, o->v.Return.value);
3764 if (!value) goto failed;
3765 if (PyObject_SetAttr(result, state->value, value) == -1)
3766 goto failed;
3767 Py_DECREF(value);
3768 break;
3769 case Delete_kind:
3770 tp = (PyTypeObject *)state->Delete_type;
3771 result = PyType_GenericNew(tp, NULL, NULL);
3772 if (!result) goto failed;
3773 value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
3774 ast2obj_expr);
3775 if (!value) goto failed;
3776 if (PyObject_SetAttr(result, state->targets, value) == -1)
3777 goto failed;
3778 Py_DECREF(value);
3779 break;
3780 case Assign_kind:
3781 tp = (PyTypeObject *)state->Assign_type;
3782 result = PyType_GenericNew(tp, NULL, NULL);
3783 if (!result) goto failed;
3784 value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
3785 ast2obj_expr);
3786 if (!value) goto failed;
3787 if (PyObject_SetAttr(result, state->targets, value) == -1)
3788 goto failed;
3789 Py_DECREF(value);
3790 value = ast2obj_expr(state, o->v.Assign.value);
3791 if (!value) goto failed;
3792 if (PyObject_SetAttr(result, state->value, value) == -1)
3793 goto failed;
3794 Py_DECREF(value);
3795 value = ast2obj_string(state, o->v.Assign.type_comment);
3796 if (!value) goto failed;
3797 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3798 goto failed;
3799 Py_DECREF(value);
3800 break;
3801 case AugAssign_kind:
3802 tp = (PyTypeObject *)state->AugAssign_type;
3803 result = PyType_GenericNew(tp, NULL, NULL);
3804 if (!result) goto failed;
3805 value = ast2obj_expr(state, o->v.AugAssign.target);
3806 if (!value) goto failed;
3807 if (PyObject_SetAttr(result, state->target, value) == -1)
3808 goto failed;
3809 Py_DECREF(value);
3810 value = ast2obj_operator(state, o->v.AugAssign.op);
3811 if (!value) goto failed;
3812 if (PyObject_SetAttr(result, state->op, value) == -1)
3813 goto failed;
3814 Py_DECREF(value);
3815 value = ast2obj_expr(state, o->v.AugAssign.value);
3816 if (!value) goto failed;
3817 if (PyObject_SetAttr(result, state->value, value) == -1)
3818 goto failed;
3819 Py_DECREF(value);
3820 break;
3821 case AnnAssign_kind:
3822 tp = (PyTypeObject *)state->AnnAssign_type;
3823 result = PyType_GenericNew(tp, NULL, NULL);
3824 if (!result) goto failed;
3825 value = ast2obj_expr(state, o->v.AnnAssign.target);
3826 if (!value) goto failed;
3827 if (PyObject_SetAttr(result, state->target, value) == -1)
3828 goto failed;
3829 Py_DECREF(value);
3830 value = ast2obj_expr(state, o->v.AnnAssign.annotation);
3831 if (!value) goto failed;
3832 if (PyObject_SetAttr(result, state->annotation, value) == -1)
3833 goto failed;
3834 Py_DECREF(value);
3835 value = ast2obj_expr(state, o->v.AnnAssign.value);
3836 if (!value) goto failed;
3837 if (PyObject_SetAttr(result, state->value, value) == -1)
3838 goto failed;
3839 Py_DECREF(value);
3840 value = ast2obj_int(state, o->v.AnnAssign.simple);
3841 if (!value) goto failed;
3842 if (PyObject_SetAttr(result, state->simple, value) == -1)
3843 goto failed;
3844 Py_DECREF(value);
3845 break;
3846 case For_kind:
3847 tp = (PyTypeObject *)state->For_type;
3848 result = PyType_GenericNew(tp, NULL, NULL);
3849 if (!result) goto failed;
3850 value = ast2obj_expr(state, o->v.For.target);
3851 if (!value) goto failed;
3852 if (PyObject_SetAttr(result, state->target, value) == -1)
3853 goto failed;
3854 Py_DECREF(value);
3855 value = ast2obj_expr(state, o->v.For.iter);
3856 if (!value) goto failed;
3857 if (PyObject_SetAttr(result, state->iter, value) == -1)
3858 goto failed;
3859 Py_DECREF(value);
3860 value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
3861 if (!value) goto failed;
3862 if (PyObject_SetAttr(result, state->body, value) == -1)
3863 goto failed;
3864 Py_DECREF(value);
3865 value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
3866 if (!value) goto failed;
3867 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3868 goto failed;
3869 Py_DECREF(value);
3870 value = ast2obj_string(state, o->v.For.type_comment);
3871 if (!value) goto failed;
3872 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3873 goto failed;
3874 Py_DECREF(value);
3875 break;
3876 case AsyncFor_kind:
3877 tp = (PyTypeObject *)state->AsyncFor_type;
3878 result = PyType_GenericNew(tp, NULL, NULL);
3879 if (!result) goto failed;
3880 value = ast2obj_expr(state, o->v.AsyncFor.target);
3881 if (!value) goto failed;
3882 if (PyObject_SetAttr(result, state->target, value) == -1)
3883 goto failed;
3884 Py_DECREF(value);
3885 value = ast2obj_expr(state, o->v.AsyncFor.iter);
3886 if (!value) goto failed;
3887 if (PyObject_SetAttr(result, state->iter, value) == -1)
3888 goto failed;
3889 Py_DECREF(value);
3890 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
3891 ast2obj_stmt);
3892 if (!value) goto failed;
3893 if (PyObject_SetAttr(result, state->body, value) == -1)
3894 goto failed;
3895 Py_DECREF(value);
3896 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
3897 ast2obj_stmt);
3898 if (!value) goto failed;
3899 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3900 goto failed;
3901 Py_DECREF(value);
3902 value = ast2obj_string(state, o->v.AsyncFor.type_comment);
3903 if (!value) goto failed;
3904 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3905 goto failed;
3906 Py_DECREF(value);
3907 break;
3908 case While_kind:
3909 tp = (PyTypeObject *)state->While_type;
3910 result = PyType_GenericNew(tp, NULL, NULL);
3911 if (!result) goto failed;
3912 value = ast2obj_expr(state, o->v.While.test);
3913 if (!value) goto failed;
3914 if (PyObject_SetAttr(result, state->test, value) == -1)
3915 goto failed;
3916 Py_DECREF(value);
3917 value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
3918 if (!value) goto failed;
3919 if (PyObject_SetAttr(result, state->body, value) == -1)
3920 goto failed;
3921 Py_DECREF(value);
3922 value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
3923 if (!value) goto failed;
3924 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3925 goto failed;
3926 Py_DECREF(value);
3927 break;
3928 case If_kind:
3929 tp = (PyTypeObject *)state->If_type;
3930 result = PyType_GenericNew(tp, NULL, NULL);
3931 if (!result) goto failed;
3932 value = ast2obj_expr(state, o->v.If.test);
3933 if (!value) goto failed;
3934 if (PyObject_SetAttr(result, state->test, value) == -1)
3935 goto failed;
3936 Py_DECREF(value);
3937 value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
3938 if (!value) goto failed;
3939 if (PyObject_SetAttr(result, state->body, value) == -1)
3940 goto failed;
3941 Py_DECREF(value);
3942 value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
3943 if (!value) goto failed;
3944 if (PyObject_SetAttr(result, state->orelse, value) == -1)
3945 goto failed;
3946 Py_DECREF(value);
3947 break;
3948 case With_kind:
3949 tp = (PyTypeObject *)state->With_type;
3950 result = PyType_GenericNew(tp, NULL, NULL);
3951 if (!result) goto failed;
3952 value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
3953 ast2obj_withitem);
3954 if (!value) goto failed;
3955 if (PyObject_SetAttr(result, state->items, value) == -1)
3956 goto failed;
3957 Py_DECREF(value);
3958 value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
3959 if (!value) goto failed;
3960 if (PyObject_SetAttr(result, state->body, value) == -1)
3961 goto failed;
3962 Py_DECREF(value);
3963 value = ast2obj_string(state, o->v.With.type_comment);
3964 if (!value) goto failed;
3965 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3966 goto failed;
3967 Py_DECREF(value);
3968 break;
3969 case AsyncWith_kind:
3970 tp = (PyTypeObject *)state->AsyncWith_type;
3971 result = PyType_GenericNew(tp, NULL, NULL);
3972 if (!result) goto failed;
3973 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
3974 ast2obj_withitem);
3975 if (!value) goto failed;
3976 if (PyObject_SetAttr(result, state->items, value) == -1)
3977 goto failed;
3978 Py_DECREF(value);
3979 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
3980 ast2obj_stmt);
3981 if (!value) goto failed;
3982 if (PyObject_SetAttr(result, state->body, value) == -1)
3983 goto failed;
3984 Py_DECREF(value);
3985 value = ast2obj_string(state, o->v.AsyncWith.type_comment);
3986 if (!value) goto failed;
3987 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
3988 goto failed;
3989 Py_DECREF(value);
3990 break;
3991 case Match_kind:
3992 tp = (PyTypeObject *)state->Match_type;
3993 result = PyType_GenericNew(tp, NULL, NULL);
3994 if (!result) goto failed;
3995 value = ast2obj_expr(state, o->v.Match.subject);
3996 if (!value) goto failed;
3997 if (PyObject_SetAttr(result, state->subject, value) == -1)
3998 goto failed;
3999 Py_DECREF(value);
4000 value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
4001 ast2obj_match_case);
4002 if (!value) goto failed;
4003 if (PyObject_SetAttr(result, state->cases, value) == -1)
4004 goto failed;
4005 Py_DECREF(value);
4006 break;
4007 case Raise_kind:
4008 tp = (PyTypeObject *)state->Raise_type;
4009 result = PyType_GenericNew(tp, NULL, NULL);
4010 if (!result) goto failed;
4011 value = ast2obj_expr(state, o->v.Raise.exc);
4012 if (!value) goto failed;
4013 if (PyObject_SetAttr(result, state->exc, value) == -1)
4014 goto failed;
4015 Py_DECREF(value);
4016 value = ast2obj_expr(state, o->v.Raise.cause);
4017 if (!value) goto failed;
4018 if (PyObject_SetAttr(result, state->cause, value) == -1)
4019 goto failed;
4020 Py_DECREF(value);
4021 break;
4022 case Try_kind:
4023 tp = (PyTypeObject *)state->Try_type;
4024 result = PyType_GenericNew(tp, NULL, NULL);
4025 if (!result) goto failed;
4026 value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
4027 if (!value) goto failed;
4028 if (PyObject_SetAttr(result, state->body, value) == -1)
4029 goto failed;
4030 Py_DECREF(value);
4031 value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
4032 ast2obj_excepthandler);
4033 if (!value) goto failed;
4034 if (PyObject_SetAttr(result, state->handlers, value) == -1)
4035 goto failed;
4036 Py_DECREF(value);
4037 value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
4038 if (!value) goto failed;
4039 if (PyObject_SetAttr(result, state->orelse, value) == -1)
4040 goto failed;
4041 Py_DECREF(value);
4042 value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
4043 ast2obj_stmt);
4044 if (!value) goto failed;
4045 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
4046 goto failed;
4047 Py_DECREF(value);
4048 break;
4049 case Assert_kind:
4050 tp = (PyTypeObject *)state->Assert_type;
4051 result = PyType_GenericNew(tp, NULL, NULL);
4052 if (!result) goto failed;
4053 value = ast2obj_expr(state, o->v.Assert.test);
4054 if (!value) goto failed;
4055 if (PyObject_SetAttr(result, state->test, value) == -1)
4056 goto failed;
4057 Py_DECREF(value);
4058 value = ast2obj_expr(state, o->v.Assert.msg);
4059 if (!value) goto failed;
4060 if (PyObject_SetAttr(result, state->msg, value) == -1)
4061 goto failed;
4062 Py_DECREF(value);
4063 break;
4064 case Import_kind:
4065 tp = (PyTypeObject *)state->Import_type;
4066 result = PyType_GenericNew(tp, NULL, NULL);
4067 if (!result) goto failed;
4068 value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
4069 ast2obj_alias);
4070 if (!value) goto failed;
4071 if (PyObject_SetAttr(result, state->names, value) == -1)
4072 goto failed;
4073 Py_DECREF(value);
4074 break;
4075 case ImportFrom_kind:
4076 tp = (PyTypeObject *)state->ImportFrom_type;
4077 result = PyType_GenericNew(tp, NULL, NULL);
4078 if (!result) goto failed;
4079 value = ast2obj_identifier(state, o->v.ImportFrom.module);
4080 if (!value) goto failed;
4081 if (PyObject_SetAttr(result, state->module, value) == -1)
4082 goto failed;
4083 Py_DECREF(value);
4084 value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
4085 ast2obj_alias);
4086 if (!value) goto failed;
4087 if (PyObject_SetAttr(result, state->names, value) == -1)
4088 goto failed;
4089 Py_DECREF(value);
4090 value = ast2obj_int(state, o->v.ImportFrom.level);
4091 if (!value) goto failed;
4092 if (PyObject_SetAttr(result, state->level, value) == -1)
4093 goto failed;
4094 Py_DECREF(value);
4095 break;
4096 case Global_kind:
4097 tp = (PyTypeObject *)state->Global_type;
4098 result = PyType_GenericNew(tp, NULL, NULL);
4099 if (!result) goto failed;
4100 value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
4101 ast2obj_identifier);
4102 if (!value) goto failed;
4103 if (PyObject_SetAttr(result, state->names, value) == -1)
4104 goto failed;
4105 Py_DECREF(value);
4106 break;
4107 case Nonlocal_kind:
4108 tp = (PyTypeObject *)state->Nonlocal_type;
4109 result = PyType_GenericNew(tp, NULL, NULL);
4110 if (!result) goto failed;
4111 value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
4112 ast2obj_identifier);
4113 if (!value) goto failed;
4114 if (PyObject_SetAttr(result, state->names, value) == -1)
4115 goto failed;
4116 Py_DECREF(value);
4117 break;
4118 case Expr_kind:
4119 tp = (PyTypeObject *)state->Expr_type;
4120 result = PyType_GenericNew(tp, NULL, NULL);
4121 if (!result) goto failed;
4122 value = ast2obj_expr(state, o->v.Expr.value);
4123 if (!value) goto failed;
4124 if (PyObject_SetAttr(result, state->value, value) == -1)
4125 goto failed;
4126 Py_DECREF(value);
4127 break;
4128 case Pass_kind:
4129 tp = (PyTypeObject *)state->Pass_type;
4130 result = PyType_GenericNew(tp, NULL, NULL);
4131 if (!result) goto failed;
4132 break;
4133 case Break_kind:
4134 tp = (PyTypeObject *)state->Break_type;
4135 result = PyType_GenericNew(tp, NULL, NULL);
4136 if (!result) goto failed;
4137 break;
4138 case Continue_kind:
4139 tp = (PyTypeObject *)state->Continue_type;
4140 result = PyType_GenericNew(tp, NULL, NULL);
4141 if (!result) goto failed;
4142 break;
4143 }
4144 value = ast2obj_int(state, o->lineno);
4145 if (!value) goto failed;
4146 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4147 goto failed;
4148 Py_DECREF(value);
4149 value = ast2obj_int(state, o->col_offset);
4150 if (!value) goto failed;
4151 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4152 goto failed;
4153 Py_DECREF(value);
4154 value = ast2obj_int(state, o->end_lineno);
4155 if (!value) goto failed;
4156 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4157 goto failed;
4158 Py_DECREF(value);
4159 value = ast2obj_int(state, o->end_col_offset);
4160 if (!value) goto failed;
4161 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4162 goto failed;
4163 Py_DECREF(value);
4164 return result;
4165 failed:
4166 Py_XDECREF(value);
4167 Py_XDECREF(result);
4168 return NULL;
4169 }
4170
4171 PyObject*
ast2obj_expr(struct ast_state * state,void * _o)4172 ast2obj_expr(struct ast_state *state, void* _o)
4173 {
4174 expr_ty o = (expr_ty)_o;
4175 PyObject *result = NULL, *value = NULL;
4176 PyTypeObject *tp;
4177 if (!o) {
4178 Py_RETURN_NONE;
4179 }
4180 switch (o->kind) {
4181 case BoolOp_kind:
4182 tp = (PyTypeObject *)state->BoolOp_type;
4183 result = PyType_GenericNew(tp, NULL, NULL);
4184 if (!result) goto failed;
4185 value = ast2obj_boolop(state, o->v.BoolOp.op);
4186 if (!value) goto failed;
4187 if (PyObject_SetAttr(result, state->op, value) == -1)
4188 goto failed;
4189 Py_DECREF(value);
4190 value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
4191 ast2obj_expr);
4192 if (!value) goto failed;
4193 if (PyObject_SetAttr(result, state->values, value) == -1)
4194 goto failed;
4195 Py_DECREF(value);
4196 break;
4197 case NamedExpr_kind:
4198 tp = (PyTypeObject *)state->NamedExpr_type;
4199 result = PyType_GenericNew(tp, NULL, NULL);
4200 if (!result) goto failed;
4201 value = ast2obj_expr(state, o->v.NamedExpr.target);
4202 if (!value) goto failed;
4203 if (PyObject_SetAttr(result, state->target, value) == -1)
4204 goto failed;
4205 Py_DECREF(value);
4206 value = ast2obj_expr(state, o->v.NamedExpr.value);
4207 if (!value) goto failed;
4208 if (PyObject_SetAttr(result, state->value, value) == -1)
4209 goto failed;
4210 Py_DECREF(value);
4211 break;
4212 case BinOp_kind:
4213 tp = (PyTypeObject *)state->BinOp_type;
4214 result = PyType_GenericNew(tp, NULL, NULL);
4215 if (!result) goto failed;
4216 value = ast2obj_expr(state, o->v.BinOp.left);
4217 if (!value) goto failed;
4218 if (PyObject_SetAttr(result, state->left, value) == -1)
4219 goto failed;
4220 Py_DECREF(value);
4221 value = ast2obj_operator(state, o->v.BinOp.op);
4222 if (!value) goto failed;
4223 if (PyObject_SetAttr(result, state->op, value) == -1)
4224 goto failed;
4225 Py_DECREF(value);
4226 value = ast2obj_expr(state, o->v.BinOp.right);
4227 if (!value) goto failed;
4228 if (PyObject_SetAttr(result, state->right, value) == -1)
4229 goto failed;
4230 Py_DECREF(value);
4231 break;
4232 case UnaryOp_kind:
4233 tp = (PyTypeObject *)state->UnaryOp_type;
4234 result = PyType_GenericNew(tp, NULL, NULL);
4235 if (!result) goto failed;
4236 value = ast2obj_unaryop(state, o->v.UnaryOp.op);
4237 if (!value) goto failed;
4238 if (PyObject_SetAttr(result, state->op, value) == -1)
4239 goto failed;
4240 Py_DECREF(value);
4241 value = ast2obj_expr(state, o->v.UnaryOp.operand);
4242 if (!value) goto failed;
4243 if (PyObject_SetAttr(result, state->operand, value) == -1)
4244 goto failed;
4245 Py_DECREF(value);
4246 break;
4247 case Lambda_kind:
4248 tp = (PyTypeObject *)state->Lambda_type;
4249 result = PyType_GenericNew(tp, NULL, NULL);
4250 if (!result) goto failed;
4251 value = ast2obj_arguments(state, o->v.Lambda.args);
4252 if (!value) goto failed;
4253 if (PyObject_SetAttr(result, state->args, value) == -1)
4254 goto failed;
4255 Py_DECREF(value);
4256 value = ast2obj_expr(state, o->v.Lambda.body);
4257 if (!value) goto failed;
4258 if (PyObject_SetAttr(result, state->body, value) == -1)
4259 goto failed;
4260 Py_DECREF(value);
4261 break;
4262 case IfExp_kind:
4263 tp = (PyTypeObject *)state->IfExp_type;
4264 result = PyType_GenericNew(tp, NULL, NULL);
4265 if (!result) goto failed;
4266 value = ast2obj_expr(state, o->v.IfExp.test);
4267 if (!value) goto failed;
4268 if (PyObject_SetAttr(result, state->test, value) == -1)
4269 goto failed;
4270 Py_DECREF(value);
4271 value = ast2obj_expr(state, o->v.IfExp.body);
4272 if (!value) goto failed;
4273 if (PyObject_SetAttr(result, state->body, value) == -1)
4274 goto failed;
4275 Py_DECREF(value);
4276 value = ast2obj_expr(state, o->v.IfExp.orelse);
4277 if (!value) goto failed;
4278 if (PyObject_SetAttr(result, state->orelse, value) == -1)
4279 goto failed;
4280 Py_DECREF(value);
4281 break;
4282 case Dict_kind:
4283 tp = (PyTypeObject *)state->Dict_type;
4284 result = PyType_GenericNew(tp, NULL, NULL);
4285 if (!result) goto failed;
4286 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
4287 if (!value) goto failed;
4288 if (PyObject_SetAttr(result, state->keys, value) == -1)
4289 goto failed;
4290 Py_DECREF(value);
4291 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
4292 if (!value) goto failed;
4293 if (PyObject_SetAttr(result, state->values, value) == -1)
4294 goto failed;
4295 Py_DECREF(value);
4296 break;
4297 case Set_kind:
4298 tp = (PyTypeObject *)state->Set_type;
4299 result = PyType_GenericNew(tp, NULL, NULL);
4300 if (!result) goto failed;
4301 value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
4302 if (!value) goto failed;
4303 if (PyObject_SetAttr(result, state->elts, value) == -1)
4304 goto failed;
4305 Py_DECREF(value);
4306 break;
4307 case ListComp_kind:
4308 tp = (PyTypeObject *)state->ListComp_type;
4309 result = PyType_GenericNew(tp, NULL, NULL);
4310 if (!result) goto failed;
4311 value = ast2obj_expr(state, o->v.ListComp.elt);
4312 if (!value) goto failed;
4313 if (PyObject_SetAttr(result, state->elt, value) == -1)
4314 goto failed;
4315 Py_DECREF(value);
4316 value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
4317 ast2obj_comprehension);
4318 if (!value) goto failed;
4319 if (PyObject_SetAttr(result, state->generators, value) == -1)
4320 goto failed;
4321 Py_DECREF(value);
4322 break;
4323 case SetComp_kind:
4324 tp = (PyTypeObject *)state->SetComp_type;
4325 result = PyType_GenericNew(tp, NULL, NULL);
4326 if (!result) goto failed;
4327 value = ast2obj_expr(state, o->v.SetComp.elt);
4328 if (!value) goto failed;
4329 if (PyObject_SetAttr(result, state->elt, value) == -1)
4330 goto failed;
4331 Py_DECREF(value);
4332 value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
4333 ast2obj_comprehension);
4334 if (!value) goto failed;
4335 if (PyObject_SetAttr(result, state->generators, value) == -1)
4336 goto failed;
4337 Py_DECREF(value);
4338 break;
4339 case DictComp_kind:
4340 tp = (PyTypeObject *)state->DictComp_type;
4341 result = PyType_GenericNew(tp, NULL, NULL);
4342 if (!result) goto failed;
4343 value = ast2obj_expr(state, o->v.DictComp.key);
4344 if (!value) goto failed;
4345 if (PyObject_SetAttr(result, state->key, value) == -1)
4346 goto failed;
4347 Py_DECREF(value);
4348 value = ast2obj_expr(state, o->v.DictComp.value);
4349 if (!value) goto failed;
4350 if (PyObject_SetAttr(result, state->value, value) == -1)
4351 goto failed;
4352 Py_DECREF(value);
4353 value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
4354 ast2obj_comprehension);
4355 if (!value) goto failed;
4356 if (PyObject_SetAttr(result, state->generators, value) == -1)
4357 goto failed;
4358 Py_DECREF(value);
4359 break;
4360 case GeneratorExp_kind:
4361 tp = (PyTypeObject *)state->GeneratorExp_type;
4362 result = PyType_GenericNew(tp, NULL, NULL);
4363 if (!result) goto failed;
4364 value = ast2obj_expr(state, o->v.GeneratorExp.elt);
4365 if (!value) goto failed;
4366 if (PyObject_SetAttr(result, state->elt, value) == -1)
4367 goto failed;
4368 Py_DECREF(value);
4369 value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
4370 ast2obj_comprehension);
4371 if (!value) goto failed;
4372 if (PyObject_SetAttr(result, state->generators, value) == -1)
4373 goto failed;
4374 Py_DECREF(value);
4375 break;
4376 case Await_kind:
4377 tp = (PyTypeObject *)state->Await_type;
4378 result = PyType_GenericNew(tp, NULL, NULL);
4379 if (!result) goto failed;
4380 value = ast2obj_expr(state, o->v.Await.value);
4381 if (!value) goto failed;
4382 if (PyObject_SetAttr(result, state->value, value) == -1)
4383 goto failed;
4384 Py_DECREF(value);
4385 break;
4386 case Yield_kind:
4387 tp = (PyTypeObject *)state->Yield_type;
4388 result = PyType_GenericNew(tp, NULL, NULL);
4389 if (!result) goto failed;
4390 value = ast2obj_expr(state, o->v.Yield.value);
4391 if (!value) goto failed;
4392 if (PyObject_SetAttr(result, state->value, value) == -1)
4393 goto failed;
4394 Py_DECREF(value);
4395 break;
4396 case YieldFrom_kind:
4397 tp = (PyTypeObject *)state->YieldFrom_type;
4398 result = PyType_GenericNew(tp, NULL, NULL);
4399 if (!result) goto failed;
4400 value = ast2obj_expr(state, o->v.YieldFrom.value);
4401 if (!value) goto failed;
4402 if (PyObject_SetAttr(result, state->value, value) == -1)
4403 goto failed;
4404 Py_DECREF(value);
4405 break;
4406 case Compare_kind:
4407 tp = (PyTypeObject *)state->Compare_type;
4408 result = PyType_GenericNew(tp, NULL, NULL);
4409 if (!result) goto failed;
4410 value = ast2obj_expr(state, o->v.Compare.left);
4411 if (!value) goto failed;
4412 if (PyObject_SetAttr(result, state->left, value) == -1)
4413 goto failed;
4414 Py_DECREF(value);
4415 {
4416 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4417 value = PyList_New(n);
4418 if (!value) goto failed;
4419 for(i = 0; i < n; i++)
4420 PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
4421 }
4422 if (!value) goto failed;
4423 if (PyObject_SetAttr(result, state->ops, value) == -1)
4424 goto failed;
4425 Py_DECREF(value);
4426 value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
4427 ast2obj_expr);
4428 if (!value) goto failed;
4429 if (PyObject_SetAttr(result, state->comparators, value) == -1)
4430 goto failed;
4431 Py_DECREF(value);
4432 break;
4433 case Call_kind:
4434 tp = (PyTypeObject *)state->Call_type;
4435 result = PyType_GenericNew(tp, NULL, NULL);
4436 if (!result) goto failed;
4437 value = ast2obj_expr(state, o->v.Call.func);
4438 if (!value) goto failed;
4439 if (PyObject_SetAttr(result, state->func, value) == -1)
4440 goto failed;
4441 Py_DECREF(value);
4442 value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
4443 if (!value) goto failed;
4444 if (PyObject_SetAttr(result, state->args, value) == -1)
4445 goto failed;
4446 Py_DECREF(value);
4447 value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
4448 ast2obj_keyword);
4449 if (!value) goto failed;
4450 if (PyObject_SetAttr(result, state->keywords, value) == -1)
4451 goto failed;
4452 Py_DECREF(value);
4453 break;
4454 case FormattedValue_kind:
4455 tp = (PyTypeObject *)state->FormattedValue_type;
4456 result = PyType_GenericNew(tp, NULL, NULL);
4457 if (!result) goto failed;
4458 value = ast2obj_expr(state, o->v.FormattedValue.value);
4459 if (!value) goto failed;
4460 if (PyObject_SetAttr(result, state->value, value) == -1)
4461 goto failed;
4462 Py_DECREF(value);
4463 value = ast2obj_int(state, o->v.FormattedValue.conversion);
4464 if (!value) goto failed;
4465 if (PyObject_SetAttr(result, state->conversion, value) == -1)
4466 goto failed;
4467 Py_DECREF(value);
4468 value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
4469 if (!value) goto failed;
4470 if (PyObject_SetAttr(result, state->format_spec, value) == -1)
4471 goto failed;
4472 Py_DECREF(value);
4473 break;
4474 case JoinedStr_kind:
4475 tp = (PyTypeObject *)state->JoinedStr_type;
4476 result = PyType_GenericNew(tp, NULL, NULL);
4477 if (!result) goto failed;
4478 value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
4479 ast2obj_expr);
4480 if (!value) goto failed;
4481 if (PyObject_SetAttr(result, state->values, value) == -1)
4482 goto failed;
4483 Py_DECREF(value);
4484 break;
4485 case Constant_kind:
4486 tp = (PyTypeObject *)state->Constant_type;
4487 result = PyType_GenericNew(tp, NULL, NULL);
4488 if (!result) goto failed;
4489 value = ast2obj_constant(state, o->v.Constant.value);
4490 if (!value) goto failed;
4491 if (PyObject_SetAttr(result, state->value, value) == -1)
4492 goto failed;
4493 Py_DECREF(value);
4494 value = ast2obj_string(state, o->v.Constant.kind);
4495 if (!value) goto failed;
4496 if (PyObject_SetAttr(result, state->kind, value) == -1)
4497 goto failed;
4498 Py_DECREF(value);
4499 break;
4500 case Attribute_kind:
4501 tp = (PyTypeObject *)state->Attribute_type;
4502 result = PyType_GenericNew(tp, NULL, NULL);
4503 if (!result) goto failed;
4504 value = ast2obj_expr(state, o->v.Attribute.value);
4505 if (!value) goto failed;
4506 if (PyObject_SetAttr(result, state->value, value) == -1)
4507 goto failed;
4508 Py_DECREF(value);
4509 value = ast2obj_identifier(state, o->v.Attribute.attr);
4510 if (!value) goto failed;
4511 if (PyObject_SetAttr(result, state->attr, value) == -1)
4512 goto failed;
4513 Py_DECREF(value);
4514 value = ast2obj_expr_context(state, o->v.Attribute.ctx);
4515 if (!value) goto failed;
4516 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4517 goto failed;
4518 Py_DECREF(value);
4519 break;
4520 case Subscript_kind:
4521 tp = (PyTypeObject *)state->Subscript_type;
4522 result = PyType_GenericNew(tp, NULL, NULL);
4523 if (!result) goto failed;
4524 value = ast2obj_expr(state, o->v.Subscript.value);
4525 if (!value) goto failed;
4526 if (PyObject_SetAttr(result, state->value, value) == -1)
4527 goto failed;
4528 Py_DECREF(value);
4529 value = ast2obj_expr(state, o->v.Subscript.slice);
4530 if (!value) goto failed;
4531 if (PyObject_SetAttr(result, state->slice, value) == -1)
4532 goto failed;
4533 Py_DECREF(value);
4534 value = ast2obj_expr_context(state, o->v.Subscript.ctx);
4535 if (!value) goto failed;
4536 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4537 goto failed;
4538 Py_DECREF(value);
4539 break;
4540 case Starred_kind:
4541 tp = (PyTypeObject *)state->Starred_type;
4542 result = PyType_GenericNew(tp, NULL, NULL);
4543 if (!result) goto failed;
4544 value = ast2obj_expr(state, o->v.Starred.value);
4545 if (!value) goto failed;
4546 if (PyObject_SetAttr(result, state->value, value) == -1)
4547 goto failed;
4548 Py_DECREF(value);
4549 value = ast2obj_expr_context(state, o->v.Starred.ctx);
4550 if (!value) goto failed;
4551 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4552 goto failed;
4553 Py_DECREF(value);
4554 break;
4555 case Name_kind:
4556 tp = (PyTypeObject *)state->Name_type;
4557 result = PyType_GenericNew(tp, NULL, NULL);
4558 if (!result) goto failed;
4559 value = ast2obj_identifier(state, o->v.Name.id);
4560 if (!value) goto failed;
4561 if (PyObject_SetAttr(result, state->id, value) == -1)
4562 goto failed;
4563 Py_DECREF(value);
4564 value = ast2obj_expr_context(state, o->v.Name.ctx);
4565 if (!value) goto failed;
4566 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4567 goto failed;
4568 Py_DECREF(value);
4569 break;
4570 case List_kind:
4571 tp = (PyTypeObject *)state->List_type;
4572 result = PyType_GenericNew(tp, NULL, NULL);
4573 if (!result) goto failed;
4574 value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
4575 if (!value) goto failed;
4576 if (PyObject_SetAttr(result, state->elts, value) == -1)
4577 goto failed;
4578 Py_DECREF(value);
4579 value = ast2obj_expr_context(state, o->v.List.ctx);
4580 if (!value) goto failed;
4581 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4582 goto failed;
4583 Py_DECREF(value);
4584 break;
4585 case Tuple_kind:
4586 tp = (PyTypeObject *)state->Tuple_type;
4587 result = PyType_GenericNew(tp, NULL, NULL);
4588 if (!result) goto failed;
4589 value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
4590 if (!value) goto failed;
4591 if (PyObject_SetAttr(result, state->elts, value) == -1)
4592 goto failed;
4593 Py_DECREF(value);
4594 value = ast2obj_expr_context(state, o->v.Tuple.ctx);
4595 if (!value) goto failed;
4596 if (PyObject_SetAttr(result, state->ctx, value) == -1)
4597 goto failed;
4598 Py_DECREF(value);
4599 break;
4600 case Slice_kind:
4601 tp = (PyTypeObject *)state->Slice_type;
4602 result = PyType_GenericNew(tp, NULL, NULL);
4603 if (!result) goto failed;
4604 value = ast2obj_expr(state, o->v.Slice.lower);
4605 if (!value) goto failed;
4606 if (PyObject_SetAttr(result, state->lower, value) == -1)
4607 goto failed;
4608 Py_DECREF(value);
4609 value = ast2obj_expr(state, o->v.Slice.upper);
4610 if (!value) goto failed;
4611 if (PyObject_SetAttr(result, state->upper, value) == -1)
4612 goto failed;
4613 Py_DECREF(value);
4614 value = ast2obj_expr(state, o->v.Slice.step);
4615 if (!value) goto failed;
4616 if (PyObject_SetAttr(result, state->step, value) == -1)
4617 goto failed;
4618 Py_DECREF(value);
4619 break;
4620 }
4621 value = ast2obj_int(state, o->lineno);
4622 if (!value) goto failed;
4623 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4624 goto failed;
4625 Py_DECREF(value);
4626 value = ast2obj_int(state, o->col_offset);
4627 if (!value) goto failed;
4628 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4629 goto failed;
4630 Py_DECREF(value);
4631 value = ast2obj_int(state, o->end_lineno);
4632 if (!value) goto failed;
4633 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4634 goto failed;
4635 Py_DECREF(value);
4636 value = ast2obj_int(state, o->end_col_offset);
4637 if (!value) goto failed;
4638 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4639 goto failed;
4640 Py_DECREF(value);
4641 return result;
4642 failed:
4643 Py_XDECREF(value);
4644 Py_XDECREF(result);
4645 return NULL;
4646 }
4647
ast2obj_expr_context(struct ast_state * state,expr_context_ty o)4648 PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
4649 {
4650 switch(o) {
4651 case Load:
4652 Py_INCREF(state->Load_singleton);
4653 return state->Load_singleton;
4654 case Store:
4655 Py_INCREF(state->Store_singleton);
4656 return state->Store_singleton;
4657 case Del:
4658 Py_INCREF(state->Del_singleton);
4659 return state->Del_singleton;
4660 }
4661 Py_UNREACHABLE();
4662 }
ast2obj_boolop(struct ast_state * state,boolop_ty o)4663 PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
4664 {
4665 switch(o) {
4666 case And:
4667 Py_INCREF(state->And_singleton);
4668 return state->And_singleton;
4669 case Or:
4670 Py_INCREF(state->Or_singleton);
4671 return state->Or_singleton;
4672 }
4673 Py_UNREACHABLE();
4674 }
ast2obj_operator(struct ast_state * state,operator_ty o)4675 PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
4676 {
4677 switch(o) {
4678 case Add:
4679 Py_INCREF(state->Add_singleton);
4680 return state->Add_singleton;
4681 case Sub:
4682 Py_INCREF(state->Sub_singleton);
4683 return state->Sub_singleton;
4684 case Mult:
4685 Py_INCREF(state->Mult_singleton);
4686 return state->Mult_singleton;
4687 case MatMult:
4688 Py_INCREF(state->MatMult_singleton);
4689 return state->MatMult_singleton;
4690 case Div:
4691 Py_INCREF(state->Div_singleton);
4692 return state->Div_singleton;
4693 case Mod:
4694 Py_INCREF(state->Mod_singleton);
4695 return state->Mod_singleton;
4696 case Pow:
4697 Py_INCREF(state->Pow_singleton);
4698 return state->Pow_singleton;
4699 case LShift:
4700 Py_INCREF(state->LShift_singleton);
4701 return state->LShift_singleton;
4702 case RShift:
4703 Py_INCREF(state->RShift_singleton);
4704 return state->RShift_singleton;
4705 case BitOr:
4706 Py_INCREF(state->BitOr_singleton);
4707 return state->BitOr_singleton;
4708 case BitXor:
4709 Py_INCREF(state->BitXor_singleton);
4710 return state->BitXor_singleton;
4711 case BitAnd:
4712 Py_INCREF(state->BitAnd_singleton);
4713 return state->BitAnd_singleton;
4714 case FloorDiv:
4715 Py_INCREF(state->FloorDiv_singleton);
4716 return state->FloorDiv_singleton;
4717 }
4718 Py_UNREACHABLE();
4719 }
ast2obj_unaryop(struct ast_state * state,unaryop_ty o)4720 PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
4721 {
4722 switch(o) {
4723 case Invert:
4724 Py_INCREF(state->Invert_singleton);
4725 return state->Invert_singleton;
4726 case Not:
4727 Py_INCREF(state->Not_singleton);
4728 return state->Not_singleton;
4729 case UAdd:
4730 Py_INCREF(state->UAdd_singleton);
4731 return state->UAdd_singleton;
4732 case USub:
4733 Py_INCREF(state->USub_singleton);
4734 return state->USub_singleton;
4735 }
4736 Py_UNREACHABLE();
4737 }
ast2obj_cmpop(struct ast_state * state,cmpop_ty o)4738 PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
4739 {
4740 switch(o) {
4741 case Eq:
4742 Py_INCREF(state->Eq_singleton);
4743 return state->Eq_singleton;
4744 case NotEq:
4745 Py_INCREF(state->NotEq_singleton);
4746 return state->NotEq_singleton;
4747 case Lt:
4748 Py_INCREF(state->Lt_singleton);
4749 return state->Lt_singleton;
4750 case LtE:
4751 Py_INCREF(state->LtE_singleton);
4752 return state->LtE_singleton;
4753 case Gt:
4754 Py_INCREF(state->Gt_singleton);
4755 return state->Gt_singleton;
4756 case GtE:
4757 Py_INCREF(state->GtE_singleton);
4758 return state->GtE_singleton;
4759 case Is:
4760 Py_INCREF(state->Is_singleton);
4761 return state->Is_singleton;
4762 case IsNot:
4763 Py_INCREF(state->IsNot_singleton);
4764 return state->IsNot_singleton;
4765 case In:
4766 Py_INCREF(state->In_singleton);
4767 return state->In_singleton;
4768 case NotIn:
4769 Py_INCREF(state->NotIn_singleton);
4770 return state->NotIn_singleton;
4771 }
4772 Py_UNREACHABLE();
4773 }
4774 PyObject*
ast2obj_comprehension(struct ast_state * state,void * _o)4775 ast2obj_comprehension(struct ast_state *state, void* _o)
4776 {
4777 comprehension_ty o = (comprehension_ty)_o;
4778 PyObject *result = NULL, *value = NULL;
4779 PyTypeObject *tp;
4780 if (!o) {
4781 Py_RETURN_NONE;
4782 }
4783 tp = (PyTypeObject *)state->comprehension_type;
4784 result = PyType_GenericNew(tp, NULL, NULL);
4785 if (!result) return NULL;
4786 value = ast2obj_expr(state, o->target);
4787 if (!value) goto failed;
4788 if (PyObject_SetAttr(result, state->target, value) == -1)
4789 goto failed;
4790 Py_DECREF(value);
4791 value = ast2obj_expr(state, o->iter);
4792 if (!value) goto failed;
4793 if (PyObject_SetAttr(result, state->iter, value) == -1)
4794 goto failed;
4795 Py_DECREF(value);
4796 value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
4797 if (!value) goto failed;
4798 if (PyObject_SetAttr(result, state->ifs, value) == -1)
4799 goto failed;
4800 Py_DECREF(value);
4801 value = ast2obj_int(state, o->is_async);
4802 if (!value) goto failed;
4803 if (PyObject_SetAttr(result, state->is_async, value) == -1)
4804 goto failed;
4805 Py_DECREF(value);
4806 return result;
4807 failed:
4808 Py_XDECREF(value);
4809 Py_XDECREF(result);
4810 return NULL;
4811 }
4812
4813 PyObject*
ast2obj_excepthandler(struct ast_state * state,void * _o)4814 ast2obj_excepthandler(struct ast_state *state, void* _o)
4815 {
4816 excepthandler_ty o = (excepthandler_ty)_o;
4817 PyObject *result = NULL, *value = NULL;
4818 PyTypeObject *tp;
4819 if (!o) {
4820 Py_RETURN_NONE;
4821 }
4822 switch (o->kind) {
4823 case ExceptHandler_kind:
4824 tp = (PyTypeObject *)state->ExceptHandler_type;
4825 result = PyType_GenericNew(tp, NULL, NULL);
4826 if (!result) goto failed;
4827 value = ast2obj_expr(state, o->v.ExceptHandler.type);
4828 if (!value) goto failed;
4829 if (PyObject_SetAttr(result, state->type, value) == -1)
4830 goto failed;
4831 Py_DECREF(value);
4832 value = ast2obj_identifier(state, o->v.ExceptHandler.name);
4833 if (!value) goto failed;
4834 if (PyObject_SetAttr(result, state->name, value) == -1)
4835 goto failed;
4836 Py_DECREF(value);
4837 value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
4838 ast2obj_stmt);
4839 if (!value) goto failed;
4840 if (PyObject_SetAttr(result, state->body, value) == -1)
4841 goto failed;
4842 Py_DECREF(value);
4843 break;
4844 }
4845 value = ast2obj_int(state, o->lineno);
4846 if (!value) goto failed;
4847 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4848 goto failed;
4849 Py_DECREF(value);
4850 value = ast2obj_int(state, o->col_offset);
4851 if (!value) goto failed;
4852 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4853 goto failed;
4854 Py_DECREF(value);
4855 value = ast2obj_int(state, o->end_lineno);
4856 if (!value) goto failed;
4857 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4858 goto failed;
4859 Py_DECREF(value);
4860 value = ast2obj_int(state, o->end_col_offset);
4861 if (!value) goto failed;
4862 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4863 goto failed;
4864 Py_DECREF(value);
4865 return result;
4866 failed:
4867 Py_XDECREF(value);
4868 Py_XDECREF(result);
4869 return NULL;
4870 }
4871
4872 PyObject*
ast2obj_arguments(struct ast_state * state,void * _o)4873 ast2obj_arguments(struct ast_state *state, void* _o)
4874 {
4875 arguments_ty o = (arguments_ty)_o;
4876 PyObject *result = NULL, *value = NULL;
4877 PyTypeObject *tp;
4878 if (!o) {
4879 Py_RETURN_NONE;
4880 }
4881 tp = (PyTypeObject *)state->arguments_type;
4882 result = PyType_GenericNew(tp, NULL, NULL);
4883 if (!result) return NULL;
4884 value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
4885 if (!value) goto failed;
4886 if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
4887 goto failed;
4888 Py_DECREF(value);
4889 value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
4890 if (!value) goto failed;
4891 if (PyObject_SetAttr(result, state->args, value) == -1)
4892 goto failed;
4893 Py_DECREF(value);
4894 value = ast2obj_arg(state, o->vararg);
4895 if (!value) goto failed;
4896 if (PyObject_SetAttr(result, state->vararg, value) == -1)
4897 goto failed;
4898 Py_DECREF(value);
4899 value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
4900 if (!value) goto failed;
4901 if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
4902 goto failed;
4903 Py_DECREF(value);
4904 value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
4905 if (!value) goto failed;
4906 if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
4907 goto failed;
4908 Py_DECREF(value);
4909 value = ast2obj_arg(state, o->kwarg);
4910 if (!value) goto failed;
4911 if (PyObject_SetAttr(result, state->kwarg, value) == -1)
4912 goto failed;
4913 Py_DECREF(value);
4914 value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
4915 if (!value) goto failed;
4916 if (PyObject_SetAttr(result, state->defaults, value) == -1)
4917 goto failed;
4918 Py_DECREF(value);
4919 return result;
4920 failed:
4921 Py_XDECREF(value);
4922 Py_XDECREF(result);
4923 return NULL;
4924 }
4925
4926 PyObject*
ast2obj_arg(struct ast_state * state,void * _o)4927 ast2obj_arg(struct ast_state *state, void* _o)
4928 {
4929 arg_ty o = (arg_ty)_o;
4930 PyObject *result = NULL, *value = NULL;
4931 PyTypeObject *tp;
4932 if (!o) {
4933 Py_RETURN_NONE;
4934 }
4935 tp = (PyTypeObject *)state->arg_type;
4936 result = PyType_GenericNew(tp, NULL, NULL);
4937 if (!result) return NULL;
4938 value = ast2obj_identifier(state, o->arg);
4939 if (!value) goto failed;
4940 if (PyObject_SetAttr(result, state->arg, value) == -1)
4941 goto failed;
4942 Py_DECREF(value);
4943 value = ast2obj_expr(state, o->annotation);
4944 if (!value) goto failed;
4945 if (PyObject_SetAttr(result, state->annotation, value) == -1)
4946 goto failed;
4947 Py_DECREF(value);
4948 value = ast2obj_string(state, o->type_comment);
4949 if (!value) goto failed;
4950 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
4951 goto failed;
4952 Py_DECREF(value);
4953 value = ast2obj_int(state, o->lineno);
4954 if (!value) goto failed;
4955 if (PyObject_SetAttr(result, state->lineno, value) < 0)
4956 goto failed;
4957 Py_DECREF(value);
4958 value = ast2obj_int(state, o->col_offset);
4959 if (!value) goto failed;
4960 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
4961 goto failed;
4962 Py_DECREF(value);
4963 value = ast2obj_int(state, o->end_lineno);
4964 if (!value) goto failed;
4965 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
4966 goto failed;
4967 Py_DECREF(value);
4968 value = ast2obj_int(state, o->end_col_offset);
4969 if (!value) goto failed;
4970 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
4971 goto failed;
4972 Py_DECREF(value);
4973 return result;
4974 failed:
4975 Py_XDECREF(value);
4976 Py_XDECREF(result);
4977 return NULL;
4978 }
4979
4980 PyObject*
ast2obj_keyword(struct ast_state * state,void * _o)4981 ast2obj_keyword(struct ast_state *state, void* _o)
4982 {
4983 keyword_ty o = (keyword_ty)_o;
4984 PyObject *result = NULL, *value = NULL;
4985 PyTypeObject *tp;
4986 if (!o) {
4987 Py_RETURN_NONE;
4988 }
4989 tp = (PyTypeObject *)state->keyword_type;
4990 result = PyType_GenericNew(tp, NULL, NULL);
4991 if (!result) return NULL;
4992 value = ast2obj_identifier(state, o->arg);
4993 if (!value) goto failed;
4994 if (PyObject_SetAttr(result, state->arg, value) == -1)
4995 goto failed;
4996 Py_DECREF(value);
4997 value = ast2obj_expr(state, o->value);
4998 if (!value) goto failed;
4999 if (PyObject_SetAttr(result, state->value, value) == -1)
5000 goto failed;
5001 Py_DECREF(value);
5002 value = ast2obj_int(state, o->lineno);
5003 if (!value) goto failed;
5004 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5005 goto failed;
5006 Py_DECREF(value);
5007 value = ast2obj_int(state, o->col_offset);
5008 if (!value) goto failed;
5009 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5010 goto failed;
5011 Py_DECREF(value);
5012 value = ast2obj_int(state, o->end_lineno);
5013 if (!value) goto failed;
5014 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5015 goto failed;
5016 Py_DECREF(value);
5017 value = ast2obj_int(state, o->end_col_offset);
5018 if (!value) goto failed;
5019 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5020 goto failed;
5021 Py_DECREF(value);
5022 return result;
5023 failed:
5024 Py_XDECREF(value);
5025 Py_XDECREF(result);
5026 return NULL;
5027 }
5028
5029 PyObject*
ast2obj_alias(struct ast_state * state,void * _o)5030 ast2obj_alias(struct ast_state *state, void* _o)
5031 {
5032 alias_ty o = (alias_ty)_o;
5033 PyObject *result = NULL, *value = NULL;
5034 PyTypeObject *tp;
5035 if (!o) {
5036 Py_RETURN_NONE;
5037 }
5038 tp = (PyTypeObject *)state->alias_type;
5039 result = PyType_GenericNew(tp, NULL, NULL);
5040 if (!result) return NULL;
5041 value = ast2obj_identifier(state, o->name);
5042 if (!value) goto failed;
5043 if (PyObject_SetAttr(result, state->name, value) == -1)
5044 goto failed;
5045 Py_DECREF(value);
5046 value = ast2obj_identifier(state, o->asname);
5047 if (!value) goto failed;
5048 if (PyObject_SetAttr(result, state->asname, value) == -1)
5049 goto failed;
5050 Py_DECREF(value);
5051 value = ast2obj_int(state, o->lineno);
5052 if (!value) goto failed;
5053 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5054 goto failed;
5055 Py_DECREF(value);
5056 value = ast2obj_int(state, o->col_offset);
5057 if (!value) goto failed;
5058 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5059 goto failed;
5060 Py_DECREF(value);
5061 value = ast2obj_int(state, o->end_lineno);
5062 if (!value) goto failed;
5063 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5064 goto failed;
5065 Py_DECREF(value);
5066 value = ast2obj_int(state, o->end_col_offset);
5067 if (!value) goto failed;
5068 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5069 goto failed;
5070 Py_DECREF(value);
5071 return result;
5072 failed:
5073 Py_XDECREF(value);
5074 Py_XDECREF(result);
5075 return NULL;
5076 }
5077
5078 PyObject*
ast2obj_withitem(struct ast_state * state,void * _o)5079 ast2obj_withitem(struct ast_state *state, void* _o)
5080 {
5081 withitem_ty o = (withitem_ty)_o;
5082 PyObject *result = NULL, *value = NULL;
5083 PyTypeObject *tp;
5084 if (!o) {
5085 Py_RETURN_NONE;
5086 }
5087 tp = (PyTypeObject *)state->withitem_type;
5088 result = PyType_GenericNew(tp, NULL, NULL);
5089 if (!result) return NULL;
5090 value = ast2obj_expr(state, o->context_expr);
5091 if (!value) goto failed;
5092 if (PyObject_SetAttr(result, state->context_expr, value) == -1)
5093 goto failed;
5094 Py_DECREF(value);
5095 value = ast2obj_expr(state, o->optional_vars);
5096 if (!value) goto failed;
5097 if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
5098 goto failed;
5099 Py_DECREF(value);
5100 return result;
5101 failed:
5102 Py_XDECREF(value);
5103 Py_XDECREF(result);
5104 return NULL;
5105 }
5106
5107 PyObject*
ast2obj_match_case(struct ast_state * state,void * _o)5108 ast2obj_match_case(struct ast_state *state, void* _o)
5109 {
5110 match_case_ty o = (match_case_ty)_o;
5111 PyObject *result = NULL, *value = NULL;
5112 PyTypeObject *tp;
5113 if (!o) {
5114 Py_RETURN_NONE;
5115 }
5116 tp = (PyTypeObject *)state->match_case_type;
5117 result = PyType_GenericNew(tp, NULL, NULL);
5118 if (!result) return NULL;
5119 value = ast2obj_pattern(state, o->pattern);
5120 if (!value) goto failed;
5121 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5122 goto failed;
5123 Py_DECREF(value);
5124 value = ast2obj_expr(state, o->guard);
5125 if (!value) goto failed;
5126 if (PyObject_SetAttr(result, state->guard, value) == -1)
5127 goto failed;
5128 Py_DECREF(value);
5129 value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
5130 if (!value) goto failed;
5131 if (PyObject_SetAttr(result, state->body, value) == -1)
5132 goto failed;
5133 Py_DECREF(value);
5134 return result;
5135 failed:
5136 Py_XDECREF(value);
5137 Py_XDECREF(result);
5138 return NULL;
5139 }
5140
5141 PyObject*
ast2obj_pattern(struct ast_state * state,void * _o)5142 ast2obj_pattern(struct ast_state *state, void* _o)
5143 {
5144 pattern_ty o = (pattern_ty)_o;
5145 PyObject *result = NULL, *value = NULL;
5146 PyTypeObject *tp;
5147 if (!o) {
5148 Py_RETURN_NONE;
5149 }
5150 switch (o->kind) {
5151 case MatchValue_kind:
5152 tp = (PyTypeObject *)state->MatchValue_type;
5153 result = PyType_GenericNew(tp, NULL, NULL);
5154 if (!result) goto failed;
5155 value = ast2obj_expr(state, o->v.MatchValue.value);
5156 if (!value) goto failed;
5157 if (PyObject_SetAttr(result, state->value, value) == -1)
5158 goto failed;
5159 Py_DECREF(value);
5160 break;
5161 case MatchSingleton_kind:
5162 tp = (PyTypeObject *)state->MatchSingleton_type;
5163 result = PyType_GenericNew(tp, NULL, NULL);
5164 if (!result) goto failed;
5165 value = ast2obj_constant(state, o->v.MatchSingleton.value);
5166 if (!value) goto failed;
5167 if (PyObject_SetAttr(result, state->value, value) == -1)
5168 goto failed;
5169 Py_DECREF(value);
5170 break;
5171 case MatchSequence_kind:
5172 tp = (PyTypeObject *)state->MatchSequence_type;
5173 result = PyType_GenericNew(tp, NULL, NULL);
5174 if (!result) goto failed;
5175 value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
5176 ast2obj_pattern);
5177 if (!value) goto failed;
5178 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5179 goto failed;
5180 Py_DECREF(value);
5181 break;
5182 case MatchMapping_kind:
5183 tp = (PyTypeObject *)state->MatchMapping_type;
5184 result = PyType_GenericNew(tp, NULL, NULL);
5185 if (!result) goto failed;
5186 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
5187 ast2obj_expr);
5188 if (!value) goto failed;
5189 if (PyObject_SetAttr(result, state->keys, value) == -1)
5190 goto failed;
5191 Py_DECREF(value);
5192 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
5193 ast2obj_pattern);
5194 if (!value) goto failed;
5195 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5196 goto failed;
5197 Py_DECREF(value);
5198 value = ast2obj_identifier(state, o->v.MatchMapping.rest);
5199 if (!value) goto failed;
5200 if (PyObject_SetAttr(result, state->rest, value) == -1)
5201 goto failed;
5202 Py_DECREF(value);
5203 break;
5204 case MatchClass_kind:
5205 tp = (PyTypeObject *)state->MatchClass_type;
5206 result = PyType_GenericNew(tp, NULL, NULL);
5207 if (!result) goto failed;
5208 value = ast2obj_expr(state, o->v.MatchClass.cls);
5209 if (!value) goto failed;
5210 if (PyObject_SetAttr(result, state->cls, value) == -1)
5211 goto failed;
5212 Py_DECREF(value);
5213 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
5214 ast2obj_pattern);
5215 if (!value) goto failed;
5216 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5217 goto failed;
5218 Py_DECREF(value);
5219 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
5220 ast2obj_identifier);
5221 if (!value) goto failed;
5222 if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
5223 goto failed;
5224 Py_DECREF(value);
5225 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
5226 ast2obj_pattern);
5227 if (!value) goto failed;
5228 if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
5229 goto failed;
5230 Py_DECREF(value);
5231 break;
5232 case MatchStar_kind:
5233 tp = (PyTypeObject *)state->MatchStar_type;
5234 result = PyType_GenericNew(tp, NULL, NULL);
5235 if (!result) goto failed;
5236 value = ast2obj_identifier(state, o->v.MatchStar.name);
5237 if (!value) goto failed;
5238 if (PyObject_SetAttr(result, state->name, value) == -1)
5239 goto failed;
5240 Py_DECREF(value);
5241 break;
5242 case MatchAs_kind:
5243 tp = (PyTypeObject *)state->MatchAs_type;
5244 result = PyType_GenericNew(tp, NULL, NULL);
5245 if (!result) goto failed;
5246 value = ast2obj_pattern(state, o->v.MatchAs.pattern);
5247 if (!value) goto failed;
5248 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5249 goto failed;
5250 Py_DECREF(value);
5251 value = ast2obj_identifier(state, o->v.MatchAs.name);
5252 if (!value) goto failed;
5253 if (PyObject_SetAttr(result, state->name, value) == -1)
5254 goto failed;
5255 Py_DECREF(value);
5256 break;
5257 case MatchOr_kind:
5258 tp = (PyTypeObject *)state->MatchOr_type;
5259 result = PyType_GenericNew(tp, NULL, NULL);
5260 if (!result) goto failed;
5261 value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
5262 ast2obj_pattern);
5263 if (!value) goto failed;
5264 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5265 goto failed;
5266 Py_DECREF(value);
5267 break;
5268 }
5269 value = ast2obj_int(state, o->lineno);
5270 if (!value) goto failed;
5271 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5272 goto failed;
5273 Py_DECREF(value);
5274 value = ast2obj_int(state, o->col_offset);
5275 if (!value) goto failed;
5276 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5277 goto failed;
5278 Py_DECREF(value);
5279 value = ast2obj_int(state, o->end_lineno);
5280 if (!value) goto failed;
5281 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5282 goto failed;
5283 Py_DECREF(value);
5284 value = ast2obj_int(state, o->end_col_offset);
5285 if (!value) goto failed;
5286 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5287 goto failed;
5288 Py_DECREF(value);
5289 return result;
5290 failed:
5291 Py_XDECREF(value);
5292 Py_XDECREF(result);
5293 return NULL;
5294 }
5295
5296 PyObject*
ast2obj_type_ignore(struct ast_state * state,void * _o)5297 ast2obj_type_ignore(struct ast_state *state, void* _o)
5298 {
5299 type_ignore_ty o = (type_ignore_ty)_o;
5300 PyObject *result = NULL, *value = NULL;
5301 PyTypeObject *tp;
5302 if (!o) {
5303 Py_RETURN_NONE;
5304 }
5305 switch (o->kind) {
5306 case TypeIgnore_kind:
5307 tp = (PyTypeObject *)state->TypeIgnore_type;
5308 result = PyType_GenericNew(tp, NULL, NULL);
5309 if (!result) goto failed;
5310 value = ast2obj_int(state, o->v.TypeIgnore.lineno);
5311 if (!value) goto failed;
5312 if (PyObject_SetAttr(result, state->lineno, value) == -1)
5313 goto failed;
5314 Py_DECREF(value);
5315 value = ast2obj_string(state, o->v.TypeIgnore.tag);
5316 if (!value) goto failed;
5317 if (PyObject_SetAttr(result, state->tag, value) == -1)
5318 goto failed;
5319 Py_DECREF(value);
5320 break;
5321 }
5322 return result;
5323 failed:
5324 Py_XDECREF(value);
5325 Py_XDECREF(result);
5326 return NULL;
5327 }
5328
5329
5330 int
obj2ast_mod(struct ast_state * state,PyObject * obj,mod_ty * out,PyArena * arena)5331 obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
5332 {
5333 int isinstance;
5334
5335 PyObject *tmp = NULL;
5336 PyObject *tp;
5337
5338 if (obj == Py_None) {
5339 *out = NULL;
5340 return 0;
5341 }
5342 tp = state->Module_type;
5343 isinstance = PyObject_IsInstance(obj, tp);
5344 if (isinstance == -1) {
5345 return 1;
5346 }
5347 if (isinstance) {
5348 asdl_stmt_seq* body;
5349 asdl_type_ignore_seq* type_ignores;
5350
5351 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5352 return 1;
5353 }
5354 if (tmp == NULL) {
5355 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5356 return 1;
5357 }
5358 else {
5359 int res;
5360 Py_ssize_t len;
5361 Py_ssize_t i;
5362 if (!PyList_Check(tmp)) {
5363 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5364 goto failed;
5365 }
5366 len = PyList_GET_SIZE(tmp);
5367 body = _Py_asdl_stmt_seq_new(len, arena);
5368 if (body == NULL) goto failed;
5369 for (i = 0; i < len; i++) {
5370 stmt_ty val;
5371 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5372 Py_INCREF(tmp2);
5373 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5374 goto failed;
5375 }
5376 res = obj2ast_stmt(state, tmp2, &val, arena);
5377 Py_LeaveRecursiveCall();
5378 Py_DECREF(tmp2);
5379 if (res != 0) goto failed;
5380 if (len != PyList_GET_SIZE(tmp)) {
5381 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5382 goto failed;
5383 }
5384 asdl_seq_SET(body, i, val);
5385 }
5386 Py_CLEAR(tmp);
5387 }
5388 if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
5389 return 1;
5390 }
5391 if (tmp == NULL) {
5392 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5393 return 1;
5394 }
5395 else {
5396 int res;
5397 Py_ssize_t len;
5398 Py_ssize_t i;
5399 if (!PyList_Check(tmp)) {
5400 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5401 goto failed;
5402 }
5403 len = PyList_GET_SIZE(tmp);
5404 type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
5405 if (type_ignores == NULL) goto failed;
5406 for (i = 0; i < len; i++) {
5407 type_ignore_ty val;
5408 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5409 Py_INCREF(tmp2);
5410 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5411 goto failed;
5412 }
5413 res = obj2ast_type_ignore(state, tmp2, &val, arena);
5414 Py_LeaveRecursiveCall();
5415 Py_DECREF(tmp2);
5416 if (res != 0) goto failed;
5417 if (len != PyList_GET_SIZE(tmp)) {
5418 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5419 goto failed;
5420 }
5421 asdl_seq_SET(type_ignores, i, val);
5422 }
5423 Py_CLEAR(tmp);
5424 }
5425 *out = _PyAST_Module(body, type_ignores, arena);
5426 if (*out == NULL) goto failed;
5427 return 0;
5428 }
5429 tp = state->Interactive_type;
5430 isinstance = PyObject_IsInstance(obj, tp);
5431 if (isinstance == -1) {
5432 return 1;
5433 }
5434 if (isinstance) {
5435 asdl_stmt_seq* body;
5436
5437 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5438 return 1;
5439 }
5440 if (tmp == NULL) {
5441 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5442 return 1;
5443 }
5444 else {
5445 int res;
5446 Py_ssize_t len;
5447 Py_ssize_t i;
5448 if (!PyList_Check(tmp)) {
5449 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5450 goto failed;
5451 }
5452 len = PyList_GET_SIZE(tmp);
5453 body = _Py_asdl_stmt_seq_new(len, arena);
5454 if (body == NULL) goto failed;
5455 for (i = 0; i < len; i++) {
5456 stmt_ty val;
5457 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5458 Py_INCREF(tmp2);
5459 if (Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
5460 goto failed;
5461 }
5462 res = obj2ast_stmt(state, tmp2, &val, arena);
5463 Py_LeaveRecursiveCall();
5464 Py_DECREF(tmp2);
5465 if (res != 0) goto failed;
5466 if (len != PyList_GET_SIZE(tmp)) {
5467 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5468 goto failed;
5469 }
5470 asdl_seq_SET(body, i, val);
5471 }
5472 Py_CLEAR(tmp);
5473 }
5474 *out = _PyAST_Interactive(body, arena);
5475 if (*out == NULL) goto failed;
5476 return 0;
5477 }
5478 tp = state->Expression_type;
5479 isinstance = PyObject_IsInstance(obj, tp);
5480 if (isinstance == -1) {
5481 return 1;
5482 }
5483 if (isinstance) {
5484 expr_ty body;
5485
5486 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5487 return 1;
5488 }
5489 if (tmp == NULL) {
5490 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5491 return 1;
5492 }
5493 else {
5494 int res;
5495 if (Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
5496 goto failed;
5497 }
5498 res = obj2ast_expr(state, tmp, &body, arena);
5499 Py_LeaveRecursiveCall();
5500 if (res != 0) goto failed;
5501 Py_CLEAR(tmp);
5502 }
5503 *out = _PyAST_Expression(body, arena);
5504 if (*out == NULL) goto failed;
5505 return 0;
5506 }
5507 tp = state->FunctionType_type;
5508 isinstance = PyObject_IsInstance(obj, tp);
5509 if (isinstance == -1) {
5510 return 1;
5511 }
5512 if (isinstance) {
5513 asdl_expr_seq* argtypes;
5514 expr_ty returns;
5515
5516 if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
5517 return 1;
5518 }
5519 if (tmp == NULL) {
5520 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5521 return 1;
5522 }
5523 else {
5524 int res;
5525 Py_ssize_t len;
5526 Py_ssize_t i;
5527 if (!PyList_Check(tmp)) {
5528 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5529 goto failed;
5530 }
5531 len = PyList_GET_SIZE(tmp);
5532 argtypes = _Py_asdl_expr_seq_new(len, arena);
5533 if (argtypes == NULL) goto failed;
5534 for (i = 0; i < len; i++) {
5535 expr_ty val;
5536 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5537 Py_INCREF(tmp2);
5538 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5539 goto failed;
5540 }
5541 res = obj2ast_expr(state, tmp2, &val, arena);
5542 Py_LeaveRecursiveCall();
5543 Py_DECREF(tmp2);
5544 if (res != 0) goto failed;
5545 if (len != PyList_GET_SIZE(tmp)) {
5546 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5547 goto failed;
5548 }
5549 asdl_seq_SET(argtypes, i, val);
5550 }
5551 Py_CLEAR(tmp);
5552 }
5553 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5554 return 1;
5555 }
5556 if (tmp == NULL) {
5557 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5558 return 1;
5559 }
5560 else {
5561 int res;
5562 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5563 goto failed;
5564 }
5565 res = obj2ast_expr(state, tmp, &returns, arena);
5566 Py_LeaveRecursiveCall();
5567 if (res != 0) goto failed;
5568 Py_CLEAR(tmp);
5569 }
5570 *out = _PyAST_FunctionType(argtypes, returns, arena);
5571 if (*out == NULL) goto failed;
5572 return 0;
5573 }
5574
5575 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5576 failed:
5577 Py_XDECREF(tmp);
5578 return 1;
5579 }
5580
5581 int
obj2ast_stmt(struct ast_state * state,PyObject * obj,stmt_ty * out,PyArena * arena)5582 obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
5583 arena)
5584 {
5585 int isinstance;
5586
5587 PyObject *tmp = NULL;
5588 PyObject *tp;
5589 int lineno;
5590 int col_offset;
5591 int end_lineno;
5592 int end_col_offset;
5593
5594 if (obj == Py_None) {
5595 *out = NULL;
5596 return 0;
5597 }
5598 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
5599 return 1;
5600 }
5601 if (tmp == NULL) {
5602 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5603 return 1;
5604 }
5605 else {
5606 int res;
5607 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5608 goto failed;
5609 }
5610 res = obj2ast_int(state, tmp, &lineno, arena);
5611 Py_LeaveRecursiveCall();
5612 if (res != 0) goto failed;
5613 Py_CLEAR(tmp);
5614 }
5615 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
5616 return 1;
5617 }
5618 if (tmp == NULL) {
5619 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5620 return 1;
5621 }
5622 else {
5623 int res;
5624 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5625 goto failed;
5626 }
5627 res = obj2ast_int(state, tmp, &col_offset, arena);
5628 Py_LeaveRecursiveCall();
5629 if (res != 0) goto failed;
5630 Py_CLEAR(tmp);
5631 }
5632 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
5633 return 1;
5634 }
5635 if (tmp == NULL || tmp == Py_None) {
5636 Py_CLEAR(tmp);
5637 end_lineno = 0;
5638 }
5639 else {
5640 int res;
5641 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5642 goto failed;
5643 }
5644 res = obj2ast_int(state, tmp, &end_lineno, arena);
5645 Py_LeaveRecursiveCall();
5646 if (res != 0) goto failed;
5647 Py_CLEAR(tmp);
5648 }
5649 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
5650 return 1;
5651 }
5652 if (tmp == NULL || tmp == Py_None) {
5653 Py_CLEAR(tmp);
5654 end_col_offset = 0;
5655 }
5656 else {
5657 int res;
5658 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5659 goto failed;
5660 }
5661 res = obj2ast_int(state, tmp, &end_col_offset, arena);
5662 Py_LeaveRecursiveCall();
5663 if (res != 0) goto failed;
5664 Py_CLEAR(tmp);
5665 }
5666 tp = state->FunctionDef_type;
5667 isinstance = PyObject_IsInstance(obj, tp);
5668 if (isinstance == -1) {
5669 return 1;
5670 }
5671 if (isinstance) {
5672 identifier name;
5673 arguments_ty args;
5674 asdl_stmt_seq* body;
5675 asdl_expr_seq* decorator_list;
5676 expr_ty returns;
5677 string type_comment;
5678
5679 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
5680 return 1;
5681 }
5682 if (tmp == NULL) {
5683 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5684 return 1;
5685 }
5686 else {
5687 int res;
5688 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5689 goto failed;
5690 }
5691 res = obj2ast_identifier(state, tmp, &name, arena);
5692 Py_LeaveRecursiveCall();
5693 if (res != 0) goto failed;
5694 Py_CLEAR(tmp);
5695 }
5696 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
5697 return 1;
5698 }
5699 if (tmp == NULL) {
5700 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5701 return 1;
5702 }
5703 else {
5704 int res;
5705 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5706 goto failed;
5707 }
5708 res = obj2ast_arguments(state, tmp, &args, arena);
5709 Py_LeaveRecursiveCall();
5710 if (res != 0) goto failed;
5711 Py_CLEAR(tmp);
5712 }
5713 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5714 return 1;
5715 }
5716 if (tmp == NULL) {
5717 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5718 return 1;
5719 }
5720 else {
5721 int res;
5722 Py_ssize_t len;
5723 Py_ssize_t i;
5724 if (!PyList_Check(tmp)) {
5725 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5726 goto failed;
5727 }
5728 len = PyList_GET_SIZE(tmp);
5729 body = _Py_asdl_stmt_seq_new(len, arena);
5730 if (body == NULL) goto failed;
5731 for (i = 0; i < len; i++) {
5732 stmt_ty val;
5733 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5734 Py_INCREF(tmp2);
5735 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5736 goto failed;
5737 }
5738 res = obj2ast_stmt(state, tmp2, &val, arena);
5739 Py_LeaveRecursiveCall();
5740 Py_DECREF(tmp2);
5741 if (res != 0) goto failed;
5742 if (len != PyList_GET_SIZE(tmp)) {
5743 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5744 goto failed;
5745 }
5746 asdl_seq_SET(body, i, val);
5747 }
5748 Py_CLEAR(tmp);
5749 }
5750 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
5751 return 1;
5752 }
5753 if (tmp == NULL) {
5754 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5755 return 1;
5756 }
5757 else {
5758 int res;
5759 Py_ssize_t len;
5760 Py_ssize_t i;
5761 if (!PyList_Check(tmp)) {
5762 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5763 goto failed;
5764 }
5765 len = PyList_GET_SIZE(tmp);
5766 decorator_list = _Py_asdl_expr_seq_new(len, arena);
5767 if (decorator_list == NULL) goto failed;
5768 for (i = 0; i < len; i++) {
5769 expr_ty val;
5770 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5771 Py_INCREF(tmp2);
5772 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5773 goto failed;
5774 }
5775 res = obj2ast_expr(state, tmp2, &val, arena);
5776 Py_LeaveRecursiveCall();
5777 Py_DECREF(tmp2);
5778 if (res != 0) goto failed;
5779 if (len != PyList_GET_SIZE(tmp)) {
5780 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5781 goto failed;
5782 }
5783 asdl_seq_SET(decorator_list, i, val);
5784 }
5785 Py_CLEAR(tmp);
5786 }
5787 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5788 return 1;
5789 }
5790 if (tmp == NULL || tmp == Py_None) {
5791 Py_CLEAR(tmp);
5792 returns = NULL;
5793 }
5794 else {
5795 int res;
5796 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5797 goto failed;
5798 }
5799 res = obj2ast_expr(state, tmp, &returns, arena);
5800 Py_LeaveRecursiveCall();
5801 if (res != 0) goto failed;
5802 Py_CLEAR(tmp);
5803 }
5804 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
5805 return 1;
5806 }
5807 if (tmp == NULL || tmp == Py_None) {
5808 Py_CLEAR(tmp);
5809 type_comment = NULL;
5810 }
5811 else {
5812 int res;
5813 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5814 goto failed;
5815 }
5816 res = obj2ast_string(state, tmp, &type_comment, arena);
5817 Py_LeaveRecursiveCall();
5818 if (res != 0) goto failed;
5819 Py_CLEAR(tmp);
5820 }
5821 *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
5822 type_comment, lineno, col_offset, end_lineno,
5823 end_col_offset, arena);
5824 if (*out == NULL) goto failed;
5825 return 0;
5826 }
5827 tp = state->AsyncFunctionDef_type;
5828 isinstance = PyObject_IsInstance(obj, tp);
5829 if (isinstance == -1) {
5830 return 1;
5831 }
5832 if (isinstance) {
5833 identifier name;
5834 arguments_ty args;
5835 asdl_stmt_seq* body;
5836 asdl_expr_seq* decorator_list;
5837 expr_ty returns;
5838 string type_comment;
5839
5840 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
5841 return 1;
5842 }
5843 if (tmp == NULL) {
5844 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5845 return 1;
5846 }
5847 else {
5848 int res;
5849 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5850 goto failed;
5851 }
5852 res = obj2ast_identifier(state, tmp, &name, arena);
5853 Py_LeaveRecursiveCall();
5854 if (res != 0) goto failed;
5855 Py_CLEAR(tmp);
5856 }
5857 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
5858 return 1;
5859 }
5860 if (tmp == NULL) {
5861 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5862 return 1;
5863 }
5864 else {
5865 int res;
5866 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5867 goto failed;
5868 }
5869 res = obj2ast_arguments(state, tmp, &args, arena);
5870 Py_LeaveRecursiveCall();
5871 if (res != 0) goto failed;
5872 Py_CLEAR(tmp);
5873 }
5874 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
5875 return 1;
5876 }
5877 if (tmp == NULL) {
5878 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5879 return 1;
5880 }
5881 else {
5882 int res;
5883 Py_ssize_t len;
5884 Py_ssize_t i;
5885 if (!PyList_Check(tmp)) {
5886 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5887 goto failed;
5888 }
5889 len = PyList_GET_SIZE(tmp);
5890 body = _Py_asdl_stmt_seq_new(len, arena);
5891 if (body == NULL) goto failed;
5892 for (i = 0; i < len; i++) {
5893 stmt_ty val;
5894 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5895 Py_INCREF(tmp2);
5896 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5897 goto failed;
5898 }
5899 res = obj2ast_stmt(state, tmp2, &val, arena);
5900 Py_LeaveRecursiveCall();
5901 Py_DECREF(tmp2);
5902 if (res != 0) goto failed;
5903 if (len != PyList_GET_SIZE(tmp)) {
5904 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5905 goto failed;
5906 }
5907 asdl_seq_SET(body, i, val);
5908 }
5909 Py_CLEAR(tmp);
5910 }
5911 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
5912 return 1;
5913 }
5914 if (tmp == NULL) {
5915 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5916 return 1;
5917 }
5918 else {
5919 int res;
5920 Py_ssize_t len;
5921 Py_ssize_t i;
5922 if (!PyList_Check(tmp)) {
5923 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
5924 goto failed;
5925 }
5926 len = PyList_GET_SIZE(tmp);
5927 decorator_list = _Py_asdl_expr_seq_new(len, arena);
5928 if (decorator_list == NULL) goto failed;
5929 for (i = 0; i < len; i++) {
5930 expr_ty val;
5931 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5932 Py_INCREF(tmp2);
5933 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5934 goto failed;
5935 }
5936 res = obj2ast_expr(state, tmp2, &val, arena);
5937 Py_LeaveRecursiveCall();
5938 Py_DECREF(tmp2);
5939 if (res != 0) goto failed;
5940 if (len != PyList_GET_SIZE(tmp)) {
5941 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5942 goto failed;
5943 }
5944 asdl_seq_SET(decorator_list, i, val);
5945 }
5946 Py_CLEAR(tmp);
5947 }
5948 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
5949 return 1;
5950 }
5951 if (tmp == NULL || tmp == Py_None) {
5952 Py_CLEAR(tmp);
5953 returns = NULL;
5954 }
5955 else {
5956 int res;
5957 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5958 goto failed;
5959 }
5960 res = obj2ast_expr(state, tmp, &returns, arena);
5961 Py_LeaveRecursiveCall();
5962 if (res != 0) goto failed;
5963 Py_CLEAR(tmp);
5964 }
5965 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
5966 return 1;
5967 }
5968 if (tmp == NULL || tmp == Py_None) {
5969 Py_CLEAR(tmp);
5970 type_comment = NULL;
5971 }
5972 else {
5973 int res;
5974 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5975 goto failed;
5976 }
5977 res = obj2ast_string(state, tmp, &type_comment, arena);
5978 Py_LeaveRecursiveCall();
5979 if (res != 0) goto failed;
5980 Py_CLEAR(tmp);
5981 }
5982 *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
5983 returns, type_comment, lineno,
5984 col_offset, end_lineno, end_col_offset,
5985 arena);
5986 if (*out == NULL) goto failed;
5987 return 0;
5988 }
5989 tp = state->ClassDef_type;
5990 isinstance = PyObject_IsInstance(obj, tp);
5991 if (isinstance == -1) {
5992 return 1;
5993 }
5994 if (isinstance) {
5995 identifier name;
5996 asdl_expr_seq* bases;
5997 asdl_keyword_seq* keywords;
5998 asdl_stmt_seq* body;
5999 asdl_expr_seq* decorator_list;
6000
6001 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
6002 return 1;
6003 }
6004 if (tmp == NULL) {
6005 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
6006 return 1;
6007 }
6008 else {
6009 int res;
6010 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6011 goto failed;
6012 }
6013 res = obj2ast_identifier(state, tmp, &name, arena);
6014 Py_LeaveRecursiveCall();
6015 if (res != 0) goto failed;
6016 Py_CLEAR(tmp);
6017 }
6018 if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
6019 return 1;
6020 }
6021 if (tmp == NULL) {
6022 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
6023 return 1;
6024 }
6025 else {
6026 int res;
6027 Py_ssize_t len;
6028 Py_ssize_t i;
6029 if (!PyList_Check(tmp)) {
6030 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6031 goto failed;
6032 }
6033 len = PyList_GET_SIZE(tmp);
6034 bases = _Py_asdl_expr_seq_new(len, arena);
6035 if (bases == NULL) goto failed;
6036 for (i = 0; i < len; i++) {
6037 expr_ty val;
6038 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6039 Py_INCREF(tmp2);
6040 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6041 goto failed;
6042 }
6043 res = obj2ast_expr(state, tmp2, &val, arena);
6044 Py_LeaveRecursiveCall();
6045 Py_DECREF(tmp2);
6046 if (res != 0) goto failed;
6047 if (len != PyList_GET_SIZE(tmp)) {
6048 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
6049 goto failed;
6050 }
6051 asdl_seq_SET(bases, i, val);
6052 }
6053 Py_CLEAR(tmp);
6054 }
6055 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
6056 return 1;
6057 }
6058 if (tmp == NULL) {
6059 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
6060 return 1;
6061 }
6062 else {
6063 int res;
6064 Py_ssize_t len;
6065 Py_ssize_t i;
6066 if (!PyList_Check(tmp)) {
6067 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6068 goto failed;
6069 }
6070 len = PyList_GET_SIZE(tmp);
6071 keywords = _Py_asdl_keyword_seq_new(len, arena);
6072 if (keywords == NULL) goto failed;
6073 for (i = 0; i < len; i++) {
6074 keyword_ty val;
6075 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6076 Py_INCREF(tmp2);
6077 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6078 goto failed;
6079 }
6080 res = obj2ast_keyword(state, tmp2, &val, arena);
6081 Py_LeaveRecursiveCall();
6082 Py_DECREF(tmp2);
6083 if (res != 0) goto failed;
6084 if (len != PyList_GET_SIZE(tmp)) {
6085 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
6086 goto failed;
6087 }
6088 asdl_seq_SET(keywords, i, val);
6089 }
6090 Py_CLEAR(tmp);
6091 }
6092 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6093 return 1;
6094 }
6095 if (tmp == NULL) {
6096 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
6097 return 1;
6098 }
6099 else {
6100 int res;
6101 Py_ssize_t len;
6102 Py_ssize_t i;
6103 if (!PyList_Check(tmp)) {
6104 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6105 goto failed;
6106 }
6107 len = PyList_GET_SIZE(tmp);
6108 body = _Py_asdl_stmt_seq_new(len, arena);
6109 if (body == NULL) goto failed;
6110 for (i = 0; i < len; i++) {
6111 stmt_ty val;
6112 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6113 Py_INCREF(tmp2);
6114 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6115 goto failed;
6116 }
6117 res = obj2ast_stmt(state, tmp2, &val, arena);
6118 Py_LeaveRecursiveCall();
6119 Py_DECREF(tmp2);
6120 if (res != 0) goto failed;
6121 if (len != PyList_GET_SIZE(tmp)) {
6122 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
6123 goto failed;
6124 }
6125 asdl_seq_SET(body, i, val);
6126 }
6127 Py_CLEAR(tmp);
6128 }
6129 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
6130 return 1;
6131 }
6132 if (tmp == NULL) {
6133 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
6134 return 1;
6135 }
6136 else {
6137 int res;
6138 Py_ssize_t len;
6139 Py_ssize_t i;
6140 if (!PyList_Check(tmp)) {
6141 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6142 goto failed;
6143 }
6144 len = PyList_GET_SIZE(tmp);
6145 decorator_list = _Py_asdl_expr_seq_new(len, arena);
6146 if (decorator_list == NULL) goto failed;
6147 for (i = 0; i < len; i++) {
6148 expr_ty val;
6149 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6150 Py_INCREF(tmp2);
6151 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6152 goto failed;
6153 }
6154 res = obj2ast_expr(state, tmp2, &val, arena);
6155 Py_LeaveRecursiveCall();
6156 Py_DECREF(tmp2);
6157 if (res != 0) goto failed;
6158 if (len != PyList_GET_SIZE(tmp)) {
6159 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
6160 goto failed;
6161 }
6162 asdl_seq_SET(decorator_list, i, val);
6163 }
6164 Py_CLEAR(tmp);
6165 }
6166 *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
6167 lineno, col_offset, end_lineno, end_col_offset,
6168 arena);
6169 if (*out == NULL) goto failed;
6170 return 0;
6171 }
6172 tp = state->Return_type;
6173 isinstance = PyObject_IsInstance(obj, tp);
6174 if (isinstance == -1) {
6175 return 1;
6176 }
6177 if (isinstance) {
6178 expr_ty value;
6179
6180 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6181 return 1;
6182 }
6183 if (tmp == NULL || tmp == Py_None) {
6184 Py_CLEAR(tmp);
6185 value = NULL;
6186 }
6187 else {
6188 int res;
6189 if (Py_EnterRecursiveCall(" while traversing 'Return' node")) {
6190 goto failed;
6191 }
6192 res = obj2ast_expr(state, tmp, &value, arena);
6193 Py_LeaveRecursiveCall();
6194 if (res != 0) goto failed;
6195 Py_CLEAR(tmp);
6196 }
6197 *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
6198 end_col_offset, arena);
6199 if (*out == NULL) goto failed;
6200 return 0;
6201 }
6202 tp = state->Delete_type;
6203 isinstance = PyObject_IsInstance(obj, tp);
6204 if (isinstance == -1) {
6205 return 1;
6206 }
6207 if (isinstance) {
6208 asdl_expr_seq* targets;
6209
6210 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6211 return 1;
6212 }
6213 if (tmp == NULL) {
6214 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
6215 return 1;
6216 }
6217 else {
6218 int res;
6219 Py_ssize_t len;
6220 Py_ssize_t i;
6221 if (!PyList_Check(tmp)) {
6222 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6223 goto failed;
6224 }
6225 len = PyList_GET_SIZE(tmp);
6226 targets = _Py_asdl_expr_seq_new(len, arena);
6227 if (targets == NULL) goto failed;
6228 for (i = 0; i < len; i++) {
6229 expr_ty val;
6230 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6231 Py_INCREF(tmp2);
6232 if (Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
6233 goto failed;
6234 }
6235 res = obj2ast_expr(state, tmp2, &val, arena);
6236 Py_LeaveRecursiveCall();
6237 Py_DECREF(tmp2);
6238 if (res != 0) goto failed;
6239 if (len != PyList_GET_SIZE(tmp)) {
6240 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
6241 goto failed;
6242 }
6243 asdl_seq_SET(targets, i, val);
6244 }
6245 Py_CLEAR(tmp);
6246 }
6247 *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
6248 end_col_offset, arena);
6249 if (*out == NULL) goto failed;
6250 return 0;
6251 }
6252 tp = state->Assign_type;
6253 isinstance = PyObject_IsInstance(obj, tp);
6254 if (isinstance == -1) {
6255 return 1;
6256 }
6257 if (isinstance) {
6258 asdl_expr_seq* targets;
6259 expr_ty value;
6260 string type_comment;
6261
6262 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
6263 return 1;
6264 }
6265 if (tmp == NULL) {
6266 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
6267 return 1;
6268 }
6269 else {
6270 int res;
6271 Py_ssize_t len;
6272 Py_ssize_t i;
6273 if (!PyList_Check(tmp)) {
6274 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6275 goto failed;
6276 }
6277 len = PyList_GET_SIZE(tmp);
6278 targets = _Py_asdl_expr_seq_new(len, arena);
6279 if (targets == NULL) goto failed;
6280 for (i = 0; i < len; i++) {
6281 expr_ty val;
6282 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6283 Py_INCREF(tmp2);
6284 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6285 goto failed;
6286 }
6287 res = obj2ast_expr(state, tmp2, &val, arena);
6288 Py_LeaveRecursiveCall();
6289 Py_DECREF(tmp2);
6290 if (res != 0) goto failed;
6291 if (len != PyList_GET_SIZE(tmp)) {
6292 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
6293 goto failed;
6294 }
6295 asdl_seq_SET(targets, i, val);
6296 }
6297 Py_CLEAR(tmp);
6298 }
6299 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6300 return 1;
6301 }
6302 if (tmp == NULL) {
6303 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
6304 return 1;
6305 }
6306 else {
6307 int res;
6308 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6309 goto failed;
6310 }
6311 res = obj2ast_expr(state, tmp, &value, arena);
6312 Py_LeaveRecursiveCall();
6313 if (res != 0) goto failed;
6314 Py_CLEAR(tmp);
6315 }
6316 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6317 return 1;
6318 }
6319 if (tmp == NULL || tmp == Py_None) {
6320 Py_CLEAR(tmp);
6321 type_comment = NULL;
6322 }
6323 else {
6324 int res;
6325 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6326 goto failed;
6327 }
6328 res = obj2ast_string(state, tmp, &type_comment, arena);
6329 Py_LeaveRecursiveCall();
6330 if (res != 0) goto failed;
6331 Py_CLEAR(tmp);
6332 }
6333 *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
6334 end_lineno, end_col_offset, arena);
6335 if (*out == NULL) goto failed;
6336 return 0;
6337 }
6338 tp = state->AugAssign_type;
6339 isinstance = PyObject_IsInstance(obj, tp);
6340 if (isinstance == -1) {
6341 return 1;
6342 }
6343 if (isinstance) {
6344 expr_ty target;
6345 operator_ty op;
6346 expr_ty value;
6347
6348 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6349 return 1;
6350 }
6351 if (tmp == NULL) {
6352 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6353 return 1;
6354 }
6355 else {
6356 int res;
6357 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6358 goto failed;
6359 }
6360 res = obj2ast_expr(state, tmp, &target, arena);
6361 Py_LeaveRecursiveCall();
6362 if (res != 0) goto failed;
6363 Py_CLEAR(tmp);
6364 }
6365 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
6366 return 1;
6367 }
6368 if (tmp == NULL) {
6369 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6370 return 1;
6371 }
6372 else {
6373 int res;
6374 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6375 goto failed;
6376 }
6377 res = obj2ast_operator(state, tmp, &op, arena);
6378 Py_LeaveRecursiveCall();
6379 if (res != 0) goto failed;
6380 Py_CLEAR(tmp);
6381 }
6382 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6383 return 1;
6384 }
6385 if (tmp == NULL) {
6386 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6387 return 1;
6388 }
6389 else {
6390 int res;
6391 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6392 goto failed;
6393 }
6394 res = obj2ast_expr(state, tmp, &value, arena);
6395 Py_LeaveRecursiveCall();
6396 if (res != 0) goto failed;
6397 Py_CLEAR(tmp);
6398 }
6399 *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
6400 end_lineno, end_col_offset, arena);
6401 if (*out == NULL) goto failed;
6402 return 0;
6403 }
6404 tp = state->AnnAssign_type;
6405 isinstance = PyObject_IsInstance(obj, tp);
6406 if (isinstance == -1) {
6407 return 1;
6408 }
6409 if (isinstance) {
6410 expr_ty target;
6411 expr_ty annotation;
6412 expr_ty value;
6413 int simple;
6414
6415 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6416 return 1;
6417 }
6418 if (tmp == NULL) {
6419 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6420 return 1;
6421 }
6422 else {
6423 int res;
6424 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6425 goto failed;
6426 }
6427 res = obj2ast_expr(state, tmp, &target, arena);
6428 Py_LeaveRecursiveCall();
6429 if (res != 0) goto failed;
6430 Py_CLEAR(tmp);
6431 }
6432 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
6433 return 1;
6434 }
6435 if (tmp == NULL) {
6436 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6437 return 1;
6438 }
6439 else {
6440 int res;
6441 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6442 goto failed;
6443 }
6444 res = obj2ast_expr(state, tmp, &annotation, arena);
6445 Py_LeaveRecursiveCall();
6446 if (res != 0) goto failed;
6447 Py_CLEAR(tmp);
6448 }
6449 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
6450 return 1;
6451 }
6452 if (tmp == NULL || tmp == Py_None) {
6453 Py_CLEAR(tmp);
6454 value = NULL;
6455 }
6456 else {
6457 int res;
6458 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6459 goto failed;
6460 }
6461 res = obj2ast_expr(state, tmp, &value, arena);
6462 Py_LeaveRecursiveCall();
6463 if (res != 0) goto failed;
6464 Py_CLEAR(tmp);
6465 }
6466 if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
6467 return 1;
6468 }
6469 if (tmp == NULL) {
6470 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6471 return 1;
6472 }
6473 else {
6474 int res;
6475 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6476 goto failed;
6477 }
6478 res = obj2ast_int(state, tmp, &simple, arena);
6479 Py_LeaveRecursiveCall();
6480 if (res != 0) goto failed;
6481 Py_CLEAR(tmp);
6482 }
6483 *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
6484 col_offset, end_lineno, end_col_offset, arena);
6485 if (*out == NULL) goto failed;
6486 return 0;
6487 }
6488 tp = state->For_type;
6489 isinstance = PyObject_IsInstance(obj, tp);
6490 if (isinstance == -1) {
6491 return 1;
6492 }
6493 if (isinstance) {
6494 expr_ty target;
6495 expr_ty iter;
6496 asdl_stmt_seq* body;
6497 asdl_stmt_seq* orelse;
6498 string type_comment;
6499
6500 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6501 return 1;
6502 }
6503 if (tmp == NULL) {
6504 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6505 return 1;
6506 }
6507 else {
6508 int res;
6509 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6510 goto failed;
6511 }
6512 res = obj2ast_expr(state, tmp, &target, arena);
6513 Py_LeaveRecursiveCall();
6514 if (res != 0) goto failed;
6515 Py_CLEAR(tmp);
6516 }
6517 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
6518 return 1;
6519 }
6520 if (tmp == NULL) {
6521 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6522 return 1;
6523 }
6524 else {
6525 int res;
6526 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6527 goto failed;
6528 }
6529 res = obj2ast_expr(state, tmp, &iter, arena);
6530 Py_LeaveRecursiveCall();
6531 if (res != 0) goto failed;
6532 Py_CLEAR(tmp);
6533 }
6534 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6535 return 1;
6536 }
6537 if (tmp == NULL) {
6538 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6539 return 1;
6540 }
6541 else {
6542 int res;
6543 Py_ssize_t len;
6544 Py_ssize_t i;
6545 if (!PyList_Check(tmp)) {
6546 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6547 goto failed;
6548 }
6549 len = PyList_GET_SIZE(tmp);
6550 body = _Py_asdl_stmt_seq_new(len, arena);
6551 if (body == NULL) goto failed;
6552 for (i = 0; i < len; i++) {
6553 stmt_ty val;
6554 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6555 Py_INCREF(tmp2);
6556 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6557 goto failed;
6558 }
6559 res = obj2ast_stmt(state, tmp2, &val, arena);
6560 Py_LeaveRecursiveCall();
6561 Py_DECREF(tmp2);
6562 if (res != 0) goto failed;
6563 if (len != PyList_GET_SIZE(tmp)) {
6564 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6565 goto failed;
6566 }
6567 asdl_seq_SET(body, i, val);
6568 }
6569 Py_CLEAR(tmp);
6570 }
6571 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6572 return 1;
6573 }
6574 if (tmp == NULL) {
6575 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6576 return 1;
6577 }
6578 else {
6579 int res;
6580 Py_ssize_t len;
6581 Py_ssize_t i;
6582 if (!PyList_Check(tmp)) {
6583 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6584 goto failed;
6585 }
6586 len = PyList_GET_SIZE(tmp);
6587 orelse = _Py_asdl_stmt_seq_new(len, arena);
6588 if (orelse == NULL) goto failed;
6589 for (i = 0; i < len; i++) {
6590 stmt_ty val;
6591 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6592 Py_INCREF(tmp2);
6593 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6594 goto failed;
6595 }
6596 res = obj2ast_stmt(state, tmp2, &val, arena);
6597 Py_LeaveRecursiveCall();
6598 Py_DECREF(tmp2);
6599 if (res != 0) goto failed;
6600 if (len != PyList_GET_SIZE(tmp)) {
6601 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6602 goto failed;
6603 }
6604 asdl_seq_SET(orelse, i, val);
6605 }
6606 Py_CLEAR(tmp);
6607 }
6608 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6609 return 1;
6610 }
6611 if (tmp == NULL || tmp == Py_None) {
6612 Py_CLEAR(tmp);
6613 type_comment = NULL;
6614 }
6615 else {
6616 int res;
6617 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6618 goto failed;
6619 }
6620 res = obj2ast_string(state, tmp, &type_comment, arena);
6621 Py_LeaveRecursiveCall();
6622 if (res != 0) goto failed;
6623 Py_CLEAR(tmp);
6624 }
6625 *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
6626 col_offset, end_lineno, end_col_offset, arena);
6627 if (*out == NULL) goto failed;
6628 return 0;
6629 }
6630 tp = state->AsyncFor_type;
6631 isinstance = PyObject_IsInstance(obj, tp);
6632 if (isinstance == -1) {
6633 return 1;
6634 }
6635 if (isinstance) {
6636 expr_ty target;
6637 expr_ty iter;
6638 asdl_stmt_seq* body;
6639 asdl_stmt_seq* orelse;
6640 string type_comment;
6641
6642 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
6643 return 1;
6644 }
6645 if (tmp == NULL) {
6646 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6647 return 1;
6648 }
6649 else {
6650 int res;
6651 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6652 goto failed;
6653 }
6654 res = obj2ast_expr(state, tmp, &target, arena);
6655 Py_LeaveRecursiveCall();
6656 if (res != 0) goto failed;
6657 Py_CLEAR(tmp);
6658 }
6659 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
6660 return 1;
6661 }
6662 if (tmp == NULL) {
6663 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6664 return 1;
6665 }
6666 else {
6667 int res;
6668 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6669 goto failed;
6670 }
6671 res = obj2ast_expr(state, tmp, &iter, arena);
6672 Py_LeaveRecursiveCall();
6673 if (res != 0) goto failed;
6674 Py_CLEAR(tmp);
6675 }
6676 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6677 return 1;
6678 }
6679 if (tmp == NULL) {
6680 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6681 return 1;
6682 }
6683 else {
6684 int res;
6685 Py_ssize_t len;
6686 Py_ssize_t i;
6687 if (!PyList_Check(tmp)) {
6688 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6689 goto failed;
6690 }
6691 len = PyList_GET_SIZE(tmp);
6692 body = _Py_asdl_stmt_seq_new(len, arena);
6693 if (body == NULL) goto failed;
6694 for (i = 0; i < len; i++) {
6695 stmt_ty val;
6696 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6697 Py_INCREF(tmp2);
6698 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6699 goto failed;
6700 }
6701 res = obj2ast_stmt(state, tmp2, &val, arena);
6702 Py_LeaveRecursiveCall();
6703 Py_DECREF(tmp2);
6704 if (res != 0) goto failed;
6705 if (len != PyList_GET_SIZE(tmp)) {
6706 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6707 goto failed;
6708 }
6709 asdl_seq_SET(body, i, val);
6710 }
6711 Py_CLEAR(tmp);
6712 }
6713 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6714 return 1;
6715 }
6716 if (tmp == NULL) {
6717 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6718 return 1;
6719 }
6720 else {
6721 int res;
6722 Py_ssize_t len;
6723 Py_ssize_t i;
6724 if (!PyList_Check(tmp)) {
6725 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6726 goto failed;
6727 }
6728 len = PyList_GET_SIZE(tmp);
6729 orelse = _Py_asdl_stmt_seq_new(len, arena);
6730 if (orelse == NULL) goto failed;
6731 for (i = 0; i < len; i++) {
6732 stmt_ty val;
6733 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6734 Py_INCREF(tmp2);
6735 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6736 goto failed;
6737 }
6738 res = obj2ast_stmt(state, tmp2, &val, arena);
6739 Py_LeaveRecursiveCall();
6740 Py_DECREF(tmp2);
6741 if (res != 0) goto failed;
6742 if (len != PyList_GET_SIZE(tmp)) {
6743 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6744 goto failed;
6745 }
6746 asdl_seq_SET(orelse, i, val);
6747 }
6748 Py_CLEAR(tmp);
6749 }
6750 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
6751 return 1;
6752 }
6753 if (tmp == NULL || tmp == Py_None) {
6754 Py_CLEAR(tmp);
6755 type_comment = NULL;
6756 }
6757 else {
6758 int res;
6759 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6760 goto failed;
6761 }
6762 res = obj2ast_string(state, tmp, &type_comment, arena);
6763 Py_LeaveRecursiveCall();
6764 if (res != 0) goto failed;
6765 Py_CLEAR(tmp);
6766 }
6767 *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
6768 lineno, col_offset, end_lineno, end_col_offset,
6769 arena);
6770 if (*out == NULL) goto failed;
6771 return 0;
6772 }
6773 tp = state->While_type;
6774 isinstance = PyObject_IsInstance(obj, tp);
6775 if (isinstance == -1) {
6776 return 1;
6777 }
6778 if (isinstance) {
6779 expr_ty test;
6780 asdl_stmt_seq* body;
6781 asdl_stmt_seq* orelse;
6782
6783 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
6784 return 1;
6785 }
6786 if (tmp == NULL) {
6787 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6788 return 1;
6789 }
6790 else {
6791 int res;
6792 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6793 goto failed;
6794 }
6795 res = obj2ast_expr(state, tmp, &test, arena);
6796 Py_LeaveRecursiveCall();
6797 if (res != 0) goto failed;
6798 Py_CLEAR(tmp);
6799 }
6800 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6801 return 1;
6802 }
6803 if (tmp == NULL) {
6804 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6805 return 1;
6806 }
6807 else {
6808 int res;
6809 Py_ssize_t len;
6810 Py_ssize_t i;
6811 if (!PyList_Check(tmp)) {
6812 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6813 goto failed;
6814 }
6815 len = PyList_GET_SIZE(tmp);
6816 body = _Py_asdl_stmt_seq_new(len, arena);
6817 if (body == NULL) goto failed;
6818 for (i = 0; i < len; i++) {
6819 stmt_ty val;
6820 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6821 Py_INCREF(tmp2);
6822 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6823 goto failed;
6824 }
6825 res = obj2ast_stmt(state, tmp2, &val, arena);
6826 Py_LeaveRecursiveCall();
6827 Py_DECREF(tmp2);
6828 if (res != 0) goto failed;
6829 if (len != PyList_GET_SIZE(tmp)) {
6830 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6831 goto failed;
6832 }
6833 asdl_seq_SET(body, i, val);
6834 }
6835 Py_CLEAR(tmp);
6836 }
6837 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6838 return 1;
6839 }
6840 if (tmp == NULL) {
6841 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6842 return 1;
6843 }
6844 else {
6845 int res;
6846 Py_ssize_t len;
6847 Py_ssize_t i;
6848 if (!PyList_Check(tmp)) {
6849 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6850 goto failed;
6851 }
6852 len = PyList_GET_SIZE(tmp);
6853 orelse = _Py_asdl_stmt_seq_new(len, arena);
6854 if (orelse == NULL) goto failed;
6855 for (i = 0; i < len; i++) {
6856 stmt_ty val;
6857 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6858 Py_INCREF(tmp2);
6859 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6860 goto failed;
6861 }
6862 res = obj2ast_stmt(state, tmp2, &val, arena);
6863 Py_LeaveRecursiveCall();
6864 Py_DECREF(tmp2);
6865 if (res != 0) goto failed;
6866 if (len != PyList_GET_SIZE(tmp)) {
6867 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6868 goto failed;
6869 }
6870 asdl_seq_SET(orelse, i, val);
6871 }
6872 Py_CLEAR(tmp);
6873 }
6874 *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
6875 end_col_offset, arena);
6876 if (*out == NULL) goto failed;
6877 return 0;
6878 }
6879 tp = state->If_type;
6880 isinstance = PyObject_IsInstance(obj, tp);
6881 if (isinstance == -1) {
6882 return 1;
6883 }
6884 if (isinstance) {
6885 expr_ty test;
6886 asdl_stmt_seq* body;
6887 asdl_stmt_seq* orelse;
6888
6889 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
6890 return 1;
6891 }
6892 if (tmp == NULL) {
6893 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6894 return 1;
6895 }
6896 else {
6897 int res;
6898 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6899 goto failed;
6900 }
6901 res = obj2ast_expr(state, tmp, &test, arena);
6902 Py_LeaveRecursiveCall();
6903 if (res != 0) goto failed;
6904 Py_CLEAR(tmp);
6905 }
6906 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
6907 return 1;
6908 }
6909 if (tmp == NULL) {
6910 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6911 return 1;
6912 }
6913 else {
6914 int res;
6915 Py_ssize_t len;
6916 Py_ssize_t i;
6917 if (!PyList_Check(tmp)) {
6918 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6919 goto failed;
6920 }
6921 len = PyList_GET_SIZE(tmp);
6922 body = _Py_asdl_stmt_seq_new(len, arena);
6923 if (body == NULL) goto failed;
6924 for (i = 0; i < len; i++) {
6925 stmt_ty val;
6926 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6927 Py_INCREF(tmp2);
6928 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6929 goto failed;
6930 }
6931 res = obj2ast_stmt(state, tmp2, &val, arena);
6932 Py_LeaveRecursiveCall();
6933 Py_DECREF(tmp2);
6934 if (res != 0) goto failed;
6935 if (len != PyList_GET_SIZE(tmp)) {
6936 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6937 goto failed;
6938 }
6939 asdl_seq_SET(body, i, val);
6940 }
6941 Py_CLEAR(tmp);
6942 }
6943 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
6944 return 1;
6945 }
6946 if (tmp == NULL) {
6947 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6948 return 1;
6949 }
6950 else {
6951 int res;
6952 Py_ssize_t len;
6953 Py_ssize_t i;
6954 if (!PyList_Check(tmp)) {
6955 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
6956 goto failed;
6957 }
6958 len = PyList_GET_SIZE(tmp);
6959 orelse = _Py_asdl_stmt_seq_new(len, arena);
6960 if (orelse == NULL) goto failed;
6961 for (i = 0; i < len; i++) {
6962 stmt_ty val;
6963 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6964 Py_INCREF(tmp2);
6965 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6966 goto failed;
6967 }
6968 res = obj2ast_stmt(state, tmp2, &val, arena);
6969 Py_LeaveRecursiveCall();
6970 Py_DECREF(tmp2);
6971 if (res != 0) goto failed;
6972 if (len != PyList_GET_SIZE(tmp)) {
6973 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6974 goto failed;
6975 }
6976 asdl_seq_SET(orelse, i, val);
6977 }
6978 Py_CLEAR(tmp);
6979 }
6980 *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
6981 end_col_offset, arena);
6982 if (*out == NULL) goto failed;
6983 return 0;
6984 }
6985 tp = state->With_type;
6986 isinstance = PyObject_IsInstance(obj, tp);
6987 if (isinstance == -1) {
6988 return 1;
6989 }
6990 if (isinstance) {
6991 asdl_withitem_seq* items;
6992 asdl_stmt_seq* body;
6993 string type_comment;
6994
6995 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
6996 return 1;
6997 }
6998 if (tmp == NULL) {
6999 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
7000 return 1;
7001 }
7002 else {
7003 int res;
7004 Py_ssize_t len;
7005 Py_ssize_t i;
7006 if (!PyList_Check(tmp)) {
7007 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7008 goto failed;
7009 }
7010 len = PyList_GET_SIZE(tmp);
7011 items = _Py_asdl_withitem_seq_new(len, arena);
7012 if (items == NULL) goto failed;
7013 for (i = 0; i < len; i++) {
7014 withitem_ty val;
7015 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7016 Py_INCREF(tmp2);
7017 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7018 goto failed;
7019 }
7020 res = obj2ast_withitem(state, tmp2, &val, arena);
7021 Py_LeaveRecursiveCall();
7022 Py_DECREF(tmp2);
7023 if (res != 0) goto failed;
7024 if (len != PyList_GET_SIZE(tmp)) {
7025 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
7026 goto failed;
7027 }
7028 asdl_seq_SET(items, i, val);
7029 }
7030 Py_CLEAR(tmp);
7031 }
7032 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7033 return 1;
7034 }
7035 if (tmp == NULL) {
7036 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
7037 return 1;
7038 }
7039 else {
7040 int res;
7041 Py_ssize_t len;
7042 Py_ssize_t i;
7043 if (!PyList_Check(tmp)) {
7044 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7045 goto failed;
7046 }
7047 len = PyList_GET_SIZE(tmp);
7048 body = _Py_asdl_stmt_seq_new(len, arena);
7049 if (body == NULL) goto failed;
7050 for (i = 0; i < len; i++) {
7051 stmt_ty val;
7052 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7053 Py_INCREF(tmp2);
7054 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7055 goto failed;
7056 }
7057 res = obj2ast_stmt(state, tmp2, &val, arena);
7058 Py_LeaveRecursiveCall();
7059 Py_DECREF(tmp2);
7060 if (res != 0) goto failed;
7061 if (len != PyList_GET_SIZE(tmp)) {
7062 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
7063 goto failed;
7064 }
7065 asdl_seq_SET(body, i, val);
7066 }
7067 Py_CLEAR(tmp);
7068 }
7069 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7070 return 1;
7071 }
7072 if (tmp == NULL || tmp == Py_None) {
7073 Py_CLEAR(tmp);
7074 type_comment = NULL;
7075 }
7076 else {
7077 int res;
7078 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7079 goto failed;
7080 }
7081 res = obj2ast_string(state, tmp, &type_comment, arena);
7082 Py_LeaveRecursiveCall();
7083 if (res != 0) goto failed;
7084 Py_CLEAR(tmp);
7085 }
7086 *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
7087 end_lineno, end_col_offset, arena);
7088 if (*out == NULL) goto failed;
7089 return 0;
7090 }
7091 tp = state->AsyncWith_type;
7092 isinstance = PyObject_IsInstance(obj, tp);
7093 if (isinstance == -1) {
7094 return 1;
7095 }
7096 if (isinstance) {
7097 asdl_withitem_seq* items;
7098 asdl_stmt_seq* body;
7099 string type_comment;
7100
7101 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
7102 return 1;
7103 }
7104 if (tmp == NULL) {
7105 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
7106 return 1;
7107 }
7108 else {
7109 int res;
7110 Py_ssize_t len;
7111 Py_ssize_t i;
7112 if (!PyList_Check(tmp)) {
7113 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7114 goto failed;
7115 }
7116 len = PyList_GET_SIZE(tmp);
7117 items = _Py_asdl_withitem_seq_new(len, arena);
7118 if (items == NULL) goto failed;
7119 for (i = 0; i < len; i++) {
7120 withitem_ty val;
7121 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7122 Py_INCREF(tmp2);
7123 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7124 goto failed;
7125 }
7126 res = obj2ast_withitem(state, tmp2, &val, arena);
7127 Py_LeaveRecursiveCall();
7128 Py_DECREF(tmp2);
7129 if (res != 0) goto failed;
7130 if (len != PyList_GET_SIZE(tmp)) {
7131 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
7132 goto failed;
7133 }
7134 asdl_seq_SET(items, i, val);
7135 }
7136 Py_CLEAR(tmp);
7137 }
7138 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7139 return 1;
7140 }
7141 if (tmp == NULL) {
7142 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
7143 return 1;
7144 }
7145 else {
7146 int res;
7147 Py_ssize_t len;
7148 Py_ssize_t i;
7149 if (!PyList_Check(tmp)) {
7150 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7151 goto failed;
7152 }
7153 len = PyList_GET_SIZE(tmp);
7154 body = _Py_asdl_stmt_seq_new(len, arena);
7155 if (body == NULL) goto failed;
7156 for (i = 0; i < len; i++) {
7157 stmt_ty val;
7158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7159 Py_INCREF(tmp2);
7160 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7161 goto failed;
7162 }
7163 res = obj2ast_stmt(state, tmp2, &val, arena);
7164 Py_LeaveRecursiveCall();
7165 Py_DECREF(tmp2);
7166 if (res != 0) goto failed;
7167 if (len != PyList_GET_SIZE(tmp)) {
7168 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
7169 goto failed;
7170 }
7171 asdl_seq_SET(body, i, val);
7172 }
7173 Py_CLEAR(tmp);
7174 }
7175 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
7176 return 1;
7177 }
7178 if (tmp == NULL || tmp == Py_None) {
7179 Py_CLEAR(tmp);
7180 type_comment = NULL;
7181 }
7182 else {
7183 int res;
7184 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7185 goto failed;
7186 }
7187 res = obj2ast_string(state, tmp, &type_comment, arena);
7188 Py_LeaveRecursiveCall();
7189 if (res != 0) goto failed;
7190 Py_CLEAR(tmp);
7191 }
7192 *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
7193 end_lineno, end_col_offset, arena);
7194 if (*out == NULL) goto failed;
7195 return 0;
7196 }
7197 tp = state->Match_type;
7198 isinstance = PyObject_IsInstance(obj, tp);
7199 if (isinstance == -1) {
7200 return 1;
7201 }
7202 if (isinstance) {
7203 expr_ty subject;
7204 asdl_match_case_seq* cases;
7205
7206 if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
7207 return 1;
7208 }
7209 if (tmp == NULL) {
7210 PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
7211 return 1;
7212 }
7213 else {
7214 int res;
7215 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7216 goto failed;
7217 }
7218 res = obj2ast_expr(state, tmp, &subject, arena);
7219 Py_LeaveRecursiveCall();
7220 if (res != 0) goto failed;
7221 Py_CLEAR(tmp);
7222 }
7223 if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
7224 return 1;
7225 }
7226 if (tmp == NULL) {
7227 PyErr_SetString(PyExc_TypeError, "required field \"cases\" missing from Match");
7228 return 1;
7229 }
7230 else {
7231 int res;
7232 Py_ssize_t len;
7233 Py_ssize_t i;
7234 if (!PyList_Check(tmp)) {
7235 PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7236 goto failed;
7237 }
7238 len = PyList_GET_SIZE(tmp);
7239 cases = _Py_asdl_match_case_seq_new(len, arena);
7240 if (cases == NULL) goto failed;
7241 for (i = 0; i < len; i++) {
7242 match_case_ty val;
7243 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7244 Py_INCREF(tmp2);
7245 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7246 goto failed;
7247 }
7248 res = obj2ast_match_case(state, tmp2, &val, arena);
7249 Py_LeaveRecursiveCall();
7250 Py_DECREF(tmp2);
7251 if (res != 0) goto failed;
7252 if (len != PyList_GET_SIZE(tmp)) {
7253 PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
7254 goto failed;
7255 }
7256 asdl_seq_SET(cases, i, val);
7257 }
7258 Py_CLEAR(tmp);
7259 }
7260 *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
7261 end_col_offset, arena);
7262 if (*out == NULL) goto failed;
7263 return 0;
7264 }
7265 tp = state->Raise_type;
7266 isinstance = PyObject_IsInstance(obj, tp);
7267 if (isinstance == -1) {
7268 return 1;
7269 }
7270 if (isinstance) {
7271 expr_ty exc;
7272 expr_ty cause;
7273
7274 if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
7275 return 1;
7276 }
7277 if (tmp == NULL || tmp == Py_None) {
7278 Py_CLEAR(tmp);
7279 exc = NULL;
7280 }
7281 else {
7282 int res;
7283 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7284 goto failed;
7285 }
7286 res = obj2ast_expr(state, tmp, &exc, arena);
7287 Py_LeaveRecursiveCall();
7288 if (res != 0) goto failed;
7289 Py_CLEAR(tmp);
7290 }
7291 if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
7292 return 1;
7293 }
7294 if (tmp == NULL || tmp == Py_None) {
7295 Py_CLEAR(tmp);
7296 cause = NULL;
7297 }
7298 else {
7299 int res;
7300 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7301 goto failed;
7302 }
7303 res = obj2ast_expr(state, tmp, &cause, arena);
7304 Py_LeaveRecursiveCall();
7305 if (res != 0) goto failed;
7306 Py_CLEAR(tmp);
7307 }
7308 *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
7309 end_col_offset, arena);
7310 if (*out == NULL) goto failed;
7311 return 0;
7312 }
7313 tp = state->Try_type;
7314 isinstance = PyObject_IsInstance(obj, tp);
7315 if (isinstance == -1) {
7316 return 1;
7317 }
7318 if (isinstance) {
7319 asdl_stmt_seq* body;
7320 asdl_excepthandler_seq* handlers;
7321 asdl_stmt_seq* orelse;
7322 asdl_stmt_seq* finalbody;
7323
7324 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
7325 return 1;
7326 }
7327 if (tmp == NULL) {
7328 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
7329 return 1;
7330 }
7331 else {
7332 int res;
7333 Py_ssize_t len;
7334 Py_ssize_t i;
7335 if (!PyList_Check(tmp)) {
7336 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7337 goto failed;
7338 }
7339 len = PyList_GET_SIZE(tmp);
7340 body = _Py_asdl_stmt_seq_new(len, arena);
7341 if (body == NULL) goto failed;
7342 for (i = 0; i < len; i++) {
7343 stmt_ty val;
7344 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7345 Py_INCREF(tmp2);
7346 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7347 goto failed;
7348 }
7349 res = obj2ast_stmt(state, tmp2, &val, arena);
7350 Py_LeaveRecursiveCall();
7351 Py_DECREF(tmp2);
7352 if (res != 0) goto failed;
7353 if (len != PyList_GET_SIZE(tmp)) {
7354 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
7355 goto failed;
7356 }
7357 asdl_seq_SET(body, i, val);
7358 }
7359 Py_CLEAR(tmp);
7360 }
7361 if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
7362 return 1;
7363 }
7364 if (tmp == NULL) {
7365 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
7366 return 1;
7367 }
7368 else {
7369 int res;
7370 Py_ssize_t len;
7371 Py_ssize_t i;
7372 if (!PyList_Check(tmp)) {
7373 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7374 goto failed;
7375 }
7376 len = PyList_GET_SIZE(tmp);
7377 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
7378 if (handlers == NULL) goto failed;
7379 for (i = 0; i < len; i++) {
7380 excepthandler_ty val;
7381 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7382 Py_INCREF(tmp2);
7383 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7384 goto failed;
7385 }
7386 res = obj2ast_excepthandler(state, tmp2, &val, arena);
7387 Py_LeaveRecursiveCall();
7388 Py_DECREF(tmp2);
7389 if (res != 0) goto failed;
7390 if (len != PyList_GET_SIZE(tmp)) {
7391 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
7392 goto failed;
7393 }
7394 asdl_seq_SET(handlers, i, val);
7395 }
7396 Py_CLEAR(tmp);
7397 }
7398 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
7399 return 1;
7400 }
7401 if (tmp == NULL) {
7402 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
7403 return 1;
7404 }
7405 else {
7406 int res;
7407 Py_ssize_t len;
7408 Py_ssize_t i;
7409 if (!PyList_Check(tmp)) {
7410 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7411 goto failed;
7412 }
7413 len = PyList_GET_SIZE(tmp);
7414 orelse = _Py_asdl_stmt_seq_new(len, arena);
7415 if (orelse == NULL) goto failed;
7416 for (i = 0; i < len; i++) {
7417 stmt_ty val;
7418 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7419 Py_INCREF(tmp2);
7420 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7421 goto failed;
7422 }
7423 res = obj2ast_stmt(state, tmp2, &val, arena);
7424 Py_LeaveRecursiveCall();
7425 Py_DECREF(tmp2);
7426 if (res != 0) goto failed;
7427 if (len != PyList_GET_SIZE(tmp)) {
7428 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
7429 goto failed;
7430 }
7431 asdl_seq_SET(orelse, i, val);
7432 }
7433 Py_CLEAR(tmp);
7434 }
7435 if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
7436 return 1;
7437 }
7438 if (tmp == NULL) {
7439 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
7440 return 1;
7441 }
7442 else {
7443 int res;
7444 Py_ssize_t len;
7445 Py_ssize_t i;
7446 if (!PyList_Check(tmp)) {
7447 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7448 goto failed;
7449 }
7450 len = PyList_GET_SIZE(tmp);
7451 finalbody = _Py_asdl_stmt_seq_new(len, arena);
7452 if (finalbody == NULL) goto failed;
7453 for (i = 0; i < len; i++) {
7454 stmt_ty val;
7455 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7456 Py_INCREF(tmp2);
7457 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7458 goto failed;
7459 }
7460 res = obj2ast_stmt(state, tmp2, &val, arena);
7461 Py_LeaveRecursiveCall();
7462 Py_DECREF(tmp2);
7463 if (res != 0) goto failed;
7464 if (len != PyList_GET_SIZE(tmp)) {
7465 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
7466 goto failed;
7467 }
7468 asdl_seq_SET(finalbody, i, val);
7469 }
7470 Py_CLEAR(tmp);
7471 }
7472 *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
7473 col_offset, end_lineno, end_col_offset, arena);
7474 if (*out == NULL) goto failed;
7475 return 0;
7476 }
7477 tp = state->Assert_type;
7478 isinstance = PyObject_IsInstance(obj, tp);
7479 if (isinstance == -1) {
7480 return 1;
7481 }
7482 if (isinstance) {
7483 expr_ty test;
7484 expr_ty msg;
7485
7486 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
7487 return 1;
7488 }
7489 if (tmp == NULL) {
7490 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
7491 return 1;
7492 }
7493 else {
7494 int res;
7495 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7496 goto failed;
7497 }
7498 res = obj2ast_expr(state, tmp, &test, arena);
7499 Py_LeaveRecursiveCall();
7500 if (res != 0) goto failed;
7501 Py_CLEAR(tmp);
7502 }
7503 if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
7504 return 1;
7505 }
7506 if (tmp == NULL || tmp == Py_None) {
7507 Py_CLEAR(tmp);
7508 msg = NULL;
7509 }
7510 else {
7511 int res;
7512 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7513 goto failed;
7514 }
7515 res = obj2ast_expr(state, tmp, &msg, arena);
7516 Py_LeaveRecursiveCall();
7517 if (res != 0) goto failed;
7518 Py_CLEAR(tmp);
7519 }
7520 *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
7521 end_col_offset, arena);
7522 if (*out == NULL) goto failed;
7523 return 0;
7524 }
7525 tp = state->Import_type;
7526 isinstance = PyObject_IsInstance(obj, tp);
7527 if (isinstance == -1) {
7528 return 1;
7529 }
7530 if (isinstance) {
7531 asdl_alias_seq* names;
7532
7533 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7534 return 1;
7535 }
7536 if (tmp == NULL) {
7537 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
7538 return 1;
7539 }
7540 else {
7541 int res;
7542 Py_ssize_t len;
7543 Py_ssize_t i;
7544 if (!PyList_Check(tmp)) {
7545 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7546 goto failed;
7547 }
7548 len = PyList_GET_SIZE(tmp);
7549 names = _Py_asdl_alias_seq_new(len, arena);
7550 if (names == NULL) goto failed;
7551 for (i = 0; i < len; i++) {
7552 alias_ty val;
7553 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7554 Py_INCREF(tmp2);
7555 if (Py_EnterRecursiveCall(" while traversing 'Import' node")) {
7556 goto failed;
7557 }
7558 res = obj2ast_alias(state, tmp2, &val, arena);
7559 Py_LeaveRecursiveCall();
7560 Py_DECREF(tmp2);
7561 if (res != 0) goto failed;
7562 if (len != PyList_GET_SIZE(tmp)) {
7563 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7564 goto failed;
7565 }
7566 asdl_seq_SET(names, i, val);
7567 }
7568 Py_CLEAR(tmp);
7569 }
7570 *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
7571 end_col_offset, arena);
7572 if (*out == NULL) goto failed;
7573 return 0;
7574 }
7575 tp = state->ImportFrom_type;
7576 isinstance = PyObject_IsInstance(obj, tp);
7577 if (isinstance == -1) {
7578 return 1;
7579 }
7580 if (isinstance) {
7581 identifier module;
7582 asdl_alias_seq* names;
7583 int level;
7584
7585 if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
7586 return 1;
7587 }
7588 if (tmp == NULL || tmp == Py_None) {
7589 Py_CLEAR(tmp);
7590 module = NULL;
7591 }
7592 else {
7593 int res;
7594 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7595 goto failed;
7596 }
7597 res = obj2ast_identifier(state, tmp, &module, arena);
7598 Py_LeaveRecursiveCall();
7599 if (res != 0) goto failed;
7600 Py_CLEAR(tmp);
7601 }
7602 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7603 return 1;
7604 }
7605 if (tmp == NULL) {
7606 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7607 return 1;
7608 }
7609 else {
7610 int res;
7611 Py_ssize_t len;
7612 Py_ssize_t i;
7613 if (!PyList_Check(tmp)) {
7614 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7615 goto failed;
7616 }
7617 len = PyList_GET_SIZE(tmp);
7618 names = _Py_asdl_alias_seq_new(len, arena);
7619 if (names == NULL) goto failed;
7620 for (i = 0; i < len; i++) {
7621 alias_ty val;
7622 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7623 Py_INCREF(tmp2);
7624 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7625 goto failed;
7626 }
7627 res = obj2ast_alias(state, tmp2, &val, arena);
7628 Py_LeaveRecursiveCall();
7629 Py_DECREF(tmp2);
7630 if (res != 0) goto failed;
7631 if (len != PyList_GET_SIZE(tmp)) {
7632 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7633 goto failed;
7634 }
7635 asdl_seq_SET(names, i, val);
7636 }
7637 Py_CLEAR(tmp);
7638 }
7639 if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
7640 return 1;
7641 }
7642 if (tmp == NULL || tmp == Py_None) {
7643 Py_CLEAR(tmp);
7644 level = 0;
7645 }
7646 else {
7647 int res;
7648 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7649 goto failed;
7650 }
7651 res = obj2ast_int(state, tmp, &level, arena);
7652 Py_LeaveRecursiveCall();
7653 if (res != 0) goto failed;
7654 Py_CLEAR(tmp);
7655 }
7656 *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
7657 end_lineno, end_col_offset, arena);
7658 if (*out == NULL) goto failed;
7659 return 0;
7660 }
7661 tp = state->Global_type;
7662 isinstance = PyObject_IsInstance(obj, tp);
7663 if (isinstance == -1) {
7664 return 1;
7665 }
7666 if (isinstance) {
7667 asdl_identifier_seq* names;
7668
7669 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7670 return 1;
7671 }
7672 if (tmp == NULL) {
7673 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7674 return 1;
7675 }
7676 else {
7677 int res;
7678 Py_ssize_t len;
7679 Py_ssize_t i;
7680 if (!PyList_Check(tmp)) {
7681 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7682 goto failed;
7683 }
7684 len = PyList_GET_SIZE(tmp);
7685 names = _Py_asdl_identifier_seq_new(len, arena);
7686 if (names == NULL) goto failed;
7687 for (i = 0; i < len; i++) {
7688 identifier val;
7689 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7690 Py_INCREF(tmp2);
7691 if (Py_EnterRecursiveCall(" while traversing 'Global' node")) {
7692 goto failed;
7693 }
7694 res = obj2ast_identifier(state, tmp2, &val, arena);
7695 Py_LeaveRecursiveCall();
7696 Py_DECREF(tmp2);
7697 if (res != 0) goto failed;
7698 if (len != PyList_GET_SIZE(tmp)) {
7699 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7700 goto failed;
7701 }
7702 asdl_seq_SET(names, i, val);
7703 }
7704 Py_CLEAR(tmp);
7705 }
7706 *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
7707 end_col_offset, arena);
7708 if (*out == NULL) goto failed;
7709 return 0;
7710 }
7711 tp = state->Nonlocal_type;
7712 isinstance = PyObject_IsInstance(obj, tp);
7713 if (isinstance == -1) {
7714 return 1;
7715 }
7716 if (isinstance) {
7717 asdl_identifier_seq* names;
7718
7719 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
7720 return 1;
7721 }
7722 if (tmp == NULL) {
7723 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7724 return 1;
7725 }
7726 else {
7727 int res;
7728 Py_ssize_t len;
7729 Py_ssize_t i;
7730 if (!PyList_Check(tmp)) {
7731 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7732 goto failed;
7733 }
7734 len = PyList_GET_SIZE(tmp);
7735 names = _Py_asdl_identifier_seq_new(len, arena);
7736 if (names == NULL) goto failed;
7737 for (i = 0; i < len; i++) {
7738 identifier val;
7739 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7740 Py_INCREF(tmp2);
7741 if (Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
7742 goto failed;
7743 }
7744 res = obj2ast_identifier(state, tmp2, &val, arena);
7745 Py_LeaveRecursiveCall();
7746 Py_DECREF(tmp2);
7747 if (res != 0) goto failed;
7748 if (len != PyList_GET_SIZE(tmp)) {
7749 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7750 goto failed;
7751 }
7752 asdl_seq_SET(names, i, val);
7753 }
7754 Py_CLEAR(tmp);
7755 }
7756 *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
7757 end_col_offset, arena);
7758 if (*out == NULL) goto failed;
7759 return 0;
7760 }
7761 tp = state->Expr_type;
7762 isinstance = PyObject_IsInstance(obj, tp);
7763 if (isinstance == -1) {
7764 return 1;
7765 }
7766 if (isinstance) {
7767 expr_ty value;
7768
7769 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
7770 return 1;
7771 }
7772 if (tmp == NULL) {
7773 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7774 return 1;
7775 }
7776 else {
7777 int res;
7778 if (Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
7779 goto failed;
7780 }
7781 res = obj2ast_expr(state, tmp, &value, arena);
7782 Py_LeaveRecursiveCall();
7783 if (res != 0) goto failed;
7784 Py_CLEAR(tmp);
7785 }
7786 *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
7787 end_col_offset, arena);
7788 if (*out == NULL) goto failed;
7789 return 0;
7790 }
7791 tp = state->Pass_type;
7792 isinstance = PyObject_IsInstance(obj, tp);
7793 if (isinstance == -1) {
7794 return 1;
7795 }
7796 if (isinstance) {
7797
7798 *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
7799 arena);
7800 if (*out == NULL) goto failed;
7801 return 0;
7802 }
7803 tp = state->Break_type;
7804 isinstance = PyObject_IsInstance(obj, tp);
7805 if (isinstance == -1) {
7806 return 1;
7807 }
7808 if (isinstance) {
7809
7810 *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
7811 arena);
7812 if (*out == NULL) goto failed;
7813 return 0;
7814 }
7815 tp = state->Continue_type;
7816 isinstance = PyObject_IsInstance(obj, tp);
7817 if (isinstance == -1) {
7818 return 1;
7819 }
7820 if (isinstance) {
7821
7822 *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
7823 arena);
7824 if (*out == NULL) goto failed;
7825 return 0;
7826 }
7827
7828 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7829 failed:
7830 Py_XDECREF(tmp);
7831 return 1;
7832 }
7833
7834 int
obj2ast_expr(struct ast_state * state,PyObject * obj,expr_ty * out,PyArena * arena)7835 obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
7836 arena)
7837 {
7838 int isinstance;
7839
7840 PyObject *tmp = NULL;
7841 PyObject *tp;
7842 int lineno;
7843 int col_offset;
7844 int end_lineno;
7845 int end_col_offset;
7846
7847 if (obj == Py_None) {
7848 *out = NULL;
7849 return 0;
7850 }
7851 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
7852 return 1;
7853 }
7854 if (tmp == NULL) {
7855 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7856 return 1;
7857 }
7858 else {
7859 int res;
7860 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7861 goto failed;
7862 }
7863 res = obj2ast_int(state, tmp, &lineno, arena);
7864 Py_LeaveRecursiveCall();
7865 if (res != 0) goto failed;
7866 Py_CLEAR(tmp);
7867 }
7868 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
7869 return 1;
7870 }
7871 if (tmp == NULL) {
7872 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7873 return 1;
7874 }
7875 else {
7876 int res;
7877 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7878 goto failed;
7879 }
7880 res = obj2ast_int(state, tmp, &col_offset, arena);
7881 Py_LeaveRecursiveCall();
7882 if (res != 0) goto failed;
7883 Py_CLEAR(tmp);
7884 }
7885 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
7886 return 1;
7887 }
7888 if (tmp == NULL || tmp == Py_None) {
7889 Py_CLEAR(tmp);
7890 end_lineno = 0;
7891 }
7892 else {
7893 int res;
7894 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7895 goto failed;
7896 }
7897 res = obj2ast_int(state, tmp, &end_lineno, arena);
7898 Py_LeaveRecursiveCall();
7899 if (res != 0) goto failed;
7900 Py_CLEAR(tmp);
7901 }
7902 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
7903 return 1;
7904 }
7905 if (tmp == NULL || tmp == Py_None) {
7906 Py_CLEAR(tmp);
7907 end_col_offset = 0;
7908 }
7909 else {
7910 int res;
7911 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7912 goto failed;
7913 }
7914 res = obj2ast_int(state, tmp, &end_col_offset, arena);
7915 Py_LeaveRecursiveCall();
7916 if (res != 0) goto failed;
7917 Py_CLEAR(tmp);
7918 }
7919 tp = state->BoolOp_type;
7920 isinstance = PyObject_IsInstance(obj, tp);
7921 if (isinstance == -1) {
7922 return 1;
7923 }
7924 if (isinstance) {
7925 boolop_ty op;
7926 asdl_expr_seq* values;
7927
7928 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
7929 return 1;
7930 }
7931 if (tmp == NULL) {
7932 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7933 return 1;
7934 }
7935 else {
7936 int res;
7937 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7938 goto failed;
7939 }
7940 res = obj2ast_boolop(state, tmp, &op, arena);
7941 Py_LeaveRecursiveCall();
7942 if (res != 0) goto failed;
7943 Py_CLEAR(tmp);
7944 }
7945 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
7946 return 1;
7947 }
7948 if (tmp == NULL) {
7949 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7950 return 1;
7951 }
7952 else {
7953 int res;
7954 Py_ssize_t len;
7955 Py_ssize_t i;
7956 if (!PyList_Check(tmp)) {
7957 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7958 goto failed;
7959 }
7960 len = PyList_GET_SIZE(tmp);
7961 values = _Py_asdl_expr_seq_new(len, arena);
7962 if (values == NULL) goto failed;
7963 for (i = 0; i < len; i++) {
7964 expr_ty val;
7965 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7966 Py_INCREF(tmp2);
7967 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7968 goto failed;
7969 }
7970 res = obj2ast_expr(state, tmp2, &val, arena);
7971 Py_LeaveRecursiveCall();
7972 Py_DECREF(tmp2);
7973 if (res != 0) goto failed;
7974 if (len != PyList_GET_SIZE(tmp)) {
7975 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7976 goto failed;
7977 }
7978 asdl_seq_SET(values, i, val);
7979 }
7980 Py_CLEAR(tmp);
7981 }
7982 *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
7983 end_col_offset, arena);
7984 if (*out == NULL) goto failed;
7985 return 0;
7986 }
7987 tp = state->NamedExpr_type;
7988 isinstance = PyObject_IsInstance(obj, tp);
7989 if (isinstance == -1) {
7990 return 1;
7991 }
7992 if (isinstance) {
7993 expr_ty target;
7994 expr_ty value;
7995
7996 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
7997 return 1;
7998 }
7999 if (tmp == NULL) {
8000 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
8001 return 1;
8002 }
8003 else {
8004 int res;
8005 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8006 goto failed;
8007 }
8008 res = obj2ast_expr(state, tmp, &target, arena);
8009 Py_LeaveRecursiveCall();
8010 if (res != 0) goto failed;
8011 Py_CLEAR(tmp);
8012 }
8013 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8014 return 1;
8015 }
8016 if (tmp == NULL) {
8017 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
8018 return 1;
8019 }
8020 else {
8021 int res;
8022 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8023 goto failed;
8024 }
8025 res = obj2ast_expr(state, tmp, &value, arena);
8026 Py_LeaveRecursiveCall();
8027 if (res != 0) goto failed;
8028 Py_CLEAR(tmp);
8029 }
8030 *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
8031 end_col_offset, arena);
8032 if (*out == NULL) goto failed;
8033 return 0;
8034 }
8035 tp = state->BinOp_type;
8036 isinstance = PyObject_IsInstance(obj, tp);
8037 if (isinstance == -1) {
8038 return 1;
8039 }
8040 if (isinstance) {
8041 expr_ty left;
8042 operator_ty op;
8043 expr_ty right;
8044
8045 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
8046 return 1;
8047 }
8048 if (tmp == NULL) {
8049 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
8050 return 1;
8051 }
8052 else {
8053 int res;
8054 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8055 goto failed;
8056 }
8057 res = obj2ast_expr(state, tmp, &left, arena);
8058 Py_LeaveRecursiveCall();
8059 if (res != 0) goto failed;
8060 Py_CLEAR(tmp);
8061 }
8062 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8063 return 1;
8064 }
8065 if (tmp == NULL) {
8066 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
8067 return 1;
8068 }
8069 else {
8070 int res;
8071 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8072 goto failed;
8073 }
8074 res = obj2ast_operator(state, tmp, &op, arena);
8075 Py_LeaveRecursiveCall();
8076 if (res != 0) goto failed;
8077 Py_CLEAR(tmp);
8078 }
8079 if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
8080 return 1;
8081 }
8082 if (tmp == NULL) {
8083 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
8084 return 1;
8085 }
8086 else {
8087 int res;
8088 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8089 goto failed;
8090 }
8091 res = obj2ast_expr(state, tmp, &right, arena);
8092 Py_LeaveRecursiveCall();
8093 if (res != 0) goto failed;
8094 Py_CLEAR(tmp);
8095 }
8096 *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
8097 end_col_offset, arena);
8098 if (*out == NULL) goto failed;
8099 return 0;
8100 }
8101 tp = state->UnaryOp_type;
8102 isinstance = PyObject_IsInstance(obj, tp);
8103 if (isinstance == -1) {
8104 return 1;
8105 }
8106 if (isinstance) {
8107 unaryop_ty op;
8108 expr_ty operand;
8109
8110 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
8111 return 1;
8112 }
8113 if (tmp == NULL) {
8114 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
8115 return 1;
8116 }
8117 else {
8118 int res;
8119 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8120 goto failed;
8121 }
8122 res = obj2ast_unaryop(state, tmp, &op, arena);
8123 Py_LeaveRecursiveCall();
8124 if (res != 0) goto failed;
8125 Py_CLEAR(tmp);
8126 }
8127 if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
8128 return 1;
8129 }
8130 if (tmp == NULL) {
8131 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
8132 return 1;
8133 }
8134 else {
8135 int res;
8136 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8137 goto failed;
8138 }
8139 res = obj2ast_expr(state, tmp, &operand, arena);
8140 Py_LeaveRecursiveCall();
8141 if (res != 0) goto failed;
8142 Py_CLEAR(tmp);
8143 }
8144 *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
8145 end_col_offset, arena);
8146 if (*out == NULL) goto failed;
8147 return 0;
8148 }
8149 tp = state->Lambda_type;
8150 isinstance = PyObject_IsInstance(obj, tp);
8151 if (isinstance == -1) {
8152 return 1;
8153 }
8154 if (isinstance) {
8155 arguments_ty args;
8156 expr_ty body;
8157
8158 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
8159 return 1;
8160 }
8161 if (tmp == NULL) {
8162 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
8163 return 1;
8164 }
8165 else {
8166 int res;
8167 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8168 goto failed;
8169 }
8170 res = obj2ast_arguments(state, tmp, &args, arena);
8171 Py_LeaveRecursiveCall();
8172 if (res != 0) goto failed;
8173 Py_CLEAR(tmp);
8174 }
8175 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8176 return 1;
8177 }
8178 if (tmp == NULL) {
8179 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
8180 return 1;
8181 }
8182 else {
8183 int res;
8184 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8185 goto failed;
8186 }
8187 res = obj2ast_expr(state, tmp, &body, arena);
8188 Py_LeaveRecursiveCall();
8189 if (res != 0) goto failed;
8190 Py_CLEAR(tmp);
8191 }
8192 *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
8193 end_col_offset, arena);
8194 if (*out == NULL) goto failed;
8195 return 0;
8196 }
8197 tp = state->IfExp_type;
8198 isinstance = PyObject_IsInstance(obj, tp);
8199 if (isinstance == -1) {
8200 return 1;
8201 }
8202 if (isinstance) {
8203 expr_ty test;
8204 expr_ty body;
8205 expr_ty orelse;
8206
8207 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
8208 return 1;
8209 }
8210 if (tmp == NULL) {
8211 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
8212 return 1;
8213 }
8214 else {
8215 int res;
8216 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8217 goto failed;
8218 }
8219 res = obj2ast_expr(state, tmp, &test, arena);
8220 Py_LeaveRecursiveCall();
8221 if (res != 0) goto failed;
8222 Py_CLEAR(tmp);
8223 }
8224 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
8225 return 1;
8226 }
8227 if (tmp == NULL) {
8228 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
8229 return 1;
8230 }
8231 else {
8232 int res;
8233 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8234 goto failed;
8235 }
8236 res = obj2ast_expr(state, tmp, &body, arena);
8237 Py_LeaveRecursiveCall();
8238 if (res != 0) goto failed;
8239 Py_CLEAR(tmp);
8240 }
8241 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
8242 return 1;
8243 }
8244 if (tmp == NULL) {
8245 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
8246 return 1;
8247 }
8248 else {
8249 int res;
8250 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8251 goto failed;
8252 }
8253 res = obj2ast_expr(state, tmp, &orelse, arena);
8254 Py_LeaveRecursiveCall();
8255 if (res != 0) goto failed;
8256 Py_CLEAR(tmp);
8257 }
8258 *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
8259 end_col_offset, arena);
8260 if (*out == NULL) goto failed;
8261 return 0;
8262 }
8263 tp = state->Dict_type;
8264 isinstance = PyObject_IsInstance(obj, tp);
8265 if (isinstance == -1) {
8266 return 1;
8267 }
8268 if (isinstance) {
8269 asdl_expr_seq* keys;
8270 asdl_expr_seq* values;
8271
8272 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
8273 return 1;
8274 }
8275 if (tmp == NULL) {
8276 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
8277 return 1;
8278 }
8279 else {
8280 int res;
8281 Py_ssize_t len;
8282 Py_ssize_t i;
8283 if (!PyList_Check(tmp)) {
8284 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8285 goto failed;
8286 }
8287 len = PyList_GET_SIZE(tmp);
8288 keys = _Py_asdl_expr_seq_new(len, arena);
8289 if (keys == NULL) goto failed;
8290 for (i = 0; i < len; i++) {
8291 expr_ty val;
8292 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8293 Py_INCREF(tmp2);
8294 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8295 goto failed;
8296 }
8297 res = obj2ast_expr(state, tmp2, &val, arena);
8298 Py_LeaveRecursiveCall();
8299 Py_DECREF(tmp2);
8300 if (res != 0) goto failed;
8301 if (len != PyList_GET_SIZE(tmp)) {
8302 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
8303 goto failed;
8304 }
8305 asdl_seq_SET(keys, i, val);
8306 }
8307 Py_CLEAR(tmp);
8308 }
8309 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
8310 return 1;
8311 }
8312 if (tmp == NULL) {
8313 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
8314 return 1;
8315 }
8316 else {
8317 int res;
8318 Py_ssize_t len;
8319 Py_ssize_t i;
8320 if (!PyList_Check(tmp)) {
8321 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8322 goto failed;
8323 }
8324 len = PyList_GET_SIZE(tmp);
8325 values = _Py_asdl_expr_seq_new(len, arena);
8326 if (values == NULL) goto failed;
8327 for (i = 0; i < len; i++) {
8328 expr_ty val;
8329 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8330 Py_INCREF(tmp2);
8331 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8332 goto failed;
8333 }
8334 res = obj2ast_expr(state, tmp2, &val, arena);
8335 Py_LeaveRecursiveCall();
8336 Py_DECREF(tmp2);
8337 if (res != 0) goto failed;
8338 if (len != PyList_GET_SIZE(tmp)) {
8339 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
8340 goto failed;
8341 }
8342 asdl_seq_SET(values, i, val);
8343 }
8344 Py_CLEAR(tmp);
8345 }
8346 *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
8347 end_col_offset, arena);
8348 if (*out == NULL) goto failed;
8349 return 0;
8350 }
8351 tp = state->Set_type;
8352 isinstance = PyObject_IsInstance(obj, tp);
8353 if (isinstance == -1) {
8354 return 1;
8355 }
8356 if (isinstance) {
8357 asdl_expr_seq* elts;
8358
8359 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
8360 return 1;
8361 }
8362 if (tmp == NULL) {
8363 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
8364 return 1;
8365 }
8366 else {
8367 int res;
8368 Py_ssize_t len;
8369 Py_ssize_t i;
8370 if (!PyList_Check(tmp)) {
8371 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8372 goto failed;
8373 }
8374 len = PyList_GET_SIZE(tmp);
8375 elts = _Py_asdl_expr_seq_new(len, arena);
8376 if (elts == NULL) goto failed;
8377 for (i = 0; i < len; i++) {
8378 expr_ty val;
8379 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8380 Py_INCREF(tmp2);
8381 if (Py_EnterRecursiveCall(" while traversing 'Set' node")) {
8382 goto failed;
8383 }
8384 res = obj2ast_expr(state, tmp2, &val, arena);
8385 Py_LeaveRecursiveCall();
8386 Py_DECREF(tmp2);
8387 if (res != 0) goto failed;
8388 if (len != PyList_GET_SIZE(tmp)) {
8389 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
8390 goto failed;
8391 }
8392 asdl_seq_SET(elts, i, val);
8393 }
8394 Py_CLEAR(tmp);
8395 }
8396 *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
8397 arena);
8398 if (*out == NULL) goto failed;
8399 return 0;
8400 }
8401 tp = state->ListComp_type;
8402 isinstance = PyObject_IsInstance(obj, tp);
8403 if (isinstance == -1) {
8404 return 1;
8405 }
8406 if (isinstance) {
8407 expr_ty elt;
8408 asdl_comprehension_seq* generators;
8409
8410 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8411 return 1;
8412 }
8413 if (tmp == NULL) {
8414 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
8415 return 1;
8416 }
8417 else {
8418 int res;
8419 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8420 goto failed;
8421 }
8422 res = obj2ast_expr(state, tmp, &elt, arena);
8423 Py_LeaveRecursiveCall();
8424 if (res != 0) goto failed;
8425 Py_CLEAR(tmp);
8426 }
8427 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8428 return 1;
8429 }
8430 if (tmp == NULL) {
8431 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
8432 return 1;
8433 }
8434 else {
8435 int res;
8436 Py_ssize_t len;
8437 Py_ssize_t i;
8438 if (!PyList_Check(tmp)) {
8439 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8440 goto failed;
8441 }
8442 len = PyList_GET_SIZE(tmp);
8443 generators = _Py_asdl_comprehension_seq_new(len, arena);
8444 if (generators == NULL) goto failed;
8445 for (i = 0; i < len; i++) {
8446 comprehension_ty val;
8447 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8448 Py_INCREF(tmp2);
8449 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8450 goto failed;
8451 }
8452 res = obj2ast_comprehension(state, tmp2, &val, arena);
8453 Py_LeaveRecursiveCall();
8454 Py_DECREF(tmp2);
8455 if (res != 0) goto failed;
8456 if (len != PyList_GET_SIZE(tmp)) {
8457 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
8458 goto failed;
8459 }
8460 asdl_seq_SET(generators, i, val);
8461 }
8462 Py_CLEAR(tmp);
8463 }
8464 *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
8465 end_col_offset, arena);
8466 if (*out == NULL) goto failed;
8467 return 0;
8468 }
8469 tp = state->SetComp_type;
8470 isinstance = PyObject_IsInstance(obj, tp);
8471 if (isinstance == -1) {
8472 return 1;
8473 }
8474 if (isinstance) {
8475 expr_ty elt;
8476 asdl_comprehension_seq* generators;
8477
8478 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8479 return 1;
8480 }
8481 if (tmp == NULL) {
8482 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
8483 return 1;
8484 }
8485 else {
8486 int res;
8487 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8488 goto failed;
8489 }
8490 res = obj2ast_expr(state, tmp, &elt, arena);
8491 Py_LeaveRecursiveCall();
8492 if (res != 0) goto failed;
8493 Py_CLEAR(tmp);
8494 }
8495 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8496 return 1;
8497 }
8498 if (tmp == NULL) {
8499 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
8500 return 1;
8501 }
8502 else {
8503 int res;
8504 Py_ssize_t len;
8505 Py_ssize_t i;
8506 if (!PyList_Check(tmp)) {
8507 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8508 goto failed;
8509 }
8510 len = PyList_GET_SIZE(tmp);
8511 generators = _Py_asdl_comprehension_seq_new(len, arena);
8512 if (generators == NULL) goto failed;
8513 for (i = 0; i < len; i++) {
8514 comprehension_ty val;
8515 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8516 Py_INCREF(tmp2);
8517 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8518 goto failed;
8519 }
8520 res = obj2ast_comprehension(state, tmp2, &val, arena);
8521 Py_LeaveRecursiveCall();
8522 Py_DECREF(tmp2);
8523 if (res != 0) goto failed;
8524 if (len != PyList_GET_SIZE(tmp)) {
8525 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
8526 goto failed;
8527 }
8528 asdl_seq_SET(generators, i, val);
8529 }
8530 Py_CLEAR(tmp);
8531 }
8532 *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
8533 end_col_offset, arena);
8534 if (*out == NULL) goto failed;
8535 return 0;
8536 }
8537 tp = state->DictComp_type;
8538 isinstance = PyObject_IsInstance(obj, tp);
8539 if (isinstance == -1) {
8540 return 1;
8541 }
8542 if (isinstance) {
8543 expr_ty key;
8544 expr_ty value;
8545 asdl_comprehension_seq* generators;
8546
8547 if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
8548 return 1;
8549 }
8550 if (tmp == NULL) {
8551 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
8552 return 1;
8553 }
8554 else {
8555 int res;
8556 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8557 goto failed;
8558 }
8559 res = obj2ast_expr(state, tmp, &key, arena);
8560 Py_LeaveRecursiveCall();
8561 if (res != 0) goto failed;
8562 Py_CLEAR(tmp);
8563 }
8564 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8565 return 1;
8566 }
8567 if (tmp == NULL) {
8568 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
8569 return 1;
8570 }
8571 else {
8572 int res;
8573 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8574 goto failed;
8575 }
8576 res = obj2ast_expr(state, tmp, &value, arena);
8577 Py_LeaveRecursiveCall();
8578 if (res != 0) goto failed;
8579 Py_CLEAR(tmp);
8580 }
8581 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8582 return 1;
8583 }
8584 if (tmp == NULL) {
8585 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
8586 return 1;
8587 }
8588 else {
8589 int res;
8590 Py_ssize_t len;
8591 Py_ssize_t i;
8592 if (!PyList_Check(tmp)) {
8593 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8594 goto failed;
8595 }
8596 len = PyList_GET_SIZE(tmp);
8597 generators = _Py_asdl_comprehension_seq_new(len, arena);
8598 if (generators == NULL) goto failed;
8599 for (i = 0; i < len; i++) {
8600 comprehension_ty val;
8601 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8602 Py_INCREF(tmp2);
8603 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8604 goto failed;
8605 }
8606 res = obj2ast_comprehension(state, tmp2, &val, arena);
8607 Py_LeaveRecursiveCall();
8608 Py_DECREF(tmp2);
8609 if (res != 0) goto failed;
8610 if (len != PyList_GET_SIZE(tmp)) {
8611 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
8612 goto failed;
8613 }
8614 asdl_seq_SET(generators, i, val);
8615 }
8616 Py_CLEAR(tmp);
8617 }
8618 *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
8619 end_lineno, end_col_offset, arena);
8620 if (*out == NULL) goto failed;
8621 return 0;
8622 }
8623 tp = state->GeneratorExp_type;
8624 isinstance = PyObject_IsInstance(obj, tp);
8625 if (isinstance == -1) {
8626 return 1;
8627 }
8628 if (isinstance) {
8629 expr_ty elt;
8630 asdl_comprehension_seq* generators;
8631
8632 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
8633 return 1;
8634 }
8635 if (tmp == NULL) {
8636 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
8637 return 1;
8638 }
8639 else {
8640 int res;
8641 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8642 goto failed;
8643 }
8644 res = obj2ast_expr(state, tmp, &elt, arena);
8645 Py_LeaveRecursiveCall();
8646 if (res != 0) goto failed;
8647 Py_CLEAR(tmp);
8648 }
8649 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
8650 return 1;
8651 }
8652 if (tmp == NULL) {
8653 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
8654 return 1;
8655 }
8656 else {
8657 int res;
8658 Py_ssize_t len;
8659 Py_ssize_t i;
8660 if (!PyList_Check(tmp)) {
8661 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8662 goto failed;
8663 }
8664 len = PyList_GET_SIZE(tmp);
8665 generators = _Py_asdl_comprehension_seq_new(len, arena);
8666 if (generators == NULL) goto failed;
8667 for (i = 0; i < len; i++) {
8668 comprehension_ty val;
8669 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8670 Py_INCREF(tmp2);
8671 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8672 goto failed;
8673 }
8674 res = obj2ast_comprehension(state, tmp2, &val, arena);
8675 Py_LeaveRecursiveCall();
8676 Py_DECREF(tmp2);
8677 if (res != 0) goto failed;
8678 if (len != PyList_GET_SIZE(tmp)) {
8679 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
8680 goto failed;
8681 }
8682 asdl_seq_SET(generators, i, val);
8683 }
8684 Py_CLEAR(tmp);
8685 }
8686 *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
8687 end_lineno, end_col_offset, arena);
8688 if (*out == NULL) goto failed;
8689 return 0;
8690 }
8691 tp = state->Await_type;
8692 isinstance = PyObject_IsInstance(obj, tp);
8693 if (isinstance == -1) {
8694 return 1;
8695 }
8696 if (isinstance) {
8697 expr_ty value;
8698
8699 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8700 return 1;
8701 }
8702 if (tmp == NULL) {
8703 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8704 return 1;
8705 }
8706 else {
8707 int res;
8708 if (Py_EnterRecursiveCall(" while traversing 'Await' node")) {
8709 goto failed;
8710 }
8711 res = obj2ast_expr(state, tmp, &value, arena);
8712 Py_LeaveRecursiveCall();
8713 if (res != 0) goto failed;
8714 Py_CLEAR(tmp);
8715 }
8716 *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
8717 end_col_offset, arena);
8718 if (*out == NULL) goto failed;
8719 return 0;
8720 }
8721 tp = state->Yield_type;
8722 isinstance = PyObject_IsInstance(obj, tp);
8723 if (isinstance == -1) {
8724 return 1;
8725 }
8726 if (isinstance) {
8727 expr_ty value;
8728
8729 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8730 return 1;
8731 }
8732 if (tmp == NULL || tmp == Py_None) {
8733 Py_CLEAR(tmp);
8734 value = NULL;
8735 }
8736 else {
8737 int res;
8738 if (Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
8739 goto failed;
8740 }
8741 res = obj2ast_expr(state, tmp, &value, arena);
8742 Py_LeaveRecursiveCall();
8743 if (res != 0) goto failed;
8744 Py_CLEAR(tmp);
8745 }
8746 *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
8747 end_col_offset, arena);
8748 if (*out == NULL) goto failed;
8749 return 0;
8750 }
8751 tp = state->YieldFrom_type;
8752 isinstance = PyObject_IsInstance(obj, tp);
8753 if (isinstance == -1) {
8754 return 1;
8755 }
8756 if (isinstance) {
8757 expr_ty value;
8758
8759 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
8760 return 1;
8761 }
8762 if (tmp == NULL) {
8763 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8764 return 1;
8765 }
8766 else {
8767 int res;
8768 if (Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
8769 goto failed;
8770 }
8771 res = obj2ast_expr(state, tmp, &value, arena);
8772 Py_LeaveRecursiveCall();
8773 if (res != 0) goto failed;
8774 Py_CLEAR(tmp);
8775 }
8776 *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
8777 end_col_offset, arena);
8778 if (*out == NULL) goto failed;
8779 return 0;
8780 }
8781 tp = state->Compare_type;
8782 isinstance = PyObject_IsInstance(obj, tp);
8783 if (isinstance == -1) {
8784 return 1;
8785 }
8786 if (isinstance) {
8787 expr_ty left;
8788 asdl_int_seq* ops;
8789 asdl_expr_seq* comparators;
8790
8791 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
8792 return 1;
8793 }
8794 if (tmp == NULL) {
8795 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8796 return 1;
8797 }
8798 else {
8799 int res;
8800 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8801 goto failed;
8802 }
8803 res = obj2ast_expr(state, tmp, &left, arena);
8804 Py_LeaveRecursiveCall();
8805 if (res != 0) goto failed;
8806 Py_CLEAR(tmp);
8807 }
8808 if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
8809 return 1;
8810 }
8811 if (tmp == NULL) {
8812 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8813 return 1;
8814 }
8815 else {
8816 int res;
8817 Py_ssize_t len;
8818 Py_ssize_t i;
8819 if (!PyList_Check(tmp)) {
8820 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8821 goto failed;
8822 }
8823 len = PyList_GET_SIZE(tmp);
8824 ops = _Py_asdl_int_seq_new(len, arena);
8825 if (ops == NULL) goto failed;
8826 for (i = 0; i < len; i++) {
8827 cmpop_ty val;
8828 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8829 Py_INCREF(tmp2);
8830 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8831 goto failed;
8832 }
8833 res = obj2ast_cmpop(state, tmp2, &val, arena);
8834 Py_LeaveRecursiveCall();
8835 Py_DECREF(tmp2);
8836 if (res != 0) goto failed;
8837 if (len != PyList_GET_SIZE(tmp)) {
8838 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8839 goto failed;
8840 }
8841 asdl_seq_SET(ops, i, val);
8842 }
8843 Py_CLEAR(tmp);
8844 }
8845 if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
8846 return 1;
8847 }
8848 if (tmp == NULL) {
8849 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8850 return 1;
8851 }
8852 else {
8853 int res;
8854 Py_ssize_t len;
8855 Py_ssize_t i;
8856 if (!PyList_Check(tmp)) {
8857 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8858 goto failed;
8859 }
8860 len = PyList_GET_SIZE(tmp);
8861 comparators = _Py_asdl_expr_seq_new(len, arena);
8862 if (comparators == NULL) goto failed;
8863 for (i = 0; i < len; i++) {
8864 expr_ty val;
8865 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8866 Py_INCREF(tmp2);
8867 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8868 goto failed;
8869 }
8870 res = obj2ast_expr(state, tmp2, &val, arena);
8871 Py_LeaveRecursiveCall();
8872 Py_DECREF(tmp2);
8873 if (res != 0) goto failed;
8874 if (len != PyList_GET_SIZE(tmp)) {
8875 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8876 goto failed;
8877 }
8878 asdl_seq_SET(comparators, i, val);
8879 }
8880 Py_CLEAR(tmp);
8881 }
8882 *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
8883 end_lineno, end_col_offset, arena);
8884 if (*out == NULL) goto failed;
8885 return 0;
8886 }
8887 tp = state->Call_type;
8888 isinstance = PyObject_IsInstance(obj, tp);
8889 if (isinstance == -1) {
8890 return 1;
8891 }
8892 if (isinstance) {
8893 expr_ty func;
8894 asdl_expr_seq* args;
8895 asdl_keyword_seq* keywords;
8896
8897 if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
8898 return 1;
8899 }
8900 if (tmp == NULL) {
8901 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8902 return 1;
8903 }
8904 else {
8905 int res;
8906 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8907 goto failed;
8908 }
8909 res = obj2ast_expr(state, tmp, &func, arena);
8910 Py_LeaveRecursiveCall();
8911 if (res != 0) goto failed;
8912 Py_CLEAR(tmp);
8913 }
8914 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
8915 return 1;
8916 }
8917 if (tmp == NULL) {
8918 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8919 return 1;
8920 }
8921 else {
8922 int res;
8923 Py_ssize_t len;
8924 Py_ssize_t i;
8925 if (!PyList_Check(tmp)) {
8926 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8927 goto failed;
8928 }
8929 len = PyList_GET_SIZE(tmp);
8930 args = _Py_asdl_expr_seq_new(len, arena);
8931 if (args == NULL) goto failed;
8932 for (i = 0; i < len; i++) {
8933 expr_ty val;
8934 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8935 Py_INCREF(tmp2);
8936 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8937 goto failed;
8938 }
8939 res = obj2ast_expr(state, tmp2, &val, arena);
8940 Py_LeaveRecursiveCall();
8941 Py_DECREF(tmp2);
8942 if (res != 0) goto failed;
8943 if (len != PyList_GET_SIZE(tmp)) {
8944 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8945 goto failed;
8946 }
8947 asdl_seq_SET(args, i, val);
8948 }
8949 Py_CLEAR(tmp);
8950 }
8951 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
8952 return 1;
8953 }
8954 if (tmp == NULL) {
8955 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8956 return 1;
8957 }
8958 else {
8959 int res;
8960 Py_ssize_t len;
8961 Py_ssize_t i;
8962 if (!PyList_Check(tmp)) {
8963 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
8964 goto failed;
8965 }
8966 len = PyList_GET_SIZE(tmp);
8967 keywords = _Py_asdl_keyword_seq_new(len, arena);
8968 if (keywords == NULL) goto failed;
8969 for (i = 0; i < len; i++) {
8970 keyword_ty val;
8971 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8972 Py_INCREF(tmp2);
8973 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8974 goto failed;
8975 }
8976 res = obj2ast_keyword(state, tmp2, &val, arena);
8977 Py_LeaveRecursiveCall();
8978 Py_DECREF(tmp2);
8979 if (res != 0) goto failed;
8980 if (len != PyList_GET_SIZE(tmp)) {
8981 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8982 goto failed;
8983 }
8984 asdl_seq_SET(keywords, i, val);
8985 }
8986 Py_CLEAR(tmp);
8987 }
8988 *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
8989 end_lineno, end_col_offset, arena);
8990 if (*out == NULL) goto failed;
8991 return 0;
8992 }
8993 tp = state->FormattedValue_type;
8994 isinstance = PyObject_IsInstance(obj, tp);
8995 if (isinstance == -1) {
8996 return 1;
8997 }
8998 if (isinstance) {
8999 expr_ty value;
9000 int conversion;
9001 expr_ty format_spec;
9002
9003 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9004 return 1;
9005 }
9006 if (tmp == NULL) {
9007 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
9008 return 1;
9009 }
9010 else {
9011 int res;
9012 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9013 goto failed;
9014 }
9015 res = obj2ast_expr(state, tmp, &value, arena);
9016 Py_LeaveRecursiveCall();
9017 if (res != 0) goto failed;
9018 Py_CLEAR(tmp);
9019 }
9020 if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
9021 return 1;
9022 }
9023 if (tmp == NULL) {
9024 PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
9025 return 1;
9026 }
9027 else {
9028 int res;
9029 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9030 goto failed;
9031 }
9032 res = obj2ast_int(state, tmp, &conversion, arena);
9033 Py_LeaveRecursiveCall();
9034 if (res != 0) goto failed;
9035 Py_CLEAR(tmp);
9036 }
9037 if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
9038 return 1;
9039 }
9040 if (tmp == NULL || tmp == Py_None) {
9041 Py_CLEAR(tmp);
9042 format_spec = NULL;
9043 }
9044 else {
9045 int res;
9046 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9047 goto failed;
9048 }
9049 res = obj2ast_expr(state, tmp, &format_spec, arena);
9050 Py_LeaveRecursiveCall();
9051 if (res != 0) goto failed;
9052 Py_CLEAR(tmp);
9053 }
9054 *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
9055 col_offset, end_lineno, end_col_offset,
9056 arena);
9057 if (*out == NULL) goto failed;
9058 return 0;
9059 }
9060 tp = state->JoinedStr_type;
9061 isinstance = PyObject_IsInstance(obj, tp);
9062 if (isinstance == -1) {
9063 return 1;
9064 }
9065 if (isinstance) {
9066 asdl_expr_seq* values;
9067
9068 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
9069 return 1;
9070 }
9071 if (tmp == NULL) {
9072 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
9073 return 1;
9074 }
9075 else {
9076 int res;
9077 Py_ssize_t len;
9078 Py_ssize_t i;
9079 if (!PyList_Check(tmp)) {
9080 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9081 goto failed;
9082 }
9083 len = PyList_GET_SIZE(tmp);
9084 values = _Py_asdl_expr_seq_new(len, arena);
9085 if (values == NULL) goto failed;
9086 for (i = 0; i < len; i++) {
9087 expr_ty val;
9088 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9089 Py_INCREF(tmp2);
9090 if (Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
9091 goto failed;
9092 }
9093 res = obj2ast_expr(state, tmp2, &val, arena);
9094 Py_LeaveRecursiveCall();
9095 Py_DECREF(tmp2);
9096 if (res != 0) goto failed;
9097 if (len != PyList_GET_SIZE(tmp)) {
9098 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
9099 goto failed;
9100 }
9101 asdl_seq_SET(values, i, val);
9102 }
9103 Py_CLEAR(tmp);
9104 }
9105 *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
9106 end_col_offset, arena);
9107 if (*out == NULL) goto failed;
9108 return 0;
9109 }
9110 tp = state->Constant_type;
9111 isinstance = PyObject_IsInstance(obj, tp);
9112 if (isinstance == -1) {
9113 return 1;
9114 }
9115 if (isinstance) {
9116 constant value;
9117 string kind;
9118
9119 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9120 return 1;
9121 }
9122 if (tmp == NULL) {
9123 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
9124 return 1;
9125 }
9126 else {
9127 int res;
9128 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9129 goto failed;
9130 }
9131 res = obj2ast_constant(state, tmp, &value, arena);
9132 Py_LeaveRecursiveCall();
9133 if (res != 0) goto failed;
9134 Py_CLEAR(tmp);
9135 }
9136 if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
9137 return 1;
9138 }
9139 if (tmp == NULL || tmp == Py_None) {
9140 Py_CLEAR(tmp);
9141 kind = NULL;
9142 }
9143 else {
9144 int res;
9145 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9146 goto failed;
9147 }
9148 res = obj2ast_string(state, tmp, &kind, arena);
9149 Py_LeaveRecursiveCall();
9150 if (res != 0) goto failed;
9151 Py_CLEAR(tmp);
9152 }
9153 *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
9154 end_col_offset, arena);
9155 if (*out == NULL) goto failed;
9156 return 0;
9157 }
9158 tp = state->Attribute_type;
9159 isinstance = PyObject_IsInstance(obj, tp);
9160 if (isinstance == -1) {
9161 return 1;
9162 }
9163 if (isinstance) {
9164 expr_ty value;
9165 identifier attr;
9166 expr_context_ty ctx;
9167
9168 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9169 return 1;
9170 }
9171 if (tmp == NULL) {
9172 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
9173 return 1;
9174 }
9175 else {
9176 int res;
9177 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9178 goto failed;
9179 }
9180 res = obj2ast_expr(state, tmp, &value, arena);
9181 Py_LeaveRecursiveCall();
9182 if (res != 0) goto failed;
9183 Py_CLEAR(tmp);
9184 }
9185 if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
9186 return 1;
9187 }
9188 if (tmp == NULL) {
9189 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
9190 return 1;
9191 }
9192 else {
9193 int res;
9194 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9195 goto failed;
9196 }
9197 res = obj2ast_identifier(state, tmp, &attr, arena);
9198 Py_LeaveRecursiveCall();
9199 if (res != 0) goto failed;
9200 Py_CLEAR(tmp);
9201 }
9202 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9203 return 1;
9204 }
9205 if (tmp == NULL) {
9206 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
9207 return 1;
9208 }
9209 else {
9210 int res;
9211 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9212 goto failed;
9213 }
9214 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9215 Py_LeaveRecursiveCall();
9216 if (res != 0) goto failed;
9217 Py_CLEAR(tmp);
9218 }
9219 *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
9220 end_lineno, end_col_offset, arena);
9221 if (*out == NULL) goto failed;
9222 return 0;
9223 }
9224 tp = state->Subscript_type;
9225 isinstance = PyObject_IsInstance(obj, tp);
9226 if (isinstance == -1) {
9227 return 1;
9228 }
9229 if (isinstance) {
9230 expr_ty value;
9231 expr_ty slice;
9232 expr_context_ty ctx;
9233
9234 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9235 return 1;
9236 }
9237 if (tmp == NULL) {
9238 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
9239 return 1;
9240 }
9241 else {
9242 int res;
9243 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9244 goto failed;
9245 }
9246 res = obj2ast_expr(state, tmp, &value, arena);
9247 Py_LeaveRecursiveCall();
9248 if (res != 0) goto failed;
9249 Py_CLEAR(tmp);
9250 }
9251 if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
9252 return 1;
9253 }
9254 if (tmp == NULL) {
9255 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
9256 return 1;
9257 }
9258 else {
9259 int res;
9260 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9261 goto failed;
9262 }
9263 res = obj2ast_expr(state, tmp, &slice, arena);
9264 Py_LeaveRecursiveCall();
9265 if (res != 0) goto failed;
9266 Py_CLEAR(tmp);
9267 }
9268 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9269 return 1;
9270 }
9271 if (tmp == NULL) {
9272 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
9273 return 1;
9274 }
9275 else {
9276 int res;
9277 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9278 goto failed;
9279 }
9280 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9281 Py_LeaveRecursiveCall();
9282 if (res != 0) goto failed;
9283 Py_CLEAR(tmp);
9284 }
9285 *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
9286 end_lineno, end_col_offset, arena);
9287 if (*out == NULL) goto failed;
9288 return 0;
9289 }
9290 tp = state->Starred_type;
9291 isinstance = PyObject_IsInstance(obj, tp);
9292 if (isinstance == -1) {
9293 return 1;
9294 }
9295 if (isinstance) {
9296 expr_ty value;
9297 expr_context_ty ctx;
9298
9299 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
9300 return 1;
9301 }
9302 if (tmp == NULL) {
9303 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
9304 return 1;
9305 }
9306 else {
9307 int res;
9308 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9309 goto failed;
9310 }
9311 res = obj2ast_expr(state, tmp, &value, arena);
9312 Py_LeaveRecursiveCall();
9313 if (res != 0) goto failed;
9314 Py_CLEAR(tmp);
9315 }
9316 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9317 return 1;
9318 }
9319 if (tmp == NULL) {
9320 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
9321 return 1;
9322 }
9323 else {
9324 int res;
9325 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9326 goto failed;
9327 }
9328 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9329 Py_LeaveRecursiveCall();
9330 if (res != 0) goto failed;
9331 Py_CLEAR(tmp);
9332 }
9333 *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
9334 end_col_offset, arena);
9335 if (*out == NULL) goto failed;
9336 return 0;
9337 }
9338 tp = state->Name_type;
9339 isinstance = PyObject_IsInstance(obj, tp);
9340 if (isinstance == -1) {
9341 return 1;
9342 }
9343 if (isinstance) {
9344 identifier id;
9345 expr_context_ty ctx;
9346
9347 if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
9348 return 1;
9349 }
9350 if (tmp == NULL) {
9351 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
9352 return 1;
9353 }
9354 else {
9355 int res;
9356 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9357 goto failed;
9358 }
9359 res = obj2ast_identifier(state, tmp, &id, arena);
9360 Py_LeaveRecursiveCall();
9361 if (res != 0) goto failed;
9362 Py_CLEAR(tmp);
9363 }
9364 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9365 return 1;
9366 }
9367 if (tmp == NULL) {
9368 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
9369 return 1;
9370 }
9371 else {
9372 int res;
9373 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9374 goto failed;
9375 }
9376 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9377 Py_LeaveRecursiveCall();
9378 if (res != 0) goto failed;
9379 Py_CLEAR(tmp);
9380 }
9381 *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
9382 end_col_offset, arena);
9383 if (*out == NULL) goto failed;
9384 return 0;
9385 }
9386 tp = state->List_type;
9387 isinstance = PyObject_IsInstance(obj, tp);
9388 if (isinstance == -1) {
9389 return 1;
9390 }
9391 if (isinstance) {
9392 asdl_expr_seq* elts;
9393 expr_context_ty ctx;
9394
9395 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
9396 return 1;
9397 }
9398 if (tmp == NULL) {
9399 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
9400 return 1;
9401 }
9402 else {
9403 int res;
9404 Py_ssize_t len;
9405 Py_ssize_t i;
9406 if (!PyList_Check(tmp)) {
9407 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9408 goto failed;
9409 }
9410 len = PyList_GET_SIZE(tmp);
9411 elts = _Py_asdl_expr_seq_new(len, arena);
9412 if (elts == NULL) goto failed;
9413 for (i = 0; i < len; i++) {
9414 expr_ty val;
9415 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9416 Py_INCREF(tmp2);
9417 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9418 goto failed;
9419 }
9420 res = obj2ast_expr(state, tmp2, &val, arena);
9421 Py_LeaveRecursiveCall();
9422 Py_DECREF(tmp2);
9423 if (res != 0) goto failed;
9424 if (len != PyList_GET_SIZE(tmp)) {
9425 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
9426 goto failed;
9427 }
9428 asdl_seq_SET(elts, i, val);
9429 }
9430 Py_CLEAR(tmp);
9431 }
9432 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9433 return 1;
9434 }
9435 if (tmp == NULL) {
9436 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
9437 return 1;
9438 }
9439 else {
9440 int res;
9441 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9442 goto failed;
9443 }
9444 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9445 Py_LeaveRecursiveCall();
9446 if (res != 0) goto failed;
9447 Py_CLEAR(tmp);
9448 }
9449 *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
9450 end_col_offset, arena);
9451 if (*out == NULL) goto failed;
9452 return 0;
9453 }
9454 tp = state->Tuple_type;
9455 isinstance = PyObject_IsInstance(obj, tp);
9456 if (isinstance == -1) {
9457 return 1;
9458 }
9459 if (isinstance) {
9460 asdl_expr_seq* elts;
9461 expr_context_ty ctx;
9462
9463 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
9464 return 1;
9465 }
9466 if (tmp == NULL) {
9467 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
9468 return 1;
9469 }
9470 else {
9471 int res;
9472 Py_ssize_t len;
9473 Py_ssize_t i;
9474 if (!PyList_Check(tmp)) {
9475 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9476 goto failed;
9477 }
9478 len = PyList_GET_SIZE(tmp);
9479 elts = _Py_asdl_expr_seq_new(len, arena);
9480 if (elts == NULL) goto failed;
9481 for (i = 0; i < len; i++) {
9482 expr_ty val;
9483 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9484 Py_INCREF(tmp2);
9485 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9486 goto failed;
9487 }
9488 res = obj2ast_expr(state, tmp2, &val, arena);
9489 Py_LeaveRecursiveCall();
9490 Py_DECREF(tmp2);
9491 if (res != 0) goto failed;
9492 if (len != PyList_GET_SIZE(tmp)) {
9493 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
9494 goto failed;
9495 }
9496 asdl_seq_SET(elts, i, val);
9497 }
9498 Py_CLEAR(tmp);
9499 }
9500 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
9501 return 1;
9502 }
9503 if (tmp == NULL) {
9504 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
9505 return 1;
9506 }
9507 else {
9508 int res;
9509 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9510 goto failed;
9511 }
9512 res = obj2ast_expr_context(state, tmp, &ctx, arena);
9513 Py_LeaveRecursiveCall();
9514 if (res != 0) goto failed;
9515 Py_CLEAR(tmp);
9516 }
9517 *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
9518 end_col_offset, arena);
9519 if (*out == NULL) goto failed;
9520 return 0;
9521 }
9522 tp = state->Slice_type;
9523 isinstance = PyObject_IsInstance(obj, tp);
9524 if (isinstance == -1) {
9525 return 1;
9526 }
9527 if (isinstance) {
9528 expr_ty lower;
9529 expr_ty upper;
9530 expr_ty step;
9531
9532 if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
9533 return 1;
9534 }
9535 if (tmp == NULL || tmp == Py_None) {
9536 Py_CLEAR(tmp);
9537 lower = NULL;
9538 }
9539 else {
9540 int res;
9541 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9542 goto failed;
9543 }
9544 res = obj2ast_expr(state, tmp, &lower, arena);
9545 Py_LeaveRecursiveCall();
9546 if (res != 0) goto failed;
9547 Py_CLEAR(tmp);
9548 }
9549 if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
9550 return 1;
9551 }
9552 if (tmp == NULL || tmp == Py_None) {
9553 Py_CLEAR(tmp);
9554 upper = NULL;
9555 }
9556 else {
9557 int res;
9558 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9559 goto failed;
9560 }
9561 res = obj2ast_expr(state, tmp, &upper, arena);
9562 Py_LeaveRecursiveCall();
9563 if (res != 0) goto failed;
9564 Py_CLEAR(tmp);
9565 }
9566 if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
9567 return 1;
9568 }
9569 if (tmp == NULL || tmp == Py_None) {
9570 Py_CLEAR(tmp);
9571 step = NULL;
9572 }
9573 else {
9574 int res;
9575 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9576 goto failed;
9577 }
9578 res = obj2ast_expr(state, tmp, &step, arena);
9579 Py_LeaveRecursiveCall();
9580 if (res != 0) goto failed;
9581 Py_CLEAR(tmp);
9582 }
9583 *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
9584 end_col_offset, arena);
9585 if (*out == NULL) goto failed;
9586 return 0;
9587 }
9588
9589 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
9590 failed:
9591 Py_XDECREF(tmp);
9592 return 1;
9593 }
9594
9595 int
obj2ast_expr_context(struct ast_state * state,PyObject * obj,expr_context_ty * out,PyArena * arena)9596 obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
9597 out, PyArena* arena)
9598 {
9599 int isinstance;
9600
9601 isinstance = PyObject_IsInstance(obj, state->Load_type);
9602 if (isinstance == -1) {
9603 return 1;
9604 }
9605 if (isinstance) {
9606 *out = Load;
9607 return 0;
9608 }
9609 isinstance = PyObject_IsInstance(obj, state->Store_type);
9610 if (isinstance == -1) {
9611 return 1;
9612 }
9613 if (isinstance) {
9614 *out = Store;
9615 return 0;
9616 }
9617 isinstance = PyObject_IsInstance(obj, state->Del_type);
9618 if (isinstance == -1) {
9619 return 1;
9620 }
9621 if (isinstance) {
9622 *out = Del;
9623 return 0;
9624 }
9625
9626 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
9627 return 1;
9628 }
9629
9630 int
obj2ast_boolop(struct ast_state * state,PyObject * obj,boolop_ty * out,PyArena * arena)9631 obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
9632 arena)
9633 {
9634 int isinstance;
9635
9636 isinstance = PyObject_IsInstance(obj, state->And_type);
9637 if (isinstance == -1) {
9638 return 1;
9639 }
9640 if (isinstance) {
9641 *out = And;
9642 return 0;
9643 }
9644 isinstance = PyObject_IsInstance(obj, state->Or_type);
9645 if (isinstance == -1) {
9646 return 1;
9647 }
9648 if (isinstance) {
9649 *out = Or;
9650 return 0;
9651 }
9652
9653 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
9654 return 1;
9655 }
9656
9657 int
obj2ast_operator(struct ast_state * state,PyObject * obj,operator_ty * out,PyArena * arena)9658 obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
9659 PyArena* arena)
9660 {
9661 int isinstance;
9662
9663 isinstance = PyObject_IsInstance(obj, state->Add_type);
9664 if (isinstance == -1) {
9665 return 1;
9666 }
9667 if (isinstance) {
9668 *out = Add;
9669 return 0;
9670 }
9671 isinstance = PyObject_IsInstance(obj, state->Sub_type);
9672 if (isinstance == -1) {
9673 return 1;
9674 }
9675 if (isinstance) {
9676 *out = Sub;
9677 return 0;
9678 }
9679 isinstance = PyObject_IsInstance(obj, state->Mult_type);
9680 if (isinstance == -1) {
9681 return 1;
9682 }
9683 if (isinstance) {
9684 *out = Mult;
9685 return 0;
9686 }
9687 isinstance = PyObject_IsInstance(obj, state->MatMult_type);
9688 if (isinstance == -1) {
9689 return 1;
9690 }
9691 if (isinstance) {
9692 *out = MatMult;
9693 return 0;
9694 }
9695 isinstance = PyObject_IsInstance(obj, state->Div_type);
9696 if (isinstance == -1) {
9697 return 1;
9698 }
9699 if (isinstance) {
9700 *out = Div;
9701 return 0;
9702 }
9703 isinstance = PyObject_IsInstance(obj, state->Mod_type);
9704 if (isinstance == -1) {
9705 return 1;
9706 }
9707 if (isinstance) {
9708 *out = Mod;
9709 return 0;
9710 }
9711 isinstance = PyObject_IsInstance(obj, state->Pow_type);
9712 if (isinstance == -1) {
9713 return 1;
9714 }
9715 if (isinstance) {
9716 *out = Pow;
9717 return 0;
9718 }
9719 isinstance = PyObject_IsInstance(obj, state->LShift_type);
9720 if (isinstance == -1) {
9721 return 1;
9722 }
9723 if (isinstance) {
9724 *out = LShift;
9725 return 0;
9726 }
9727 isinstance = PyObject_IsInstance(obj, state->RShift_type);
9728 if (isinstance == -1) {
9729 return 1;
9730 }
9731 if (isinstance) {
9732 *out = RShift;
9733 return 0;
9734 }
9735 isinstance = PyObject_IsInstance(obj, state->BitOr_type);
9736 if (isinstance == -1) {
9737 return 1;
9738 }
9739 if (isinstance) {
9740 *out = BitOr;
9741 return 0;
9742 }
9743 isinstance = PyObject_IsInstance(obj, state->BitXor_type);
9744 if (isinstance == -1) {
9745 return 1;
9746 }
9747 if (isinstance) {
9748 *out = BitXor;
9749 return 0;
9750 }
9751 isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
9752 if (isinstance == -1) {
9753 return 1;
9754 }
9755 if (isinstance) {
9756 *out = BitAnd;
9757 return 0;
9758 }
9759 isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
9760 if (isinstance == -1) {
9761 return 1;
9762 }
9763 if (isinstance) {
9764 *out = FloorDiv;
9765 return 0;
9766 }
9767
9768 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
9769 return 1;
9770 }
9771
9772 int
obj2ast_unaryop(struct ast_state * state,PyObject * obj,unaryop_ty * out,PyArena * arena)9773 obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
9774 PyArena* arena)
9775 {
9776 int isinstance;
9777
9778 isinstance = PyObject_IsInstance(obj, state->Invert_type);
9779 if (isinstance == -1) {
9780 return 1;
9781 }
9782 if (isinstance) {
9783 *out = Invert;
9784 return 0;
9785 }
9786 isinstance = PyObject_IsInstance(obj, state->Not_type);
9787 if (isinstance == -1) {
9788 return 1;
9789 }
9790 if (isinstance) {
9791 *out = Not;
9792 return 0;
9793 }
9794 isinstance = PyObject_IsInstance(obj, state->UAdd_type);
9795 if (isinstance == -1) {
9796 return 1;
9797 }
9798 if (isinstance) {
9799 *out = UAdd;
9800 return 0;
9801 }
9802 isinstance = PyObject_IsInstance(obj, state->USub_type);
9803 if (isinstance == -1) {
9804 return 1;
9805 }
9806 if (isinstance) {
9807 *out = USub;
9808 return 0;
9809 }
9810
9811 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9812 return 1;
9813 }
9814
9815 int
obj2ast_cmpop(struct ast_state * state,PyObject * obj,cmpop_ty * out,PyArena * arena)9816 obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
9817 arena)
9818 {
9819 int isinstance;
9820
9821 isinstance = PyObject_IsInstance(obj, state->Eq_type);
9822 if (isinstance == -1) {
9823 return 1;
9824 }
9825 if (isinstance) {
9826 *out = Eq;
9827 return 0;
9828 }
9829 isinstance = PyObject_IsInstance(obj, state->NotEq_type);
9830 if (isinstance == -1) {
9831 return 1;
9832 }
9833 if (isinstance) {
9834 *out = NotEq;
9835 return 0;
9836 }
9837 isinstance = PyObject_IsInstance(obj, state->Lt_type);
9838 if (isinstance == -1) {
9839 return 1;
9840 }
9841 if (isinstance) {
9842 *out = Lt;
9843 return 0;
9844 }
9845 isinstance = PyObject_IsInstance(obj, state->LtE_type);
9846 if (isinstance == -1) {
9847 return 1;
9848 }
9849 if (isinstance) {
9850 *out = LtE;
9851 return 0;
9852 }
9853 isinstance = PyObject_IsInstance(obj, state->Gt_type);
9854 if (isinstance == -1) {
9855 return 1;
9856 }
9857 if (isinstance) {
9858 *out = Gt;
9859 return 0;
9860 }
9861 isinstance = PyObject_IsInstance(obj, state->GtE_type);
9862 if (isinstance == -1) {
9863 return 1;
9864 }
9865 if (isinstance) {
9866 *out = GtE;
9867 return 0;
9868 }
9869 isinstance = PyObject_IsInstance(obj, state->Is_type);
9870 if (isinstance == -1) {
9871 return 1;
9872 }
9873 if (isinstance) {
9874 *out = Is;
9875 return 0;
9876 }
9877 isinstance = PyObject_IsInstance(obj, state->IsNot_type);
9878 if (isinstance == -1) {
9879 return 1;
9880 }
9881 if (isinstance) {
9882 *out = IsNot;
9883 return 0;
9884 }
9885 isinstance = PyObject_IsInstance(obj, state->In_type);
9886 if (isinstance == -1) {
9887 return 1;
9888 }
9889 if (isinstance) {
9890 *out = In;
9891 return 0;
9892 }
9893 isinstance = PyObject_IsInstance(obj, state->NotIn_type);
9894 if (isinstance == -1) {
9895 return 1;
9896 }
9897 if (isinstance) {
9898 *out = NotIn;
9899 return 0;
9900 }
9901
9902 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9903 return 1;
9904 }
9905
9906 int
obj2ast_comprehension(struct ast_state * state,PyObject * obj,comprehension_ty * out,PyArena * arena)9907 obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
9908 out, PyArena* arena)
9909 {
9910 PyObject* tmp = NULL;
9911 expr_ty target;
9912 expr_ty iter;
9913 asdl_expr_seq* ifs;
9914 int is_async;
9915
9916 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
9917 return 1;
9918 }
9919 if (tmp == NULL) {
9920 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9921 return 1;
9922 }
9923 else {
9924 int res;
9925 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9926 goto failed;
9927 }
9928 res = obj2ast_expr(state, tmp, &target, arena);
9929 Py_LeaveRecursiveCall();
9930 if (res != 0) goto failed;
9931 Py_CLEAR(tmp);
9932 }
9933 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
9934 return 1;
9935 }
9936 if (tmp == NULL) {
9937 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9938 return 1;
9939 }
9940 else {
9941 int res;
9942 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9943 goto failed;
9944 }
9945 res = obj2ast_expr(state, tmp, &iter, arena);
9946 Py_LeaveRecursiveCall();
9947 if (res != 0) goto failed;
9948 Py_CLEAR(tmp);
9949 }
9950 if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
9951 return 1;
9952 }
9953 if (tmp == NULL) {
9954 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9955 return 1;
9956 }
9957 else {
9958 int res;
9959 Py_ssize_t len;
9960 Py_ssize_t i;
9961 if (!PyList_Check(tmp)) {
9962 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
9963 goto failed;
9964 }
9965 len = PyList_GET_SIZE(tmp);
9966 ifs = _Py_asdl_expr_seq_new(len, arena);
9967 if (ifs == NULL) goto failed;
9968 for (i = 0; i < len; i++) {
9969 expr_ty val;
9970 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9971 Py_INCREF(tmp2);
9972 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9973 goto failed;
9974 }
9975 res = obj2ast_expr(state, tmp2, &val, arena);
9976 Py_LeaveRecursiveCall();
9977 Py_DECREF(tmp2);
9978 if (res != 0) goto failed;
9979 if (len != PyList_GET_SIZE(tmp)) {
9980 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9981 goto failed;
9982 }
9983 asdl_seq_SET(ifs, i, val);
9984 }
9985 Py_CLEAR(tmp);
9986 }
9987 if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
9988 return 1;
9989 }
9990 if (tmp == NULL) {
9991 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9992 return 1;
9993 }
9994 else {
9995 int res;
9996 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9997 goto failed;
9998 }
9999 res = obj2ast_int(state, tmp, &is_async, arena);
10000 Py_LeaveRecursiveCall();
10001 if (res != 0) goto failed;
10002 Py_CLEAR(tmp);
10003 }
10004 *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
10005 return 0;
10006 failed:
10007 Py_XDECREF(tmp);
10008 return 1;
10009 }
10010
10011 int
obj2ast_excepthandler(struct ast_state * state,PyObject * obj,excepthandler_ty * out,PyArena * arena)10012 obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
10013 out, PyArena* arena)
10014 {
10015 int isinstance;
10016
10017 PyObject *tmp = NULL;
10018 PyObject *tp;
10019 int lineno;
10020 int col_offset;
10021 int end_lineno;
10022 int end_col_offset;
10023
10024 if (obj == Py_None) {
10025 *out = NULL;
10026 return 0;
10027 }
10028 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10029 return 1;
10030 }
10031 if (tmp == NULL) {
10032 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
10033 return 1;
10034 }
10035 else {
10036 int res;
10037 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10038 goto failed;
10039 }
10040 res = obj2ast_int(state, tmp, &lineno, arena);
10041 Py_LeaveRecursiveCall();
10042 if (res != 0) goto failed;
10043 Py_CLEAR(tmp);
10044 }
10045 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10046 return 1;
10047 }
10048 if (tmp == NULL) {
10049 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
10050 return 1;
10051 }
10052 else {
10053 int res;
10054 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10055 goto failed;
10056 }
10057 res = obj2ast_int(state, tmp, &col_offset, arena);
10058 Py_LeaveRecursiveCall();
10059 if (res != 0) goto failed;
10060 Py_CLEAR(tmp);
10061 }
10062 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10063 return 1;
10064 }
10065 if (tmp == NULL || tmp == Py_None) {
10066 Py_CLEAR(tmp);
10067 end_lineno = 0;
10068 }
10069 else {
10070 int res;
10071 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10072 goto failed;
10073 }
10074 res = obj2ast_int(state, tmp, &end_lineno, arena);
10075 Py_LeaveRecursiveCall();
10076 if (res != 0) goto failed;
10077 Py_CLEAR(tmp);
10078 }
10079 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10080 return 1;
10081 }
10082 if (tmp == NULL || tmp == Py_None) {
10083 Py_CLEAR(tmp);
10084 end_col_offset = 0;
10085 }
10086 else {
10087 int res;
10088 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10089 goto failed;
10090 }
10091 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10092 Py_LeaveRecursiveCall();
10093 if (res != 0) goto failed;
10094 Py_CLEAR(tmp);
10095 }
10096 tp = state->ExceptHandler_type;
10097 isinstance = PyObject_IsInstance(obj, tp);
10098 if (isinstance == -1) {
10099 return 1;
10100 }
10101 if (isinstance) {
10102 expr_ty type;
10103 identifier name;
10104 asdl_stmt_seq* body;
10105
10106 if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
10107 return 1;
10108 }
10109 if (tmp == NULL || tmp == Py_None) {
10110 Py_CLEAR(tmp);
10111 type = NULL;
10112 }
10113 else {
10114 int res;
10115 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10116 goto failed;
10117 }
10118 res = obj2ast_expr(state, tmp, &type, arena);
10119 Py_LeaveRecursiveCall();
10120 if (res != 0) goto failed;
10121 Py_CLEAR(tmp);
10122 }
10123 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
10124 return 1;
10125 }
10126 if (tmp == NULL || tmp == Py_None) {
10127 Py_CLEAR(tmp);
10128 name = NULL;
10129 }
10130 else {
10131 int res;
10132 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10133 goto failed;
10134 }
10135 res = obj2ast_identifier(state, tmp, &name, arena);
10136 Py_LeaveRecursiveCall();
10137 if (res != 0) goto failed;
10138 Py_CLEAR(tmp);
10139 }
10140 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10141 return 1;
10142 }
10143 if (tmp == NULL) {
10144 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
10145 return 1;
10146 }
10147 else {
10148 int res;
10149 Py_ssize_t len;
10150 Py_ssize_t i;
10151 if (!PyList_Check(tmp)) {
10152 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10153 goto failed;
10154 }
10155 len = PyList_GET_SIZE(tmp);
10156 body = _Py_asdl_stmt_seq_new(len, arena);
10157 if (body == NULL) goto failed;
10158 for (i = 0; i < len; i++) {
10159 stmt_ty val;
10160 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10161 Py_INCREF(tmp2);
10162 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10163 goto failed;
10164 }
10165 res = obj2ast_stmt(state, tmp2, &val, arena);
10166 Py_LeaveRecursiveCall();
10167 Py_DECREF(tmp2);
10168 if (res != 0) goto failed;
10169 if (len != PyList_GET_SIZE(tmp)) {
10170 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
10171 goto failed;
10172 }
10173 asdl_seq_SET(body, i, val);
10174 }
10175 Py_CLEAR(tmp);
10176 }
10177 *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
10178 end_lineno, end_col_offset, arena);
10179 if (*out == NULL) goto failed;
10180 return 0;
10181 }
10182
10183 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
10184 failed:
10185 Py_XDECREF(tmp);
10186 return 1;
10187 }
10188
10189 int
obj2ast_arguments(struct ast_state * state,PyObject * obj,arguments_ty * out,PyArena * arena)10190 obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
10191 PyArena* arena)
10192 {
10193 PyObject* tmp = NULL;
10194 asdl_arg_seq* posonlyargs;
10195 asdl_arg_seq* args;
10196 arg_ty vararg;
10197 asdl_arg_seq* kwonlyargs;
10198 asdl_expr_seq* kw_defaults;
10199 arg_ty kwarg;
10200 asdl_expr_seq* defaults;
10201
10202 if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
10203 return 1;
10204 }
10205 if (tmp == NULL) {
10206 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
10207 return 1;
10208 }
10209 else {
10210 int res;
10211 Py_ssize_t len;
10212 Py_ssize_t i;
10213 if (!PyList_Check(tmp)) {
10214 PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10215 goto failed;
10216 }
10217 len = PyList_GET_SIZE(tmp);
10218 posonlyargs = _Py_asdl_arg_seq_new(len, arena);
10219 if (posonlyargs == NULL) goto failed;
10220 for (i = 0; i < len; i++) {
10221 arg_ty val;
10222 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10223 Py_INCREF(tmp2);
10224 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10225 goto failed;
10226 }
10227 res = obj2ast_arg(state, tmp2, &val, arena);
10228 Py_LeaveRecursiveCall();
10229 Py_DECREF(tmp2);
10230 if (res != 0) goto failed;
10231 if (len != PyList_GET_SIZE(tmp)) {
10232 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
10233 goto failed;
10234 }
10235 asdl_seq_SET(posonlyargs, i, val);
10236 }
10237 Py_CLEAR(tmp);
10238 }
10239 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
10240 return 1;
10241 }
10242 if (tmp == NULL) {
10243 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
10244 return 1;
10245 }
10246 else {
10247 int res;
10248 Py_ssize_t len;
10249 Py_ssize_t i;
10250 if (!PyList_Check(tmp)) {
10251 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10252 goto failed;
10253 }
10254 len = PyList_GET_SIZE(tmp);
10255 args = _Py_asdl_arg_seq_new(len, arena);
10256 if (args == NULL) goto failed;
10257 for (i = 0; i < len; i++) {
10258 arg_ty val;
10259 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10260 Py_INCREF(tmp2);
10261 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10262 goto failed;
10263 }
10264 res = obj2ast_arg(state, tmp2, &val, arena);
10265 Py_LeaveRecursiveCall();
10266 Py_DECREF(tmp2);
10267 if (res != 0) goto failed;
10268 if (len != PyList_GET_SIZE(tmp)) {
10269 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
10270 goto failed;
10271 }
10272 asdl_seq_SET(args, i, val);
10273 }
10274 Py_CLEAR(tmp);
10275 }
10276 if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
10277 return 1;
10278 }
10279 if (tmp == NULL || tmp == Py_None) {
10280 Py_CLEAR(tmp);
10281 vararg = NULL;
10282 }
10283 else {
10284 int res;
10285 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10286 goto failed;
10287 }
10288 res = obj2ast_arg(state, tmp, &vararg, arena);
10289 Py_LeaveRecursiveCall();
10290 if (res != 0) goto failed;
10291 Py_CLEAR(tmp);
10292 }
10293 if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
10294 return 1;
10295 }
10296 if (tmp == NULL) {
10297 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
10298 return 1;
10299 }
10300 else {
10301 int res;
10302 Py_ssize_t len;
10303 Py_ssize_t i;
10304 if (!PyList_Check(tmp)) {
10305 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10306 goto failed;
10307 }
10308 len = PyList_GET_SIZE(tmp);
10309 kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
10310 if (kwonlyargs == NULL) goto failed;
10311 for (i = 0; i < len; i++) {
10312 arg_ty val;
10313 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10314 Py_INCREF(tmp2);
10315 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10316 goto failed;
10317 }
10318 res = obj2ast_arg(state, tmp2, &val, arena);
10319 Py_LeaveRecursiveCall();
10320 Py_DECREF(tmp2);
10321 if (res != 0) goto failed;
10322 if (len != PyList_GET_SIZE(tmp)) {
10323 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
10324 goto failed;
10325 }
10326 asdl_seq_SET(kwonlyargs, i, val);
10327 }
10328 Py_CLEAR(tmp);
10329 }
10330 if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
10331 return 1;
10332 }
10333 if (tmp == NULL) {
10334 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
10335 return 1;
10336 }
10337 else {
10338 int res;
10339 Py_ssize_t len;
10340 Py_ssize_t i;
10341 if (!PyList_Check(tmp)) {
10342 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10343 goto failed;
10344 }
10345 len = PyList_GET_SIZE(tmp);
10346 kw_defaults = _Py_asdl_expr_seq_new(len, arena);
10347 if (kw_defaults == NULL) goto failed;
10348 for (i = 0; i < len; i++) {
10349 expr_ty val;
10350 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10351 Py_INCREF(tmp2);
10352 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10353 goto failed;
10354 }
10355 res = obj2ast_expr(state, tmp2, &val, arena);
10356 Py_LeaveRecursiveCall();
10357 Py_DECREF(tmp2);
10358 if (res != 0) goto failed;
10359 if (len != PyList_GET_SIZE(tmp)) {
10360 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
10361 goto failed;
10362 }
10363 asdl_seq_SET(kw_defaults, i, val);
10364 }
10365 Py_CLEAR(tmp);
10366 }
10367 if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
10368 return 1;
10369 }
10370 if (tmp == NULL || tmp == Py_None) {
10371 Py_CLEAR(tmp);
10372 kwarg = NULL;
10373 }
10374 else {
10375 int res;
10376 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10377 goto failed;
10378 }
10379 res = obj2ast_arg(state, tmp, &kwarg, arena);
10380 Py_LeaveRecursiveCall();
10381 if (res != 0) goto failed;
10382 Py_CLEAR(tmp);
10383 }
10384 if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
10385 return 1;
10386 }
10387 if (tmp == NULL) {
10388 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
10389 return 1;
10390 }
10391 else {
10392 int res;
10393 Py_ssize_t len;
10394 Py_ssize_t i;
10395 if (!PyList_Check(tmp)) {
10396 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10397 goto failed;
10398 }
10399 len = PyList_GET_SIZE(tmp);
10400 defaults = _Py_asdl_expr_seq_new(len, arena);
10401 if (defaults == NULL) goto failed;
10402 for (i = 0; i < len; i++) {
10403 expr_ty val;
10404 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10405 Py_INCREF(tmp2);
10406 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10407 goto failed;
10408 }
10409 res = obj2ast_expr(state, tmp2, &val, arena);
10410 Py_LeaveRecursiveCall();
10411 Py_DECREF(tmp2);
10412 if (res != 0) goto failed;
10413 if (len != PyList_GET_SIZE(tmp)) {
10414 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
10415 goto failed;
10416 }
10417 asdl_seq_SET(defaults, i, val);
10418 }
10419 Py_CLEAR(tmp);
10420 }
10421 *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
10422 kwarg, defaults, arena);
10423 return 0;
10424 failed:
10425 Py_XDECREF(tmp);
10426 return 1;
10427 }
10428
10429 int
obj2ast_arg(struct ast_state * state,PyObject * obj,arg_ty * out,PyArena * arena)10430 obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
10431 {
10432 PyObject* tmp = NULL;
10433 identifier arg;
10434 expr_ty annotation;
10435 string type_comment;
10436 int lineno;
10437 int col_offset;
10438 int end_lineno;
10439 int end_col_offset;
10440
10441 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
10442 return 1;
10443 }
10444 if (tmp == NULL) {
10445 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
10446 return 1;
10447 }
10448 else {
10449 int res;
10450 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10451 goto failed;
10452 }
10453 res = obj2ast_identifier(state, tmp, &arg, arena);
10454 Py_LeaveRecursiveCall();
10455 if (res != 0) goto failed;
10456 Py_CLEAR(tmp);
10457 }
10458 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
10459 return 1;
10460 }
10461 if (tmp == NULL || tmp == Py_None) {
10462 Py_CLEAR(tmp);
10463 annotation = NULL;
10464 }
10465 else {
10466 int res;
10467 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10468 goto failed;
10469 }
10470 res = obj2ast_expr(state, tmp, &annotation, arena);
10471 Py_LeaveRecursiveCall();
10472 if (res != 0) goto failed;
10473 Py_CLEAR(tmp);
10474 }
10475 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
10476 return 1;
10477 }
10478 if (tmp == NULL || tmp == Py_None) {
10479 Py_CLEAR(tmp);
10480 type_comment = NULL;
10481 }
10482 else {
10483 int res;
10484 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10485 goto failed;
10486 }
10487 res = obj2ast_string(state, tmp, &type_comment, arena);
10488 Py_LeaveRecursiveCall();
10489 if (res != 0) goto failed;
10490 Py_CLEAR(tmp);
10491 }
10492 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10493 return 1;
10494 }
10495 if (tmp == NULL) {
10496 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
10497 return 1;
10498 }
10499 else {
10500 int res;
10501 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10502 goto failed;
10503 }
10504 res = obj2ast_int(state, tmp, &lineno, arena);
10505 Py_LeaveRecursiveCall();
10506 if (res != 0) goto failed;
10507 Py_CLEAR(tmp);
10508 }
10509 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10510 return 1;
10511 }
10512 if (tmp == NULL) {
10513 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
10514 return 1;
10515 }
10516 else {
10517 int res;
10518 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10519 goto failed;
10520 }
10521 res = obj2ast_int(state, tmp, &col_offset, arena);
10522 Py_LeaveRecursiveCall();
10523 if (res != 0) goto failed;
10524 Py_CLEAR(tmp);
10525 }
10526 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10527 return 1;
10528 }
10529 if (tmp == NULL || tmp == Py_None) {
10530 Py_CLEAR(tmp);
10531 end_lineno = 0;
10532 }
10533 else {
10534 int res;
10535 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10536 goto failed;
10537 }
10538 res = obj2ast_int(state, tmp, &end_lineno, arena);
10539 Py_LeaveRecursiveCall();
10540 if (res != 0) goto failed;
10541 Py_CLEAR(tmp);
10542 }
10543 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10544 return 1;
10545 }
10546 if (tmp == NULL || tmp == Py_None) {
10547 Py_CLEAR(tmp);
10548 end_col_offset = 0;
10549 }
10550 else {
10551 int res;
10552 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10553 goto failed;
10554 }
10555 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10556 Py_LeaveRecursiveCall();
10557 if (res != 0) goto failed;
10558 Py_CLEAR(tmp);
10559 }
10560 *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
10561 end_lineno, end_col_offset, arena);
10562 return 0;
10563 failed:
10564 Py_XDECREF(tmp);
10565 return 1;
10566 }
10567
10568 int
obj2ast_keyword(struct ast_state * state,PyObject * obj,keyword_ty * out,PyArena * arena)10569 obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
10570 PyArena* arena)
10571 {
10572 PyObject* tmp = NULL;
10573 identifier arg;
10574 expr_ty value;
10575 int lineno;
10576 int col_offset;
10577 int end_lineno;
10578 int end_col_offset;
10579
10580 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
10581 return 1;
10582 }
10583 if (tmp == NULL || tmp == Py_None) {
10584 Py_CLEAR(tmp);
10585 arg = NULL;
10586 }
10587 else {
10588 int res;
10589 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10590 goto failed;
10591 }
10592 res = obj2ast_identifier(state, tmp, &arg, arena);
10593 Py_LeaveRecursiveCall();
10594 if (res != 0) goto failed;
10595 Py_CLEAR(tmp);
10596 }
10597 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
10598 return 1;
10599 }
10600 if (tmp == NULL) {
10601 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
10602 return 1;
10603 }
10604 else {
10605 int res;
10606 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10607 goto failed;
10608 }
10609 res = obj2ast_expr(state, tmp, &value, arena);
10610 Py_LeaveRecursiveCall();
10611 if (res != 0) goto failed;
10612 Py_CLEAR(tmp);
10613 }
10614 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10615 return 1;
10616 }
10617 if (tmp == NULL) {
10618 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
10619 return 1;
10620 }
10621 else {
10622 int res;
10623 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10624 goto failed;
10625 }
10626 res = obj2ast_int(state, tmp, &lineno, arena);
10627 Py_LeaveRecursiveCall();
10628 if (res != 0) goto failed;
10629 Py_CLEAR(tmp);
10630 }
10631 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10632 return 1;
10633 }
10634 if (tmp == NULL) {
10635 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
10636 return 1;
10637 }
10638 else {
10639 int res;
10640 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10641 goto failed;
10642 }
10643 res = obj2ast_int(state, tmp, &col_offset, arena);
10644 Py_LeaveRecursiveCall();
10645 if (res != 0) goto failed;
10646 Py_CLEAR(tmp);
10647 }
10648 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10649 return 1;
10650 }
10651 if (tmp == NULL || tmp == Py_None) {
10652 Py_CLEAR(tmp);
10653 end_lineno = 0;
10654 }
10655 else {
10656 int res;
10657 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10658 goto failed;
10659 }
10660 res = obj2ast_int(state, tmp, &end_lineno, arena);
10661 Py_LeaveRecursiveCall();
10662 if (res != 0) goto failed;
10663 Py_CLEAR(tmp);
10664 }
10665 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10666 return 1;
10667 }
10668 if (tmp == NULL || tmp == Py_None) {
10669 Py_CLEAR(tmp);
10670 end_col_offset = 0;
10671 }
10672 else {
10673 int res;
10674 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10675 goto failed;
10676 }
10677 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10678 Py_LeaveRecursiveCall();
10679 if (res != 0) goto failed;
10680 Py_CLEAR(tmp);
10681 }
10682 *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
10683 end_col_offset, arena);
10684 return 0;
10685 failed:
10686 Py_XDECREF(tmp);
10687 return 1;
10688 }
10689
10690 int
obj2ast_alias(struct ast_state * state,PyObject * obj,alias_ty * out,PyArena * arena)10691 obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
10692 arena)
10693 {
10694 PyObject* tmp = NULL;
10695 identifier name;
10696 identifier asname;
10697 int lineno;
10698 int col_offset;
10699 int end_lineno;
10700 int end_col_offset;
10701
10702 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
10703 return 1;
10704 }
10705 if (tmp == NULL) {
10706 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
10707 return 1;
10708 }
10709 else {
10710 int res;
10711 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10712 goto failed;
10713 }
10714 res = obj2ast_identifier(state, tmp, &name, arena);
10715 Py_LeaveRecursiveCall();
10716 if (res != 0) goto failed;
10717 Py_CLEAR(tmp);
10718 }
10719 if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
10720 return 1;
10721 }
10722 if (tmp == NULL || tmp == Py_None) {
10723 Py_CLEAR(tmp);
10724 asname = NULL;
10725 }
10726 else {
10727 int res;
10728 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10729 goto failed;
10730 }
10731 res = obj2ast_identifier(state, tmp, &asname, arena);
10732 Py_LeaveRecursiveCall();
10733 if (res != 0) goto failed;
10734 Py_CLEAR(tmp);
10735 }
10736 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10737 return 1;
10738 }
10739 if (tmp == NULL) {
10740 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
10741 return 1;
10742 }
10743 else {
10744 int res;
10745 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10746 goto failed;
10747 }
10748 res = obj2ast_int(state, tmp, &lineno, arena);
10749 Py_LeaveRecursiveCall();
10750 if (res != 0) goto failed;
10751 Py_CLEAR(tmp);
10752 }
10753 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10754 return 1;
10755 }
10756 if (tmp == NULL) {
10757 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
10758 return 1;
10759 }
10760 else {
10761 int res;
10762 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10763 goto failed;
10764 }
10765 res = obj2ast_int(state, tmp, &col_offset, arena);
10766 Py_LeaveRecursiveCall();
10767 if (res != 0) goto failed;
10768 Py_CLEAR(tmp);
10769 }
10770 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10771 return 1;
10772 }
10773 if (tmp == NULL || tmp == Py_None) {
10774 Py_CLEAR(tmp);
10775 end_lineno = 0;
10776 }
10777 else {
10778 int res;
10779 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10780 goto failed;
10781 }
10782 res = obj2ast_int(state, tmp, &end_lineno, arena);
10783 Py_LeaveRecursiveCall();
10784 if (res != 0) goto failed;
10785 Py_CLEAR(tmp);
10786 }
10787 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10788 return 1;
10789 }
10790 if (tmp == NULL || tmp == Py_None) {
10791 Py_CLEAR(tmp);
10792 end_col_offset = 0;
10793 }
10794 else {
10795 int res;
10796 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10797 goto failed;
10798 }
10799 res = obj2ast_int(state, tmp, &end_col_offset, arena);
10800 Py_LeaveRecursiveCall();
10801 if (res != 0) goto failed;
10802 Py_CLEAR(tmp);
10803 }
10804 *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
10805 end_col_offset, arena);
10806 return 0;
10807 failed:
10808 Py_XDECREF(tmp);
10809 return 1;
10810 }
10811
10812 int
obj2ast_withitem(struct ast_state * state,PyObject * obj,withitem_ty * out,PyArena * arena)10813 obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
10814 PyArena* arena)
10815 {
10816 PyObject* tmp = NULL;
10817 expr_ty context_expr;
10818 expr_ty optional_vars;
10819
10820 if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
10821 return 1;
10822 }
10823 if (tmp == NULL) {
10824 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
10825 return 1;
10826 }
10827 else {
10828 int res;
10829 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10830 goto failed;
10831 }
10832 res = obj2ast_expr(state, tmp, &context_expr, arena);
10833 Py_LeaveRecursiveCall();
10834 if (res != 0) goto failed;
10835 Py_CLEAR(tmp);
10836 }
10837 if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
10838 return 1;
10839 }
10840 if (tmp == NULL || tmp == Py_None) {
10841 Py_CLEAR(tmp);
10842 optional_vars = NULL;
10843 }
10844 else {
10845 int res;
10846 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10847 goto failed;
10848 }
10849 res = obj2ast_expr(state, tmp, &optional_vars, arena);
10850 Py_LeaveRecursiveCall();
10851 if (res != 0) goto failed;
10852 Py_CLEAR(tmp);
10853 }
10854 *out = _PyAST_withitem(context_expr, optional_vars, arena);
10855 return 0;
10856 failed:
10857 Py_XDECREF(tmp);
10858 return 1;
10859 }
10860
10861 int
obj2ast_match_case(struct ast_state * state,PyObject * obj,match_case_ty * out,PyArena * arena)10862 obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
10863 PyArena* arena)
10864 {
10865 PyObject* tmp = NULL;
10866 pattern_ty pattern;
10867 expr_ty guard;
10868 asdl_stmt_seq* body;
10869
10870 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
10871 return 1;
10872 }
10873 if (tmp == NULL) {
10874 PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
10875 return 1;
10876 }
10877 else {
10878 int res;
10879 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10880 goto failed;
10881 }
10882 res = obj2ast_pattern(state, tmp, &pattern, arena);
10883 Py_LeaveRecursiveCall();
10884 if (res != 0) goto failed;
10885 Py_CLEAR(tmp);
10886 }
10887 if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
10888 return 1;
10889 }
10890 if (tmp == NULL || tmp == Py_None) {
10891 Py_CLEAR(tmp);
10892 guard = NULL;
10893 }
10894 else {
10895 int res;
10896 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10897 goto failed;
10898 }
10899 res = obj2ast_expr(state, tmp, &guard, arena);
10900 Py_LeaveRecursiveCall();
10901 if (res != 0) goto failed;
10902 Py_CLEAR(tmp);
10903 }
10904 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10905 return 1;
10906 }
10907 if (tmp == NULL) {
10908 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from match_case");
10909 return 1;
10910 }
10911 else {
10912 int res;
10913 Py_ssize_t len;
10914 Py_ssize_t i;
10915 if (!PyList_Check(tmp)) {
10916 PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10917 goto failed;
10918 }
10919 len = PyList_GET_SIZE(tmp);
10920 body = _Py_asdl_stmt_seq_new(len, arena);
10921 if (body == NULL) goto failed;
10922 for (i = 0; i < len; i++) {
10923 stmt_ty val;
10924 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10925 Py_INCREF(tmp2);
10926 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10927 goto failed;
10928 }
10929 res = obj2ast_stmt(state, tmp2, &val, arena);
10930 Py_LeaveRecursiveCall();
10931 Py_DECREF(tmp2);
10932 if (res != 0) goto failed;
10933 if (len != PyList_GET_SIZE(tmp)) {
10934 PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
10935 goto failed;
10936 }
10937 asdl_seq_SET(body, i, val);
10938 }
10939 Py_CLEAR(tmp);
10940 }
10941 *out = _PyAST_match_case(pattern, guard, body, arena);
10942 return 0;
10943 failed:
10944 Py_XDECREF(tmp);
10945 return 1;
10946 }
10947
10948 int
obj2ast_pattern(struct ast_state * state,PyObject * obj,pattern_ty * out,PyArena * arena)10949 obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
10950 PyArena* arena)
10951 {
10952 int isinstance;
10953
10954 PyObject *tmp = NULL;
10955 PyObject *tp;
10956 int lineno;
10957 int col_offset;
10958 int end_lineno;
10959 int end_col_offset;
10960
10961 if (obj == Py_None) {
10962 *out = NULL;
10963 return 0;
10964 }
10965 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10966 return 1;
10967 }
10968 if (tmp == NULL) {
10969 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
10970 return 1;
10971 }
10972 else {
10973 int res;
10974 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10975 goto failed;
10976 }
10977 res = obj2ast_int(state, tmp, &lineno, arena);
10978 Py_LeaveRecursiveCall();
10979 if (res != 0) goto failed;
10980 Py_CLEAR(tmp);
10981 }
10982 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10983 return 1;
10984 }
10985 if (tmp == NULL) {
10986 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
10987 return 1;
10988 }
10989 else {
10990 int res;
10991 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10992 goto failed;
10993 }
10994 res = obj2ast_int(state, tmp, &col_offset, arena);
10995 Py_LeaveRecursiveCall();
10996 if (res != 0) goto failed;
10997 Py_CLEAR(tmp);
10998 }
10999 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11000 return 1;
11001 }
11002 if (tmp == NULL) {
11003 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
11004 return 1;
11005 }
11006 else {
11007 int res;
11008 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11009 goto failed;
11010 }
11011 res = obj2ast_int(state, tmp, &end_lineno, arena);
11012 Py_LeaveRecursiveCall();
11013 if (res != 0) goto failed;
11014 Py_CLEAR(tmp);
11015 }
11016 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11017 return 1;
11018 }
11019 if (tmp == NULL) {
11020 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
11021 return 1;
11022 }
11023 else {
11024 int res;
11025 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11026 goto failed;
11027 }
11028 res = obj2ast_int(state, tmp, &end_col_offset, arena);
11029 Py_LeaveRecursiveCall();
11030 if (res != 0) goto failed;
11031 Py_CLEAR(tmp);
11032 }
11033 tp = state->MatchValue_type;
11034 isinstance = PyObject_IsInstance(obj, tp);
11035 if (isinstance == -1) {
11036 return 1;
11037 }
11038 if (isinstance) {
11039 expr_ty value;
11040
11041 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11042 return 1;
11043 }
11044 if (tmp == NULL) {
11045 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
11046 return 1;
11047 }
11048 else {
11049 int res;
11050 if (Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
11051 goto failed;
11052 }
11053 res = obj2ast_expr(state, tmp, &value, arena);
11054 Py_LeaveRecursiveCall();
11055 if (res != 0) goto failed;
11056 Py_CLEAR(tmp);
11057 }
11058 *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
11059 end_col_offset, arena);
11060 if (*out == NULL) goto failed;
11061 return 0;
11062 }
11063 tp = state->MatchSingleton_type;
11064 isinstance = PyObject_IsInstance(obj, tp);
11065 if (isinstance == -1) {
11066 return 1;
11067 }
11068 if (isinstance) {
11069 constant value;
11070
11071 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11072 return 1;
11073 }
11074 if (tmp == NULL) {
11075 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
11076 return 1;
11077 }
11078 else {
11079 int res;
11080 if (Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
11081 goto failed;
11082 }
11083 res = obj2ast_constant(state, tmp, &value, arena);
11084 Py_LeaveRecursiveCall();
11085 if (res != 0) goto failed;
11086 Py_CLEAR(tmp);
11087 }
11088 *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
11089 end_col_offset, arena);
11090 if (*out == NULL) goto failed;
11091 return 0;
11092 }
11093 tp = state->MatchSequence_type;
11094 isinstance = PyObject_IsInstance(obj, tp);
11095 if (isinstance == -1) {
11096 return 1;
11097 }
11098 if (isinstance) {
11099 asdl_pattern_seq* patterns;
11100
11101 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11102 return 1;
11103 }
11104 if (tmp == NULL) {
11105 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchSequence");
11106 return 1;
11107 }
11108 else {
11109 int res;
11110 Py_ssize_t len;
11111 Py_ssize_t i;
11112 if (!PyList_Check(tmp)) {
11113 PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11114 goto failed;
11115 }
11116 len = PyList_GET_SIZE(tmp);
11117 patterns = _Py_asdl_pattern_seq_new(len, arena);
11118 if (patterns == NULL) goto failed;
11119 for (i = 0; i < len; i++) {
11120 pattern_ty val;
11121 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11122 Py_INCREF(tmp2);
11123 if (Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
11124 goto failed;
11125 }
11126 res = obj2ast_pattern(state, tmp2, &val, arena);
11127 Py_LeaveRecursiveCall();
11128 Py_DECREF(tmp2);
11129 if (res != 0) goto failed;
11130 if (len != PyList_GET_SIZE(tmp)) {
11131 PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
11132 goto failed;
11133 }
11134 asdl_seq_SET(patterns, i, val);
11135 }
11136 Py_CLEAR(tmp);
11137 }
11138 *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
11139 end_col_offset, arena);
11140 if (*out == NULL) goto failed;
11141 return 0;
11142 }
11143 tp = state->MatchMapping_type;
11144 isinstance = PyObject_IsInstance(obj, tp);
11145 if (isinstance == -1) {
11146 return 1;
11147 }
11148 if (isinstance) {
11149 asdl_expr_seq* keys;
11150 asdl_pattern_seq* patterns;
11151 identifier rest;
11152
11153 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
11154 return 1;
11155 }
11156 if (tmp == NULL) {
11157 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from MatchMapping");
11158 return 1;
11159 }
11160 else {
11161 int res;
11162 Py_ssize_t len;
11163 Py_ssize_t i;
11164 if (!PyList_Check(tmp)) {
11165 PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11166 goto failed;
11167 }
11168 len = PyList_GET_SIZE(tmp);
11169 keys = _Py_asdl_expr_seq_new(len, arena);
11170 if (keys == NULL) goto failed;
11171 for (i = 0; i < len; i++) {
11172 expr_ty val;
11173 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11174 Py_INCREF(tmp2);
11175 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11176 goto failed;
11177 }
11178 res = obj2ast_expr(state, tmp2, &val, arena);
11179 Py_LeaveRecursiveCall();
11180 Py_DECREF(tmp2);
11181 if (res != 0) goto failed;
11182 if (len != PyList_GET_SIZE(tmp)) {
11183 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
11184 goto failed;
11185 }
11186 asdl_seq_SET(keys, i, val);
11187 }
11188 Py_CLEAR(tmp);
11189 }
11190 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11191 return 1;
11192 }
11193 if (tmp == NULL) {
11194 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchMapping");
11195 return 1;
11196 }
11197 else {
11198 int res;
11199 Py_ssize_t len;
11200 Py_ssize_t i;
11201 if (!PyList_Check(tmp)) {
11202 PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11203 goto failed;
11204 }
11205 len = PyList_GET_SIZE(tmp);
11206 patterns = _Py_asdl_pattern_seq_new(len, arena);
11207 if (patterns == NULL) goto failed;
11208 for (i = 0; i < len; i++) {
11209 pattern_ty val;
11210 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11211 Py_INCREF(tmp2);
11212 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11213 goto failed;
11214 }
11215 res = obj2ast_pattern(state, tmp2, &val, arena);
11216 Py_LeaveRecursiveCall();
11217 Py_DECREF(tmp2);
11218 if (res != 0) goto failed;
11219 if (len != PyList_GET_SIZE(tmp)) {
11220 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
11221 goto failed;
11222 }
11223 asdl_seq_SET(patterns, i, val);
11224 }
11225 Py_CLEAR(tmp);
11226 }
11227 if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
11228 return 1;
11229 }
11230 if (tmp == NULL || tmp == Py_None) {
11231 Py_CLEAR(tmp);
11232 rest = NULL;
11233 }
11234 else {
11235 int res;
11236 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11237 goto failed;
11238 }
11239 res = obj2ast_identifier(state, tmp, &rest, arena);
11240 Py_LeaveRecursiveCall();
11241 if (res != 0) goto failed;
11242 Py_CLEAR(tmp);
11243 }
11244 *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
11245 end_lineno, end_col_offset, arena);
11246 if (*out == NULL) goto failed;
11247 return 0;
11248 }
11249 tp = state->MatchClass_type;
11250 isinstance = PyObject_IsInstance(obj, tp);
11251 if (isinstance == -1) {
11252 return 1;
11253 }
11254 if (isinstance) {
11255 expr_ty cls;
11256 asdl_pattern_seq* patterns;
11257 asdl_identifier_seq* kwd_attrs;
11258 asdl_pattern_seq* kwd_patterns;
11259
11260 if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
11261 return 1;
11262 }
11263 if (tmp == NULL) {
11264 PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
11265 return 1;
11266 }
11267 else {
11268 int res;
11269 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11270 goto failed;
11271 }
11272 res = obj2ast_expr(state, tmp, &cls, arena);
11273 Py_LeaveRecursiveCall();
11274 if (res != 0) goto failed;
11275 Py_CLEAR(tmp);
11276 }
11277 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11278 return 1;
11279 }
11280 if (tmp == NULL) {
11281 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchClass");
11282 return 1;
11283 }
11284 else {
11285 int res;
11286 Py_ssize_t len;
11287 Py_ssize_t i;
11288 if (!PyList_Check(tmp)) {
11289 PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11290 goto failed;
11291 }
11292 len = PyList_GET_SIZE(tmp);
11293 patterns = _Py_asdl_pattern_seq_new(len, arena);
11294 if (patterns == NULL) goto failed;
11295 for (i = 0; i < len; i++) {
11296 pattern_ty val;
11297 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11298 Py_INCREF(tmp2);
11299 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11300 goto failed;
11301 }
11302 res = obj2ast_pattern(state, tmp2, &val, arena);
11303 Py_LeaveRecursiveCall();
11304 Py_DECREF(tmp2);
11305 if (res != 0) goto failed;
11306 if (len != PyList_GET_SIZE(tmp)) {
11307 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
11308 goto failed;
11309 }
11310 asdl_seq_SET(patterns, i, val);
11311 }
11312 Py_CLEAR(tmp);
11313 }
11314 if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
11315 return 1;
11316 }
11317 if (tmp == NULL) {
11318 PyErr_SetString(PyExc_TypeError, "required field \"kwd_attrs\" missing from MatchClass");
11319 return 1;
11320 }
11321 else {
11322 int res;
11323 Py_ssize_t len;
11324 Py_ssize_t i;
11325 if (!PyList_Check(tmp)) {
11326 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11327 goto failed;
11328 }
11329 len = PyList_GET_SIZE(tmp);
11330 kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
11331 if (kwd_attrs == NULL) goto failed;
11332 for (i = 0; i < len; i++) {
11333 identifier val;
11334 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11335 Py_INCREF(tmp2);
11336 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11337 goto failed;
11338 }
11339 res = obj2ast_identifier(state, tmp2, &val, arena);
11340 Py_LeaveRecursiveCall();
11341 Py_DECREF(tmp2);
11342 if (res != 0) goto failed;
11343 if (len != PyList_GET_SIZE(tmp)) {
11344 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
11345 goto failed;
11346 }
11347 asdl_seq_SET(kwd_attrs, i, val);
11348 }
11349 Py_CLEAR(tmp);
11350 }
11351 if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
11352 return 1;
11353 }
11354 if (tmp == NULL) {
11355 PyErr_SetString(PyExc_TypeError, "required field \"kwd_patterns\" missing from MatchClass");
11356 return 1;
11357 }
11358 else {
11359 int res;
11360 Py_ssize_t len;
11361 Py_ssize_t i;
11362 if (!PyList_Check(tmp)) {
11363 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11364 goto failed;
11365 }
11366 len = PyList_GET_SIZE(tmp);
11367 kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
11368 if (kwd_patterns == NULL) goto failed;
11369 for (i = 0; i < len; i++) {
11370 pattern_ty val;
11371 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11372 Py_INCREF(tmp2);
11373 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11374 goto failed;
11375 }
11376 res = obj2ast_pattern(state, tmp2, &val, arena);
11377 Py_LeaveRecursiveCall();
11378 Py_DECREF(tmp2);
11379 if (res != 0) goto failed;
11380 if (len != PyList_GET_SIZE(tmp)) {
11381 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
11382 goto failed;
11383 }
11384 asdl_seq_SET(kwd_patterns, i, val);
11385 }
11386 Py_CLEAR(tmp);
11387 }
11388 *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
11389 lineno, col_offset, end_lineno,
11390 end_col_offset, arena);
11391 if (*out == NULL) goto failed;
11392 return 0;
11393 }
11394 tp = state->MatchStar_type;
11395 isinstance = PyObject_IsInstance(obj, tp);
11396 if (isinstance == -1) {
11397 return 1;
11398 }
11399 if (isinstance) {
11400 identifier name;
11401
11402 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11403 return 1;
11404 }
11405 if (tmp == NULL || tmp == Py_None) {
11406 Py_CLEAR(tmp);
11407 name = NULL;
11408 }
11409 else {
11410 int res;
11411 if (Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
11412 goto failed;
11413 }
11414 res = obj2ast_identifier(state, tmp, &name, arena);
11415 Py_LeaveRecursiveCall();
11416 if (res != 0) goto failed;
11417 Py_CLEAR(tmp);
11418 }
11419 *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
11420 end_col_offset, arena);
11421 if (*out == NULL) goto failed;
11422 return 0;
11423 }
11424 tp = state->MatchAs_type;
11425 isinstance = PyObject_IsInstance(obj, tp);
11426 if (isinstance == -1) {
11427 return 1;
11428 }
11429 if (isinstance) {
11430 pattern_ty pattern;
11431 identifier name;
11432
11433 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11434 return 1;
11435 }
11436 if (tmp == NULL || tmp == Py_None) {
11437 Py_CLEAR(tmp);
11438 pattern = NULL;
11439 }
11440 else {
11441 int res;
11442 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11443 goto failed;
11444 }
11445 res = obj2ast_pattern(state, tmp, &pattern, arena);
11446 Py_LeaveRecursiveCall();
11447 if (res != 0) goto failed;
11448 Py_CLEAR(tmp);
11449 }
11450 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11451 return 1;
11452 }
11453 if (tmp == NULL || tmp == Py_None) {
11454 Py_CLEAR(tmp);
11455 name = NULL;
11456 }
11457 else {
11458 int res;
11459 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11460 goto failed;
11461 }
11462 res = obj2ast_identifier(state, tmp, &name, arena);
11463 Py_LeaveRecursiveCall();
11464 if (res != 0) goto failed;
11465 Py_CLEAR(tmp);
11466 }
11467 *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
11468 end_col_offset, arena);
11469 if (*out == NULL) goto failed;
11470 return 0;
11471 }
11472 tp = state->MatchOr_type;
11473 isinstance = PyObject_IsInstance(obj, tp);
11474 if (isinstance == -1) {
11475 return 1;
11476 }
11477 if (isinstance) {
11478 asdl_pattern_seq* patterns;
11479
11480 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11481 return 1;
11482 }
11483 if (tmp == NULL) {
11484 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchOr");
11485 return 1;
11486 }
11487 else {
11488 int res;
11489 Py_ssize_t len;
11490 Py_ssize_t i;
11491 if (!PyList_Check(tmp)) {
11492 PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11493 goto failed;
11494 }
11495 len = PyList_GET_SIZE(tmp);
11496 patterns = _Py_asdl_pattern_seq_new(len, arena);
11497 if (patterns == NULL) goto failed;
11498 for (i = 0; i < len; i++) {
11499 pattern_ty val;
11500 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11501 Py_INCREF(tmp2);
11502 if (Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
11503 goto failed;
11504 }
11505 res = obj2ast_pattern(state, tmp2, &val, arena);
11506 Py_LeaveRecursiveCall();
11507 Py_DECREF(tmp2);
11508 if (res != 0) goto failed;
11509 if (len != PyList_GET_SIZE(tmp)) {
11510 PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
11511 goto failed;
11512 }
11513 asdl_seq_SET(patterns, i, val);
11514 }
11515 Py_CLEAR(tmp);
11516 }
11517 *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
11518 end_col_offset, arena);
11519 if (*out == NULL) goto failed;
11520 return 0;
11521 }
11522
11523 PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
11524 failed:
11525 Py_XDECREF(tmp);
11526 return 1;
11527 }
11528
11529 int
obj2ast_type_ignore(struct ast_state * state,PyObject * obj,type_ignore_ty * out,PyArena * arena)11530 obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
11531 out, PyArena* arena)
11532 {
11533 int isinstance;
11534
11535 PyObject *tmp = NULL;
11536 PyObject *tp;
11537
11538 if (obj == Py_None) {
11539 *out = NULL;
11540 return 0;
11541 }
11542 tp = state->TypeIgnore_type;
11543 isinstance = PyObject_IsInstance(obj, tp);
11544 if (isinstance == -1) {
11545 return 1;
11546 }
11547 if (isinstance) {
11548 int lineno;
11549 string tag;
11550
11551 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
11552 return 1;
11553 }
11554 if (tmp == NULL) {
11555 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
11556 return 1;
11557 }
11558 else {
11559 int res;
11560 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11561 goto failed;
11562 }
11563 res = obj2ast_int(state, tmp, &lineno, arena);
11564 Py_LeaveRecursiveCall();
11565 if (res != 0) goto failed;
11566 Py_CLEAR(tmp);
11567 }
11568 if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
11569 return 1;
11570 }
11571 if (tmp == NULL) {
11572 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
11573 return 1;
11574 }
11575 else {
11576 int res;
11577 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11578 goto failed;
11579 }
11580 res = obj2ast_string(state, tmp, &tag, arena);
11581 Py_LeaveRecursiveCall();
11582 if (res != 0) goto failed;
11583 Py_CLEAR(tmp);
11584 }
11585 *out = _PyAST_TypeIgnore(lineno, tag, arena);
11586 if (*out == NULL) goto failed;
11587 return 0;
11588 }
11589
11590 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
11591 failed:
11592 Py_XDECREF(tmp);
11593 return 1;
11594 }
11595
11596
11597 static int
astmodule_exec(PyObject * m)11598 astmodule_exec(PyObject *m)
11599 {
11600 struct ast_state *state = get_ast_state();
11601 if (state == NULL) {
11602 return -1;
11603 }
11604 if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
11605 return -1;
11606 }
11607 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
11608 return -1;
11609 }
11610 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
11611 return -1;
11612 }
11613 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
11614 return -1;
11615 }
11616 if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
11617 return -1;
11618 }
11619 if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
11620 return -1;
11621 }
11622 if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
11623 return -1;
11624 }
11625 if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
11626 return -1;
11627 }
11628 if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
11629 {
11630 return -1;
11631 }
11632 if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
11633 return -1;
11634 }
11635 if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
11636 return -1;
11637 }
11638 if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
11639 state->AsyncFunctionDef_type) < 0) {
11640 return -1;
11641 }
11642 if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
11643 return -1;
11644 }
11645 if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
11646 return -1;
11647 }
11648 if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
11649 return -1;
11650 }
11651 if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
11652 return -1;
11653 }
11654 if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
11655 return -1;
11656 }
11657 if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
11658 return -1;
11659 }
11660 if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
11661 return -1;
11662 }
11663 if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
11664 return -1;
11665 }
11666 if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
11667 return -1;
11668 }
11669 if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
11670 return -1;
11671 }
11672 if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
11673 return -1;
11674 }
11675 if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
11676 return -1;
11677 }
11678 if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
11679 return -1;
11680 }
11681 if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
11682 return -1;
11683 }
11684 if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
11685 return -1;
11686 }
11687 if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
11688 return -1;
11689 }
11690 if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
11691 return -1;
11692 }
11693 if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
11694 return -1;
11695 }
11696 if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
11697 return -1;
11698 }
11699 if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
11700 return -1;
11701 }
11702 if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
11703 return -1;
11704 }
11705 if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
11706 return -1;
11707 }
11708 if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
11709 return -1;
11710 }
11711 if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
11712 return -1;
11713 }
11714 if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
11715 return -1;
11716 }
11717 if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
11718 return -1;
11719 }
11720 if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
11721 return -1;
11722 }
11723 if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
11724 return -1;
11725 }
11726 if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
11727 return -1;
11728 }
11729 if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
11730 return -1;
11731 }
11732 if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
11733 return -1;
11734 }
11735 if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
11736 return -1;
11737 }
11738 if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
11739 return -1;
11740 }
11741 if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
11742 return -1;
11743 }
11744 if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
11745 return -1;
11746 }
11747 if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
11748 return -1;
11749 }
11750 if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
11751 {
11752 return -1;
11753 }
11754 if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
11755 return -1;
11756 }
11757 if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
11758 return -1;
11759 }
11760 if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
11761 return -1;
11762 }
11763 if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
11764 return -1;
11765 }
11766 if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
11767 return -1;
11768 }
11769 if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
11770 < 0) {
11771 return -1;
11772 }
11773 if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
11774 return -1;
11775 }
11776 if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
11777 return -1;
11778 }
11779 if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
11780 return -1;
11781 }
11782 if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
11783 return -1;
11784 }
11785 if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
11786 return -1;
11787 }
11788 if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
11789 return -1;
11790 }
11791 if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
11792 return -1;
11793 }
11794 if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
11795 return -1;
11796 }
11797 if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
11798 return -1;
11799 }
11800 if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
11801 {
11802 return -1;
11803 }
11804 if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
11805 return -1;
11806 }
11807 if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
11808 return -1;
11809 }
11810 if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
11811 return -1;
11812 }
11813 if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
11814 return -1;
11815 }
11816 if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
11817 return -1;
11818 }
11819 if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
11820 return -1;
11821 }
11822 if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
11823 return -1;
11824 }
11825 if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
11826 return -1;
11827 }
11828 if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
11829 return -1;
11830 }
11831 if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
11832 return -1;
11833 }
11834 if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
11835 return -1;
11836 }
11837 if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
11838 return -1;
11839 }
11840 if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
11841 return -1;
11842 }
11843 if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
11844 return -1;
11845 }
11846 if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
11847 return -1;
11848 }
11849 if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
11850 return -1;
11851 }
11852 if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
11853 return -1;
11854 }
11855 if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
11856 return -1;
11857 }
11858 if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
11859 return -1;
11860 }
11861 if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
11862 return -1;
11863 }
11864 if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
11865 return -1;
11866 }
11867 if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
11868 return -1;
11869 }
11870 if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
11871 return -1;
11872 }
11873 if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
11874 return -1;
11875 }
11876 if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
11877 return -1;
11878 }
11879 if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
11880 return -1;
11881 }
11882 if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
11883 return -1;
11884 }
11885 if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
11886 return -1;
11887 }
11888 if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
11889 return -1;
11890 }
11891 if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
11892 return -1;
11893 }
11894 if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
11895 return -1;
11896 }
11897 if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
11898 return -1;
11899 }
11900 if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
11901 return -1;
11902 }
11903 if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
11904 return -1;
11905 }
11906 if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
11907 return -1;
11908 }
11909 if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
11910 return -1;
11911 }
11912 if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
11913 0) {
11914 return -1;
11915 }
11916 if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
11917 0) {
11918 return -1;
11919 }
11920 if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
11921 0) {
11922 return -1;
11923 }
11924 if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
11925 return -1;
11926 }
11927 if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
11928 return -1;
11929 }
11930 if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
11931 return -1;
11932 }
11933 if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
11934 return -1;
11935 }
11936 if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
11937 return -1;
11938 }
11939 if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
11940 return -1;
11941 }
11942 if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
11943 return -1;
11944 }
11945 if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
11946 return -1;
11947 }
11948 if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
11949 < 0) {
11950 return -1;
11951 }
11952 if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
11953 0) {
11954 return -1;
11955 }
11956 if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
11957 {
11958 return -1;
11959 }
11960 if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
11961 return -1;
11962 }
11963 if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
11964 return -1;
11965 }
11966 if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
11967 return -1;
11968 }
11969 if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
11970 return -1;
11971 }
11972 if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
11973 return -1;
11974 }
11975 if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
11976 return -1;
11977 }
11978 return 0;
11979 }
11980
11981 static PyModuleDef_Slot astmodule_slots[] = {
11982 {Py_mod_exec, astmodule_exec},
11983 {0, NULL}
11984 };
11985
11986 static struct PyModuleDef _astmodule = {
11987 PyModuleDef_HEAD_INIT,
11988 .m_name = "_ast",
11989 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
11990 .m_size = 0,
11991 .m_slots = astmodule_slots,
11992 };
11993
11994 PyMODINIT_FUNC
PyInit__ast(void)11995 PyInit__ast(void)
11996 {
11997 return PyModuleDef_Init(&_astmodule);
11998 }
11999
12000
PyAST_mod2obj(mod_ty t)12001 PyObject* PyAST_mod2obj(mod_ty t)
12002 {
12003 struct ast_state *state = get_ast_state();
12004 if (state == NULL) {
12005 return NULL;
12006 }
12007 return ast2obj_mod(state, t);
12008 }
12009
12010 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
PyAST_obj2mod(PyObject * ast,PyArena * arena,int mode)12011 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
12012 {
12013 const char * const req_name[] = {"Module", "Expression", "Interactive"};
12014 int isinstance;
12015
12016 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
12017 return NULL;
12018 }
12019
12020 struct ast_state *state = get_ast_state();
12021 if (state == NULL) {
12022 return NULL;
12023 }
12024
12025 PyObject *req_type[3];
12026 req_type[0] = state->Module_type;
12027 req_type[1] = state->Expression_type;
12028 req_type[2] = state->Interactive_type;
12029
12030 assert(0 <= mode && mode <= 2);
12031
12032 isinstance = PyObject_IsInstance(ast, req_type[mode]);
12033 if (isinstance == -1)
12034 return NULL;
12035 if (!isinstance) {
12036 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
12037 req_name[mode], _PyType_Name(Py_TYPE(ast)));
12038 return NULL;
12039 }
12040
12041 mod_ty res = NULL;
12042 if (obj2ast_mod(state, ast, &res, arena) != 0)
12043 return NULL;
12044 else
12045 return res;
12046 }
12047
PyAST_Check(PyObject * obj)12048 int PyAST_Check(PyObject* obj)
12049 {
12050 struct ast_state *state = get_ast_state();
12051 if (state == NULL) {
12052 return -1;
12053 }
12054 return PyObject_IsInstance(obj, state->AST_type);
12055 }
12056
12057
12058