Updated to reflect change in logging.config to remove out-of-date comment in _install...
[python.git] / Python / Python-ast.c
blobf958145a23317903b2cdab062b85c47b4fb368b5
1 /* File automatically generated by Parser/asdl_c.py. */
4 /*
5 __version__ 62047.
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
12 #include "Python.h"
13 #include "Python-ast.h"
15 static PyTypeObject AST_type;
16 static PyTypeObject *mod_type;
17 static PyObject* ast2obj_mod(void*);
18 static PyTypeObject *Module_type;
19 static char *Module_fields[]={
20 "body",
22 static PyTypeObject *Interactive_type;
23 static char *Interactive_fields[]={
24 "body",
26 static PyTypeObject *Expression_type;
27 static char *Expression_fields[]={
28 "body",
30 static PyTypeObject *Suite_type;
31 static char *Suite_fields[]={
32 "body",
34 static PyTypeObject *stmt_type;
35 static char *stmt_attributes[] = {
36 "lineno",
37 "col_offset",
39 static PyObject* ast2obj_stmt(void*);
40 static PyTypeObject *FunctionDef_type;
41 static char *FunctionDef_fields[]={
42 "name",
43 "args",
44 "body",
45 "decorator_list",
47 static PyTypeObject *ClassDef_type;
48 static char *ClassDef_fields[]={
49 "name",
50 "bases",
51 "body",
52 "decorator_list",
54 static PyTypeObject *Return_type;
55 static char *Return_fields[]={
56 "value",
58 static PyTypeObject *Delete_type;
59 static char *Delete_fields[]={
60 "targets",
62 static PyTypeObject *Assign_type;
63 static char *Assign_fields[]={
64 "targets",
65 "value",
67 static PyTypeObject *AugAssign_type;
68 static char *AugAssign_fields[]={
69 "target",
70 "op",
71 "value",
73 static PyTypeObject *Print_type;
74 static char *Print_fields[]={
75 "dest",
76 "values",
77 "nl",
79 static PyTypeObject *For_type;
80 static char *For_fields[]={
81 "target",
82 "iter",
83 "body",
84 "orelse",
86 static PyTypeObject *While_type;
87 static char *While_fields[]={
88 "test",
89 "body",
90 "orelse",
92 static PyTypeObject *If_type;
93 static char *If_fields[]={
94 "test",
95 "body",
96 "orelse",
98 static PyTypeObject *With_type;
99 static char *With_fields[]={
100 "context_expr",
101 "optional_vars",
102 "body",
104 static PyTypeObject *Raise_type;
105 static char *Raise_fields[]={
106 "type",
107 "inst",
108 "tback",
110 static PyTypeObject *TryExcept_type;
111 static char *TryExcept_fields[]={
112 "body",
113 "handlers",
114 "orelse",
116 static PyTypeObject *TryFinally_type;
117 static char *TryFinally_fields[]={
118 "body",
119 "finalbody",
121 static PyTypeObject *Assert_type;
122 static char *Assert_fields[]={
123 "test",
124 "msg",
126 static PyTypeObject *Import_type;
127 static char *Import_fields[]={
128 "names",
130 static PyTypeObject *ImportFrom_type;
131 static char *ImportFrom_fields[]={
132 "module",
133 "names",
134 "level",
136 static PyTypeObject *Exec_type;
137 static char *Exec_fields[]={
138 "body",
139 "globals",
140 "locals",
142 static PyTypeObject *Global_type;
143 static char *Global_fields[]={
144 "names",
146 static PyTypeObject *Expr_type;
147 static char *Expr_fields[]={
148 "value",
150 static PyTypeObject *Pass_type;
151 static PyTypeObject *Break_type;
152 static PyTypeObject *Continue_type;
153 static PyTypeObject *expr_type;
154 static char *expr_attributes[] = {
155 "lineno",
156 "col_offset",
158 static PyObject* ast2obj_expr(void*);
159 static PyTypeObject *BoolOp_type;
160 static char *BoolOp_fields[]={
161 "op",
162 "values",
164 static PyTypeObject *BinOp_type;
165 static char *BinOp_fields[]={
166 "left",
167 "op",
168 "right",
170 static PyTypeObject *UnaryOp_type;
171 static char *UnaryOp_fields[]={
172 "op",
173 "operand",
175 static PyTypeObject *Lambda_type;
176 static char *Lambda_fields[]={
177 "args",
178 "body",
180 static PyTypeObject *IfExp_type;
181 static char *IfExp_fields[]={
182 "test",
183 "body",
184 "orelse",
186 static PyTypeObject *Dict_type;
187 static char *Dict_fields[]={
188 "keys",
189 "values",
191 static PyTypeObject *ListComp_type;
192 static char *ListComp_fields[]={
193 "elt",
194 "generators",
196 static PyTypeObject *GeneratorExp_type;
197 static char *GeneratorExp_fields[]={
198 "elt",
199 "generators",
201 static PyTypeObject *Yield_type;
202 static char *Yield_fields[]={
203 "value",
205 static PyTypeObject *Compare_type;
206 static char *Compare_fields[]={
207 "left",
208 "ops",
209 "comparators",
211 static PyTypeObject *Call_type;
212 static char *Call_fields[]={
213 "func",
214 "args",
215 "keywords",
216 "starargs",
217 "kwargs",
219 static PyTypeObject *Repr_type;
220 static char *Repr_fields[]={
221 "value",
223 static PyTypeObject *Num_type;
224 static char *Num_fields[]={
225 "n",
227 static PyTypeObject *Str_type;
228 static char *Str_fields[]={
229 "s",
231 static PyTypeObject *Attribute_type;
232 static char *Attribute_fields[]={
233 "value",
234 "attr",
235 "ctx",
237 static PyTypeObject *Subscript_type;
238 static char *Subscript_fields[]={
239 "value",
240 "slice",
241 "ctx",
243 static PyTypeObject *Name_type;
244 static char *Name_fields[]={
245 "id",
246 "ctx",
248 static PyTypeObject *List_type;
249 static char *List_fields[]={
250 "elts",
251 "ctx",
253 static PyTypeObject *Tuple_type;
254 static char *Tuple_fields[]={
255 "elts",
256 "ctx",
258 static PyTypeObject *expr_context_type;
259 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
260 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
261 static PyObject* ast2obj_expr_context(expr_context_ty);
262 static PyTypeObject *Load_type;
263 static PyTypeObject *Store_type;
264 static PyTypeObject *Del_type;
265 static PyTypeObject *AugLoad_type;
266 static PyTypeObject *AugStore_type;
267 static PyTypeObject *Param_type;
268 static PyTypeObject *slice_type;
269 static PyObject* ast2obj_slice(void*);
270 static PyTypeObject *Ellipsis_type;
271 static PyTypeObject *Slice_type;
272 static char *Slice_fields[]={
273 "lower",
274 "upper",
275 "step",
277 static PyTypeObject *ExtSlice_type;
278 static char *ExtSlice_fields[]={
279 "dims",
281 static PyTypeObject *Index_type;
282 static char *Index_fields[]={
283 "value",
285 static PyTypeObject *boolop_type;
286 static PyObject *And_singleton, *Or_singleton;
287 static PyObject* ast2obj_boolop(boolop_ty);
288 static PyTypeObject *And_type;
289 static PyTypeObject *Or_type;
290 static PyTypeObject *operator_type;
291 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
292 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
293 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
294 *FloorDiv_singleton;
295 static PyObject* ast2obj_operator(operator_ty);
296 static PyTypeObject *Add_type;
297 static PyTypeObject *Sub_type;
298 static PyTypeObject *Mult_type;
299 static PyTypeObject *Div_type;
300 static PyTypeObject *Mod_type;
301 static PyTypeObject *Pow_type;
302 static PyTypeObject *LShift_type;
303 static PyTypeObject *RShift_type;
304 static PyTypeObject *BitOr_type;
305 static PyTypeObject *BitXor_type;
306 static PyTypeObject *BitAnd_type;
307 static PyTypeObject *FloorDiv_type;
308 static PyTypeObject *unaryop_type;
309 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
310 *USub_singleton;
311 static PyObject* ast2obj_unaryop(unaryop_ty);
312 static PyTypeObject *Invert_type;
313 static PyTypeObject *Not_type;
314 static PyTypeObject *UAdd_type;
315 static PyTypeObject *USub_type;
316 static PyTypeObject *cmpop_type;
317 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
318 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
319 *NotIn_singleton;
320 static PyObject* ast2obj_cmpop(cmpop_ty);
321 static PyTypeObject *Eq_type;
322 static PyTypeObject *NotEq_type;
323 static PyTypeObject *Lt_type;
324 static PyTypeObject *LtE_type;
325 static PyTypeObject *Gt_type;
326 static PyTypeObject *GtE_type;
327 static PyTypeObject *Is_type;
328 static PyTypeObject *IsNot_type;
329 static PyTypeObject *In_type;
330 static PyTypeObject *NotIn_type;
331 static PyTypeObject *comprehension_type;
332 static PyObject* ast2obj_comprehension(void*);
333 static char *comprehension_fields[]={
334 "target",
335 "iter",
336 "ifs",
338 static PyTypeObject *excepthandler_type;
339 static char *excepthandler_attributes[] = {
340 "lineno",
341 "col_offset",
343 static PyObject* ast2obj_excepthandler(void*);
344 static PyTypeObject *ExceptHandler_type;
345 static char *ExceptHandler_fields[]={
346 "type",
347 "name",
348 "body",
350 static PyTypeObject *arguments_type;
351 static PyObject* ast2obj_arguments(void*);
352 static char *arguments_fields[]={
353 "args",
354 "vararg",
355 "kwarg",
356 "defaults",
358 static PyTypeObject *keyword_type;
359 static PyObject* ast2obj_keyword(void*);
360 static char *keyword_fields[]={
361 "arg",
362 "value",
364 static PyTypeObject *alias_type;
365 static PyObject* ast2obj_alias(void*);
366 static char *alias_fields[]={
367 "name",
368 "asname",
372 static int
373 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
375 Py_ssize_t i, numfields = 0;
376 int res = -1;
377 PyObject *key, *value, *fields;
378 fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
379 if (!fields)
380 PyErr_Clear();
381 if (fields) {
382 numfields = PySequence_Size(fields);
383 if (numfields == -1)
384 goto cleanup;
386 res = 0; /* if no error occurs, this stays 0 to the end */
387 if (PyTuple_GET_SIZE(args) > 0) {
388 if (numfields != PyTuple_GET_SIZE(args)) {
389 PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
390 "%" PY_FORMAT_SIZE_T "d positional argument%s",
391 Py_TYPE(self)->tp_name,
392 numfields == 0 ? "" : "either 0 or ",
393 numfields, numfields == 1 ? "" : "s");
394 res = -1;
395 goto cleanup;
397 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
398 /* cannot be reached when fields is NULL */
399 PyObject *name = PySequence_GetItem(fields, i);
400 if (!name) {
401 res = -1;
402 goto cleanup;
404 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
405 Py_DECREF(name);
406 if (res < 0)
407 goto cleanup;
410 if (kw) {
411 i = 0; /* needed by PyDict_Next */
412 while (PyDict_Next(kw, &i, &key, &value)) {
413 res = PyObject_SetAttr(self, key, value);
414 if (res < 0)
415 goto cleanup;
418 cleanup:
419 Py_XDECREF(fields);
420 return res;
423 /* Pickling support */
424 static PyObject *
425 ast_type_reduce(PyObject *self, PyObject *unused)
427 PyObject *res;
428 PyObject *dict = PyObject_GetAttrString(self, "__dict__");
429 if (dict == NULL) {
430 if (PyErr_ExceptionMatches(PyExc_AttributeError))
431 PyErr_Clear();
432 else
433 return NULL;
435 if (dict) {
436 res = Py_BuildValue("O()O", Py_TYPE(self), dict);
437 Py_DECREF(dict);
438 return res;
440 return Py_BuildValue("O()", Py_TYPE(self));
443 static PyMethodDef ast_type_methods[] = {
444 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
445 {NULL}
448 static PyTypeObject AST_type = {
449 PyVarObject_HEAD_INIT(&PyType_Type, 0)
450 "_ast.AST",
451 sizeof(PyObject),
453 0, /* tp_dealloc */
454 0, /* tp_print */
455 0, /* tp_getattr */
456 0, /* tp_setattr */
457 0, /* tp_compare */
458 0, /* tp_repr */
459 0, /* tp_as_number */
460 0, /* tp_as_sequence */
461 0, /* tp_as_mapping */
462 0, /* tp_hash */
463 0, /* tp_call */
464 0, /* tp_str */
465 PyObject_GenericGetAttr, /* tp_getattro */
466 PyObject_GenericSetAttr, /* tp_setattro */
467 0, /* tp_as_buffer */
468 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
469 0, /* tp_doc */
470 0, /* tp_traverse */
471 0, /* tp_clear */
472 0, /* tp_richcompare */
473 0, /* tp_weaklistoffset */
474 0, /* tp_iter */
475 0, /* tp_iternext */
476 ast_type_methods, /* tp_methods */
477 0, /* tp_members */
478 0, /* tp_getset */
479 0, /* tp_base */
480 0, /* tp_dict */
481 0, /* tp_descr_get */
482 0, /* tp_descr_set */
483 0, /* tp_dictoffset */
484 (initproc)ast_type_init, /* tp_init */
485 PyType_GenericAlloc, /* tp_alloc */
486 PyType_GenericNew, /* tp_new */
487 PyObject_Del, /* tp_free */
491 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
493 PyObject *fnames, *result;
494 int i;
495 fnames = PyTuple_New(num_fields);
496 if (!fnames) return NULL;
497 for (i = 0; i < num_fields; i++) {
498 PyObject *field = PyString_FromString(fields[i]);
499 if (!field) {
500 Py_DECREF(fnames);
501 return NULL;
503 PyTuple_SET_ITEM(fnames, i, field);
505 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
506 type, base, "_fields", fnames, "__module__", "_ast");
507 Py_DECREF(fnames);
508 return (PyTypeObject*)result;
511 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
513 int i, result;
514 PyObject *s, *l = PyTuple_New(num_fields);
515 if (!l) return 0;
516 for(i = 0; i < num_fields; i++) {
517 s = PyString_FromString(attrs[i]);
518 if (!s) {
519 Py_DECREF(l);
520 return 0;
522 PyTuple_SET_ITEM(l, i, s);
524 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
525 Py_DECREF(l);
526 return result;
529 /* Conversion AST -> Python */
531 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
533 int i, n = asdl_seq_LEN(seq);
534 PyObject *result = PyList_New(n);
535 PyObject *value;
536 if (!result)
537 return NULL;
538 for (i = 0; i < n; i++) {
539 value = func(asdl_seq_GET(seq, i));
540 if (!value) {
541 Py_DECREF(result);
542 return NULL;
544 PyList_SET_ITEM(result, i, value);
546 return result;
549 static PyObject* ast2obj_object(void *o)
551 if (!o)
552 o = Py_None;
553 Py_INCREF((PyObject*)o);
554 return (PyObject*)o;
556 #define ast2obj_identifier ast2obj_object
557 #define ast2obj_string ast2obj_object
558 static PyObject* ast2obj_bool(bool b)
560 return PyBool_FromLong(b);
563 static PyObject* ast2obj_int(long b)
565 return PyInt_FromLong(b);
568 /* Conversion Python -> AST */
570 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
572 if (obj == Py_None)
573 obj = NULL;
574 if (obj)
575 PyArena_AddPyObject(arena, obj);
576 Py_XINCREF(obj);
577 *out = obj;
578 return 0;
581 #define obj2ast_identifier obj2ast_object
582 #define obj2ast_string obj2ast_object
584 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
586 int i;
587 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
588 PyObject *s = PyObject_Repr(obj);
589 if (s == NULL) return 1;
590 PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
591 PyString_AS_STRING(s));
592 Py_DECREF(s);
593 return 1;
596 i = (int)PyLong_AsLong(obj);
597 if (i == -1 && PyErr_Occurred())
598 return 1;
599 *out = i;
600 return 0;
603 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
605 if (!PyBool_Check(obj)) {
606 PyObject *s = PyObject_Repr(obj);
607 if (s == NULL) return 1;
608 PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
609 PyString_AS_STRING(s));
610 Py_DECREF(s);
611 return 1;
614 *out = (obj == Py_True);
615 return 0;
619 static int init_types(void)
621 static int initialized;
622 if (initialized) return 1;
623 mod_type = make_type("mod", &AST_type, NULL, 0);
624 if (!mod_type) return 0;
625 if (!add_attributes(mod_type, NULL, 0)) return 0;
626 Module_type = make_type("Module", mod_type, Module_fields, 1);
627 if (!Module_type) return 0;
628 Interactive_type = make_type("Interactive", mod_type,
629 Interactive_fields, 1);
630 if (!Interactive_type) return 0;
631 Expression_type = make_type("Expression", mod_type, Expression_fields,
633 if (!Expression_type) return 0;
634 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
635 if (!Suite_type) return 0;
636 stmt_type = make_type("stmt", &AST_type, NULL, 0);
637 if (!stmt_type) return 0;
638 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
639 FunctionDef_type = make_type("FunctionDef", stmt_type,
640 FunctionDef_fields, 4);
641 if (!FunctionDef_type) return 0;
642 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
643 if (!ClassDef_type) return 0;
644 Return_type = make_type("Return", stmt_type, Return_fields, 1);
645 if (!Return_type) return 0;
646 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
647 if (!Delete_type) return 0;
648 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
649 if (!Assign_type) return 0;
650 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
651 if (!AugAssign_type) return 0;
652 Print_type = make_type("Print", stmt_type, Print_fields, 3);
653 if (!Print_type) return 0;
654 For_type = make_type("For", stmt_type, For_fields, 4);
655 if (!For_type) return 0;
656 While_type = make_type("While", stmt_type, While_fields, 3);
657 if (!While_type) return 0;
658 If_type = make_type("If", stmt_type, If_fields, 3);
659 if (!If_type) return 0;
660 With_type = make_type("With", stmt_type, With_fields, 3);
661 if (!With_type) return 0;
662 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
663 if (!Raise_type) return 0;
664 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
665 if (!TryExcept_type) return 0;
666 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
668 if (!TryFinally_type) return 0;
669 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
670 if (!Assert_type) return 0;
671 Import_type = make_type("Import", stmt_type, Import_fields, 1);
672 if (!Import_type) return 0;
673 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
675 if (!ImportFrom_type) return 0;
676 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
677 if (!Exec_type) return 0;
678 Global_type = make_type("Global", stmt_type, Global_fields, 1);
679 if (!Global_type) return 0;
680 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
681 if (!Expr_type) return 0;
682 Pass_type = make_type("Pass", stmt_type, NULL, 0);
683 if (!Pass_type) return 0;
684 Break_type = make_type("Break", stmt_type, NULL, 0);
685 if (!Break_type) return 0;
686 Continue_type = make_type("Continue", stmt_type, NULL, 0);
687 if (!Continue_type) return 0;
688 expr_type = make_type("expr", &AST_type, NULL, 0);
689 if (!expr_type) return 0;
690 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
691 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
692 if (!BoolOp_type) return 0;
693 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
694 if (!BinOp_type) return 0;
695 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
696 if (!UnaryOp_type) return 0;
697 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
698 if (!Lambda_type) return 0;
699 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
700 if (!IfExp_type) return 0;
701 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
702 if (!Dict_type) return 0;
703 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
704 if (!ListComp_type) return 0;
705 GeneratorExp_type = make_type("GeneratorExp", expr_type,
706 GeneratorExp_fields, 2);
707 if (!GeneratorExp_type) return 0;
708 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
709 if (!Yield_type) return 0;
710 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
711 if (!Compare_type) return 0;
712 Call_type = make_type("Call", expr_type, Call_fields, 5);
713 if (!Call_type) return 0;
714 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
715 if (!Repr_type) return 0;
716 Num_type = make_type("Num", expr_type, Num_fields, 1);
717 if (!Num_type) return 0;
718 Str_type = make_type("Str", expr_type, Str_fields, 1);
719 if (!Str_type) return 0;
720 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
721 if (!Attribute_type) return 0;
722 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
723 if (!Subscript_type) return 0;
724 Name_type = make_type("Name", expr_type, Name_fields, 2);
725 if (!Name_type) return 0;
726 List_type = make_type("List", expr_type, List_fields, 2);
727 if (!List_type) return 0;
728 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
729 if (!Tuple_type) return 0;
730 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
731 if (!expr_context_type) return 0;
732 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
733 Load_type = make_type("Load", expr_context_type, NULL, 0);
734 if (!Load_type) return 0;
735 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
736 if (!Load_singleton) return 0;
737 Store_type = make_type("Store", expr_context_type, NULL, 0);
738 if (!Store_type) return 0;
739 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
740 if (!Store_singleton) return 0;
741 Del_type = make_type("Del", expr_context_type, NULL, 0);
742 if (!Del_type) return 0;
743 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
744 if (!Del_singleton) return 0;
745 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
746 if (!AugLoad_type) return 0;
747 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
748 if (!AugLoad_singleton) return 0;
749 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
750 if (!AugStore_type) return 0;
751 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
752 if (!AugStore_singleton) return 0;
753 Param_type = make_type("Param", expr_context_type, NULL, 0);
754 if (!Param_type) return 0;
755 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
756 if (!Param_singleton) return 0;
757 slice_type = make_type("slice", &AST_type, NULL, 0);
758 if (!slice_type) return 0;
759 if (!add_attributes(slice_type, NULL, 0)) return 0;
760 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
761 if (!Ellipsis_type) return 0;
762 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
763 if (!Slice_type) return 0;
764 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
765 if (!ExtSlice_type) return 0;
766 Index_type = make_type("Index", slice_type, Index_fields, 1);
767 if (!Index_type) return 0;
768 boolop_type = make_type("boolop", &AST_type, NULL, 0);
769 if (!boolop_type) return 0;
770 if (!add_attributes(boolop_type, NULL, 0)) return 0;
771 And_type = make_type("And", boolop_type, NULL, 0);
772 if (!And_type) return 0;
773 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
774 if (!And_singleton) return 0;
775 Or_type = make_type("Or", boolop_type, NULL, 0);
776 if (!Or_type) return 0;
777 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
778 if (!Or_singleton) return 0;
779 operator_type = make_type("operator", &AST_type, NULL, 0);
780 if (!operator_type) return 0;
781 if (!add_attributes(operator_type, NULL, 0)) return 0;
782 Add_type = make_type("Add", operator_type, NULL, 0);
783 if (!Add_type) return 0;
784 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
785 if (!Add_singleton) return 0;
786 Sub_type = make_type("Sub", operator_type, NULL, 0);
787 if (!Sub_type) return 0;
788 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
789 if (!Sub_singleton) return 0;
790 Mult_type = make_type("Mult", operator_type, NULL, 0);
791 if (!Mult_type) return 0;
792 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
793 if (!Mult_singleton) return 0;
794 Div_type = make_type("Div", operator_type, NULL, 0);
795 if (!Div_type) return 0;
796 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
797 if (!Div_singleton) return 0;
798 Mod_type = make_type("Mod", operator_type, NULL, 0);
799 if (!Mod_type) return 0;
800 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
801 if (!Mod_singleton) return 0;
802 Pow_type = make_type("Pow", operator_type, NULL, 0);
803 if (!Pow_type) return 0;
804 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
805 if (!Pow_singleton) return 0;
806 LShift_type = make_type("LShift", operator_type, NULL, 0);
807 if (!LShift_type) return 0;
808 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
809 if (!LShift_singleton) return 0;
810 RShift_type = make_type("RShift", operator_type, NULL, 0);
811 if (!RShift_type) return 0;
812 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
813 if (!RShift_singleton) return 0;
814 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
815 if (!BitOr_type) return 0;
816 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
817 if (!BitOr_singleton) return 0;
818 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
819 if (!BitXor_type) return 0;
820 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
821 if (!BitXor_singleton) return 0;
822 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
823 if (!BitAnd_type) return 0;
824 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
825 if (!BitAnd_singleton) return 0;
826 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
827 if (!FloorDiv_type) return 0;
828 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
829 if (!FloorDiv_singleton) return 0;
830 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
831 if (!unaryop_type) return 0;
832 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
833 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
834 if (!Invert_type) return 0;
835 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
836 if (!Invert_singleton) return 0;
837 Not_type = make_type("Not", unaryop_type, NULL, 0);
838 if (!Not_type) return 0;
839 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
840 if (!Not_singleton) return 0;
841 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
842 if (!UAdd_type) return 0;
843 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
844 if (!UAdd_singleton) return 0;
845 USub_type = make_type("USub", unaryop_type, NULL, 0);
846 if (!USub_type) return 0;
847 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
848 if (!USub_singleton) return 0;
849 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
850 if (!cmpop_type) return 0;
851 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
852 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
853 if (!Eq_type) return 0;
854 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
855 if (!Eq_singleton) return 0;
856 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
857 if (!NotEq_type) return 0;
858 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
859 if (!NotEq_singleton) return 0;
860 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
861 if (!Lt_type) return 0;
862 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
863 if (!Lt_singleton) return 0;
864 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
865 if (!LtE_type) return 0;
866 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
867 if (!LtE_singleton) return 0;
868 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
869 if (!Gt_type) return 0;
870 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
871 if (!Gt_singleton) return 0;
872 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
873 if (!GtE_type) return 0;
874 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
875 if (!GtE_singleton) return 0;
876 Is_type = make_type("Is", cmpop_type, NULL, 0);
877 if (!Is_type) return 0;
878 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
879 if (!Is_singleton) return 0;
880 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
881 if (!IsNot_type) return 0;
882 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
883 if (!IsNot_singleton) return 0;
884 In_type = make_type("In", cmpop_type, NULL, 0);
885 if (!In_type) return 0;
886 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
887 if (!In_singleton) return 0;
888 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
889 if (!NotIn_type) return 0;
890 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
891 if (!NotIn_singleton) return 0;
892 comprehension_type = make_type("comprehension", &AST_type,
893 comprehension_fields, 3);
894 if (!comprehension_type) return 0;
895 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
896 if (!excepthandler_type) return 0;
897 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
898 return 0;
899 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
900 ExceptHandler_fields, 3);
901 if (!ExceptHandler_type) return 0;
902 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
903 if (!arguments_type) return 0;
904 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
905 if (!keyword_type) return 0;
906 alias_type = make_type("alias", &AST_type, alias_fields, 2);
907 if (!alias_type) return 0;
908 initialized = 1;
909 return 1;
912 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
913 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
914 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
915 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
916 arena);
917 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
918 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
919 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
920 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
921 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
922 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
923 arena);
924 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
925 arena);
926 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
927 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
928 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
930 mod_ty
931 Module(asdl_seq * body, PyArena *arena)
933 mod_ty p;
934 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
935 if (!p)
936 return NULL;
937 p->kind = Module_kind;
938 p->v.Module.body = body;
939 return p;
942 mod_ty
943 Interactive(asdl_seq * body, PyArena *arena)
945 mod_ty p;
946 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
947 if (!p)
948 return NULL;
949 p->kind = Interactive_kind;
950 p->v.Interactive.body = body;
951 return p;
954 mod_ty
955 Expression(expr_ty body, PyArena *arena)
957 mod_ty p;
958 if (!body) {
959 PyErr_SetString(PyExc_ValueError,
960 "field body is required for Expression");
961 return NULL;
963 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
964 if (!p)
965 return NULL;
966 p->kind = Expression_kind;
967 p->v.Expression.body = body;
968 return p;
971 mod_ty
972 Suite(asdl_seq * body, PyArena *arena)
974 mod_ty p;
975 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
976 if (!p)
977 return NULL;
978 p->kind = Suite_kind;
979 p->v.Suite.body = body;
980 return p;
983 stmt_ty
984 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
985 decorator_list, int lineno, int col_offset, PyArena *arena)
987 stmt_ty p;
988 if (!name) {
989 PyErr_SetString(PyExc_ValueError,
990 "field name is required for FunctionDef");
991 return NULL;
993 if (!args) {
994 PyErr_SetString(PyExc_ValueError,
995 "field args is required for FunctionDef");
996 return NULL;
998 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
999 if (!p)
1000 return NULL;
1001 p->kind = FunctionDef_kind;
1002 p->v.FunctionDef.name = name;
1003 p->v.FunctionDef.args = args;
1004 p->v.FunctionDef.body = body;
1005 p->v.FunctionDef.decorator_list = decorator_list;
1006 p->lineno = lineno;
1007 p->col_offset = col_offset;
1008 return p;
1011 stmt_ty
1012 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
1013 decorator_list, int lineno, int col_offset, PyArena *arena)
1015 stmt_ty p;
1016 if (!name) {
1017 PyErr_SetString(PyExc_ValueError,
1018 "field name is required for ClassDef");
1019 return NULL;
1021 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1022 if (!p)
1023 return NULL;
1024 p->kind = ClassDef_kind;
1025 p->v.ClassDef.name = name;
1026 p->v.ClassDef.bases = bases;
1027 p->v.ClassDef.body = body;
1028 p->v.ClassDef.decorator_list = decorator_list;
1029 p->lineno = lineno;
1030 p->col_offset = col_offset;
1031 return p;
1034 stmt_ty
1035 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
1037 stmt_ty p;
1038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1039 if (!p)
1040 return NULL;
1041 p->kind = Return_kind;
1042 p->v.Return.value = value;
1043 p->lineno = lineno;
1044 p->col_offset = col_offset;
1045 return p;
1048 stmt_ty
1049 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
1051 stmt_ty p;
1052 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1053 if (!p)
1054 return NULL;
1055 p->kind = Delete_kind;
1056 p->v.Delete.targets = targets;
1057 p->lineno = lineno;
1058 p->col_offset = col_offset;
1059 return p;
1062 stmt_ty
1063 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1064 *arena)
1066 stmt_ty p;
1067 if (!value) {
1068 PyErr_SetString(PyExc_ValueError,
1069 "field value is required for Assign");
1070 return NULL;
1072 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1073 if (!p)
1074 return NULL;
1075 p->kind = Assign_kind;
1076 p->v.Assign.targets = targets;
1077 p->v.Assign.value = value;
1078 p->lineno = lineno;
1079 p->col_offset = col_offset;
1080 return p;
1083 stmt_ty
1084 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1085 col_offset, PyArena *arena)
1087 stmt_ty p;
1088 if (!target) {
1089 PyErr_SetString(PyExc_ValueError,
1090 "field target is required for AugAssign");
1091 return NULL;
1093 if (!op) {
1094 PyErr_SetString(PyExc_ValueError,
1095 "field op is required for AugAssign");
1096 return NULL;
1098 if (!value) {
1099 PyErr_SetString(PyExc_ValueError,
1100 "field value is required for AugAssign");
1101 return NULL;
1103 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1104 if (!p)
1105 return NULL;
1106 p->kind = AugAssign_kind;
1107 p->v.AugAssign.target = target;
1108 p->v.AugAssign.op = op;
1109 p->v.AugAssign.value = value;
1110 p->lineno = lineno;
1111 p->col_offset = col_offset;
1112 return p;
1115 stmt_ty
1116 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
1117 PyArena *arena)
1119 stmt_ty p;
1120 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1121 if (!p)
1122 return NULL;
1123 p->kind = Print_kind;
1124 p->v.Print.dest = dest;
1125 p->v.Print.values = values;
1126 p->v.Print.nl = nl;
1127 p->lineno = lineno;
1128 p->col_offset = col_offset;
1129 return p;
1132 stmt_ty
1133 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1134 lineno, int col_offset, PyArena *arena)
1136 stmt_ty p;
1137 if (!target) {
1138 PyErr_SetString(PyExc_ValueError,
1139 "field target is required for For");
1140 return NULL;
1142 if (!iter) {
1143 PyErr_SetString(PyExc_ValueError,
1144 "field iter is required for For");
1145 return NULL;
1147 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1148 if (!p)
1149 return NULL;
1150 p->kind = For_kind;
1151 p->v.For.target = target;
1152 p->v.For.iter = iter;
1153 p->v.For.body = body;
1154 p->v.For.orelse = orelse;
1155 p->lineno = lineno;
1156 p->col_offset = col_offset;
1157 return p;
1160 stmt_ty
1161 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1162 col_offset, PyArena *arena)
1164 stmt_ty p;
1165 if (!test) {
1166 PyErr_SetString(PyExc_ValueError,
1167 "field test is required for While");
1168 return NULL;
1170 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1171 if (!p)
1172 return NULL;
1173 p->kind = While_kind;
1174 p->v.While.test = test;
1175 p->v.While.body = body;
1176 p->v.While.orelse = orelse;
1177 p->lineno = lineno;
1178 p->col_offset = col_offset;
1179 return p;
1182 stmt_ty
1183 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1184 col_offset, PyArena *arena)
1186 stmt_ty p;
1187 if (!test) {
1188 PyErr_SetString(PyExc_ValueError,
1189 "field test is required for If");
1190 return NULL;
1192 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1193 if (!p)
1194 return NULL;
1195 p->kind = If_kind;
1196 p->v.If.test = test;
1197 p->v.If.body = body;
1198 p->v.If.orelse = orelse;
1199 p->lineno = lineno;
1200 p->col_offset = col_offset;
1201 return p;
1204 stmt_ty
1205 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1206 int col_offset, PyArena *arena)
1208 stmt_ty p;
1209 if (!context_expr) {
1210 PyErr_SetString(PyExc_ValueError,
1211 "field context_expr is required for With");
1212 return NULL;
1214 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1215 if (!p)
1216 return NULL;
1217 p->kind = With_kind;
1218 p->v.With.context_expr = context_expr;
1219 p->v.With.optional_vars = optional_vars;
1220 p->v.With.body = body;
1221 p->lineno = lineno;
1222 p->col_offset = col_offset;
1223 return p;
1226 stmt_ty
1227 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1228 PyArena *arena)
1230 stmt_ty p;
1231 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1232 if (!p)
1233 return NULL;
1234 p->kind = Raise_kind;
1235 p->v.Raise.type = type;
1236 p->v.Raise.inst = inst;
1237 p->v.Raise.tback = tback;
1238 p->lineno = lineno;
1239 p->col_offset = col_offset;
1240 return p;
1243 stmt_ty
1244 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1245 int col_offset, PyArena *arena)
1247 stmt_ty p;
1248 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1249 if (!p)
1250 return NULL;
1251 p->kind = TryExcept_kind;
1252 p->v.TryExcept.body = body;
1253 p->v.TryExcept.handlers = handlers;
1254 p->v.TryExcept.orelse = orelse;
1255 p->lineno = lineno;
1256 p->col_offset = col_offset;
1257 return p;
1260 stmt_ty
1261 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1262 PyArena *arena)
1264 stmt_ty p;
1265 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1266 if (!p)
1267 return NULL;
1268 p->kind = TryFinally_kind;
1269 p->v.TryFinally.body = body;
1270 p->v.TryFinally.finalbody = finalbody;
1271 p->lineno = lineno;
1272 p->col_offset = col_offset;
1273 return p;
1276 stmt_ty
1277 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1279 stmt_ty p;
1280 if (!test) {
1281 PyErr_SetString(PyExc_ValueError,
1282 "field test is required for Assert");
1283 return NULL;
1285 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1286 if (!p)
1287 return NULL;
1288 p->kind = Assert_kind;
1289 p->v.Assert.test = test;
1290 p->v.Assert.msg = msg;
1291 p->lineno = lineno;
1292 p->col_offset = col_offset;
1293 return p;
1296 stmt_ty
1297 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1299 stmt_ty p;
1300 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1301 if (!p)
1302 return NULL;
1303 p->kind = Import_kind;
1304 p->v.Import.names = names;
1305 p->lineno = lineno;
1306 p->col_offset = col_offset;
1307 return p;
1310 stmt_ty
1311 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1312 col_offset, PyArena *arena)
1314 stmt_ty p;
1315 if (!module) {
1316 PyErr_SetString(PyExc_ValueError,
1317 "field module is required for ImportFrom");
1318 return NULL;
1320 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1321 if (!p)
1322 return NULL;
1323 p->kind = ImportFrom_kind;
1324 p->v.ImportFrom.module = module;
1325 p->v.ImportFrom.names = names;
1326 p->v.ImportFrom.level = level;
1327 p->lineno = lineno;
1328 p->col_offset = col_offset;
1329 return p;
1332 stmt_ty
1333 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1334 PyArena *arena)
1336 stmt_ty p;
1337 if (!body) {
1338 PyErr_SetString(PyExc_ValueError,
1339 "field body is required for Exec");
1340 return NULL;
1342 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1343 if (!p)
1344 return NULL;
1345 p->kind = Exec_kind;
1346 p->v.Exec.body = body;
1347 p->v.Exec.globals = globals;
1348 p->v.Exec.locals = locals;
1349 p->lineno = lineno;
1350 p->col_offset = col_offset;
1351 return p;
1354 stmt_ty
1355 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1357 stmt_ty p;
1358 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1359 if (!p)
1360 return NULL;
1361 p->kind = Global_kind;
1362 p->v.Global.names = names;
1363 p->lineno = lineno;
1364 p->col_offset = col_offset;
1365 return p;
1368 stmt_ty
1369 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1371 stmt_ty p;
1372 if (!value) {
1373 PyErr_SetString(PyExc_ValueError,
1374 "field value is required for Expr");
1375 return NULL;
1377 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1378 if (!p)
1379 return NULL;
1380 p->kind = Expr_kind;
1381 p->v.Expr.value = value;
1382 p->lineno = lineno;
1383 p->col_offset = col_offset;
1384 return p;
1387 stmt_ty
1388 Pass(int lineno, int col_offset, PyArena *arena)
1390 stmt_ty p;
1391 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1392 if (!p)
1393 return NULL;
1394 p->kind = Pass_kind;
1395 p->lineno = lineno;
1396 p->col_offset = col_offset;
1397 return p;
1400 stmt_ty
1401 Break(int lineno, int col_offset, PyArena *arena)
1403 stmt_ty p;
1404 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1405 if (!p)
1406 return NULL;
1407 p->kind = Break_kind;
1408 p->lineno = lineno;
1409 p->col_offset = col_offset;
1410 return p;
1413 stmt_ty
1414 Continue(int lineno, int col_offset, PyArena *arena)
1416 stmt_ty p;
1417 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1418 if (!p)
1419 return NULL;
1420 p->kind = Continue_kind;
1421 p->lineno = lineno;
1422 p->col_offset = col_offset;
1423 return p;
1426 expr_ty
1427 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1428 *arena)
1430 expr_ty p;
1431 if (!op) {
1432 PyErr_SetString(PyExc_ValueError,
1433 "field op is required for BoolOp");
1434 return NULL;
1436 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1437 if (!p)
1438 return NULL;
1439 p->kind = BoolOp_kind;
1440 p->v.BoolOp.op = op;
1441 p->v.BoolOp.values = values;
1442 p->lineno = lineno;
1443 p->col_offset = col_offset;
1444 return p;
1447 expr_ty
1448 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1449 PyArena *arena)
1451 expr_ty p;
1452 if (!left) {
1453 PyErr_SetString(PyExc_ValueError,
1454 "field left is required for BinOp");
1455 return NULL;
1457 if (!op) {
1458 PyErr_SetString(PyExc_ValueError,
1459 "field op is required for BinOp");
1460 return NULL;
1462 if (!right) {
1463 PyErr_SetString(PyExc_ValueError,
1464 "field right is required for BinOp");
1465 return NULL;
1467 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1468 if (!p)
1469 return NULL;
1470 p->kind = BinOp_kind;
1471 p->v.BinOp.left = left;
1472 p->v.BinOp.op = op;
1473 p->v.BinOp.right = right;
1474 p->lineno = lineno;
1475 p->col_offset = col_offset;
1476 return p;
1479 expr_ty
1480 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1481 *arena)
1483 expr_ty p;
1484 if (!op) {
1485 PyErr_SetString(PyExc_ValueError,
1486 "field op is required for UnaryOp");
1487 return NULL;
1489 if (!operand) {
1490 PyErr_SetString(PyExc_ValueError,
1491 "field operand is required for UnaryOp");
1492 return NULL;
1494 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1495 if (!p)
1496 return NULL;
1497 p->kind = UnaryOp_kind;
1498 p->v.UnaryOp.op = op;
1499 p->v.UnaryOp.operand = operand;
1500 p->lineno = lineno;
1501 p->col_offset = col_offset;
1502 return p;
1505 expr_ty
1506 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1507 *arena)
1509 expr_ty p;
1510 if (!args) {
1511 PyErr_SetString(PyExc_ValueError,
1512 "field args is required for Lambda");
1513 return NULL;
1515 if (!body) {
1516 PyErr_SetString(PyExc_ValueError,
1517 "field body is required for Lambda");
1518 return NULL;
1520 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1521 if (!p)
1522 return NULL;
1523 p->kind = Lambda_kind;
1524 p->v.Lambda.args = args;
1525 p->v.Lambda.body = body;
1526 p->lineno = lineno;
1527 p->col_offset = col_offset;
1528 return p;
1531 expr_ty
1532 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1533 PyArena *arena)
1535 expr_ty p;
1536 if (!test) {
1537 PyErr_SetString(PyExc_ValueError,
1538 "field test is required for IfExp");
1539 return NULL;
1541 if (!body) {
1542 PyErr_SetString(PyExc_ValueError,
1543 "field body is required for IfExp");
1544 return NULL;
1546 if (!orelse) {
1547 PyErr_SetString(PyExc_ValueError,
1548 "field orelse is required for IfExp");
1549 return NULL;
1551 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1552 if (!p)
1553 return NULL;
1554 p->kind = IfExp_kind;
1555 p->v.IfExp.test = test;
1556 p->v.IfExp.body = body;
1557 p->v.IfExp.orelse = orelse;
1558 p->lineno = lineno;
1559 p->col_offset = col_offset;
1560 return p;
1563 expr_ty
1564 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1565 *arena)
1567 expr_ty p;
1568 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1569 if (!p)
1570 return NULL;
1571 p->kind = Dict_kind;
1572 p->v.Dict.keys = keys;
1573 p->v.Dict.values = values;
1574 p->lineno = lineno;
1575 p->col_offset = col_offset;
1576 return p;
1579 expr_ty
1580 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1581 PyArena *arena)
1583 expr_ty p;
1584 if (!elt) {
1585 PyErr_SetString(PyExc_ValueError,
1586 "field elt is required for ListComp");
1587 return NULL;
1589 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1590 if (!p)
1591 return NULL;
1592 p->kind = ListComp_kind;
1593 p->v.ListComp.elt = elt;
1594 p->v.ListComp.generators = generators;
1595 p->lineno = lineno;
1596 p->col_offset = col_offset;
1597 return p;
1600 expr_ty
1601 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1602 PyArena *arena)
1604 expr_ty p;
1605 if (!elt) {
1606 PyErr_SetString(PyExc_ValueError,
1607 "field elt is required for GeneratorExp");
1608 return NULL;
1610 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1611 if (!p)
1612 return NULL;
1613 p->kind = GeneratorExp_kind;
1614 p->v.GeneratorExp.elt = elt;
1615 p->v.GeneratorExp.generators = generators;
1616 p->lineno = lineno;
1617 p->col_offset = col_offset;
1618 return p;
1621 expr_ty
1622 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1624 expr_ty p;
1625 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1626 if (!p)
1627 return NULL;
1628 p->kind = Yield_kind;
1629 p->v.Yield.value = value;
1630 p->lineno = lineno;
1631 p->col_offset = col_offset;
1632 return p;
1635 expr_ty
1636 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1637 int col_offset, PyArena *arena)
1639 expr_ty p;
1640 if (!left) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field left is required for Compare");
1643 return NULL;
1645 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1646 if (!p)
1647 return NULL;
1648 p->kind = Compare_kind;
1649 p->v.Compare.left = left;
1650 p->v.Compare.ops = ops;
1651 p->v.Compare.comparators = comparators;
1652 p->lineno = lineno;
1653 p->col_offset = col_offset;
1654 return p;
1657 expr_ty
1658 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1659 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1661 expr_ty p;
1662 if (!func) {
1663 PyErr_SetString(PyExc_ValueError,
1664 "field func is required for Call");
1665 return NULL;
1667 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1668 if (!p)
1669 return NULL;
1670 p->kind = Call_kind;
1671 p->v.Call.func = func;
1672 p->v.Call.args = args;
1673 p->v.Call.keywords = keywords;
1674 p->v.Call.starargs = starargs;
1675 p->v.Call.kwargs = kwargs;
1676 p->lineno = lineno;
1677 p->col_offset = col_offset;
1678 return p;
1681 expr_ty
1682 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1684 expr_ty p;
1685 if (!value) {
1686 PyErr_SetString(PyExc_ValueError,
1687 "field value is required for Repr");
1688 return NULL;
1690 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1691 if (!p)
1692 return NULL;
1693 p->kind = Repr_kind;
1694 p->v.Repr.value = value;
1695 p->lineno = lineno;
1696 p->col_offset = col_offset;
1697 return p;
1700 expr_ty
1701 Num(object n, int lineno, int col_offset, PyArena *arena)
1703 expr_ty p;
1704 if (!n) {
1705 PyErr_SetString(PyExc_ValueError,
1706 "field n is required for Num");
1707 return NULL;
1709 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1710 if (!p)
1711 return NULL;
1712 p->kind = Num_kind;
1713 p->v.Num.n = n;
1714 p->lineno = lineno;
1715 p->col_offset = col_offset;
1716 return p;
1719 expr_ty
1720 Str(string s, int lineno, int col_offset, PyArena *arena)
1722 expr_ty p;
1723 if (!s) {
1724 PyErr_SetString(PyExc_ValueError,
1725 "field s is required for Str");
1726 return NULL;
1728 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1729 if (!p)
1730 return NULL;
1731 p->kind = Str_kind;
1732 p->v.Str.s = s;
1733 p->lineno = lineno;
1734 p->col_offset = col_offset;
1735 return p;
1738 expr_ty
1739 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1740 col_offset, PyArena *arena)
1742 expr_ty p;
1743 if (!value) {
1744 PyErr_SetString(PyExc_ValueError,
1745 "field value is required for Attribute");
1746 return NULL;
1748 if (!attr) {
1749 PyErr_SetString(PyExc_ValueError,
1750 "field attr is required for Attribute");
1751 return NULL;
1753 if (!ctx) {
1754 PyErr_SetString(PyExc_ValueError,
1755 "field ctx is required for Attribute");
1756 return NULL;
1758 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1759 if (!p)
1760 return NULL;
1761 p->kind = Attribute_kind;
1762 p->v.Attribute.value = value;
1763 p->v.Attribute.attr = attr;
1764 p->v.Attribute.ctx = ctx;
1765 p->lineno = lineno;
1766 p->col_offset = col_offset;
1767 return p;
1770 expr_ty
1771 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1772 col_offset, PyArena *arena)
1774 expr_ty p;
1775 if (!value) {
1776 PyErr_SetString(PyExc_ValueError,
1777 "field value is required for Subscript");
1778 return NULL;
1780 if (!slice) {
1781 PyErr_SetString(PyExc_ValueError,
1782 "field slice is required for Subscript");
1783 return NULL;
1785 if (!ctx) {
1786 PyErr_SetString(PyExc_ValueError,
1787 "field ctx is required for Subscript");
1788 return NULL;
1790 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1791 if (!p)
1792 return NULL;
1793 p->kind = Subscript_kind;
1794 p->v.Subscript.value = value;
1795 p->v.Subscript.slice = slice;
1796 p->v.Subscript.ctx = ctx;
1797 p->lineno = lineno;
1798 p->col_offset = col_offset;
1799 return p;
1802 expr_ty
1803 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1804 *arena)
1806 expr_ty p;
1807 if (!id) {
1808 PyErr_SetString(PyExc_ValueError,
1809 "field id is required for Name");
1810 return NULL;
1812 if (!ctx) {
1813 PyErr_SetString(PyExc_ValueError,
1814 "field ctx is required for Name");
1815 return NULL;
1817 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1818 if (!p)
1819 return NULL;
1820 p->kind = Name_kind;
1821 p->v.Name.id = id;
1822 p->v.Name.ctx = ctx;
1823 p->lineno = lineno;
1824 p->col_offset = col_offset;
1825 return p;
1828 expr_ty
1829 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1830 *arena)
1832 expr_ty p;
1833 if (!ctx) {
1834 PyErr_SetString(PyExc_ValueError,
1835 "field ctx is required for List");
1836 return NULL;
1838 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1839 if (!p)
1840 return NULL;
1841 p->kind = List_kind;
1842 p->v.List.elts = elts;
1843 p->v.List.ctx = ctx;
1844 p->lineno = lineno;
1845 p->col_offset = col_offset;
1846 return p;
1849 expr_ty
1850 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1851 *arena)
1853 expr_ty p;
1854 if (!ctx) {
1855 PyErr_SetString(PyExc_ValueError,
1856 "field ctx is required for Tuple");
1857 return NULL;
1859 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1860 if (!p)
1861 return NULL;
1862 p->kind = Tuple_kind;
1863 p->v.Tuple.elts = elts;
1864 p->v.Tuple.ctx = ctx;
1865 p->lineno = lineno;
1866 p->col_offset = col_offset;
1867 return p;
1870 slice_ty
1871 Ellipsis(PyArena *arena)
1873 slice_ty p;
1874 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1875 if (!p)
1876 return NULL;
1877 p->kind = Ellipsis_kind;
1878 return p;
1881 slice_ty
1882 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1884 slice_ty p;
1885 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1886 if (!p)
1887 return NULL;
1888 p->kind = Slice_kind;
1889 p->v.Slice.lower = lower;
1890 p->v.Slice.upper = upper;
1891 p->v.Slice.step = step;
1892 return p;
1895 slice_ty
1896 ExtSlice(asdl_seq * dims, PyArena *arena)
1898 slice_ty p;
1899 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1900 if (!p)
1901 return NULL;
1902 p->kind = ExtSlice_kind;
1903 p->v.ExtSlice.dims = dims;
1904 return p;
1907 slice_ty
1908 Index(expr_ty value, PyArena *arena)
1910 slice_ty p;
1911 if (!value) {
1912 PyErr_SetString(PyExc_ValueError,
1913 "field value is required for Index");
1914 return NULL;
1916 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1917 if (!p)
1918 return NULL;
1919 p->kind = Index_kind;
1920 p->v.Index.value = value;
1921 return p;
1924 comprehension_ty
1925 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
1927 comprehension_ty p;
1928 if (!target) {
1929 PyErr_SetString(PyExc_ValueError,
1930 "field target is required for comprehension");
1931 return NULL;
1933 if (!iter) {
1934 PyErr_SetString(PyExc_ValueError,
1935 "field iter is required for comprehension");
1936 return NULL;
1938 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
1939 if (!p)
1940 return NULL;
1941 p->target = target;
1942 p->iter = iter;
1943 p->ifs = ifs;
1944 return p;
1947 excepthandler_ty
1948 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1949 col_offset, PyArena *arena)
1951 excepthandler_ty p;
1952 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
1953 if (!p)
1954 return NULL;
1955 p->kind = ExceptHandler_kind;
1956 p->v.ExceptHandler.type = type;
1957 p->v.ExceptHandler.name = name;
1958 p->v.ExceptHandler.body = body;
1959 p->lineno = lineno;
1960 p->col_offset = col_offset;
1961 return p;
1964 arguments_ty
1965 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
1966 defaults, PyArena *arena)
1968 arguments_ty p;
1969 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
1970 if (!p)
1971 return NULL;
1972 p->args = args;
1973 p->vararg = vararg;
1974 p->kwarg = kwarg;
1975 p->defaults = defaults;
1976 return p;
1979 keyword_ty
1980 keyword(identifier arg, expr_ty value, PyArena *arena)
1982 keyword_ty p;
1983 if (!arg) {
1984 PyErr_SetString(PyExc_ValueError,
1985 "field arg is required for keyword");
1986 return NULL;
1988 if (!value) {
1989 PyErr_SetString(PyExc_ValueError,
1990 "field value is required for keyword");
1991 return NULL;
1993 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
1994 if (!p)
1995 return NULL;
1996 p->arg = arg;
1997 p->value = value;
1998 return p;
2001 alias_ty
2002 alias(identifier name, identifier asname, PyArena *arena)
2004 alias_ty p;
2005 if (!name) {
2006 PyErr_SetString(PyExc_ValueError,
2007 "field name is required for alias");
2008 return NULL;
2010 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2011 if (!p)
2012 return NULL;
2013 p->name = name;
2014 p->asname = asname;
2015 return p;
2019 PyObject*
2020 ast2obj_mod(void* _o)
2022 mod_ty o = (mod_ty)_o;
2023 PyObject *result = NULL, *value = NULL;
2024 if (!o) {
2025 Py_INCREF(Py_None);
2026 return Py_None;
2029 switch (o->kind) {
2030 case Module_kind:
2031 result = PyType_GenericNew(Module_type, NULL, NULL);
2032 if (!result) goto failed;
2033 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2034 if (!value) goto failed;
2035 if (PyObject_SetAttrString(result, "body", value) == -1)
2036 goto failed;
2037 Py_DECREF(value);
2038 break;
2039 case Interactive_kind:
2040 result = PyType_GenericNew(Interactive_type, NULL, NULL);
2041 if (!result) goto failed;
2042 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2043 if (!value) goto failed;
2044 if (PyObject_SetAttrString(result, "body", value) == -1)
2045 goto failed;
2046 Py_DECREF(value);
2047 break;
2048 case Expression_kind:
2049 result = PyType_GenericNew(Expression_type, NULL, NULL);
2050 if (!result) goto failed;
2051 value = ast2obj_expr(o->v.Expression.body);
2052 if (!value) goto failed;
2053 if (PyObject_SetAttrString(result, "body", value) == -1)
2054 goto failed;
2055 Py_DECREF(value);
2056 break;
2057 case Suite_kind:
2058 result = PyType_GenericNew(Suite_type, NULL, NULL);
2059 if (!result) goto failed;
2060 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2061 if (!value) goto failed;
2062 if (PyObject_SetAttrString(result, "body", value) == -1)
2063 goto failed;
2064 Py_DECREF(value);
2065 break;
2067 return result;
2068 failed:
2069 Py_XDECREF(value);
2070 Py_XDECREF(result);
2071 return NULL;
2074 PyObject*
2075 ast2obj_stmt(void* _o)
2077 stmt_ty o = (stmt_ty)_o;
2078 PyObject *result = NULL, *value = NULL;
2079 if (!o) {
2080 Py_INCREF(Py_None);
2081 return Py_None;
2084 switch (o->kind) {
2085 case FunctionDef_kind:
2086 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2087 if (!result) goto failed;
2088 value = ast2obj_identifier(o->v.FunctionDef.name);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "name", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
2093 value = ast2obj_arguments(o->v.FunctionDef.args);
2094 if (!value) goto failed;
2095 if (PyObject_SetAttrString(result, "args", value) == -1)
2096 goto failed;
2097 Py_DECREF(value);
2098 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2099 if (!value) goto failed;
2100 if (PyObject_SetAttrString(result, "body", value) == -1)
2101 goto failed;
2102 Py_DECREF(value);
2103 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2104 ast2obj_expr);
2105 if (!value) goto failed;
2106 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2108 goto failed;
2109 Py_DECREF(value);
2110 break;
2111 case ClassDef_kind:
2112 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2113 if (!result) goto failed;
2114 value = ast2obj_identifier(o->v.ClassDef.name);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "name", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
2119 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "bases", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "body", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_list(o->v.ClassDef.decorator_list,
2130 ast2obj_expr);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2134 goto failed;
2135 Py_DECREF(value);
2136 break;
2137 case Return_kind:
2138 result = PyType_GenericNew(Return_type, NULL, NULL);
2139 if (!result) goto failed;
2140 value = ast2obj_expr(o->v.Return.value);
2141 if (!value) goto failed;
2142 if (PyObject_SetAttrString(result, "value", value) == -1)
2143 goto failed;
2144 Py_DECREF(value);
2145 break;
2146 case Delete_kind:
2147 result = PyType_GenericNew(Delete_type, NULL, NULL);
2148 if (!result) goto failed;
2149 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "targets", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 break;
2155 case Assign_kind:
2156 result = PyType_GenericNew(Assign_type, NULL, NULL);
2157 if (!result) goto failed;
2158 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2159 if (!value) goto failed;
2160 if (PyObject_SetAttrString(result, "targets", value) == -1)
2161 goto failed;
2162 Py_DECREF(value);
2163 value = ast2obj_expr(o->v.Assign.value);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "value", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 break;
2169 case AugAssign_kind:
2170 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2171 if (!result) goto failed;
2172 value = ast2obj_expr(o->v.AugAssign.target);
2173 if (!value) goto failed;
2174 if (PyObject_SetAttrString(result, "target", value) == -1)
2175 goto failed;
2176 Py_DECREF(value);
2177 value = ast2obj_operator(o->v.AugAssign.op);
2178 if (!value) goto failed;
2179 if (PyObject_SetAttrString(result, "op", value) == -1)
2180 goto failed;
2181 Py_DECREF(value);
2182 value = ast2obj_expr(o->v.AugAssign.value);
2183 if (!value) goto failed;
2184 if (PyObject_SetAttrString(result, "value", value) == -1)
2185 goto failed;
2186 Py_DECREF(value);
2187 break;
2188 case Print_kind:
2189 result = PyType_GenericNew(Print_type, NULL, NULL);
2190 if (!result) goto failed;
2191 value = ast2obj_expr(o->v.Print.dest);
2192 if (!value) goto failed;
2193 if (PyObject_SetAttrString(result, "dest", value) == -1)
2194 goto failed;
2195 Py_DECREF(value);
2196 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2197 if (!value) goto failed;
2198 if (PyObject_SetAttrString(result, "values", value) == -1)
2199 goto failed;
2200 Py_DECREF(value);
2201 value = ast2obj_bool(o->v.Print.nl);
2202 if (!value) goto failed;
2203 if (PyObject_SetAttrString(result, "nl", value) == -1)
2204 goto failed;
2205 Py_DECREF(value);
2206 break;
2207 case For_kind:
2208 result = PyType_GenericNew(For_type, NULL, NULL);
2209 if (!result) goto failed;
2210 value = ast2obj_expr(o->v.For.target);
2211 if (!value) goto failed;
2212 if (PyObject_SetAttrString(result, "target", value) == -1)
2213 goto failed;
2214 Py_DECREF(value);
2215 value = ast2obj_expr(o->v.For.iter);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "iter", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
2220 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "body", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
2225 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2226 if (!value) goto failed;
2227 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2228 goto failed;
2229 Py_DECREF(value);
2230 break;
2231 case While_kind:
2232 result = PyType_GenericNew(While_type, NULL, NULL);
2233 if (!result) goto failed;
2234 value = ast2obj_expr(o->v.While.test);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "test", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
2239 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2240 if (!value) goto failed;
2241 if (PyObject_SetAttrString(result, "body", value) == -1)
2242 goto failed;
2243 Py_DECREF(value);
2244 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2245 if (!value) goto failed;
2246 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2247 goto failed;
2248 Py_DECREF(value);
2249 break;
2250 case If_kind:
2251 result = PyType_GenericNew(If_type, NULL, NULL);
2252 if (!result) goto failed;
2253 value = ast2obj_expr(o->v.If.test);
2254 if (!value) goto failed;
2255 if (PyObject_SetAttrString(result, "test", value) == -1)
2256 goto failed;
2257 Py_DECREF(value);
2258 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2259 if (!value) goto failed;
2260 if (PyObject_SetAttrString(result, "body", value) == -1)
2261 goto failed;
2262 Py_DECREF(value);
2263 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2264 if (!value) goto failed;
2265 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2266 goto failed;
2267 Py_DECREF(value);
2268 break;
2269 case With_kind:
2270 result = PyType_GenericNew(With_type, NULL, NULL);
2271 if (!result) goto failed;
2272 value = ast2obj_expr(o->v.With.context_expr);
2273 if (!value) goto failed;
2274 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2275 goto failed;
2276 Py_DECREF(value);
2277 value = ast2obj_expr(o->v.With.optional_vars);
2278 if (!value) goto failed;
2279 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2281 goto failed;
2282 Py_DECREF(value);
2283 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "body", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
2288 break;
2289 case Raise_kind:
2290 result = PyType_GenericNew(Raise_type, NULL, NULL);
2291 if (!result) goto failed;
2292 value = ast2obj_expr(o->v.Raise.type);
2293 if (!value) goto failed;
2294 if (PyObject_SetAttrString(result, "type", value) == -1)
2295 goto failed;
2296 Py_DECREF(value);
2297 value = ast2obj_expr(o->v.Raise.inst);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "inst", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
2302 value = ast2obj_expr(o->v.Raise.tback);
2303 if (!value) goto failed;
2304 if (PyObject_SetAttrString(result, "tback", value) == -1)
2305 goto failed;
2306 Py_DECREF(value);
2307 break;
2308 case TryExcept_kind:
2309 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2310 if (!result) goto failed;
2311 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2312 if (!value) goto failed;
2313 if (PyObject_SetAttrString(result, "body", value) == -1)
2314 goto failed;
2315 Py_DECREF(value);
2316 value = ast2obj_list(o->v.TryExcept.handlers,
2317 ast2obj_excepthandler);
2318 if (!value) goto failed;
2319 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2320 goto failed;
2321 Py_DECREF(value);
2322 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2323 if (!value) goto failed;
2324 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2325 goto failed;
2326 Py_DECREF(value);
2327 break;
2328 case TryFinally_kind:
2329 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2330 if (!result) goto failed;
2331 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2332 if (!value) goto failed;
2333 if (PyObject_SetAttrString(result, "body", value) == -1)
2334 goto failed;
2335 Py_DECREF(value);
2336 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2337 if (!value) goto failed;
2338 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2339 goto failed;
2340 Py_DECREF(value);
2341 break;
2342 case Assert_kind:
2343 result = PyType_GenericNew(Assert_type, NULL, NULL);
2344 if (!result) goto failed;
2345 value = ast2obj_expr(o->v.Assert.test);
2346 if (!value) goto failed;
2347 if (PyObject_SetAttrString(result, "test", value) == -1)
2348 goto failed;
2349 Py_DECREF(value);
2350 value = ast2obj_expr(o->v.Assert.msg);
2351 if (!value) goto failed;
2352 if (PyObject_SetAttrString(result, "msg", value) == -1)
2353 goto failed;
2354 Py_DECREF(value);
2355 break;
2356 case Import_kind:
2357 result = PyType_GenericNew(Import_type, NULL, NULL);
2358 if (!result) goto failed;
2359 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2360 if (!value) goto failed;
2361 if (PyObject_SetAttrString(result, "names", value) == -1)
2362 goto failed;
2363 Py_DECREF(value);
2364 break;
2365 case ImportFrom_kind:
2366 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2367 if (!result) goto failed;
2368 value = ast2obj_identifier(o->v.ImportFrom.module);
2369 if (!value) goto failed;
2370 if (PyObject_SetAttrString(result, "module", value) == -1)
2371 goto failed;
2372 Py_DECREF(value);
2373 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2374 if (!value) goto failed;
2375 if (PyObject_SetAttrString(result, "names", value) == -1)
2376 goto failed;
2377 Py_DECREF(value);
2378 value = ast2obj_int(o->v.ImportFrom.level);
2379 if (!value) goto failed;
2380 if (PyObject_SetAttrString(result, "level", value) == -1)
2381 goto failed;
2382 Py_DECREF(value);
2383 break;
2384 case Exec_kind:
2385 result = PyType_GenericNew(Exec_type, NULL, NULL);
2386 if (!result) goto failed;
2387 value = ast2obj_expr(o->v.Exec.body);
2388 if (!value) goto failed;
2389 if (PyObject_SetAttrString(result, "body", value) == -1)
2390 goto failed;
2391 Py_DECREF(value);
2392 value = ast2obj_expr(o->v.Exec.globals);
2393 if (!value) goto failed;
2394 if (PyObject_SetAttrString(result, "globals", value) == -1)
2395 goto failed;
2396 Py_DECREF(value);
2397 value = ast2obj_expr(o->v.Exec.locals);
2398 if (!value) goto failed;
2399 if (PyObject_SetAttrString(result, "locals", value) == -1)
2400 goto failed;
2401 Py_DECREF(value);
2402 break;
2403 case Global_kind:
2404 result = PyType_GenericNew(Global_type, NULL, NULL);
2405 if (!result) goto failed;
2406 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2407 if (!value) goto failed;
2408 if (PyObject_SetAttrString(result, "names", value) == -1)
2409 goto failed;
2410 Py_DECREF(value);
2411 break;
2412 case Expr_kind:
2413 result = PyType_GenericNew(Expr_type, NULL, NULL);
2414 if (!result) goto failed;
2415 value = ast2obj_expr(o->v.Expr.value);
2416 if (!value) goto failed;
2417 if (PyObject_SetAttrString(result, "value", value) == -1)
2418 goto failed;
2419 Py_DECREF(value);
2420 break;
2421 case Pass_kind:
2422 result = PyType_GenericNew(Pass_type, NULL, NULL);
2423 if (!result) goto failed;
2424 break;
2425 case Break_kind:
2426 result = PyType_GenericNew(Break_type, NULL, NULL);
2427 if (!result) goto failed;
2428 break;
2429 case Continue_kind:
2430 result = PyType_GenericNew(Continue_type, NULL, NULL);
2431 if (!result) goto failed;
2432 break;
2434 value = ast2obj_int(o->lineno);
2435 if (!value) goto failed;
2436 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2437 goto failed;
2438 Py_DECREF(value);
2439 value = ast2obj_int(o->col_offset);
2440 if (!value) goto failed;
2441 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2442 goto failed;
2443 Py_DECREF(value);
2444 return result;
2445 failed:
2446 Py_XDECREF(value);
2447 Py_XDECREF(result);
2448 return NULL;
2451 PyObject*
2452 ast2obj_expr(void* _o)
2454 expr_ty o = (expr_ty)_o;
2455 PyObject *result = NULL, *value = NULL;
2456 if (!o) {
2457 Py_INCREF(Py_None);
2458 return Py_None;
2461 switch (o->kind) {
2462 case BoolOp_kind:
2463 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_boolop(o->v.BoolOp.op);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "op", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2471 if (!value) goto failed;
2472 if (PyObject_SetAttrString(result, "values", value) == -1)
2473 goto failed;
2474 Py_DECREF(value);
2475 break;
2476 case BinOp_kind:
2477 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2478 if (!result) goto failed;
2479 value = ast2obj_expr(o->v.BinOp.left);
2480 if (!value) goto failed;
2481 if (PyObject_SetAttrString(result, "left", value) == -1)
2482 goto failed;
2483 Py_DECREF(value);
2484 value = ast2obj_operator(o->v.BinOp.op);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "op", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
2489 value = ast2obj_expr(o->v.BinOp.right);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "right", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2494 break;
2495 case UnaryOp_kind:
2496 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2497 if (!result) goto failed;
2498 value = ast2obj_unaryop(o->v.UnaryOp.op);
2499 if (!value) goto failed;
2500 if (PyObject_SetAttrString(result, "op", value) == -1)
2501 goto failed;
2502 Py_DECREF(value);
2503 value = ast2obj_expr(o->v.UnaryOp.operand);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "operand", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
2508 break;
2509 case Lambda_kind:
2510 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_arguments(o->v.Lambda.args);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "args", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
2517 value = ast2obj_expr(o->v.Lambda.body);
2518 if (!value) goto failed;
2519 if (PyObject_SetAttrString(result, "body", value) == -1)
2520 goto failed;
2521 Py_DECREF(value);
2522 break;
2523 case IfExp_kind:
2524 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2525 if (!result) goto failed;
2526 value = ast2obj_expr(o->v.IfExp.test);
2527 if (!value) goto failed;
2528 if (PyObject_SetAttrString(result, "test", value) == -1)
2529 goto failed;
2530 Py_DECREF(value);
2531 value = ast2obj_expr(o->v.IfExp.body);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "body", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_expr(o->v.IfExp.orelse);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
2541 break;
2542 case Dict_kind:
2543 result = PyType_GenericNew(Dict_type, NULL, NULL);
2544 if (!result) goto failed;
2545 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "keys", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
2550 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2551 if (!value) goto failed;
2552 if (PyObject_SetAttrString(result, "values", value) == -1)
2553 goto failed;
2554 Py_DECREF(value);
2555 break;
2556 case ListComp_kind:
2557 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2558 if (!result) goto failed;
2559 value = ast2obj_expr(o->v.ListComp.elt);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "elt", value) == -1)
2562 goto failed;
2563 Py_DECREF(value);
2564 value = ast2obj_list(o->v.ListComp.generators,
2565 ast2obj_comprehension);
2566 if (!value) goto failed;
2567 if (PyObject_SetAttrString(result, "generators", value) == -1)
2568 goto failed;
2569 Py_DECREF(value);
2570 break;
2571 case GeneratorExp_kind:
2572 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2573 if (!result) goto failed;
2574 value = ast2obj_expr(o->v.GeneratorExp.elt);
2575 if (!value) goto failed;
2576 if (PyObject_SetAttrString(result, "elt", value) == -1)
2577 goto failed;
2578 Py_DECREF(value);
2579 value = ast2obj_list(o->v.GeneratorExp.generators,
2580 ast2obj_comprehension);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "generators", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
2585 break;
2586 case Yield_kind:
2587 result = PyType_GenericNew(Yield_type, NULL, NULL);
2588 if (!result) goto failed;
2589 value = ast2obj_expr(o->v.Yield.value);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "value", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
2594 break;
2595 case Compare_kind:
2596 result = PyType_GenericNew(Compare_type, NULL, NULL);
2597 if (!result) goto failed;
2598 value = ast2obj_expr(o->v.Compare.left);
2599 if (!value) goto failed;
2600 if (PyObject_SetAttrString(result, "left", value) == -1)
2601 goto failed;
2602 Py_DECREF(value);
2604 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2605 value = PyList_New(n);
2606 if (!value) goto failed;
2607 for(i = 0; i < n; i++)
2608 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2610 if (!value) goto failed;
2611 if (PyObject_SetAttrString(result, "ops", value) == -1)
2612 goto failed;
2613 Py_DECREF(value);
2614 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2615 if (!value) goto failed;
2616 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2617 goto failed;
2618 Py_DECREF(value);
2619 break;
2620 case Call_kind:
2621 result = PyType_GenericNew(Call_type, NULL, NULL);
2622 if (!result) goto failed;
2623 value = ast2obj_expr(o->v.Call.func);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "func", value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
2628 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2629 if (!value) goto failed;
2630 if (PyObject_SetAttrString(result, "args", value) == -1)
2631 goto failed;
2632 Py_DECREF(value);
2633 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2634 if (!value) goto failed;
2635 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2636 goto failed;
2637 Py_DECREF(value);
2638 value = ast2obj_expr(o->v.Call.starargs);
2639 if (!value) goto failed;
2640 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2641 goto failed;
2642 Py_DECREF(value);
2643 value = ast2obj_expr(o->v.Call.kwargs);
2644 if (!value) goto failed;
2645 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2646 goto failed;
2647 Py_DECREF(value);
2648 break;
2649 case Repr_kind:
2650 result = PyType_GenericNew(Repr_type, NULL, NULL);
2651 if (!result) goto failed;
2652 value = ast2obj_expr(o->v.Repr.value);
2653 if (!value) goto failed;
2654 if (PyObject_SetAttrString(result, "value", value) == -1)
2655 goto failed;
2656 Py_DECREF(value);
2657 break;
2658 case Num_kind:
2659 result = PyType_GenericNew(Num_type, NULL, NULL);
2660 if (!result) goto failed;
2661 value = ast2obj_object(o->v.Num.n);
2662 if (!value) goto failed;
2663 if (PyObject_SetAttrString(result, "n", value) == -1)
2664 goto failed;
2665 Py_DECREF(value);
2666 break;
2667 case Str_kind:
2668 result = PyType_GenericNew(Str_type, NULL, NULL);
2669 if (!result) goto failed;
2670 value = ast2obj_string(o->v.Str.s);
2671 if (!value) goto failed;
2672 if (PyObject_SetAttrString(result, "s", value) == -1)
2673 goto failed;
2674 Py_DECREF(value);
2675 break;
2676 case Attribute_kind:
2677 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2678 if (!result) goto failed;
2679 value = ast2obj_expr(o->v.Attribute.value);
2680 if (!value) goto failed;
2681 if (PyObject_SetAttrString(result, "value", value) == -1)
2682 goto failed;
2683 Py_DECREF(value);
2684 value = ast2obj_identifier(o->v.Attribute.attr);
2685 if (!value) goto failed;
2686 if (PyObject_SetAttrString(result, "attr", value) == -1)
2687 goto failed;
2688 Py_DECREF(value);
2689 value = ast2obj_expr_context(o->v.Attribute.ctx);
2690 if (!value) goto failed;
2691 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2692 goto failed;
2693 Py_DECREF(value);
2694 break;
2695 case Subscript_kind:
2696 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2697 if (!result) goto failed;
2698 value = ast2obj_expr(o->v.Subscript.value);
2699 if (!value) goto failed;
2700 if (PyObject_SetAttrString(result, "value", value) == -1)
2701 goto failed;
2702 Py_DECREF(value);
2703 value = ast2obj_slice(o->v.Subscript.slice);
2704 if (!value) goto failed;
2705 if (PyObject_SetAttrString(result, "slice", value) == -1)
2706 goto failed;
2707 Py_DECREF(value);
2708 value = ast2obj_expr_context(o->v.Subscript.ctx);
2709 if (!value) goto failed;
2710 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2711 goto failed;
2712 Py_DECREF(value);
2713 break;
2714 case Name_kind:
2715 result = PyType_GenericNew(Name_type, NULL, NULL);
2716 if (!result) goto failed;
2717 value = ast2obj_identifier(o->v.Name.id);
2718 if (!value) goto failed;
2719 if (PyObject_SetAttrString(result, "id", value) == -1)
2720 goto failed;
2721 Py_DECREF(value);
2722 value = ast2obj_expr_context(o->v.Name.ctx);
2723 if (!value) goto failed;
2724 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2725 goto failed;
2726 Py_DECREF(value);
2727 break;
2728 case List_kind:
2729 result = PyType_GenericNew(List_type, NULL, NULL);
2730 if (!result) goto failed;
2731 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2732 if (!value) goto failed;
2733 if (PyObject_SetAttrString(result, "elts", value) == -1)
2734 goto failed;
2735 Py_DECREF(value);
2736 value = ast2obj_expr_context(o->v.List.ctx);
2737 if (!value) goto failed;
2738 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2739 goto failed;
2740 Py_DECREF(value);
2741 break;
2742 case Tuple_kind:
2743 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2744 if (!result) goto failed;
2745 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2746 if (!value) goto failed;
2747 if (PyObject_SetAttrString(result, "elts", value) == -1)
2748 goto failed;
2749 Py_DECREF(value);
2750 value = ast2obj_expr_context(o->v.Tuple.ctx);
2751 if (!value) goto failed;
2752 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2753 goto failed;
2754 Py_DECREF(value);
2755 break;
2757 value = ast2obj_int(o->lineno);
2758 if (!value) goto failed;
2759 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2760 goto failed;
2761 Py_DECREF(value);
2762 value = ast2obj_int(o->col_offset);
2763 if (!value) goto failed;
2764 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2765 goto failed;
2766 Py_DECREF(value);
2767 return result;
2768 failed:
2769 Py_XDECREF(value);
2770 Py_XDECREF(result);
2771 return NULL;
2774 PyObject* ast2obj_expr_context(expr_context_ty o)
2776 switch(o) {
2777 case Load:
2778 Py_INCREF(Load_singleton);
2779 return Load_singleton;
2780 case Store:
2781 Py_INCREF(Store_singleton);
2782 return Store_singleton;
2783 case Del:
2784 Py_INCREF(Del_singleton);
2785 return Del_singleton;
2786 case AugLoad:
2787 Py_INCREF(AugLoad_singleton);
2788 return AugLoad_singleton;
2789 case AugStore:
2790 Py_INCREF(AugStore_singleton);
2791 return AugStore_singleton;
2792 case Param:
2793 Py_INCREF(Param_singleton);
2794 return Param_singleton;
2795 default:
2796 /* should never happen, but just in case ... */
2797 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
2798 return NULL;
2801 PyObject*
2802 ast2obj_slice(void* _o)
2804 slice_ty o = (slice_ty)_o;
2805 PyObject *result = NULL, *value = NULL;
2806 if (!o) {
2807 Py_INCREF(Py_None);
2808 return Py_None;
2811 switch (o->kind) {
2812 case Ellipsis_kind:
2813 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2814 if (!result) goto failed;
2815 break;
2816 case Slice_kind:
2817 result = PyType_GenericNew(Slice_type, NULL, NULL);
2818 if (!result) goto failed;
2819 value = ast2obj_expr(o->v.Slice.lower);
2820 if (!value) goto failed;
2821 if (PyObject_SetAttrString(result, "lower", value) == -1)
2822 goto failed;
2823 Py_DECREF(value);
2824 value = ast2obj_expr(o->v.Slice.upper);
2825 if (!value) goto failed;
2826 if (PyObject_SetAttrString(result, "upper", value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
2829 value = ast2obj_expr(o->v.Slice.step);
2830 if (!value) goto failed;
2831 if (PyObject_SetAttrString(result, "step", value) == -1)
2832 goto failed;
2833 Py_DECREF(value);
2834 break;
2835 case ExtSlice_kind:
2836 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2837 if (!result) goto failed;
2838 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2839 if (!value) goto failed;
2840 if (PyObject_SetAttrString(result, "dims", value) == -1)
2841 goto failed;
2842 Py_DECREF(value);
2843 break;
2844 case Index_kind:
2845 result = PyType_GenericNew(Index_type, NULL, NULL);
2846 if (!result) goto failed;
2847 value = ast2obj_expr(o->v.Index.value);
2848 if (!value) goto failed;
2849 if (PyObject_SetAttrString(result, "value", value) == -1)
2850 goto failed;
2851 Py_DECREF(value);
2852 break;
2854 return result;
2855 failed:
2856 Py_XDECREF(value);
2857 Py_XDECREF(result);
2858 return NULL;
2861 PyObject* ast2obj_boolop(boolop_ty o)
2863 switch(o) {
2864 case And:
2865 Py_INCREF(And_singleton);
2866 return And_singleton;
2867 case Or:
2868 Py_INCREF(Or_singleton);
2869 return Or_singleton;
2870 default:
2871 /* should never happen, but just in case ... */
2872 PyErr_Format(PyExc_SystemError, "unknown boolop found");
2873 return NULL;
2876 PyObject* ast2obj_operator(operator_ty o)
2878 switch(o) {
2879 case Add:
2880 Py_INCREF(Add_singleton);
2881 return Add_singleton;
2882 case Sub:
2883 Py_INCREF(Sub_singleton);
2884 return Sub_singleton;
2885 case Mult:
2886 Py_INCREF(Mult_singleton);
2887 return Mult_singleton;
2888 case Div:
2889 Py_INCREF(Div_singleton);
2890 return Div_singleton;
2891 case Mod:
2892 Py_INCREF(Mod_singleton);
2893 return Mod_singleton;
2894 case Pow:
2895 Py_INCREF(Pow_singleton);
2896 return Pow_singleton;
2897 case LShift:
2898 Py_INCREF(LShift_singleton);
2899 return LShift_singleton;
2900 case RShift:
2901 Py_INCREF(RShift_singleton);
2902 return RShift_singleton;
2903 case BitOr:
2904 Py_INCREF(BitOr_singleton);
2905 return BitOr_singleton;
2906 case BitXor:
2907 Py_INCREF(BitXor_singleton);
2908 return BitXor_singleton;
2909 case BitAnd:
2910 Py_INCREF(BitAnd_singleton);
2911 return BitAnd_singleton;
2912 case FloorDiv:
2913 Py_INCREF(FloorDiv_singleton);
2914 return FloorDiv_singleton;
2915 default:
2916 /* should never happen, but just in case ... */
2917 PyErr_Format(PyExc_SystemError, "unknown operator found");
2918 return NULL;
2921 PyObject* ast2obj_unaryop(unaryop_ty o)
2923 switch(o) {
2924 case Invert:
2925 Py_INCREF(Invert_singleton);
2926 return Invert_singleton;
2927 case Not:
2928 Py_INCREF(Not_singleton);
2929 return Not_singleton;
2930 case UAdd:
2931 Py_INCREF(UAdd_singleton);
2932 return UAdd_singleton;
2933 case USub:
2934 Py_INCREF(USub_singleton);
2935 return USub_singleton;
2936 default:
2937 /* should never happen, but just in case ... */
2938 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
2939 return NULL;
2942 PyObject* ast2obj_cmpop(cmpop_ty o)
2944 switch(o) {
2945 case Eq:
2946 Py_INCREF(Eq_singleton);
2947 return Eq_singleton;
2948 case NotEq:
2949 Py_INCREF(NotEq_singleton);
2950 return NotEq_singleton;
2951 case Lt:
2952 Py_INCREF(Lt_singleton);
2953 return Lt_singleton;
2954 case LtE:
2955 Py_INCREF(LtE_singleton);
2956 return LtE_singleton;
2957 case Gt:
2958 Py_INCREF(Gt_singleton);
2959 return Gt_singleton;
2960 case GtE:
2961 Py_INCREF(GtE_singleton);
2962 return GtE_singleton;
2963 case Is:
2964 Py_INCREF(Is_singleton);
2965 return Is_singleton;
2966 case IsNot:
2967 Py_INCREF(IsNot_singleton);
2968 return IsNot_singleton;
2969 case In:
2970 Py_INCREF(In_singleton);
2971 return In_singleton;
2972 case NotIn:
2973 Py_INCREF(NotIn_singleton);
2974 return NotIn_singleton;
2975 default:
2976 /* should never happen, but just in case ... */
2977 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
2978 return NULL;
2981 PyObject*
2982 ast2obj_comprehension(void* _o)
2984 comprehension_ty o = (comprehension_ty)_o;
2985 PyObject *result = NULL, *value = NULL;
2986 if (!o) {
2987 Py_INCREF(Py_None);
2988 return Py_None;
2991 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2992 if (!result) return NULL;
2993 value = ast2obj_expr(o->target);
2994 if (!value) goto failed;
2995 if (PyObject_SetAttrString(result, "target", value) == -1)
2996 goto failed;
2997 Py_DECREF(value);
2998 value = ast2obj_expr(o->iter);
2999 if (!value) goto failed;
3000 if (PyObject_SetAttrString(result, "iter", value) == -1)
3001 goto failed;
3002 Py_DECREF(value);
3003 value = ast2obj_list(o->ifs, ast2obj_expr);
3004 if (!value) goto failed;
3005 if (PyObject_SetAttrString(result, "ifs", value) == -1)
3006 goto failed;
3007 Py_DECREF(value);
3008 return result;
3009 failed:
3010 Py_XDECREF(value);
3011 Py_XDECREF(result);
3012 return NULL;
3015 PyObject*
3016 ast2obj_excepthandler(void* _o)
3018 excepthandler_ty o = (excepthandler_ty)_o;
3019 PyObject *result = NULL, *value = NULL;
3020 if (!o) {
3021 Py_INCREF(Py_None);
3022 return Py_None;
3025 switch (o->kind) {
3026 case ExceptHandler_kind:
3027 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3028 if (!result) goto failed;
3029 value = ast2obj_expr(o->v.ExceptHandler.type);
3030 if (!value) goto failed;
3031 if (PyObject_SetAttrString(result, "type", value) == -1)
3032 goto failed;
3033 Py_DECREF(value);
3034 value = ast2obj_expr(o->v.ExceptHandler.name);
3035 if (!value) goto failed;
3036 if (PyObject_SetAttrString(result, "name", value) == -1)
3037 goto failed;
3038 Py_DECREF(value);
3039 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3040 if (!value) goto failed;
3041 if (PyObject_SetAttrString(result, "body", value) == -1)
3042 goto failed;
3043 Py_DECREF(value);
3044 break;
3046 value = ast2obj_int(o->lineno);
3047 if (!value) goto failed;
3048 if (PyObject_SetAttrString(result, "lineno", value) < 0)
3049 goto failed;
3050 Py_DECREF(value);
3051 value = ast2obj_int(o->col_offset);
3052 if (!value) goto failed;
3053 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
3054 goto failed;
3055 Py_DECREF(value);
3056 return result;
3057 failed:
3058 Py_XDECREF(value);
3059 Py_XDECREF(result);
3060 return NULL;
3063 PyObject*
3064 ast2obj_arguments(void* _o)
3066 arguments_ty o = (arguments_ty)_o;
3067 PyObject *result = NULL, *value = NULL;
3068 if (!o) {
3069 Py_INCREF(Py_None);
3070 return Py_None;
3073 result = PyType_GenericNew(arguments_type, NULL, NULL);
3074 if (!result) return NULL;
3075 value = ast2obj_list(o->args, ast2obj_expr);
3076 if (!value) goto failed;
3077 if (PyObject_SetAttrString(result, "args", value) == -1)
3078 goto failed;
3079 Py_DECREF(value);
3080 value = ast2obj_identifier(o->vararg);
3081 if (!value) goto failed;
3082 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3083 goto failed;
3084 Py_DECREF(value);
3085 value = ast2obj_identifier(o->kwarg);
3086 if (!value) goto failed;
3087 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3088 goto failed;
3089 Py_DECREF(value);
3090 value = ast2obj_list(o->defaults, ast2obj_expr);
3091 if (!value) goto failed;
3092 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3093 goto failed;
3094 Py_DECREF(value);
3095 return result;
3096 failed:
3097 Py_XDECREF(value);
3098 Py_XDECREF(result);
3099 return NULL;
3102 PyObject*
3103 ast2obj_keyword(void* _o)
3105 keyword_ty o = (keyword_ty)_o;
3106 PyObject *result = NULL, *value = NULL;
3107 if (!o) {
3108 Py_INCREF(Py_None);
3109 return Py_None;
3112 result = PyType_GenericNew(keyword_type, NULL, NULL);
3113 if (!result) return NULL;
3114 value = ast2obj_identifier(o->arg);
3115 if (!value) goto failed;
3116 if (PyObject_SetAttrString(result, "arg", value) == -1)
3117 goto failed;
3118 Py_DECREF(value);
3119 value = ast2obj_expr(o->value);
3120 if (!value) goto failed;
3121 if (PyObject_SetAttrString(result, "value", value) == -1)
3122 goto failed;
3123 Py_DECREF(value);
3124 return result;
3125 failed:
3126 Py_XDECREF(value);
3127 Py_XDECREF(result);
3128 return NULL;
3131 PyObject*
3132 ast2obj_alias(void* _o)
3134 alias_ty o = (alias_ty)_o;
3135 PyObject *result = NULL, *value = NULL;
3136 if (!o) {
3137 Py_INCREF(Py_None);
3138 return Py_None;
3141 result = PyType_GenericNew(alias_type, NULL, NULL);
3142 if (!result) return NULL;
3143 value = ast2obj_identifier(o->name);
3144 if (!value) goto failed;
3145 if (PyObject_SetAttrString(result, "name", value) == -1)
3146 goto failed;
3147 Py_DECREF(value);
3148 value = ast2obj_identifier(o->asname);
3149 if (!value) goto failed;
3150 if (PyObject_SetAttrString(result, "asname", value) == -1)
3151 goto failed;
3152 Py_DECREF(value);
3153 return result;
3154 failed:
3155 Py_XDECREF(value);
3156 Py_XDECREF(result);
3157 return NULL;
3162 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3164 PyObject* tmp = NULL;
3167 if (obj == Py_None) {
3168 *out = NULL;
3169 return 0;
3171 if (PyObject_IsInstance(obj, (PyObject*)Module_type)) {
3172 asdl_seq* body;
3174 if (PyObject_HasAttrString(obj, "body")) {
3175 int res;
3176 Py_ssize_t len;
3177 Py_ssize_t i;
3178 tmp = PyObject_GetAttrString(obj, "body");
3179 if (tmp == NULL) goto failed;
3180 if (!PyList_Check(tmp)) {
3181 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3182 goto failed;
3184 len = PyList_GET_SIZE(tmp);
3185 body = asdl_seq_new(len, arena);
3186 if (body == NULL) goto failed;
3187 for (i = 0; i < len; i++) {
3188 stmt_ty value;
3189 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3190 if (res != 0) goto failed;
3191 asdl_seq_SET(body, i, value);
3193 Py_XDECREF(tmp);
3194 tmp = NULL;
3195 } else {
3196 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
3197 return 1;
3199 *out = Module(body, arena);
3200 if (*out == NULL) goto failed;
3201 return 0;
3203 if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) {
3204 asdl_seq* body;
3206 if (PyObject_HasAttrString(obj, "body")) {
3207 int res;
3208 Py_ssize_t len;
3209 Py_ssize_t i;
3210 tmp = PyObject_GetAttrString(obj, "body");
3211 if (tmp == NULL) goto failed;
3212 if (!PyList_Check(tmp)) {
3213 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3214 goto failed;
3216 len = PyList_GET_SIZE(tmp);
3217 body = asdl_seq_new(len, arena);
3218 if (body == NULL) goto failed;
3219 for (i = 0; i < len; i++) {
3220 stmt_ty value;
3221 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3222 if (res != 0) goto failed;
3223 asdl_seq_SET(body, i, value);
3225 Py_XDECREF(tmp);
3226 tmp = NULL;
3227 } else {
3228 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
3229 return 1;
3231 *out = Interactive(body, arena);
3232 if (*out == NULL) goto failed;
3233 return 0;
3235 if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) {
3236 expr_ty body;
3238 if (PyObject_HasAttrString(obj, "body")) {
3239 int res;
3240 tmp = PyObject_GetAttrString(obj, "body");
3241 if (tmp == NULL) goto failed;
3242 res = obj2ast_expr(tmp, &body, arena);
3243 if (res != 0) goto failed;
3244 Py_XDECREF(tmp);
3245 tmp = NULL;
3246 } else {
3247 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
3248 return 1;
3250 *out = Expression(body, arena);
3251 if (*out == NULL) goto failed;
3252 return 0;
3254 if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) {
3255 asdl_seq* body;
3257 if (PyObject_HasAttrString(obj, "body")) {
3258 int res;
3259 Py_ssize_t len;
3260 Py_ssize_t i;
3261 tmp = PyObject_GetAttrString(obj, "body");
3262 if (tmp == NULL) goto failed;
3263 if (!PyList_Check(tmp)) {
3264 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3265 goto failed;
3267 len = PyList_GET_SIZE(tmp);
3268 body = asdl_seq_new(len, arena);
3269 if (body == NULL) goto failed;
3270 for (i = 0; i < len; i++) {
3271 stmt_ty value;
3272 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3273 if (res != 0) goto failed;
3274 asdl_seq_SET(body, i, value);
3276 Py_XDECREF(tmp);
3277 tmp = NULL;
3278 } else {
3279 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
3280 return 1;
3282 *out = Suite(body, arena);
3283 if (*out == NULL) goto failed;
3284 return 0;
3287 tmp = PyObject_Repr(obj);
3288 if (tmp == NULL) goto failed;
3289 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
3290 failed:
3291 Py_XDECREF(tmp);
3292 return 1;
3296 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
3298 PyObject* tmp = NULL;
3300 int lineno;
3301 int col_offset;
3303 if (obj == Py_None) {
3304 *out = NULL;
3305 return 0;
3307 if (PyObject_HasAttrString(obj, "lineno")) {
3308 int res;
3309 tmp = PyObject_GetAttrString(obj, "lineno");
3310 if (tmp == NULL) goto failed;
3311 res = obj2ast_int(tmp, &lineno, arena);
3312 if (res != 0) goto failed;
3313 Py_XDECREF(tmp);
3314 tmp = NULL;
3315 } else {
3316 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
3317 return 1;
3319 if (PyObject_HasAttrString(obj, "col_offset")) {
3320 int res;
3321 tmp = PyObject_GetAttrString(obj, "col_offset");
3322 if (tmp == NULL) goto failed;
3323 res = obj2ast_int(tmp, &col_offset, arena);
3324 if (res != 0) goto failed;
3325 Py_XDECREF(tmp);
3326 tmp = NULL;
3327 } else {
3328 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
3329 return 1;
3331 if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) {
3332 identifier name;
3333 arguments_ty args;
3334 asdl_seq* body;
3335 asdl_seq* decorator_list;
3337 if (PyObject_HasAttrString(obj, "name")) {
3338 int res;
3339 tmp = PyObject_GetAttrString(obj, "name");
3340 if (tmp == NULL) goto failed;
3341 res = obj2ast_identifier(tmp, &name, arena);
3342 if (res != 0) goto failed;
3343 Py_XDECREF(tmp);
3344 tmp = NULL;
3345 } else {
3346 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
3347 return 1;
3349 if (PyObject_HasAttrString(obj, "args")) {
3350 int res;
3351 tmp = PyObject_GetAttrString(obj, "args");
3352 if (tmp == NULL) goto failed;
3353 res = obj2ast_arguments(tmp, &args, arena);
3354 if (res != 0) goto failed;
3355 Py_XDECREF(tmp);
3356 tmp = NULL;
3357 } else {
3358 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
3359 return 1;
3361 if (PyObject_HasAttrString(obj, "body")) {
3362 int res;
3363 Py_ssize_t len;
3364 Py_ssize_t i;
3365 tmp = PyObject_GetAttrString(obj, "body");
3366 if (tmp == NULL) goto failed;
3367 if (!PyList_Check(tmp)) {
3368 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3369 goto failed;
3371 len = PyList_GET_SIZE(tmp);
3372 body = asdl_seq_new(len, arena);
3373 if (body == NULL) goto failed;
3374 for (i = 0; i < len; i++) {
3375 stmt_ty value;
3376 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3377 if (res != 0) goto failed;
3378 asdl_seq_SET(body, i, value);
3380 Py_XDECREF(tmp);
3381 tmp = NULL;
3382 } else {
3383 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
3384 return 1;
3386 if (PyObject_HasAttrString(obj, "decorator_list")) {
3387 int res;
3388 Py_ssize_t len;
3389 Py_ssize_t i;
3390 tmp = PyObject_GetAttrString(obj, "decorator_list");
3391 if (tmp == NULL) goto failed;
3392 if (!PyList_Check(tmp)) {
3393 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3394 goto failed;
3396 len = PyList_GET_SIZE(tmp);
3397 decorator_list = asdl_seq_new(len, arena);
3398 if (decorator_list == NULL) goto failed;
3399 for (i = 0; i < len; i++) {
3400 expr_ty value;
3401 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3402 if (res != 0) goto failed;
3403 asdl_seq_SET(decorator_list, i, value);
3405 Py_XDECREF(tmp);
3406 tmp = NULL;
3407 } else {
3408 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
3409 return 1;
3411 *out = FunctionDef(name, args, body, decorator_list, lineno,
3412 col_offset, arena);
3413 if (*out == NULL) goto failed;
3414 return 0;
3416 if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) {
3417 identifier name;
3418 asdl_seq* bases;
3419 asdl_seq* body;
3420 asdl_seq* decorator_list;
3422 if (PyObject_HasAttrString(obj, "name")) {
3423 int res;
3424 tmp = PyObject_GetAttrString(obj, "name");
3425 if (tmp == NULL) goto failed;
3426 res = obj2ast_identifier(tmp, &name, arena);
3427 if (res != 0) goto failed;
3428 Py_XDECREF(tmp);
3429 tmp = NULL;
3430 } else {
3431 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
3432 return 1;
3434 if (PyObject_HasAttrString(obj, "bases")) {
3435 int res;
3436 Py_ssize_t len;
3437 Py_ssize_t i;
3438 tmp = PyObject_GetAttrString(obj, "bases");
3439 if (tmp == NULL) goto failed;
3440 if (!PyList_Check(tmp)) {
3441 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3442 goto failed;
3444 len = PyList_GET_SIZE(tmp);
3445 bases = asdl_seq_new(len, arena);
3446 if (bases == NULL) goto failed;
3447 for (i = 0; i < len; i++) {
3448 expr_ty value;
3449 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3450 if (res != 0) goto failed;
3451 asdl_seq_SET(bases, i, value);
3453 Py_XDECREF(tmp);
3454 tmp = NULL;
3455 } else {
3456 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
3457 return 1;
3459 if (PyObject_HasAttrString(obj, "body")) {
3460 int res;
3461 Py_ssize_t len;
3462 Py_ssize_t i;
3463 tmp = PyObject_GetAttrString(obj, "body");
3464 if (tmp == NULL) goto failed;
3465 if (!PyList_Check(tmp)) {
3466 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3467 goto failed;
3469 len = PyList_GET_SIZE(tmp);
3470 body = asdl_seq_new(len, arena);
3471 if (body == NULL) goto failed;
3472 for (i = 0; i < len; i++) {
3473 stmt_ty value;
3474 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3475 if (res != 0) goto failed;
3476 asdl_seq_SET(body, i, value);
3478 Py_XDECREF(tmp);
3479 tmp = NULL;
3480 } else {
3481 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
3482 return 1;
3484 if (PyObject_HasAttrString(obj, "decorator_list")) {
3485 int res;
3486 Py_ssize_t len;
3487 Py_ssize_t i;
3488 tmp = PyObject_GetAttrString(obj, "decorator_list");
3489 if (tmp == NULL) goto failed;
3490 if (!PyList_Check(tmp)) {
3491 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3492 goto failed;
3494 len = PyList_GET_SIZE(tmp);
3495 decorator_list = asdl_seq_new(len, arena);
3496 if (decorator_list == NULL) goto failed;
3497 for (i = 0; i < len; i++) {
3498 expr_ty value;
3499 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3500 if (res != 0) goto failed;
3501 asdl_seq_SET(decorator_list, i, value);
3503 Py_XDECREF(tmp);
3504 tmp = NULL;
3505 } else {
3506 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
3507 return 1;
3509 *out = ClassDef(name, bases, body, decorator_list, lineno,
3510 col_offset, arena);
3511 if (*out == NULL) goto failed;
3512 return 0;
3514 if (PyObject_IsInstance(obj, (PyObject*)Return_type)) {
3515 expr_ty value;
3517 if (PyObject_HasAttrString(obj, "value")) {
3518 int res;
3519 tmp = PyObject_GetAttrString(obj, "value");
3520 if (tmp == NULL) goto failed;
3521 res = obj2ast_expr(tmp, &value, arena);
3522 if (res != 0) goto failed;
3523 Py_XDECREF(tmp);
3524 tmp = NULL;
3525 } else {
3526 value = NULL;
3528 *out = Return(value, lineno, col_offset, arena);
3529 if (*out == NULL) goto failed;
3530 return 0;
3532 if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) {
3533 asdl_seq* targets;
3535 if (PyObject_HasAttrString(obj, "targets")) {
3536 int res;
3537 Py_ssize_t len;
3538 Py_ssize_t i;
3539 tmp = PyObject_GetAttrString(obj, "targets");
3540 if (tmp == NULL) goto failed;
3541 if (!PyList_Check(tmp)) {
3542 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3543 goto failed;
3545 len = PyList_GET_SIZE(tmp);
3546 targets = asdl_seq_new(len, arena);
3547 if (targets == NULL) goto failed;
3548 for (i = 0; i < len; i++) {
3549 expr_ty value;
3550 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3551 if (res != 0) goto failed;
3552 asdl_seq_SET(targets, i, value);
3554 Py_XDECREF(tmp);
3555 tmp = NULL;
3556 } else {
3557 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
3558 return 1;
3560 *out = Delete(targets, lineno, col_offset, arena);
3561 if (*out == NULL) goto failed;
3562 return 0;
3564 if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) {
3565 asdl_seq* targets;
3566 expr_ty value;
3568 if (PyObject_HasAttrString(obj, "targets")) {
3569 int res;
3570 Py_ssize_t len;
3571 Py_ssize_t i;
3572 tmp = PyObject_GetAttrString(obj, "targets");
3573 if (tmp == NULL) goto failed;
3574 if (!PyList_Check(tmp)) {
3575 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3576 goto failed;
3578 len = PyList_GET_SIZE(tmp);
3579 targets = asdl_seq_new(len, arena);
3580 if (targets == NULL) goto failed;
3581 for (i = 0; i < len; i++) {
3582 expr_ty value;
3583 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3584 if (res != 0) goto failed;
3585 asdl_seq_SET(targets, i, value);
3587 Py_XDECREF(tmp);
3588 tmp = NULL;
3589 } else {
3590 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
3591 return 1;
3593 if (PyObject_HasAttrString(obj, "value")) {
3594 int res;
3595 tmp = PyObject_GetAttrString(obj, "value");
3596 if (tmp == NULL) goto failed;
3597 res = obj2ast_expr(tmp, &value, arena);
3598 if (res != 0) goto failed;
3599 Py_XDECREF(tmp);
3600 tmp = NULL;
3601 } else {
3602 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
3603 return 1;
3605 *out = Assign(targets, value, lineno, col_offset, arena);
3606 if (*out == NULL) goto failed;
3607 return 0;
3609 if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) {
3610 expr_ty target;
3611 operator_ty op;
3612 expr_ty value;
3614 if (PyObject_HasAttrString(obj, "target")) {
3615 int res;
3616 tmp = PyObject_GetAttrString(obj, "target");
3617 if (tmp == NULL) goto failed;
3618 res = obj2ast_expr(tmp, &target, arena);
3619 if (res != 0) goto failed;
3620 Py_XDECREF(tmp);
3621 tmp = NULL;
3622 } else {
3623 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
3624 return 1;
3626 if (PyObject_HasAttrString(obj, "op")) {
3627 int res;
3628 tmp = PyObject_GetAttrString(obj, "op");
3629 if (tmp == NULL) goto failed;
3630 res = obj2ast_operator(tmp, &op, arena);
3631 if (res != 0) goto failed;
3632 Py_XDECREF(tmp);
3633 tmp = NULL;
3634 } else {
3635 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
3636 return 1;
3638 if (PyObject_HasAttrString(obj, "value")) {
3639 int res;
3640 tmp = PyObject_GetAttrString(obj, "value");
3641 if (tmp == NULL) goto failed;
3642 res = obj2ast_expr(tmp, &value, arena);
3643 if (res != 0) goto failed;
3644 Py_XDECREF(tmp);
3645 tmp = NULL;
3646 } else {
3647 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
3648 return 1;
3650 *out = AugAssign(target, op, value, lineno, col_offset, arena);
3651 if (*out == NULL) goto failed;
3652 return 0;
3654 if (PyObject_IsInstance(obj, (PyObject*)Print_type)) {
3655 expr_ty dest;
3656 asdl_seq* values;
3657 bool nl;
3659 if (PyObject_HasAttrString(obj, "dest")) {
3660 int res;
3661 tmp = PyObject_GetAttrString(obj, "dest");
3662 if (tmp == NULL) goto failed;
3663 res = obj2ast_expr(tmp, &dest, arena);
3664 if (res != 0) goto failed;
3665 Py_XDECREF(tmp);
3666 tmp = NULL;
3667 } else {
3668 dest = NULL;
3670 if (PyObject_HasAttrString(obj, "values")) {
3671 int res;
3672 Py_ssize_t len;
3673 Py_ssize_t i;
3674 tmp = PyObject_GetAttrString(obj, "values");
3675 if (tmp == NULL) goto failed;
3676 if (!PyList_Check(tmp)) {
3677 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3678 goto failed;
3680 len = PyList_GET_SIZE(tmp);
3681 values = asdl_seq_new(len, arena);
3682 if (values == NULL) goto failed;
3683 for (i = 0; i < len; i++) {
3684 expr_ty value;
3685 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3686 if (res != 0) goto failed;
3687 asdl_seq_SET(values, i, value);
3689 Py_XDECREF(tmp);
3690 tmp = NULL;
3691 } else {
3692 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
3693 return 1;
3695 if (PyObject_HasAttrString(obj, "nl")) {
3696 int res;
3697 tmp = PyObject_GetAttrString(obj, "nl");
3698 if (tmp == NULL) goto failed;
3699 res = obj2ast_bool(tmp, &nl, arena);
3700 if (res != 0) goto failed;
3701 Py_XDECREF(tmp);
3702 tmp = NULL;
3703 } else {
3704 PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
3705 return 1;
3707 *out = Print(dest, values, nl, lineno, col_offset, arena);
3708 if (*out == NULL) goto failed;
3709 return 0;
3711 if (PyObject_IsInstance(obj, (PyObject*)For_type)) {
3712 expr_ty target;
3713 expr_ty iter;
3714 asdl_seq* body;
3715 asdl_seq* orelse;
3717 if (PyObject_HasAttrString(obj, "target")) {
3718 int res;
3719 tmp = PyObject_GetAttrString(obj, "target");
3720 if (tmp == NULL) goto failed;
3721 res = obj2ast_expr(tmp, &target, arena);
3722 if (res != 0) goto failed;
3723 Py_XDECREF(tmp);
3724 tmp = NULL;
3725 } else {
3726 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
3727 return 1;
3729 if (PyObject_HasAttrString(obj, "iter")) {
3730 int res;
3731 tmp = PyObject_GetAttrString(obj, "iter");
3732 if (tmp == NULL) goto failed;
3733 res = obj2ast_expr(tmp, &iter, arena);
3734 if (res != 0) goto failed;
3735 Py_XDECREF(tmp);
3736 tmp = NULL;
3737 } else {
3738 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
3739 return 1;
3741 if (PyObject_HasAttrString(obj, "body")) {
3742 int res;
3743 Py_ssize_t len;
3744 Py_ssize_t i;
3745 tmp = PyObject_GetAttrString(obj, "body");
3746 if (tmp == NULL) goto failed;
3747 if (!PyList_Check(tmp)) {
3748 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3749 goto failed;
3751 len = PyList_GET_SIZE(tmp);
3752 body = asdl_seq_new(len, arena);
3753 if (body == NULL) goto failed;
3754 for (i = 0; i < len; i++) {
3755 stmt_ty value;
3756 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3757 if (res != 0) goto failed;
3758 asdl_seq_SET(body, i, value);
3760 Py_XDECREF(tmp);
3761 tmp = NULL;
3762 } else {
3763 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
3764 return 1;
3766 if (PyObject_HasAttrString(obj, "orelse")) {
3767 int res;
3768 Py_ssize_t len;
3769 Py_ssize_t i;
3770 tmp = PyObject_GetAttrString(obj, "orelse");
3771 if (tmp == NULL) goto failed;
3772 if (!PyList_Check(tmp)) {
3773 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3774 goto failed;
3776 len = PyList_GET_SIZE(tmp);
3777 orelse = asdl_seq_new(len, arena);
3778 if (orelse == NULL) goto failed;
3779 for (i = 0; i < len; i++) {
3780 stmt_ty value;
3781 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3782 if (res != 0) goto failed;
3783 asdl_seq_SET(orelse, i, value);
3785 Py_XDECREF(tmp);
3786 tmp = NULL;
3787 } else {
3788 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
3789 return 1;
3791 *out = For(target, iter, body, orelse, lineno, col_offset,
3792 arena);
3793 if (*out == NULL) goto failed;
3794 return 0;
3796 if (PyObject_IsInstance(obj, (PyObject*)While_type)) {
3797 expr_ty test;
3798 asdl_seq* body;
3799 asdl_seq* orelse;
3801 if (PyObject_HasAttrString(obj, "test")) {
3802 int res;
3803 tmp = PyObject_GetAttrString(obj, "test");
3804 if (tmp == NULL) goto failed;
3805 res = obj2ast_expr(tmp, &test, arena);
3806 if (res != 0) goto failed;
3807 Py_XDECREF(tmp);
3808 tmp = NULL;
3809 } else {
3810 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
3811 return 1;
3813 if (PyObject_HasAttrString(obj, "body")) {
3814 int res;
3815 Py_ssize_t len;
3816 Py_ssize_t i;
3817 tmp = PyObject_GetAttrString(obj, "body");
3818 if (tmp == NULL) goto failed;
3819 if (!PyList_Check(tmp)) {
3820 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3821 goto failed;
3823 len = PyList_GET_SIZE(tmp);
3824 body = asdl_seq_new(len, arena);
3825 if (body == NULL) goto failed;
3826 for (i = 0; i < len; i++) {
3827 stmt_ty value;
3828 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3829 if (res != 0) goto failed;
3830 asdl_seq_SET(body, i, value);
3832 Py_XDECREF(tmp);
3833 tmp = NULL;
3834 } else {
3835 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
3836 return 1;
3838 if (PyObject_HasAttrString(obj, "orelse")) {
3839 int res;
3840 Py_ssize_t len;
3841 Py_ssize_t i;
3842 tmp = PyObject_GetAttrString(obj, "orelse");
3843 if (tmp == NULL) goto failed;
3844 if (!PyList_Check(tmp)) {
3845 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3846 goto failed;
3848 len = PyList_GET_SIZE(tmp);
3849 orelse = asdl_seq_new(len, arena);
3850 if (orelse == NULL) goto failed;
3851 for (i = 0; i < len; i++) {
3852 stmt_ty value;
3853 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3854 if (res != 0) goto failed;
3855 asdl_seq_SET(orelse, i, value);
3857 Py_XDECREF(tmp);
3858 tmp = NULL;
3859 } else {
3860 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
3861 return 1;
3863 *out = While(test, body, orelse, lineno, col_offset, arena);
3864 if (*out == NULL) goto failed;
3865 return 0;
3867 if (PyObject_IsInstance(obj, (PyObject*)If_type)) {
3868 expr_ty test;
3869 asdl_seq* body;
3870 asdl_seq* orelse;
3872 if (PyObject_HasAttrString(obj, "test")) {
3873 int res;
3874 tmp = PyObject_GetAttrString(obj, "test");
3875 if (tmp == NULL) goto failed;
3876 res = obj2ast_expr(tmp, &test, arena);
3877 if (res != 0) goto failed;
3878 Py_XDECREF(tmp);
3879 tmp = NULL;
3880 } else {
3881 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
3882 return 1;
3884 if (PyObject_HasAttrString(obj, "body")) {
3885 int res;
3886 Py_ssize_t len;
3887 Py_ssize_t i;
3888 tmp = PyObject_GetAttrString(obj, "body");
3889 if (tmp == NULL) goto failed;
3890 if (!PyList_Check(tmp)) {
3891 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3892 goto failed;
3894 len = PyList_GET_SIZE(tmp);
3895 body = asdl_seq_new(len, arena);
3896 if (body == NULL) goto failed;
3897 for (i = 0; i < len; i++) {
3898 stmt_ty value;
3899 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3900 if (res != 0) goto failed;
3901 asdl_seq_SET(body, i, value);
3903 Py_XDECREF(tmp);
3904 tmp = NULL;
3905 } else {
3906 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
3907 return 1;
3909 if (PyObject_HasAttrString(obj, "orelse")) {
3910 int res;
3911 Py_ssize_t len;
3912 Py_ssize_t i;
3913 tmp = PyObject_GetAttrString(obj, "orelse");
3914 if (tmp == NULL) goto failed;
3915 if (!PyList_Check(tmp)) {
3916 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3917 goto failed;
3919 len = PyList_GET_SIZE(tmp);
3920 orelse = asdl_seq_new(len, arena);
3921 if (orelse == NULL) goto failed;
3922 for (i = 0; i < len; i++) {
3923 stmt_ty value;
3924 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3925 if (res != 0) goto failed;
3926 asdl_seq_SET(orelse, i, value);
3928 Py_XDECREF(tmp);
3929 tmp = NULL;
3930 } else {
3931 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
3932 return 1;
3934 *out = If(test, body, orelse, lineno, col_offset, arena);
3935 if (*out == NULL) goto failed;
3936 return 0;
3938 if (PyObject_IsInstance(obj, (PyObject*)With_type)) {
3939 expr_ty context_expr;
3940 expr_ty optional_vars;
3941 asdl_seq* body;
3943 if (PyObject_HasAttrString(obj, "context_expr")) {
3944 int res;
3945 tmp = PyObject_GetAttrString(obj, "context_expr");
3946 if (tmp == NULL) goto failed;
3947 res = obj2ast_expr(tmp, &context_expr, arena);
3948 if (res != 0) goto failed;
3949 Py_XDECREF(tmp);
3950 tmp = NULL;
3951 } else {
3952 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
3953 return 1;
3955 if (PyObject_HasAttrString(obj, "optional_vars")) {
3956 int res;
3957 tmp = PyObject_GetAttrString(obj, "optional_vars");
3958 if (tmp == NULL) goto failed;
3959 res = obj2ast_expr(tmp, &optional_vars, arena);
3960 if (res != 0) goto failed;
3961 Py_XDECREF(tmp);
3962 tmp = NULL;
3963 } else {
3964 optional_vars = NULL;
3966 if (PyObject_HasAttrString(obj, "body")) {
3967 int res;
3968 Py_ssize_t len;
3969 Py_ssize_t i;
3970 tmp = PyObject_GetAttrString(obj, "body");
3971 if (tmp == NULL) goto failed;
3972 if (!PyList_Check(tmp)) {
3973 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3974 goto failed;
3976 len = PyList_GET_SIZE(tmp);
3977 body = asdl_seq_new(len, arena);
3978 if (body == NULL) goto failed;
3979 for (i = 0; i < len; i++) {
3980 stmt_ty value;
3981 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3982 if (res != 0) goto failed;
3983 asdl_seq_SET(body, i, value);
3985 Py_XDECREF(tmp);
3986 tmp = NULL;
3987 } else {
3988 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
3989 return 1;
3991 *out = With(context_expr, optional_vars, body, lineno,
3992 col_offset, arena);
3993 if (*out == NULL) goto failed;
3994 return 0;
3996 if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) {
3997 expr_ty type;
3998 expr_ty inst;
3999 expr_ty tback;
4001 if (PyObject_HasAttrString(obj, "type")) {
4002 int res;
4003 tmp = PyObject_GetAttrString(obj, "type");
4004 if (tmp == NULL) goto failed;
4005 res = obj2ast_expr(tmp, &type, arena);
4006 if (res != 0) goto failed;
4007 Py_XDECREF(tmp);
4008 tmp = NULL;
4009 } else {
4010 type = NULL;
4012 if (PyObject_HasAttrString(obj, "inst")) {
4013 int res;
4014 tmp = PyObject_GetAttrString(obj, "inst");
4015 if (tmp == NULL) goto failed;
4016 res = obj2ast_expr(tmp, &inst, arena);
4017 if (res != 0) goto failed;
4018 Py_XDECREF(tmp);
4019 tmp = NULL;
4020 } else {
4021 inst = NULL;
4023 if (PyObject_HasAttrString(obj, "tback")) {
4024 int res;
4025 tmp = PyObject_GetAttrString(obj, "tback");
4026 if (tmp == NULL) goto failed;
4027 res = obj2ast_expr(tmp, &tback, arena);
4028 if (res != 0) goto failed;
4029 Py_XDECREF(tmp);
4030 tmp = NULL;
4031 } else {
4032 tback = NULL;
4034 *out = Raise(type, inst, tback, lineno, col_offset, arena);
4035 if (*out == NULL) goto failed;
4036 return 0;
4038 if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) {
4039 asdl_seq* body;
4040 asdl_seq* handlers;
4041 asdl_seq* orelse;
4043 if (PyObject_HasAttrString(obj, "body")) {
4044 int res;
4045 Py_ssize_t len;
4046 Py_ssize_t i;
4047 tmp = PyObject_GetAttrString(obj, "body");
4048 if (tmp == NULL) goto failed;
4049 if (!PyList_Check(tmp)) {
4050 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4051 goto failed;
4053 len = PyList_GET_SIZE(tmp);
4054 body = asdl_seq_new(len, arena);
4055 if (body == NULL) goto failed;
4056 for (i = 0; i < len; i++) {
4057 stmt_ty value;
4058 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4059 if (res != 0) goto failed;
4060 asdl_seq_SET(body, i, value);
4062 Py_XDECREF(tmp);
4063 tmp = NULL;
4064 } else {
4065 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
4066 return 1;
4068 if (PyObject_HasAttrString(obj, "handlers")) {
4069 int res;
4070 Py_ssize_t len;
4071 Py_ssize_t i;
4072 tmp = PyObject_GetAttrString(obj, "handlers");
4073 if (tmp == NULL) goto failed;
4074 if (!PyList_Check(tmp)) {
4075 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4076 goto failed;
4078 len = PyList_GET_SIZE(tmp);
4079 handlers = asdl_seq_new(len, arena);
4080 if (handlers == NULL) goto failed;
4081 for (i = 0; i < len; i++) {
4082 excepthandler_ty value;
4083 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
4084 if (res != 0) goto failed;
4085 asdl_seq_SET(handlers, i, value);
4087 Py_XDECREF(tmp);
4088 tmp = NULL;
4089 } else {
4090 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
4091 return 1;
4093 if (PyObject_HasAttrString(obj, "orelse")) {
4094 int res;
4095 Py_ssize_t len;
4096 Py_ssize_t i;
4097 tmp = PyObject_GetAttrString(obj, "orelse");
4098 if (tmp == NULL) goto failed;
4099 if (!PyList_Check(tmp)) {
4100 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4101 goto failed;
4103 len = PyList_GET_SIZE(tmp);
4104 orelse = asdl_seq_new(len, arena);
4105 if (orelse == NULL) goto failed;
4106 for (i = 0; i < len; i++) {
4107 stmt_ty value;
4108 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4109 if (res != 0) goto failed;
4110 asdl_seq_SET(orelse, i, value);
4112 Py_XDECREF(tmp);
4113 tmp = NULL;
4114 } else {
4115 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
4116 return 1;
4118 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
4119 arena);
4120 if (*out == NULL) goto failed;
4121 return 0;
4123 if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) {
4124 asdl_seq* body;
4125 asdl_seq* finalbody;
4127 if (PyObject_HasAttrString(obj, "body")) {
4128 int res;
4129 Py_ssize_t len;
4130 Py_ssize_t i;
4131 tmp = PyObject_GetAttrString(obj, "body");
4132 if (tmp == NULL) goto failed;
4133 if (!PyList_Check(tmp)) {
4134 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4135 goto failed;
4137 len = PyList_GET_SIZE(tmp);
4138 body = asdl_seq_new(len, arena);
4139 if (body == NULL) goto failed;
4140 for (i = 0; i < len; i++) {
4141 stmt_ty value;
4142 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4143 if (res != 0) goto failed;
4144 asdl_seq_SET(body, i, value);
4146 Py_XDECREF(tmp);
4147 tmp = NULL;
4148 } else {
4149 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
4150 return 1;
4152 if (PyObject_HasAttrString(obj, "finalbody")) {
4153 int res;
4154 Py_ssize_t len;
4155 Py_ssize_t i;
4156 tmp = PyObject_GetAttrString(obj, "finalbody");
4157 if (tmp == NULL) goto failed;
4158 if (!PyList_Check(tmp)) {
4159 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4160 goto failed;
4162 len = PyList_GET_SIZE(tmp);
4163 finalbody = asdl_seq_new(len, arena);
4164 if (finalbody == NULL) goto failed;
4165 for (i = 0; i < len; i++) {
4166 stmt_ty value;
4167 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4168 if (res != 0) goto failed;
4169 asdl_seq_SET(finalbody, i, value);
4171 Py_XDECREF(tmp);
4172 tmp = NULL;
4173 } else {
4174 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
4175 return 1;
4177 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
4178 if (*out == NULL) goto failed;
4179 return 0;
4181 if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) {
4182 expr_ty test;
4183 expr_ty msg;
4185 if (PyObject_HasAttrString(obj, "test")) {
4186 int res;
4187 tmp = PyObject_GetAttrString(obj, "test");
4188 if (tmp == NULL) goto failed;
4189 res = obj2ast_expr(tmp, &test, arena);
4190 if (res != 0) goto failed;
4191 Py_XDECREF(tmp);
4192 tmp = NULL;
4193 } else {
4194 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
4195 return 1;
4197 if (PyObject_HasAttrString(obj, "msg")) {
4198 int res;
4199 tmp = PyObject_GetAttrString(obj, "msg");
4200 if (tmp == NULL) goto failed;
4201 res = obj2ast_expr(tmp, &msg, arena);
4202 if (res != 0) goto failed;
4203 Py_XDECREF(tmp);
4204 tmp = NULL;
4205 } else {
4206 msg = NULL;
4208 *out = Assert(test, msg, lineno, col_offset, arena);
4209 if (*out == NULL) goto failed;
4210 return 0;
4212 if (PyObject_IsInstance(obj, (PyObject*)Import_type)) {
4213 asdl_seq* names;
4215 if (PyObject_HasAttrString(obj, "names")) {
4216 int res;
4217 Py_ssize_t len;
4218 Py_ssize_t i;
4219 tmp = PyObject_GetAttrString(obj, "names");
4220 if (tmp == NULL) goto failed;
4221 if (!PyList_Check(tmp)) {
4222 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4223 goto failed;
4225 len = PyList_GET_SIZE(tmp);
4226 names = asdl_seq_new(len, arena);
4227 if (names == NULL) goto failed;
4228 for (i = 0; i < len; i++) {
4229 alias_ty value;
4230 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4231 if (res != 0) goto failed;
4232 asdl_seq_SET(names, i, value);
4234 Py_XDECREF(tmp);
4235 tmp = NULL;
4236 } else {
4237 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
4238 return 1;
4240 *out = Import(names, lineno, col_offset, arena);
4241 if (*out == NULL) goto failed;
4242 return 0;
4244 if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) {
4245 identifier module;
4246 asdl_seq* names;
4247 int level;
4249 if (PyObject_HasAttrString(obj, "module")) {
4250 int res;
4251 tmp = PyObject_GetAttrString(obj, "module");
4252 if (tmp == NULL) goto failed;
4253 res = obj2ast_identifier(tmp, &module, arena);
4254 if (res != 0) goto failed;
4255 Py_XDECREF(tmp);
4256 tmp = NULL;
4257 } else {
4258 PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom");
4259 return 1;
4261 if (PyObject_HasAttrString(obj, "names")) {
4262 int res;
4263 Py_ssize_t len;
4264 Py_ssize_t i;
4265 tmp = PyObject_GetAttrString(obj, "names");
4266 if (tmp == NULL) goto failed;
4267 if (!PyList_Check(tmp)) {
4268 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4269 goto failed;
4271 len = PyList_GET_SIZE(tmp);
4272 names = asdl_seq_new(len, arena);
4273 if (names == NULL) goto failed;
4274 for (i = 0; i < len; i++) {
4275 alias_ty value;
4276 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4277 if (res != 0) goto failed;
4278 asdl_seq_SET(names, i, value);
4280 Py_XDECREF(tmp);
4281 tmp = NULL;
4282 } else {
4283 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
4284 return 1;
4286 if (PyObject_HasAttrString(obj, "level")) {
4287 int res;
4288 tmp = PyObject_GetAttrString(obj, "level");
4289 if (tmp == NULL) goto failed;
4290 res = obj2ast_int(tmp, &level, arena);
4291 if (res != 0) goto failed;
4292 Py_XDECREF(tmp);
4293 tmp = NULL;
4294 } else {
4295 level = 0;
4297 *out = ImportFrom(module, names, level, lineno, col_offset,
4298 arena);
4299 if (*out == NULL) goto failed;
4300 return 0;
4302 if (PyObject_IsInstance(obj, (PyObject*)Exec_type)) {
4303 expr_ty body;
4304 expr_ty globals;
4305 expr_ty locals;
4307 if (PyObject_HasAttrString(obj, "body")) {
4308 int res;
4309 tmp = PyObject_GetAttrString(obj, "body");
4310 if (tmp == NULL) goto failed;
4311 res = obj2ast_expr(tmp, &body, arena);
4312 if (res != 0) goto failed;
4313 Py_XDECREF(tmp);
4314 tmp = NULL;
4315 } else {
4316 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
4317 return 1;
4319 if (PyObject_HasAttrString(obj, "globals")) {
4320 int res;
4321 tmp = PyObject_GetAttrString(obj, "globals");
4322 if (tmp == NULL) goto failed;
4323 res = obj2ast_expr(tmp, &globals, arena);
4324 if (res != 0) goto failed;
4325 Py_XDECREF(tmp);
4326 tmp = NULL;
4327 } else {
4328 globals = NULL;
4330 if (PyObject_HasAttrString(obj, "locals")) {
4331 int res;
4332 tmp = PyObject_GetAttrString(obj, "locals");
4333 if (tmp == NULL) goto failed;
4334 res = obj2ast_expr(tmp, &locals, arena);
4335 if (res != 0) goto failed;
4336 Py_XDECREF(tmp);
4337 tmp = NULL;
4338 } else {
4339 locals = NULL;
4341 *out = Exec(body, globals, locals, lineno, col_offset, arena);
4342 if (*out == NULL) goto failed;
4343 return 0;
4345 if (PyObject_IsInstance(obj, (PyObject*)Global_type)) {
4346 asdl_seq* names;
4348 if (PyObject_HasAttrString(obj, "names")) {
4349 int res;
4350 Py_ssize_t len;
4351 Py_ssize_t i;
4352 tmp = PyObject_GetAttrString(obj, "names");
4353 if (tmp == NULL) goto failed;
4354 if (!PyList_Check(tmp)) {
4355 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4356 goto failed;
4358 len = PyList_GET_SIZE(tmp);
4359 names = asdl_seq_new(len, arena);
4360 if (names == NULL) goto failed;
4361 for (i = 0; i < len; i++) {
4362 identifier value;
4363 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
4364 if (res != 0) goto failed;
4365 asdl_seq_SET(names, i, value);
4367 Py_XDECREF(tmp);
4368 tmp = NULL;
4369 } else {
4370 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
4371 return 1;
4373 *out = Global(names, lineno, col_offset, arena);
4374 if (*out == NULL) goto failed;
4375 return 0;
4377 if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) {
4378 expr_ty value;
4380 if (PyObject_HasAttrString(obj, "value")) {
4381 int res;
4382 tmp = PyObject_GetAttrString(obj, "value");
4383 if (tmp == NULL) goto failed;
4384 res = obj2ast_expr(tmp, &value, arena);
4385 if (res != 0) goto failed;
4386 Py_XDECREF(tmp);
4387 tmp = NULL;
4388 } else {
4389 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
4390 return 1;
4392 *out = Expr(value, lineno, col_offset, arena);
4393 if (*out == NULL) goto failed;
4394 return 0;
4396 if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) {
4398 *out = Pass(lineno, col_offset, arena);
4399 if (*out == NULL) goto failed;
4400 return 0;
4402 if (PyObject_IsInstance(obj, (PyObject*)Break_type)) {
4404 *out = Break(lineno, col_offset, arena);
4405 if (*out == NULL) goto failed;
4406 return 0;
4408 if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) {
4410 *out = Continue(lineno, col_offset, arena);
4411 if (*out == NULL) goto failed;
4412 return 0;
4415 tmp = PyObject_Repr(obj);
4416 if (tmp == NULL) goto failed;
4417 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
4418 failed:
4419 Py_XDECREF(tmp);
4420 return 1;
4424 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
4426 PyObject* tmp = NULL;
4428 int lineno;
4429 int col_offset;
4431 if (obj == Py_None) {
4432 *out = NULL;
4433 return 0;
4435 if (PyObject_HasAttrString(obj, "lineno")) {
4436 int res;
4437 tmp = PyObject_GetAttrString(obj, "lineno");
4438 if (tmp == NULL) goto failed;
4439 res = obj2ast_int(tmp, &lineno, arena);
4440 if (res != 0) goto failed;
4441 Py_XDECREF(tmp);
4442 tmp = NULL;
4443 } else {
4444 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
4445 return 1;
4447 if (PyObject_HasAttrString(obj, "col_offset")) {
4448 int res;
4449 tmp = PyObject_GetAttrString(obj, "col_offset");
4450 if (tmp == NULL) goto failed;
4451 res = obj2ast_int(tmp, &col_offset, arena);
4452 if (res != 0) goto failed;
4453 Py_XDECREF(tmp);
4454 tmp = NULL;
4455 } else {
4456 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
4457 return 1;
4459 if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) {
4460 boolop_ty op;
4461 asdl_seq* values;
4463 if (PyObject_HasAttrString(obj, "op")) {
4464 int res;
4465 tmp = PyObject_GetAttrString(obj, "op");
4466 if (tmp == NULL) goto failed;
4467 res = obj2ast_boolop(tmp, &op, arena);
4468 if (res != 0) goto failed;
4469 Py_XDECREF(tmp);
4470 tmp = NULL;
4471 } else {
4472 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
4473 return 1;
4475 if (PyObject_HasAttrString(obj, "values")) {
4476 int res;
4477 Py_ssize_t len;
4478 Py_ssize_t i;
4479 tmp = PyObject_GetAttrString(obj, "values");
4480 if (tmp == NULL) goto failed;
4481 if (!PyList_Check(tmp)) {
4482 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4483 goto failed;
4485 len = PyList_GET_SIZE(tmp);
4486 values = asdl_seq_new(len, arena);
4487 if (values == NULL) goto failed;
4488 for (i = 0; i < len; i++) {
4489 expr_ty value;
4490 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4491 if (res != 0) goto failed;
4492 asdl_seq_SET(values, i, value);
4494 Py_XDECREF(tmp);
4495 tmp = NULL;
4496 } else {
4497 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
4498 return 1;
4500 *out = BoolOp(op, values, lineno, col_offset, arena);
4501 if (*out == NULL) goto failed;
4502 return 0;
4504 if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) {
4505 expr_ty left;
4506 operator_ty op;
4507 expr_ty right;
4509 if (PyObject_HasAttrString(obj, "left")) {
4510 int res;
4511 tmp = PyObject_GetAttrString(obj, "left");
4512 if (tmp == NULL) goto failed;
4513 res = obj2ast_expr(tmp, &left, arena);
4514 if (res != 0) goto failed;
4515 Py_XDECREF(tmp);
4516 tmp = NULL;
4517 } else {
4518 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
4519 return 1;
4521 if (PyObject_HasAttrString(obj, "op")) {
4522 int res;
4523 tmp = PyObject_GetAttrString(obj, "op");
4524 if (tmp == NULL) goto failed;
4525 res = obj2ast_operator(tmp, &op, arena);
4526 if (res != 0) goto failed;
4527 Py_XDECREF(tmp);
4528 tmp = NULL;
4529 } else {
4530 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
4531 return 1;
4533 if (PyObject_HasAttrString(obj, "right")) {
4534 int res;
4535 tmp = PyObject_GetAttrString(obj, "right");
4536 if (tmp == NULL) goto failed;
4537 res = obj2ast_expr(tmp, &right, arena);
4538 if (res != 0) goto failed;
4539 Py_XDECREF(tmp);
4540 tmp = NULL;
4541 } else {
4542 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
4543 return 1;
4545 *out = BinOp(left, op, right, lineno, col_offset, arena);
4546 if (*out == NULL) goto failed;
4547 return 0;
4549 if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) {
4550 unaryop_ty op;
4551 expr_ty operand;
4553 if (PyObject_HasAttrString(obj, "op")) {
4554 int res;
4555 tmp = PyObject_GetAttrString(obj, "op");
4556 if (tmp == NULL) goto failed;
4557 res = obj2ast_unaryop(tmp, &op, arena);
4558 if (res != 0) goto failed;
4559 Py_XDECREF(tmp);
4560 tmp = NULL;
4561 } else {
4562 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
4563 return 1;
4565 if (PyObject_HasAttrString(obj, "operand")) {
4566 int res;
4567 tmp = PyObject_GetAttrString(obj, "operand");
4568 if (tmp == NULL) goto failed;
4569 res = obj2ast_expr(tmp, &operand, arena);
4570 if (res != 0) goto failed;
4571 Py_XDECREF(tmp);
4572 tmp = NULL;
4573 } else {
4574 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
4575 return 1;
4577 *out = UnaryOp(op, operand, lineno, col_offset, arena);
4578 if (*out == NULL) goto failed;
4579 return 0;
4581 if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) {
4582 arguments_ty args;
4583 expr_ty body;
4585 if (PyObject_HasAttrString(obj, "args")) {
4586 int res;
4587 tmp = PyObject_GetAttrString(obj, "args");
4588 if (tmp == NULL) goto failed;
4589 res = obj2ast_arguments(tmp, &args, arena);
4590 if (res != 0) goto failed;
4591 Py_XDECREF(tmp);
4592 tmp = NULL;
4593 } else {
4594 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
4595 return 1;
4597 if (PyObject_HasAttrString(obj, "body")) {
4598 int res;
4599 tmp = PyObject_GetAttrString(obj, "body");
4600 if (tmp == NULL) goto failed;
4601 res = obj2ast_expr(tmp, &body, arena);
4602 if (res != 0) goto failed;
4603 Py_XDECREF(tmp);
4604 tmp = NULL;
4605 } else {
4606 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
4607 return 1;
4609 *out = Lambda(args, body, lineno, col_offset, arena);
4610 if (*out == NULL) goto failed;
4611 return 0;
4613 if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) {
4614 expr_ty test;
4615 expr_ty body;
4616 expr_ty orelse;
4618 if (PyObject_HasAttrString(obj, "test")) {
4619 int res;
4620 tmp = PyObject_GetAttrString(obj, "test");
4621 if (tmp == NULL) goto failed;
4622 res = obj2ast_expr(tmp, &test, arena);
4623 if (res != 0) goto failed;
4624 Py_XDECREF(tmp);
4625 tmp = NULL;
4626 } else {
4627 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
4628 return 1;
4630 if (PyObject_HasAttrString(obj, "body")) {
4631 int res;
4632 tmp = PyObject_GetAttrString(obj, "body");
4633 if (tmp == NULL) goto failed;
4634 res = obj2ast_expr(tmp, &body, arena);
4635 if (res != 0) goto failed;
4636 Py_XDECREF(tmp);
4637 tmp = NULL;
4638 } else {
4639 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
4640 return 1;
4642 if (PyObject_HasAttrString(obj, "orelse")) {
4643 int res;
4644 tmp = PyObject_GetAttrString(obj, "orelse");
4645 if (tmp == NULL) goto failed;
4646 res = obj2ast_expr(tmp, &orelse, arena);
4647 if (res != 0) goto failed;
4648 Py_XDECREF(tmp);
4649 tmp = NULL;
4650 } else {
4651 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
4652 return 1;
4654 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
4655 if (*out == NULL) goto failed;
4656 return 0;
4658 if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) {
4659 asdl_seq* keys;
4660 asdl_seq* values;
4662 if (PyObject_HasAttrString(obj, "keys")) {
4663 int res;
4664 Py_ssize_t len;
4665 Py_ssize_t i;
4666 tmp = PyObject_GetAttrString(obj, "keys");
4667 if (tmp == NULL) goto failed;
4668 if (!PyList_Check(tmp)) {
4669 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4670 goto failed;
4672 len = PyList_GET_SIZE(tmp);
4673 keys = asdl_seq_new(len, arena);
4674 if (keys == NULL) goto failed;
4675 for (i = 0; i < len; i++) {
4676 expr_ty value;
4677 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4678 if (res != 0) goto failed;
4679 asdl_seq_SET(keys, i, value);
4681 Py_XDECREF(tmp);
4682 tmp = NULL;
4683 } else {
4684 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
4685 return 1;
4687 if (PyObject_HasAttrString(obj, "values")) {
4688 int res;
4689 Py_ssize_t len;
4690 Py_ssize_t i;
4691 tmp = PyObject_GetAttrString(obj, "values");
4692 if (tmp == NULL) goto failed;
4693 if (!PyList_Check(tmp)) {
4694 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4695 goto failed;
4697 len = PyList_GET_SIZE(tmp);
4698 values = asdl_seq_new(len, arena);
4699 if (values == NULL) goto failed;
4700 for (i = 0; i < len; i++) {
4701 expr_ty value;
4702 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4703 if (res != 0) goto failed;
4704 asdl_seq_SET(values, i, value);
4706 Py_XDECREF(tmp);
4707 tmp = NULL;
4708 } else {
4709 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
4710 return 1;
4712 *out = Dict(keys, values, lineno, col_offset, arena);
4713 if (*out == NULL) goto failed;
4714 return 0;
4716 if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) {
4717 expr_ty elt;
4718 asdl_seq* generators;
4720 if (PyObject_HasAttrString(obj, "elt")) {
4721 int res;
4722 tmp = PyObject_GetAttrString(obj, "elt");
4723 if (tmp == NULL) goto failed;
4724 res = obj2ast_expr(tmp, &elt, arena);
4725 if (res != 0) goto failed;
4726 Py_XDECREF(tmp);
4727 tmp = NULL;
4728 } else {
4729 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
4730 return 1;
4732 if (PyObject_HasAttrString(obj, "generators")) {
4733 int res;
4734 Py_ssize_t len;
4735 Py_ssize_t i;
4736 tmp = PyObject_GetAttrString(obj, "generators");
4737 if (tmp == NULL) goto failed;
4738 if (!PyList_Check(tmp)) {
4739 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4740 goto failed;
4742 len = PyList_GET_SIZE(tmp);
4743 generators = asdl_seq_new(len, arena);
4744 if (generators == NULL) goto failed;
4745 for (i = 0; i < len; i++) {
4746 comprehension_ty value;
4747 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
4748 if (res != 0) goto failed;
4749 asdl_seq_SET(generators, i, value);
4751 Py_XDECREF(tmp);
4752 tmp = NULL;
4753 } else {
4754 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
4755 return 1;
4757 *out = ListComp(elt, generators, lineno, col_offset, arena);
4758 if (*out == NULL) goto failed;
4759 return 0;
4761 if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) {
4762 expr_ty elt;
4763 asdl_seq* generators;
4765 if (PyObject_HasAttrString(obj, "elt")) {
4766 int res;
4767 tmp = PyObject_GetAttrString(obj, "elt");
4768 if (tmp == NULL) goto failed;
4769 res = obj2ast_expr(tmp, &elt, arena);
4770 if (res != 0) goto failed;
4771 Py_XDECREF(tmp);
4772 tmp = NULL;
4773 } else {
4774 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
4775 return 1;
4777 if (PyObject_HasAttrString(obj, "generators")) {
4778 int res;
4779 Py_ssize_t len;
4780 Py_ssize_t i;
4781 tmp = PyObject_GetAttrString(obj, "generators");
4782 if (tmp == NULL) goto failed;
4783 if (!PyList_Check(tmp)) {
4784 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4785 goto failed;
4787 len = PyList_GET_SIZE(tmp);
4788 generators = asdl_seq_new(len, arena);
4789 if (generators == NULL) goto failed;
4790 for (i = 0; i < len; i++) {
4791 comprehension_ty value;
4792 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
4793 if (res != 0) goto failed;
4794 asdl_seq_SET(generators, i, value);
4796 Py_XDECREF(tmp);
4797 tmp = NULL;
4798 } else {
4799 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
4800 return 1;
4802 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
4803 if (*out == NULL) goto failed;
4804 return 0;
4806 if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) {
4807 expr_ty value;
4809 if (PyObject_HasAttrString(obj, "value")) {
4810 int res;
4811 tmp = PyObject_GetAttrString(obj, "value");
4812 if (tmp == NULL) goto failed;
4813 res = obj2ast_expr(tmp, &value, arena);
4814 if (res != 0) goto failed;
4815 Py_XDECREF(tmp);
4816 tmp = NULL;
4817 } else {
4818 value = NULL;
4820 *out = Yield(value, lineno, col_offset, arena);
4821 if (*out == NULL) goto failed;
4822 return 0;
4824 if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) {
4825 expr_ty left;
4826 asdl_int_seq* ops;
4827 asdl_seq* comparators;
4829 if (PyObject_HasAttrString(obj, "left")) {
4830 int res;
4831 tmp = PyObject_GetAttrString(obj, "left");
4832 if (tmp == NULL) goto failed;
4833 res = obj2ast_expr(tmp, &left, arena);
4834 if (res != 0) goto failed;
4835 Py_XDECREF(tmp);
4836 tmp = NULL;
4837 } else {
4838 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
4839 return 1;
4841 if (PyObject_HasAttrString(obj, "ops")) {
4842 int res;
4843 Py_ssize_t len;
4844 Py_ssize_t i;
4845 tmp = PyObject_GetAttrString(obj, "ops");
4846 if (tmp == NULL) goto failed;
4847 if (!PyList_Check(tmp)) {
4848 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4849 goto failed;
4851 len = PyList_GET_SIZE(tmp);
4852 ops = asdl_int_seq_new(len, arena);
4853 if (ops == NULL) goto failed;
4854 for (i = 0; i < len; i++) {
4855 cmpop_ty value;
4856 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
4857 if (res != 0) goto failed;
4858 asdl_seq_SET(ops, i, value);
4860 Py_XDECREF(tmp);
4861 tmp = NULL;
4862 } else {
4863 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
4864 return 1;
4866 if (PyObject_HasAttrString(obj, "comparators")) {
4867 int res;
4868 Py_ssize_t len;
4869 Py_ssize_t i;
4870 tmp = PyObject_GetAttrString(obj, "comparators");
4871 if (tmp == NULL) goto failed;
4872 if (!PyList_Check(tmp)) {
4873 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4874 goto failed;
4876 len = PyList_GET_SIZE(tmp);
4877 comparators = asdl_seq_new(len, arena);
4878 if (comparators == NULL) goto failed;
4879 for (i = 0; i < len; i++) {
4880 expr_ty value;
4881 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4882 if (res != 0) goto failed;
4883 asdl_seq_SET(comparators, i, value);
4885 Py_XDECREF(tmp);
4886 tmp = NULL;
4887 } else {
4888 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
4889 return 1;
4891 *out = Compare(left, ops, comparators, lineno, col_offset,
4892 arena);
4893 if (*out == NULL) goto failed;
4894 return 0;
4896 if (PyObject_IsInstance(obj, (PyObject*)Call_type)) {
4897 expr_ty func;
4898 asdl_seq* args;
4899 asdl_seq* keywords;
4900 expr_ty starargs;
4901 expr_ty kwargs;
4903 if (PyObject_HasAttrString(obj, "func")) {
4904 int res;
4905 tmp = PyObject_GetAttrString(obj, "func");
4906 if (tmp == NULL) goto failed;
4907 res = obj2ast_expr(tmp, &func, arena);
4908 if (res != 0) goto failed;
4909 Py_XDECREF(tmp);
4910 tmp = NULL;
4911 } else {
4912 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
4913 return 1;
4915 if (PyObject_HasAttrString(obj, "args")) {
4916 int res;
4917 Py_ssize_t len;
4918 Py_ssize_t i;
4919 tmp = PyObject_GetAttrString(obj, "args");
4920 if (tmp == NULL) goto failed;
4921 if (!PyList_Check(tmp)) {
4922 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4923 goto failed;
4925 len = PyList_GET_SIZE(tmp);
4926 args = asdl_seq_new(len, arena);
4927 if (args == NULL) goto failed;
4928 for (i = 0; i < len; i++) {
4929 expr_ty value;
4930 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4931 if (res != 0) goto failed;
4932 asdl_seq_SET(args, i, value);
4934 Py_XDECREF(tmp);
4935 tmp = NULL;
4936 } else {
4937 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
4938 return 1;
4940 if (PyObject_HasAttrString(obj, "keywords")) {
4941 int res;
4942 Py_ssize_t len;
4943 Py_ssize_t i;
4944 tmp = PyObject_GetAttrString(obj, "keywords");
4945 if (tmp == NULL) goto failed;
4946 if (!PyList_Check(tmp)) {
4947 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4948 goto failed;
4950 len = PyList_GET_SIZE(tmp);
4951 keywords = asdl_seq_new(len, arena);
4952 if (keywords == NULL) goto failed;
4953 for (i = 0; i < len; i++) {
4954 keyword_ty value;
4955 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
4956 if (res != 0) goto failed;
4957 asdl_seq_SET(keywords, i, value);
4959 Py_XDECREF(tmp);
4960 tmp = NULL;
4961 } else {
4962 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
4963 return 1;
4965 if (PyObject_HasAttrString(obj, "starargs")) {
4966 int res;
4967 tmp = PyObject_GetAttrString(obj, "starargs");
4968 if (tmp == NULL) goto failed;
4969 res = obj2ast_expr(tmp, &starargs, arena);
4970 if (res != 0) goto failed;
4971 Py_XDECREF(tmp);
4972 tmp = NULL;
4973 } else {
4974 starargs = NULL;
4976 if (PyObject_HasAttrString(obj, "kwargs")) {
4977 int res;
4978 tmp = PyObject_GetAttrString(obj, "kwargs");
4979 if (tmp == NULL) goto failed;
4980 res = obj2ast_expr(tmp, &kwargs, arena);
4981 if (res != 0) goto failed;
4982 Py_XDECREF(tmp);
4983 tmp = NULL;
4984 } else {
4985 kwargs = NULL;
4987 *out = Call(func, args, keywords, starargs, kwargs, lineno,
4988 col_offset, arena);
4989 if (*out == NULL) goto failed;
4990 return 0;
4992 if (PyObject_IsInstance(obj, (PyObject*)Repr_type)) {
4993 expr_ty value;
4995 if (PyObject_HasAttrString(obj, "value")) {
4996 int res;
4997 tmp = PyObject_GetAttrString(obj, "value");
4998 if (tmp == NULL) goto failed;
4999 res = obj2ast_expr(tmp, &value, arena);
5000 if (res != 0) goto failed;
5001 Py_XDECREF(tmp);
5002 tmp = NULL;
5003 } else {
5004 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
5005 return 1;
5007 *out = Repr(value, lineno, col_offset, arena);
5008 if (*out == NULL) goto failed;
5009 return 0;
5011 if (PyObject_IsInstance(obj, (PyObject*)Num_type)) {
5012 object n;
5014 if (PyObject_HasAttrString(obj, "n")) {
5015 int res;
5016 tmp = PyObject_GetAttrString(obj, "n");
5017 if (tmp == NULL) goto failed;
5018 res = obj2ast_object(tmp, &n, arena);
5019 if (res != 0) goto failed;
5020 Py_XDECREF(tmp);
5021 tmp = NULL;
5022 } else {
5023 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
5024 return 1;
5026 *out = Num(n, lineno, col_offset, arena);
5027 if (*out == NULL) goto failed;
5028 return 0;
5030 if (PyObject_IsInstance(obj, (PyObject*)Str_type)) {
5031 string s;
5033 if (PyObject_HasAttrString(obj, "s")) {
5034 int res;
5035 tmp = PyObject_GetAttrString(obj, "s");
5036 if (tmp == NULL) goto failed;
5037 res = obj2ast_string(tmp, &s, arena);
5038 if (res != 0) goto failed;
5039 Py_XDECREF(tmp);
5040 tmp = NULL;
5041 } else {
5042 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
5043 return 1;
5045 *out = Str(s, lineno, col_offset, arena);
5046 if (*out == NULL) goto failed;
5047 return 0;
5049 if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) {
5050 expr_ty value;
5051 identifier attr;
5052 expr_context_ty ctx;
5054 if (PyObject_HasAttrString(obj, "value")) {
5055 int res;
5056 tmp = PyObject_GetAttrString(obj, "value");
5057 if (tmp == NULL) goto failed;
5058 res = obj2ast_expr(tmp, &value, arena);
5059 if (res != 0) goto failed;
5060 Py_XDECREF(tmp);
5061 tmp = NULL;
5062 } else {
5063 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
5064 return 1;
5066 if (PyObject_HasAttrString(obj, "attr")) {
5067 int res;
5068 tmp = PyObject_GetAttrString(obj, "attr");
5069 if (tmp == NULL) goto failed;
5070 res = obj2ast_identifier(tmp, &attr, arena);
5071 if (res != 0) goto failed;
5072 Py_XDECREF(tmp);
5073 tmp = NULL;
5074 } else {
5075 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
5076 return 1;
5078 if (PyObject_HasAttrString(obj, "ctx")) {
5079 int res;
5080 tmp = PyObject_GetAttrString(obj, "ctx");
5081 if (tmp == NULL) goto failed;
5082 res = obj2ast_expr_context(tmp, &ctx, arena);
5083 if (res != 0) goto failed;
5084 Py_XDECREF(tmp);
5085 tmp = NULL;
5086 } else {
5087 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
5088 return 1;
5090 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
5091 if (*out == NULL) goto failed;
5092 return 0;
5094 if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) {
5095 expr_ty value;
5096 slice_ty slice;
5097 expr_context_ty ctx;
5099 if (PyObject_HasAttrString(obj, "value")) {
5100 int res;
5101 tmp = PyObject_GetAttrString(obj, "value");
5102 if (tmp == NULL) goto failed;
5103 res = obj2ast_expr(tmp, &value, arena);
5104 if (res != 0) goto failed;
5105 Py_XDECREF(tmp);
5106 tmp = NULL;
5107 } else {
5108 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
5109 return 1;
5111 if (PyObject_HasAttrString(obj, "slice")) {
5112 int res;
5113 tmp = PyObject_GetAttrString(obj, "slice");
5114 if (tmp == NULL) goto failed;
5115 res = obj2ast_slice(tmp, &slice, arena);
5116 if (res != 0) goto failed;
5117 Py_XDECREF(tmp);
5118 tmp = NULL;
5119 } else {
5120 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
5121 return 1;
5123 if (PyObject_HasAttrString(obj, "ctx")) {
5124 int res;
5125 tmp = PyObject_GetAttrString(obj, "ctx");
5126 if (tmp == NULL) goto failed;
5127 res = obj2ast_expr_context(tmp, &ctx, arena);
5128 if (res != 0) goto failed;
5129 Py_XDECREF(tmp);
5130 tmp = NULL;
5131 } else {
5132 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
5133 return 1;
5135 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
5136 if (*out == NULL) goto failed;
5137 return 0;
5139 if (PyObject_IsInstance(obj, (PyObject*)Name_type)) {
5140 identifier id;
5141 expr_context_ty ctx;
5143 if (PyObject_HasAttrString(obj, "id")) {
5144 int res;
5145 tmp = PyObject_GetAttrString(obj, "id");
5146 if (tmp == NULL) goto failed;
5147 res = obj2ast_identifier(tmp, &id, arena);
5148 if (res != 0) goto failed;
5149 Py_XDECREF(tmp);
5150 tmp = NULL;
5151 } else {
5152 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
5153 return 1;
5155 if (PyObject_HasAttrString(obj, "ctx")) {
5156 int res;
5157 tmp = PyObject_GetAttrString(obj, "ctx");
5158 if (tmp == NULL) goto failed;
5159 res = obj2ast_expr_context(tmp, &ctx, arena);
5160 if (res != 0) goto failed;
5161 Py_XDECREF(tmp);
5162 tmp = NULL;
5163 } else {
5164 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
5165 return 1;
5167 *out = Name(id, ctx, lineno, col_offset, arena);
5168 if (*out == NULL) goto failed;
5169 return 0;
5171 if (PyObject_IsInstance(obj, (PyObject*)List_type)) {
5172 asdl_seq* elts;
5173 expr_context_ty ctx;
5175 if (PyObject_HasAttrString(obj, "elts")) {
5176 int res;
5177 Py_ssize_t len;
5178 Py_ssize_t i;
5179 tmp = PyObject_GetAttrString(obj, "elts");
5180 if (tmp == NULL) goto failed;
5181 if (!PyList_Check(tmp)) {
5182 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5183 goto failed;
5185 len = PyList_GET_SIZE(tmp);
5186 elts = asdl_seq_new(len, arena);
5187 if (elts == NULL) goto failed;
5188 for (i = 0; i < len; i++) {
5189 expr_ty value;
5190 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5191 if (res != 0) goto failed;
5192 asdl_seq_SET(elts, i, value);
5194 Py_XDECREF(tmp);
5195 tmp = NULL;
5196 } else {
5197 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
5198 return 1;
5200 if (PyObject_HasAttrString(obj, "ctx")) {
5201 int res;
5202 tmp = PyObject_GetAttrString(obj, "ctx");
5203 if (tmp == NULL) goto failed;
5204 res = obj2ast_expr_context(tmp, &ctx, arena);
5205 if (res != 0) goto failed;
5206 Py_XDECREF(tmp);
5207 tmp = NULL;
5208 } else {
5209 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
5210 return 1;
5212 *out = List(elts, ctx, lineno, col_offset, arena);
5213 if (*out == NULL) goto failed;
5214 return 0;
5216 if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) {
5217 asdl_seq* elts;
5218 expr_context_ty ctx;
5220 if (PyObject_HasAttrString(obj, "elts")) {
5221 int res;
5222 Py_ssize_t len;
5223 Py_ssize_t i;
5224 tmp = PyObject_GetAttrString(obj, "elts");
5225 if (tmp == NULL) goto failed;
5226 if (!PyList_Check(tmp)) {
5227 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5228 goto failed;
5230 len = PyList_GET_SIZE(tmp);
5231 elts = asdl_seq_new(len, arena);
5232 if (elts == NULL) goto failed;
5233 for (i = 0; i < len; i++) {
5234 expr_ty value;
5235 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5236 if (res != 0) goto failed;
5237 asdl_seq_SET(elts, i, value);
5239 Py_XDECREF(tmp);
5240 tmp = NULL;
5241 } else {
5242 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
5243 return 1;
5245 if (PyObject_HasAttrString(obj, "ctx")) {
5246 int res;
5247 tmp = PyObject_GetAttrString(obj, "ctx");
5248 if (tmp == NULL) goto failed;
5249 res = obj2ast_expr_context(tmp, &ctx, arena);
5250 if (res != 0) goto failed;
5251 Py_XDECREF(tmp);
5252 tmp = NULL;
5253 } else {
5254 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
5255 return 1;
5257 *out = Tuple(elts, ctx, lineno, col_offset, arena);
5258 if (*out == NULL) goto failed;
5259 return 0;
5262 tmp = PyObject_Repr(obj);
5263 if (tmp == NULL) goto failed;
5264 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
5265 failed:
5266 Py_XDECREF(tmp);
5267 return 1;
5271 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
5273 PyObject* tmp = NULL;
5275 if (PyObject_IsInstance(obj, (PyObject*)Load_type)) {
5276 *out = Load;
5277 return 0;
5279 if (PyObject_IsInstance(obj, (PyObject*)Store_type)) {
5280 *out = Store;
5281 return 0;
5283 if (PyObject_IsInstance(obj, (PyObject*)Del_type)) {
5284 *out = Del;
5285 return 0;
5287 if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) {
5288 *out = AugLoad;
5289 return 0;
5291 if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) {
5292 *out = AugStore;
5293 return 0;
5295 if (PyObject_IsInstance(obj, (PyObject*)Param_type)) {
5296 *out = Param;
5297 return 0;
5300 tmp = PyObject_Repr(obj);
5301 if (tmp == NULL) goto failed;
5302 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
5303 failed:
5304 Py_XDECREF(tmp);
5305 return 1;
5309 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
5311 PyObject* tmp = NULL;
5314 if (obj == Py_None) {
5315 *out = NULL;
5316 return 0;
5318 if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) {
5320 *out = Ellipsis(arena);
5321 if (*out == NULL) goto failed;
5322 return 0;
5324 if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) {
5325 expr_ty lower;
5326 expr_ty upper;
5327 expr_ty step;
5329 if (PyObject_HasAttrString(obj, "lower")) {
5330 int res;
5331 tmp = PyObject_GetAttrString(obj, "lower");
5332 if (tmp == NULL) goto failed;
5333 res = obj2ast_expr(tmp, &lower, arena);
5334 if (res != 0) goto failed;
5335 Py_XDECREF(tmp);
5336 tmp = NULL;
5337 } else {
5338 lower = NULL;
5340 if (PyObject_HasAttrString(obj, "upper")) {
5341 int res;
5342 tmp = PyObject_GetAttrString(obj, "upper");
5343 if (tmp == NULL) goto failed;
5344 res = obj2ast_expr(tmp, &upper, arena);
5345 if (res != 0) goto failed;
5346 Py_XDECREF(tmp);
5347 tmp = NULL;
5348 } else {
5349 upper = NULL;
5351 if (PyObject_HasAttrString(obj, "step")) {
5352 int res;
5353 tmp = PyObject_GetAttrString(obj, "step");
5354 if (tmp == NULL) goto failed;
5355 res = obj2ast_expr(tmp, &step, arena);
5356 if (res != 0) goto failed;
5357 Py_XDECREF(tmp);
5358 tmp = NULL;
5359 } else {
5360 step = NULL;
5362 *out = Slice(lower, upper, step, arena);
5363 if (*out == NULL) goto failed;
5364 return 0;
5366 if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) {
5367 asdl_seq* dims;
5369 if (PyObject_HasAttrString(obj, "dims")) {
5370 int res;
5371 Py_ssize_t len;
5372 Py_ssize_t i;
5373 tmp = PyObject_GetAttrString(obj, "dims");
5374 if (tmp == NULL) goto failed;
5375 if (!PyList_Check(tmp)) {
5376 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5377 goto failed;
5379 len = PyList_GET_SIZE(tmp);
5380 dims = asdl_seq_new(len, arena);
5381 if (dims == NULL) goto failed;
5382 for (i = 0; i < len; i++) {
5383 slice_ty value;
5384 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
5385 if (res != 0) goto failed;
5386 asdl_seq_SET(dims, i, value);
5388 Py_XDECREF(tmp);
5389 tmp = NULL;
5390 } else {
5391 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
5392 return 1;
5394 *out = ExtSlice(dims, arena);
5395 if (*out == NULL) goto failed;
5396 return 0;
5398 if (PyObject_IsInstance(obj, (PyObject*)Index_type)) {
5399 expr_ty value;
5401 if (PyObject_HasAttrString(obj, "value")) {
5402 int res;
5403 tmp = PyObject_GetAttrString(obj, "value");
5404 if (tmp == NULL) goto failed;
5405 res = obj2ast_expr(tmp, &value, arena);
5406 if (res != 0) goto failed;
5407 Py_XDECREF(tmp);
5408 tmp = NULL;
5409 } else {
5410 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
5411 return 1;
5413 *out = Index(value, arena);
5414 if (*out == NULL) goto failed;
5415 return 0;
5418 tmp = PyObject_Repr(obj);
5419 if (tmp == NULL) goto failed;
5420 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
5421 failed:
5422 Py_XDECREF(tmp);
5423 return 1;
5427 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
5429 PyObject* tmp = NULL;
5431 if (PyObject_IsInstance(obj, (PyObject*)And_type)) {
5432 *out = And;
5433 return 0;
5435 if (PyObject_IsInstance(obj, (PyObject*)Or_type)) {
5436 *out = Or;
5437 return 0;
5440 tmp = PyObject_Repr(obj);
5441 if (tmp == NULL) goto failed;
5442 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
5443 failed:
5444 Py_XDECREF(tmp);
5445 return 1;
5449 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
5451 PyObject* tmp = NULL;
5453 if (PyObject_IsInstance(obj, (PyObject*)Add_type)) {
5454 *out = Add;
5455 return 0;
5457 if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) {
5458 *out = Sub;
5459 return 0;
5461 if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) {
5462 *out = Mult;
5463 return 0;
5465 if (PyObject_IsInstance(obj, (PyObject*)Div_type)) {
5466 *out = Div;
5467 return 0;
5469 if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) {
5470 *out = Mod;
5471 return 0;
5473 if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) {
5474 *out = Pow;
5475 return 0;
5477 if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) {
5478 *out = LShift;
5479 return 0;
5481 if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) {
5482 *out = RShift;
5483 return 0;
5485 if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) {
5486 *out = BitOr;
5487 return 0;
5489 if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) {
5490 *out = BitXor;
5491 return 0;
5493 if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) {
5494 *out = BitAnd;
5495 return 0;
5497 if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) {
5498 *out = FloorDiv;
5499 return 0;
5502 tmp = PyObject_Repr(obj);
5503 if (tmp == NULL) goto failed;
5504 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
5505 failed:
5506 Py_XDECREF(tmp);
5507 return 1;
5511 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
5513 PyObject* tmp = NULL;
5515 if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) {
5516 *out = Invert;
5517 return 0;
5519 if (PyObject_IsInstance(obj, (PyObject*)Not_type)) {
5520 *out = Not;
5521 return 0;
5523 if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) {
5524 *out = UAdd;
5525 return 0;
5527 if (PyObject_IsInstance(obj, (PyObject*)USub_type)) {
5528 *out = USub;
5529 return 0;
5532 tmp = PyObject_Repr(obj);
5533 if (tmp == NULL) goto failed;
5534 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
5535 failed:
5536 Py_XDECREF(tmp);
5537 return 1;
5541 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
5543 PyObject* tmp = NULL;
5545 if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) {
5546 *out = Eq;
5547 return 0;
5549 if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) {
5550 *out = NotEq;
5551 return 0;
5553 if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) {
5554 *out = Lt;
5555 return 0;
5557 if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) {
5558 *out = LtE;
5559 return 0;
5561 if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) {
5562 *out = Gt;
5563 return 0;
5565 if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) {
5566 *out = GtE;
5567 return 0;
5569 if (PyObject_IsInstance(obj, (PyObject*)Is_type)) {
5570 *out = Is;
5571 return 0;
5573 if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) {
5574 *out = IsNot;
5575 return 0;
5577 if (PyObject_IsInstance(obj, (PyObject*)In_type)) {
5578 *out = In;
5579 return 0;
5581 if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) {
5582 *out = NotIn;
5583 return 0;
5586 tmp = PyObject_Repr(obj);
5587 if (tmp == NULL) goto failed;
5588 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
5589 failed:
5590 Py_XDECREF(tmp);
5591 return 1;
5595 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
5597 PyObject* tmp = NULL;
5598 expr_ty target;
5599 expr_ty iter;
5600 asdl_seq* ifs;
5602 if (PyObject_HasAttrString(obj, "target")) {
5603 int res;
5604 tmp = PyObject_GetAttrString(obj, "target");
5605 if (tmp == NULL) goto failed;
5606 res = obj2ast_expr(tmp, &target, arena);
5607 if (res != 0) goto failed;
5608 Py_XDECREF(tmp);
5609 tmp = NULL;
5610 } else {
5611 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
5612 return 1;
5614 if (PyObject_HasAttrString(obj, "iter")) {
5615 int res;
5616 tmp = PyObject_GetAttrString(obj, "iter");
5617 if (tmp == NULL) goto failed;
5618 res = obj2ast_expr(tmp, &iter, arena);
5619 if (res != 0) goto failed;
5620 Py_XDECREF(tmp);
5621 tmp = NULL;
5622 } else {
5623 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
5624 return 1;
5626 if (PyObject_HasAttrString(obj, "ifs")) {
5627 int res;
5628 Py_ssize_t len;
5629 Py_ssize_t i;
5630 tmp = PyObject_GetAttrString(obj, "ifs");
5631 if (tmp == NULL) goto failed;
5632 if (!PyList_Check(tmp)) {
5633 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5634 goto failed;
5636 len = PyList_GET_SIZE(tmp);
5637 ifs = asdl_seq_new(len, arena);
5638 if (ifs == NULL) goto failed;
5639 for (i = 0; i < len; i++) {
5640 expr_ty value;
5641 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5642 if (res != 0) goto failed;
5643 asdl_seq_SET(ifs, i, value);
5645 Py_XDECREF(tmp);
5646 tmp = NULL;
5647 } else {
5648 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
5649 return 1;
5651 *out = comprehension(target, iter, ifs, arena);
5652 return 0;
5653 failed:
5654 Py_XDECREF(tmp);
5655 return 1;
5659 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
5661 PyObject* tmp = NULL;
5663 int lineno;
5664 int col_offset;
5666 if (obj == Py_None) {
5667 *out = NULL;
5668 return 0;
5670 if (PyObject_HasAttrString(obj, "lineno")) {
5671 int res;
5672 tmp = PyObject_GetAttrString(obj, "lineno");
5673 if (tmp == NULL) goto failed;
5674 res = obj2ast_int(tmp, &lineno, arena);
5675 if (res != 0) goto failed;
5676 Py_XDECREF(tmp);
5677 tmp = NULL;
5678 } else {
5679 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
5680 return 1;
5682 if (PyObject_HasAttrString(obj, "col_offset")) {
5683 int res;
5684 tmp = PyObject_GetAttrString(obj, "col_offset");
5685 if (tmp == NULL) goto failed;
5686 res = obj2ast_int(tmp, &col_offset, arena);
5687 if (res != 0) goto failed;
5688 Py_XDECREF(tmp);
5689 tmp = NULL;
5690 } else {
5691 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
5692 return 1;
5694 if (PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type)) {
5695 expr_ty type;
5696 expr_ty name;
5697 asdl_seq* body;
5699 if (PyObject_HasAttrString(obj, "type")) {
5700 int res;
5701 tmp = PyObject_GetAttrString(obj, "type");
5702 if (tmp == NULL) goto failed;
5703 res = obj2ast_expr(tmp, &type, arena);
5704 if (res != 0) goto failed;
5705 Py_XDECREF(tmp);
5706 tmp = NULL;
5707 } else {
5708 type = NULL;
5710 if (PyObject_HasAttrString(obj, "name")) {
5711 int res;
5712 tmp = PyObject_GetAttrString(obj, "name");
5713 if (tmp == NULL) goto failed;
5714 res = obj2ast_expr(tmp, &name, arena);
5715 if (res != 0) goto failed;
5716 Py_XDECREF(tmp);
5717 tmp = NULL;
5718 } else {
5719 name = NULL;
5721 if (PyObject_HasAttrString(obj, "body")) {
5722 int res;
5723 Py_ssize_t len;
5724 Py_ssize_t i;
5725 tmp = PyObject_GetAttrString(obj, "body");
5726 if (tmp == NULL) goto failed;
5727 if (!PyList_Check(tmp)) {
5728 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5729 goto failed;
5731 len = PyList_GET_SIZE(tmp);
5732 body = asdl_seq_new(len, arena);
5733 if (body == NULL) goto failed;
5734 for (i = 0; i < len; i++) {
5735 stmt_ty value;
5736 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
5737 if (res != 0) goto failed;
5738 asdl_seq_SET(body, i, value);
5740 Py_XDECREF(tmp);
5741 tmp = NULL;
5742 } else {
5743 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
5744 return 1;
5746 *out = ExceptHandler(type, name, body, lineno, col_offset,
5747 arena);
5748 if (*out == NULL) goto failed;
5749 return 0;
5752 tmp = PyObject_Repr(obj);
5753 if (tmp == NULL) goto failed;
5754 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
5755 failed:
5756 Py_XDECREF(tmp);
5757 return 1;
5761 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
5763 PyObject* tmp = NULL;
5764 asdl_seq* args;
5765 identifier vararg;
5766 identifier kwarg;
5767 asdl_seq* defaults;
5769 if (PyObject_HasAttrString(obj, "args")) {
5770 int res;
5771 Py_ssize_t len;
5772 Py_ssize_t i;
5773 tmp = PyObject_GetAttrString(obj, "args");
5774 if (tmp == NULL) goto failed;
5775 if (!PyList_Check(tmp)) {
5776 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5777 goto failed;
5779 len = PyList_GET_SIZE(tmp);
5780 args = asdl_seq_new(len, arena);
5781 if (args == NULL) goto failed;
5782 for (i = 0; i < len; i++) {
5783 expr_ty value;
5784 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5785 if (res != 0) goto failed;
5786 asdl_seq_SET(args, i, value);
5788 Py_XDECREF(tmp);
5789 tmp = NULL;
5790 } else {
5791 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
5792 return 1;
5794 if (PyObject_HasAttrString(obj, "vararg")) {
5795 int res;
5796 tmp = PyObject_GetAttrString(obj, "vararg");
5797 if (tmp == NULL) goto failed;
5798 res = obj2ast_identifier(tmp, &vararg, arena);
5799 if (res != 0) goto failed;
5800 Py_XDECREF(tmp);
5801 tmp = NULL;
5802 } else {
5803 vararg = NULL;
5805 if (PyObject_HasAttrString(obj, "kwarg")) {
5806 int res;
5807 tmp = PyObject_GetAttrString(obj, "kwarg");
5808 if (tmp == NULL) goto failed;
5809 res = obj2ast_identifier(tmp, &kwarg, arena);
5810 if (res != 0) goto failed;
5811 Py_XDECREF(tmp);
5812 tmp = NULL;
5813 } else {
5814 kwarg = NULL;
5816 if (PyObject_HasAttrString(obj, "defaults")) {
5817 int res;
5818 Py_ssize_t len;
5819 Py_ssize_t i;
5820 tmp = PyObject_GetAttrString(obj, "defaults");
5821 if (tmp == NULL) goto failed;
5822 if (!PyList_Check(tmp)) {
5823 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5824 goto failed;
5826 len = PyList_GET_SIZE(tmp);
5827 defaults = asdl_seq_new(len, arena);
5828 if (defaults == NULL) goto failed;
5829 for (i = 0; i < len; i++) {
5830 expr_ty value;
5831 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5832 if (res != 0) goto failed;
5833 asdl_seq_SET(defaults, i, value);
5835 Py_XDECREF(tmp);
5836 tmp = NULL;
5837 } else {
5838 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
5839 return 1;
5841 *out = arguments(args, vararg, kwarg, defaults, arena);
5842 return 0;
5843 failed:
5844 Py_XDECREF(tmp);
5845 return 1;
5849 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
5851 PyObject* tmp = NULL;
5852 identifier arg;
5853 expr_ty value;
5855 if (PyObject_HasAttrString(obj, "arg")) {
5856 int res;
5857 tmp = PyObject_GetAttrString(obj, "arg");
5858 if (tmp == NULL) goto failed;
5859 res = obj2ast_identifier(tmp, &arg, arena);
5860 if (res != 0) goto failed;
5861 Py_XDECREF(tmp);
5862 tmp = NULL;
5863 } else {
5864 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
5865 return 1;
5867 if (PyObject_HasAttrString(obj, "value")) {
5868 int res;
5869 tmp = PyObject_GetAttrString(obj, "value");
5870 if (tmp == NULL) goto failed;
5871 res = obj2ast_expr(tmp, &value, arena);
5872 if (res != 0) goto failed;
5873 Py_XDECREF(tmp);
5874 tmp = NULL;
5875 } else {
5876 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
5877 return 1;
5879 *out = keyword(arg, value, arena);
5880 return 0;
5881 failed:
5882 Py_XDECREF(tmp);
5883 return 1;
5887 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
5889 PyObject* tmp = NULL;
5890 identifier name;
5891 identifier asname;
5893 if (PyObject_HasAttrString(obj, "name")) {
5894 int res;
5895 tmp = PyObject_GetAttrString(obj, "name");
5896 if (tmp == NULL) goto failed;
5897 res = obj2ast_identifier(tmp, &name, arena);
5898 if (res != 0) goto failed;
5899 Py_XDECREF(tmp);
5900 tmp = NULL;
5901 } else {
5902 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
5903 return 1;
5905 if (PyObject_HasAttrString(obj, "asname")) {
5906 int res;
5907 tmp = PyObject_GetAttrString(obj, "asname");
5908 if (tmp == NULL) goto failed;
5909 res = obj2ast_identifier(tmp, &asname, arena);
5910 if (res != 0) goto failed;
5911 Py_XDECREF(tmp);
5912 tmp = NULL;
5913 } else {
5914 asname = NULL;
5916 *out = alias(name, asname, arena);
5917 return 0;
5918 failed:
5919 Py_XDECREF(tmp);
5920 return 1;
5924 PyMODINIT_FUNC
5925 init_ast(void)
5927 PyObject *m, *d;
5928 if (!init_types()) return;
5929 m = Py_InitModule3("_ast", NULL, NULL);
5930 if (!m) return;
5931 d = PyModule_GetDict(m);
5932 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
5933 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
5934 return;
5935 if (PyModule_AddStringConstant(m, "__version__", "62047") < 0)
5936 return;
5937 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
5938 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
5939 return;
5940 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
5941 < 0) return;
5942 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
5943 0) return;
5944 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
5945 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
5946 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
5947 < 0) return;
5948 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
5949 return;
5950 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
5951 return;
5952 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
5953 return;
5954 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
5955 return;
5956 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
5957 0) return;
5958 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
5959 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
5960 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
5961 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
5962 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
5963 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
5964 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
5965 0) return;
5966 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
5967 0) return;
5968 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
5969 return;
5970 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
5971 return;
5972 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
5973 0) return;
5974 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
5975 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
5976 return;
5977 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
5978 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
5979 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
5980 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
5981 return;
5982 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
5983 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
5984 return;
5985 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
5986 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
5987 return;
5988 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
5989 return;
5990 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
5991 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
5992 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
5993 return;
5994 if (PyDict_SetItemString(d, "GeneratorExp",
5995 (PyObject*)GeneratorExp_type) < 0) return;
5996 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
5997 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
5998 return;
5999 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
6000 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
6001 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
6002 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
6003 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
6004 0) return;
6005 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
6006 0) return;
6007 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
6008 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
6009 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
6010 if (PyDict_SetItemString(d, "expr_context",
6011 (PyObject*)expr_context_type) < 0) return;
6012 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
6013 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
6014 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
6015 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
6016 return;
6017 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
6018 return;
6019 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
6020 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
6021 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
6022 return;
6023 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
6024 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
6025 return;
6026 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
6027 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
6028 return;
6029 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
6030 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
6031 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
6032 return;
6033 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
6034 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
6035 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
6036 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
6037 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
6038 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
6039 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
6040 return;
6041 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
6042 return;
6043 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
6044 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
6045 return;
6046 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
6047 return;
6048 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
6049 return;
6050 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
6051 return;
6052 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
6053 return;
6054 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
6055 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
6056 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
6057 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
6058 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
6059 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
6060 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
6061 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
6062 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
6063 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
6064 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
6065 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
6066 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
6067 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
6068 if (PyDict_SetItemString(d, "comprehension",
6069 (PyObject*)comprehension_type) < 0) return;
6070 if (PyDict_SetItemString(d, "excepthandler",
6071 (PyObject*)excepthandler_type) < 0) return;
6072 if (PyDict_SetItemString(d, "ExceptHandler",
6073 (PyObject*)ExceptHandler_type) < 0) return;
6074 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
6075 0) return;
6076 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
6077 return;
6078 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
6082 PyObject* PyAST_mod2obj(mod_ty t)
6084 init_types();
6085 return ast2obj_mod(t);
6088 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6089 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
6091 mod_ty res;
6092 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
6093 (PyObject*)Interactive_type};
6094 char *req_name[] = {"Module", "Expression", "Interactive"};
6095 assert(0 <= mode && mode <= 2);
6097 init_types();
6099 if (!PyObject_IsInstance(ast, req_type[mode])) {
6100 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
6101 req_name[mode], Py_TYPE(ast)->tp_name);
6102 return NULL;
6104 if (obj2ast_mod(ast, &res, arena) != 0)
6105 return NULL;
6106 else
6107 return res;
6110 int PyAST_Check(PyObject* obj)
6112 init_types();
6113 return PyObject_IsInstance(obj, (PyObject*)&AST_type);