1 /* File automatically generated by Parser/asdl_c.py. */
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.
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[]={
22 static PyTypeObject *Interactive_type;
23 static char *Interactive_fields[]={
26 static PyTypeObject *Expression_type;
27 static char *Expression_fields[]={
30 static PyTypeObject *Suite_type;
31 static char *Suite_fields[]={
34 static PyTypeObject *stmt_type;
35 static char *stmt_attributes[] = {
39 static PyObject* ast2obj_stmt(void*);
40 static PyTypeObject *FunctionDef_type;
41 static char *FunctionDef_fields[]={
47 static PyTypeObject *ClassDef_type;
48 static char *ClassDef_fields[]={
54 static PyTypeObject *Return_type;
55 static char *Return_fields[]={
58 static PyTypeObject *Delete_type;
59 static char *Delete_fields[]={
62 static PyTypeObject *Assign_type;
63 static char *Assign_fields[]={
67 static PyTypeObject *AugAssign_type;
68 static char *AugAssign_fields[]={
73 static PyTypeObject *Print_type;
74 static char *Print_fields[]={
79 static PyTypeObject *For_type;
80 static char *For_fields[]={
86 static PyTypeObject *While_type;
87 static char *While_fields[]={
92 static PyTypeObject *If_type;
93 static char *If_fields[]={
98 static PyTypeObject *With_type;
99 static char *With_fields[]={
104 static PyTypeObject *Raise_type;
105 static char *Raise_fields[]={
110 static PyTypeObject *TryExcept_type;
111 static char *TryExcept_fields[]={
116 static PyTypeObject *TryFinally_type;
117 static char *TryFinally_fields[]={
121 static PyTypeObject *Assert_type;
122 static char *Assert_fields[]={
126 static PyTypeObject *Import_type;
127 static char *Import_fields[]={
130 static PyTypeObject *ImportFrom_type;
131 static char *ImportFrom_fields[]={
136 static PyTypeObject *Exec_type;
137 static char *Exec_fields[]={
142 static PyTypeObject *Global_type;
143 static char *Global_fields[]={
146 static PyTypeObject *Expr_type;
147 static char *Expr_fields[]={
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[] = {
158 static PyObject* ast2obj_expr(void*);
159 static PyTypeObject *BoolOp_type;
160 static char *BoolOp_fields[]={
164 static PyTypeObject *BinOp_type;
165 static char *BinOp_fields[]={
170 static PyTypeObject *UnaryOp_type;
171 static char *UnaryOp_fields[]={
175 static PyTypeObject *Lambda_type;
176 static char *Lambda_fields[]={
180 static PyTypeObject *IfExp_type;
181 static char *IfExp_fields[]={
186 static PyTypeObject *Dict_type;
187 static char *Dict_fields[]={
191 static PyTypeObject *Set_type;
192 static char *Set_fields[]={
195 static PyTypeObject *ListComp_type;
196 static char *ListComp_fields[]={
200 static PyTypeObject *SetComp_type;
201 static char *SetComp_fields[]={
205 static PyTypeObject *DictComp_type;
206 static char *DictComp_fields[]={
211 static PyTypeObject *GeneratorExp_type;
212 static char *GeneratorExp_fields[]={
216 static PyTypeObject *Yield_type;
217 static char *Yield_fields[]={
220 static PyTypeObject *Compare_type;
221 static char *Compare_fields[]={
226 static PyTypeObject *Call_type;
227 static char *Call_fields[]={
234 static PyTypeObject *Repr_type;
235 static char *Repr_fields[]={
238 static PyTypeObject *Num_type;
239 static char *Num_fields[]={
242 static PyTypeObject *Str_type;
243 static char *Str_fields[]={
246 static PyTypeObject *Attribute_type;
247 static char *Attribute_fields[]={
252 static PyTypeObject *Subscript_type;
253 static char *Subscript_fields[]={
258 static PyTypeObject *Name_type;
259 static char *Name_fields[]={
263 static PyTypeObject *List_type;
264 static char *List_fields[]={
268 static PyTypeObject *Tuple_type;
269 static char *Tuple_fields[]={
273 static PyTypeObject *expr_context_type;
274 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
275 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
276 static PyObject* ast2obj_expr_context(expr_context_ty);
277 static PyTypeObject *Load_type;
278 static PyTypeObject *Store_type;
279 static PyTypeObject *Del_type;
280 static PyTypeObject *AugLoad_type;
281 static PyTypeObject *AugStore_type;
282 static PyTypeObject *Param_type;
283 static PyTypeObject *slice_type;
284 static PyObject* ast2obj_slice(void*);
285 static PyTypeObject *Ellipsis_type;
286 static PyTypeObject *Slice_type;
287 static char *Slice_fields[]={
292 static PyTypeObject *ExtSlice_type;
293 static char *ExtSlice_fields[]={
296 static PyTypeObject *Index_type;
297 static char *Index_fields[]={
300 static PyTypeObject *boolop_type;
301 static PyObject *And_singleton, *Or_singleton;
302 static PyObject* ast2obj_boolop(boolop_ty);
303 static PyTypeObject *And_type;
304 static PyTypeObject *Or_type;
305 static PyTypeObject *operator_type;
306 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
307 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
308 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
310 static PyObject* ast2obj_operator(operator_ty);
311 static PyTypeObject *Add_type;
312 static PyTypeObject *Sub_type;
313 static PyTypeObject *Mult_type;
314 static PyTypeObject *Div_type;
315 static PyTypeObject *Mod_type;
316 static PyTypeObject *Pow_type;
317 static PyTypeObject *LShift_type;
318 static PyTypeObject *RShift_type;
319 static PyTypeObject *BitOr_type;
320 static PyTypeObject *BitXor_type;
321 static PyTypeObject *BitAnd_type;
322 static PyTypeObject *FloorDiv_type;
323 static PyTypeObject *unaryop_type;
324 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
326 static PyObject* ast2obj_unaryop(unaryop_ty);
327 static PyTypeObject *Invert_type;
328 static PyTypeObject *Not_type;
329 static PyTypeObject *UAdd_type;
330 static PyTypeObject *USub_type;
331 static PyTypeObject *cmpop_type;
332 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
333 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
335 static PyObject* ast2obj_cmpop(cmpop_ty);
336 static PyTypeObject *Eq_type;
337 static PyTypeObject *NotEq_type;
338 static PyTypeObject *Lt_type;
339 static PyTypeObject *LtE_type;
340 static PyTypeObject *Gt_type;
341 static PyTypeObject *GtE_type;
342 static PyTypeObject *Is_type;
343 static PyTypeObject *IsNot_type;
344 static PyTypeObject *In_type;
345 static PyTypeObject *NotIn_type;
346 static PyTypeObject *comprehension_type;
347 static PyObject* ast2obj_comprehension(void*);
348 static char *comprehension_fields[]={
353 static PyTypeObject *excepthandler_type;
354 static char *excepthandler_attributes[] = {
358 static PyObject* ast2obj_excepthandler(void*);
359 static PyTypeObject *ExceptHandler_type;
360 static char *ExceptHandler_fields[]={
365 static PyTypeObject *arguments_type;
366 static PyObject* ast2obj_arguments(void*);
367 static char *arguments_fields[]={
373 static PyTypeObject *keyword_type;
374 static PyObject* ast2obj_keyword(void*);
375 static char *keyword_fields[]={
379 static PyTypeObject *alias_type;
380 static PyObject* ast2obj_alias(void*);
381 static char *alias_fields[]={
388 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
390 Py_ssize_t i, numfields = 0;
392 PyObject *key, *value, *fields;
393 fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
397 numfields = PySequence_Size(fields);
401 res = 0; /* if no error occurs, this stays 0 to the end */
402 if (PyTuple_GET_SIZE(args) > 0) {
403 if (numfields != PyTuple_GET_SIZE(args)) {
404 PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
405 "%zd positional argument%s",
406 Py_TYPE(self)->tp_name,
407 numfields == 0 ? "" : "either 0 or ",
408 numfields, numfields == 1 ? "" : "s");
412 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
413 /* cannot be reached when fields is NULL */
414 PyObject *name = PySequence_GetItem(fields, i);
419 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
426 i = 0; /* needed by PyDict_Next */
427 while (PyDict_Next(kw, &i, &key, &value)) {
428 res = PyObject_SetAttr(self, key, value);
438 /* Pickling support */
440 ast_type_reduce(PyObject *self, PyObject *unused)
443 PyObject *dict = PyObject_GetAttrString(self, "__dict__");
445 if (PyErr_ExceptionMatches(PyExc_AttributeError))
451 res = Py_BuildValue("O()O", Py_TYPE(self), dict);
455 return Py_BuildValue("O()", Py_TYPE(self));
458 static PyMethodDef ast_type_methods[] = {
459 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
463 static PyTypeObject AST_type = {
464 PyVarObject_HEAD_INIT(&PyType_Type, 0)
474 0, /* tp_as_number */
475 0, /* tp_as_sequence */
476 0, /* tp_as_mapping */
480 PyObject_GenericGetAttr, /* tp_getattro */
481 PyObject_GenericSetAttr, /* tp_setattro */
482 0, /* tp_as_buffer */
483 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
487 0, /* tp_richcompare */
488 0, /* tp_weaklistoffset */
491 ast_type_methods, /* tp_methods */
496 0, /* tp_descr_get */
497 0, /* tp_descr_set */
498 0, /* tp_dictoffset */
499 (initproc)ast_type_init, /* tp_init */
500 PyType_GenericAlloc, /* tp_alloc */
501 PyType_GenericNew, /* tp_new */
502 PyObject_Del, /* tp_free */
506 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
508 PyObject *fnames, *result;
510 fnames = PyTuple_New(num_fields);
511 if (!fnames) return NULL;
512 for (i = 0; i < num_fields; i++) {
513 PyObject *field = PyString_FromString(fields[i]);
518 PyTuple_SET_ITEM(fnames, i, field);
520 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
521 type, base, "_fields", fnames, "__module__", "_ast");
523 return (PyTypeObject*)result;
526 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
529 PyObject *s, *l = PyTuple_New(num_fields);
532 for (i = 0; i < num_fields; i++) {
533 s = PyString_FromString(attrs[i]);
538 PyTuple_SET_ITEM(l, i, s);
540 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
545 /* Conversion AST -> Python */
547 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
549 int i, n = asdl_seq_LEN(seq);
550 PyObject *result = PyList_New(n);
554 for (i = 0; i < n; i++) {
555 value = func(asdl_seq_GET(seq, i));
560 PyList_SET_ITEM(result, i, value);
565 static PyObject* ast2obj_object(void *o)
569 Py_INCREF((PyObject*)o);
572 #define ast2obj_identifier ast2obj_object
573 #define ast2obj_string ast2obj_object
574 static PyObject* ast2obj_bool(bool b)
576 return PyBool_FromLong(b);
579 static PyObject* ast2obj_int(long b)
581 return PyInt_FromLong(b);
584 /* Conversion Python -> AST */
586 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
591 PyArena_AddPyObject(arena, obj);
597 #define obj2ast_identifier obj2ast_object
598 #define obj2ast_string obj2ast_object
600 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
603 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
604 PyObject *s = PyObject_Repr(obj);
605 if (s == NULL) return 1;
606 PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
607 PyString_AS_STRING(s));
612 i = (int)PyLong_AsLong(obj);
613 if (i == -1 && PyErr_Occurred())
619 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
621 if (!PyBool_Check(obj)) {
622 PyObject *s = PyObject_Repr(obj);
623 if (s == NULL) return 1;
624 PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
625 PyString_AS_STRING(s));
630 *out = (obj == Py_True);
634 static int add_ast_fields(void)
636 PyObject *empty_tuple, *d;
637 if (PyType_Ready(&AST_type) < 0)
639 d = AST_type.tp_dict;
640 empty_tuple = PyTuple_New(0);
642 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
643 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
644 Py_XDECREF(empty_tuple);
647 Py_DECREF(empty_tuple);
652 static int init_types(void)
654 static int initialized;
655 if (initialized) return 1;
656 if (add_ast_fields() < 0) return 0;
657 mod_type = make_type("mod", &AST_type, NULL, 0);
658 if (!mod_type) return 0;
659 if (!add_attributes(mod_type, NULL, 0)) return 0;
660 Module_type = make_type("Module", mod_type, Module_fields, 1);
661 if (!Module_type) return 0;
662 Interactive_type = make_type("Interactive", mod_type,
663 Interactive_fields, 1);
664 if (!Interactive_type) return 0;
665 Expression_type = make_type("Expression", mod_type, Expression_fields,
667 if (!Expression_type) return 0;
668 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
669 if (!Suite_type) return 0;
670 stmt_type = make_type("stmt", &AST_type, NULL, 0);
671 if (!stmt_type) return 0;
672 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
673 FunctionDef_type = make_type("FunctionDef", stmt_type,
674 FunctionDef_fields, 4);
675 if (!FunctionDef_type) return 0;
676 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
677 if (!ClassDef_type) return 0;
678 Return_type = make_type("Return", stmt_type, Return_fields, 1);
679 if (!Return_type) return 0;
680 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
681 if (!Delete_type) return 0;
682 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
683 if (!Assign_type) return 0;
684 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
685 if (!AugAssign_type) return 0;
686 Print_type = make_type("Print", stmt_type, Print_fields, 3);
687 if (!Print_type) return 0;
688 For_type = make_type("For", stmt_type, For_fields, 4);
689 if (!For_type) return 0;
690 While_type = make_type("While", stmt_type, While_fields, 3);
691 if (!While_type) return 0;
692 If_type = make_type("If", stmt_type, If_fields, 3);
693 if (!If_type) return 0;
694 With_type = make_type("With", stmt_type, With_fields, 3);
695 if (!With_type) return 0;
696 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
697 if (!Raise_type) return 0;
698 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
699 if (!TryExcept_type) return 0;
700 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
702 if (!TryFinally_type) return 0;
703 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
704 if (!Assert_type) return 0;
705 Import_type = make_type("Import", stmt_type, Import_fields, 1);
706 if (!Import_type) return 0;
707 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
709 if (!ImportFrom_type) return 0;
710 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
711 if (!Exec_type) return 0;
712 Global_type = make_type("Global", stmt_type, Global_fields, 1);
713 if (!Global_type) return 0;
714 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
715 if (!Expr_type) return 0;
716 Pass_type = make_type("Pass", stmt_type, NULL, 0);
717 if (!Pass_type) return 0;
718 Break_type = make_type("Break", stmt_type, NULL, 0);
719 if (!Break_type) return 0;
720 Continue_type = make_type("Continue", stmt_type, NULL, 0);
721 if (!Continue_type) return 0;
722 expr_type = make_type("expr", &AST_type, NULL, 0);
723 if (!expr_type) return 0;
724 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
725 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
726 if (!BoolOp_type) return 0;
727 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
728 if (!BinOp_type) return 0;
729 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
730 if (!UnaryOp_type) return 0;
731 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
732 if (!Lambda_type) return 0;
733 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
734 if (!IfExp_type) return 0;
735 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
736 if (!Dict_type) return 0;
737 Set_type = make_type("Set", expr_type, Set_fields, 1);
738 if (!Set_type) return 0;
739 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
740 if (!ListComp_type) return 0;
741 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
742 if (!SetComp_type) return 0;
743 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
744 if (!DictComp_type) return 0;
745 GeneratorExp_type = make_type("GeneratorExp", expr_type,
746 GeneratorExp_fields, 2);
747 if (!GeneratorExp_type) return 0;
748 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
749 if (!Yield_type) return 0;
750 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
751 if (!Compare_type) return 0;
752 Call_type = make_type("Call", expr_type, Call_fields, 5);
753 if (!Call_type) return 0;
754 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
755 if (!Repr_type) return 0;
756 Num_type = make_type("Num", expr_type, Num_fields, 1);
757 if (!Num_type) return 0;
758 Str_type = make_type("Str", expr_type, Str_fields, 1);
759 if (!Str_type) return 0;
760 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
761 if (!Attribute_type) return 0;
762 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
763 if (!Subscript_type) return 0;
764 Name_type = make_type("Name", expr_type, Name_fields, 2);
765 if (!Name_type) return 0;
766 List_type = make_type("List", expr_type, List_fields, 2);
767 if (!List_type) return 0;
768 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
769 if (!Tuple_type) return 0;
770 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
771 if (!expr_context_type) return 0;
772 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
773 Load_type = make_type("Load", expr_context_type, NULL, 0);
774 if (!Load_type) return 0;
775 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
776 if (!Load_singleton) return 0;
777 Store_type = make_type("Store", expr_context_type, NULL, 0);
778 if (!Store_type) return 0;
779 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
780 if (!Store_singleton) return 0;
781 Del_type = make_type("Del", expr_context_type, NULL, 0);
782 if (!Del_type) return 0;
783 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
784 if (!Del_singleton) return 0;
785 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
786 if (!AugLoad_type) return 0;
787 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
788 if (!AugLoad_singleton) return 0;
789 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
790 if (!AugStore_type) return 0;
791 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
792 if (!AugStore_singleton) return 0;
793 Param_type = make_type("Param", expr_context_type, NULL, 0);
794 if (!Param_type) return 0;
795 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
796 if (!Param_singleton) return 0;
797 slice_type = make_type("slice", &AST_type, NULL, 0);
798 if (!slice_type) return 0;
799 if (!add_attributes(slice_type, NULL, 0)) return 0;
800 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
801 if (!Ellipsis_type) return 0;
802 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
803 if (!Slice_type) return 0;
804 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
805 if (!ExtSlice_type) return 0;
806 Index_type = make_type("Index", slice_type, Index_fields, 1);
807 if (!Index_type) return 0;
808 boolop_type = make_type("boolop", &AST_type, NULL, 0);
809 if (!boolop_type) return 0;
810 if (!add_attributes(boolop_type, NULL, 0)) return 0;
811 And_type = make_type("And", boolop_type, NULL, 0);
812 if (!And_type) return 0;
813 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
814 if (!And_singleton) return 0;
815 Or_type = make_type("Or", boolop_type, NULL, 0);
816 if (!Or_type) return 0;
817 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
818 if (!Or_singleton) return 0;
819 operator_type = make_type("operator", &AST_type, NULL, 0);
820 if (!operator_type) return 0;
821 if (!add_attributes(operator_type, NULL, 0)) return 0;
822 Add_type = make_type("Add", operator_type, NULL, 0);
823 if (!Add_type) return 0;
824 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
825 if (!Add_singleton) return 0;
826 Sub_type = make_type("Sub", operator_type, NULL, 0);
827 if (!Sub_type) return 0;
828 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
829 if (!Sub_singleton) return 0;
830 Mult_type = make_type("Mult", operator_type, NULL, 0);
831 if (!Mult_type) return 0;
832 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
833 if (!Mult_singleton) return 0;
834 Div_type = make_type("Div", operator_type, NULL, 0);
835 if (!Div_type) return 0;
836 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
837 if (!Div_singleton) return 0;
838 Mod_type = make_type("Mod", operator_type, NULL, 0);
839 if (!Mod_type) return 0;
840 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
841 if (!Mod_singleton) return 0;
842 Pow_type = make_type("Pow", operator_type, NULL, 0);
843 if (!Pow_type) return 0;
844 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
845 if (!Pow_singleton) return 0;
846 LShift_type = make_type("LShift", operator_type, NULL, 0);
847 if (!LShift_type) return 0;
848 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
849 if (!LShift_singleton) return 0;
850 RShift_type = make_type("RShift", operator_type, NULL, 0);
851 if (!RShift_type) return 0;
852 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
853 if (!RShift_singleton) return 0;
854 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
855 if (!BitOr_type) return 0;
856 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
857 if (!BitOr_singleton) return 0;
858 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
859 if (!BitXor_type) return 0;
860 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
861 if (!BitXor_singleton) return 0;
862 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
863 if (!BitAnd_type) return 0;
864 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
865 if (!BitAnd_singleton) return 0;
866 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
867 if (!FloorDiv_type) return 0;
868 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
869 if (!FloorDiv_singleton) return 0;
870 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
871 if (!unaryop_type) return 0;
872 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
873 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
874 if (!Invert_type) return 0;
875 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
876 if (!Invert_singleton) return 0;
877 Not_type = make_type("Not", unaryop_type, NULL, 0);
878 if (!Not_type) return 0;
879 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
880 if (!Not_singleton) return 0;
881 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
882 if (!UAdd_type) return 0;
883 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
884 if (!UAdd_singleton) return 0;
885 USub_type = make_type("USub", unaryop_type, NULL, 0);
886 if (!USub_type) return 0;
887 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
888 if (!USub_singleton) return 0;
889 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
890 if (!cmpop_type) return 0;
891 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
892 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
893 if (!Eq_type) return 0;
894 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
895 if (!Eq_singleton) return 0;
896 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
897 if (!NotEq_type) return 0;
898 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
899 if (!NotEq_singleton) return 0;
900 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
901 if (!Lt_type) return 0;
902 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
903 if (!Lt_singleton) return 0;
904 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
905 if (!LtE_type) return 0;
906 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
907 if (!LtE_singleton) return 0;
908 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
909 if (!Gt_type) return 0;
910 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
911 if (!Gt_singleton) return 0;
912 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
913 if (!GtE_type) return 0;
914 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
915 if (!GtE_singleton) return 0;
916 Is_type = make_type("Is", cmpop_type, NULL, 0);
917 if (!Is_type) return 0;
918 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
919 if (!Is_singleton) return 0;
920 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
921 if (!IsNot_type) return 0;
922 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
923 if (!IsNot_singleton) return 0;
924 In_type = make_type("In", cmpop_type, NULL, 0);
925 if (!In_type) return 0;
926 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
927 if (!In_singleton) return 0;
928 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
929 if (!NotIn_type) return 0;
930 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
931 if (!NotIn_singleton) return 0;
932 comprehension_type = make_type("comprehension", &AST_type,
933 comprehension_fields, 3);
934 if (!comprehension_type) return 0;
935 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
936 if (!excepthandler_type) return 0;
937 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
939 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
940 ExceptHandler_fields, 3);
941 if (!ExceptHandler_type) return 0;
942 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
943 if (!arguments_type) return 0;
944 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
945 if (!keyword_type) return 0;
946 alias_type = make_type("alias", &AST_type, alias_fields, 2);
947 if (!alias_type) return 0;
952 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
953 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
954 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
955 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
957 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
958 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
959 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
960 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
961 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
962 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
964 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
966 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
967 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
968 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
971 Module(asdl_seq * body, PyArena *arena)
974 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
977 p->kind = Module_kind;
978 p->v.Module.body = body;
983 Interactive(asdl_seq * body, PyArena *arena)
986 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
989 p->kind = Interactive_kind;
990 p->v.Interactive.body = body;
995 Expression(expr_ty body, PyArena *arena)
999 PyErr_SetString(PyExc_ValueError,
1000 "field body is required for Expression");
1003 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1006 p->kind = Expression_kind;
1007 p->v.Expression.body = body;
1012 Suite(asdl_seq * body, PyArena *arena)
1015 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1018 p->kind = Suite_kind;
1019 p->v.Suite.body = body;
1024 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
1025 decorator_list, int lineno, int col_offset, PyArena *arena)
1029 PyErr_SetString(PyExc_ValueError,
1030 "field name is required for FunctionDef");
1034 PyErr_SetString(PyExc_ValueError,
1035 "field args is required for FunctionDef");
1038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1041 p->kind = FunctionDef_kind;
1042 p->v.FunctionDef.name = name;
1043 p->v.FunctionDef.args = args;
1044 p->v.FunctionDef.body = body;
1045 p->v.FunctionDef.decorator_list = decorator_list;
1047 p->col_offset = col_offset;
1052 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
1053 decorator_list, int lineno, int col_offset, PyArena *arena)
1057 PyErr_SetString(PyExc_ValueError,
1058 "field name is required for ClassDef");
1061 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1064 p->kind = ClassDef_kind;
1065 p->v.ClassDef.name = name;
1066 p->v.ClassDef.bases = bases;
1067 p->v.ClassDef.body = body;
1068 p->v.ClassDef.decorator_list = decorator_list;
1070 p->col_offset = col_offset;
1075 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
1078 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1081 p->kind = Return_kind;
1082 p->v.Return.value = value;
1084 p->col_offset = col_offset;
1089 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
1092 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1095 p->kind = Delete_kind;
1096 p->v.Delete.targets = targets;
1098 p->col_offset = col_offset;
1103 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1108 PyErr_SetString(PyExc_ValueError,
1109 "field value is required for Assign");
1112 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1115 p->kind = Assign_kind;
1116 p->v.Assign.targets = targets;
1117 p->v.Assign.value = value;
1119 p->col_offset = col_offset;
1124 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1125 col_offset, PyArena *arena)
1129 PyErr_SetString(PyExc_ValueError,
1130 "field target is required for AugAssign");
1134 PyErr_SetString(PyExc_ValueError,
1135 "field op is required for AugAssign");
1139 PyErr_SetString(PyExc_ValueError,
1140 "field value is required for AugAssign");
1143 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1146 p->kind = AugAssign_kind;
1147 p->v.AugAssign.target = target;
1148 p->v.AugAssign.op = op;
1149 p->v.AugAssign.value = value;
1151 p->col_offset = col_offset;
1156 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
1160 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1163 p->kind = Print_kind;
1164 p->v.Print.dest = dest;
1165 p->v.Print.values = values;
1168 p->col_offset = col_offset;
1173 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1174 lineno, int col_offset, PyArena *arena)
1178 PyErr_SetString(PyExc_ValueError,
1179 "field target is required for For");
1183 PyErr_SetString(PyExc_ValueError,
1184 "field iter is required for For");
1187 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1191 p->v.For.target = target;
1192 p->v.For.iter = iter;
1193 p->v.For.body = body;
1194 p->v.For.orelse = orelse;
1196 p->col_offset = col_offset;
1201 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1202 col_offset, PyArena *arena)
1206 PyErr_SetString(PyExc_ValueError,
1207 "field test is required for While");
1210 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1213 p->kind = While_kind;
1214 p->v.While.test = test;
1215 p->v.While.body = body;
1216 p->v.While.orelse = orelse;
1218 p->col_offset = col_offset;
1223 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1224 col_offset, PyArena *arena)
1228 PyErr_SetString(PyExc_ValueError,
1229 "field test is required for If");
1232 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1236 p->v.If.test = test;
1237 p->v.If.body = body;
1238 p->v.If.orelse = orelse;
1240 p->col_offset = col_offset;
1245 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1246 int col_offset, PyArena *arena)
1249 if (!context_expr) {
1250 PyErr_SetString(PyExc_ValueError,
1251 "field context_expr is required for With");
1254 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1257 p->kind = With_kind;
1258 p->v.With.context_expr = context_expr;
1259 p->v.With.optional_vars = optional_vars;
1260 p->v.With.body = body;
1262 p->col_offset = col_offset;
1267 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1271 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1274 p->kind = Raise_kind;
1275 p->v.Raise.type = type;
1276 p->v.Raise.inst = inst;
1277 p->v.Raise.tback = tback;
1279 p->col_offset = col_offset;
1284 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1285 int col_offset, PyArena *arena)
1288 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1291 p->kind = TryExcept_kind;
1292 p->v.TryExcept.body = body;
1293 p->v.TryExcept.handlers = handlers;
1294 p->v.TryExcept.orelse = orelse;
1296 p->col_offset = col_offset;
1301 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1305 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1308 p->kind = TryFinally_kind;
1309 p->v.TryFinally.body = body;
1310 p->v.TryFinally.finalbody = finalbody;
1312 p->col_offset = col_offset;
1317 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1321 PyErr_SetString(PyExc_ValueError,
1322 "field test is required for Assert");
1325 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1328 p->kind = Assert_kind;
1329 p->v.Assert.test = test;
1330 p->v.Assert.msg = msg;
1332 p->col_offset = col_offset;
1337 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1340 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1343 p->kind = Import_kind;
1344 p->v.Import.names = names;
1346 p->col_offset = col_offset;
1351 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1352 col_offset, PyArena *arena)
1355 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1358 p->kind = ImportFrom_kind;
1359 p->v.ImportFrom.module = module;
1360 p->v.ImportFrom.names = names;
1361 p->v.ImportFrom.level = level;
1363 p->col_offset = col_offset;
1368 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1373 PyErr_SetString(PyExc_ValueError,
1374 "field body is required for Exec");
1377 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1380 p->kind = Exec_kind;
1381 p->v.Exec.body = body;
1382 p->v.Exec.globals = globals;
1383 p->v.Exec.locals = locals;
1385 p->col_offset = col_offset;
1390 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1393 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1396 p->kind = Global_kind;
1397 p->v.Global.names = names;
1399 p->col_offset = col_offset;
1404 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1408 PyErr_SetString(PyExc_ValueError,
1409 "field value is required for Expr");
1412 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1415 p->kind = Expr_kind;
1416 p->v.Expr.value = value;
1418 p->col_offset = col_offset;
1423 Pass(int lineno, int col_offset, PyArena *arena)
1426 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1429 p->kind = Pass_kind;
1431 p->col_offset = col_offset;
1436 Break(int lineno, int col_offset, PyArena *arena)
1439 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1442 p->kind = Break_kind;
1444 p->col_offset = col_offset;
1449 Continue(int lineno, int col_offset, PyArena *arena)
1452 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1455 p->kind = Continue_kind;
1457 p->col_offset = col_offset;
1462 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1467 PyErr_SetString(PyExc_ValueError,
1468 "field op is required for BoolOp");
1471 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1474 p->kind = BoolOp_kind;
1475 p->v.BoolOp.op = op;
1476 p->v.BoolOp.values = values;
1478 p->col_offset = col_offset;
1483 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1488 PyErr_SetString(PyExc_ValueError,
1489 "field left is required for BinOp");
1493 PyErr_SetString(PyExc_ValueError,
1494 "field op is required for BinOp");
1498 PyErr_SetString(PyExc_ValueError,
1499 "field right is required for BinOp");
1502 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1505 p->kind = BinOp_kind;
1506 p->v.BinOp.left = left;
1508 p->v.BinOp.right = right;
1510 p->col_offset = col_offset;
1515 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1520 PyErr_SetString(PyExc_ValueError,
1521 "field op is required for UnaryOp");
1525 PyErr_SetString(PyExc_ValueError,
1526 "field operand is required for UnaryOp");
1529 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1532 p->kind = UnaryOp_kind;
1533 p->v.UnaryOp.op = op;
1534 p->v.UnaryOp.operand = operand;
1536 p->col_offset = col_offset;
1541 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1546 PyErr_SetString(PyExc_ValueError,
1547 "field args is required for Lambda");
1551 PyErr_SetString(PyExc_ValueError,
1552 "field body is required for Lambda");
1555 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1558 p->kind = Lambda_kind;
1559 p->v.Lambda.args = args;
1560 p->v.Lambda.body = body;
1562 p->col_offset = col_offset;
1567 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1572 PyErr_SetString(PyExc_ValueError,
1573 "field test is required for IfExp");
1577 PyErr_SetString(PyExc_ValueError,
1578 "field body is required for IfExp");
1582 PyErr_SetString(PyExc_ValueError,
1583 "field orelse is required for IfExp");
1586 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1589 p->kind = IfExp_kind;
1590 p->v.IfExp.test = test;
1591 p->v.IfExp.body = body;
1592 p->v.IfExp.orelse = orelse;
1594 p->col_offset = col_offset;
1599 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1603 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1606 p->kind = Dict_kind;
1607 p->v.Dict.keys = keys;
1608 p->v.Dict.values = values;
1610 p->col_offset = col_offset;
1615 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1618 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1622 p->v.Set.elts = elts;
1624 p->col_offset = col_offset;
1629 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1634 PyErr_SetString(PyExc_ValueError,
1635 "field elt is required for ListComp");
1638 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1641 p->kind = ListComp_kind;
1642 p->v.ListComp.elt = elt;
1643 p->v.ListComp.generators = generators;
1645 p->col_offset = col_offset;
1650 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1655 PyErr_SetString(PyExc_ValueError,
1656 "field elt is required for SetComp");
1659 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1662 p->kind = SetComp_kind;
1663 p->v.SetComp.elt = elt;
1664 p->v.SetComp.generators = generators;
1666 p->col_offset = col_offset;
1671 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1672 col_offset, PyArena *arena)
1676 PyErr_SetString(PyExc_ValueError,
1677 "field key is required for DictComp");
1681 PyErr_SetString(PyExc_ValueError,
1682 "field value is required for DictComp");
1685 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1688 p->kind = DictComp_kind;
1689 p->v.DictComp.key = key;
1690 p->v.DictComp.value = value;
1691 p->v.DictComp.generators = generators;
1693 p->col_offset = col_offset;
1698 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1703 PyErr_SetString(PyExc_ValueError,
1704 "field elt is required for GeneratorExp");
1707 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1710 p->kind = GeneratorExp_kind;
1711 p->v.GeneratorExp.elt = elt;
1712 p->v.GeneratorExp.generators = generators;
1714 p->col_offset = col_offset;
1719 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1722 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1725 p->kind = Yield_kind;
1726 p->v.Yield.value = value;
1728 p->col_offset = col_offset;
1733 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1734 int col_offset, PyArena *arena)
1738 PyErr_SetString(PyExc_ValueError,
1739 "field left is required for Compare");
1742 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1745 p->kind = Compare_kind;
1746 p->v.Compare.left = left;
1747 p->v.Compare.ops = ops;
1748 p->v.Compare.comparators = comparators;
1750 p->col_offset = col_offset;
1755 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1756 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1760 PyErr_SetString(PyExc_ValueError,
1761 "field func is required for Call");
1764 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1767 p->kind = Call_kind;
1768 p->v.Call.func = func;
1769 p->v.Call.args = args;
1770 p->v.Call.keywords = keywords;
1771 p->v.Call.starargs = starargs;
1772 p->v.Call.kwargs = kwargs;
1774 p->col_offset = col_offset;
1779 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1783 PyErr_SetString(PyExc_ValueError,
1784 "field value is required for Repr");
1787 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1790 p->kind = Repr_kind;
1791 p->v.Repr.value = value;
1793 p->col_offset = col_offset;
1798 Num(object n, int lineno, int col_offset, PyArena *arena)
1802 PyErr_SetString(PyExc_ValueError,
1803 "field n is required for Num");
1806 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1812 p->col_offset = col_offset;
1817 Str(string s, int lineno, int col_offset, PyArena *arena)
1821 PyErr_SetString(PyExc_ValueError,
1822 "field s is required for Str");
1825 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1831 p->col_offset = col_offset;
1836 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1837 col_offset, PyArena *arena)
1841 PyErr_SetString(PyExc_ValueError,
1842 "field value is required for Attribute");
1846 PyErr_SetString(PyExc_ValueError,
1847 "field attr is required for Attribute");
1851 PyErr_SetString(PyExc_ValueError,
1852 "field ctx is required for Attribute");
1855 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1858 p->kind = Attribute_kind;
1859 p->v.Attribute.value = value;
1860 p->v.Attribute.attr = attr;
1861 p->v.Attribute.ctx = ctx;
1863 p->col_offset = col_offset;
1868 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1869 col_offset, PyArena *arena)
1873 PyErr_SetString(PyExc_ValueError,
1874 "field value is required for Subscript");
1878 PyErr_SetString(PyExc_ValueError,
1879 "field slice is required for Subscript");
1883 PyErr_SetString(PyExc_ValueError,
1884 "field ctx is required for Subscript");
1887 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1890 p->kind = Subscript_kind;
1891 p->v.Subscript.value = value;
1892 p->v.Subscript.slice = slice;
1893 p->v.Subscript.ctx = ctx;
1895 p->col_offset = col_offset;
1900 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1905 PyErr_SetString(PyExc_ValueError,
1906 "field id is required for Name");
1910 PyErr_SetString(PyExc_ValueError,
1911 "field ctx is required for Name");
1914 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1917 p->kind = Name_kind;
1919 p->v.Name.ctx = ctx;
1921 p->col_offset = col_offset;
1926 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1931 PyErr_SetString(PyExc_ValueError,
1932 "field ctx is required for List");
1935 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1938 p->kind = List_kind;
1939 p->v.List.elts = elts;
1940 p->v.List.ctx = ctx;
1942 p->col_offset = col_offset;
1947 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1952 PyErr_SetString(PyExc_ValueError,
1953 "field ctx is required for Tuple");
1956 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1959 p->kind = Tuple_kind;
1960 p->v.Tuple.elts = elts;
1961 p->v.Tuple.ctx = ctx;
1963 p->col_offset = col_offset;
1968 Ellipsis(PyArena *arena)
1971 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1974 p->kind = Ellipsis_kind;
1979 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1982 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1985 p->kind = Slice_kind;
1986 p->v.Slice.lower = lower;
1987 p->v.Slice.upper = upper;
1988 p->v.Slice.step = step;
1993 ExtSlice(asdl_seq * dims, PyArena *arena)
1996 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1999 p->kind = ExtSlice_kind;
2000 p->v.ExtSlice.dims = dims;
2005 Index(expr_ty value, PyArena *arena)
2009 PyErr_SetString(PyExc_ValueError,
2010 "field value is required for Index");
2013 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2016 p->kind = Index_kind;
2017 p->v.Index.value = value;
2022 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
2026 PyErr_SetString(PyExc_ValueError,
2027 "field target is required for comprehension");
2031 PyErr_SetString(PyExc_ValueError,
2032 "field iter is required for comprehension");
2035 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
2045 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
2046 col_offset, PyArena *arena)
2049 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
2052 p->kind = ExceptHandler_kind;
2053 p->v.ExceptHandler.type = type;
2054 p->v.ExceptHandler.name = name;
2055 p->v.ExceptHandler.body = body;
2057 p->col_offset = col_offset;
2062 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
2063 defaults, PyArena *arena)
2066 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2072 p->defaults = defaults;
2077 keyword(identifier arg, expr_ty value, PyArena *arena)
2081 PyErr_SetString(PyExc_ValueError,
2082 "field arg is required for keyword");
2086 PyErr_SetString(PyExc_ValueError,
2087 "field value is required for keyword");
2090 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
2099 alias(identifier name, identifier asname, PyArena *arena)
2103 PyErr_SetString(PyExc_ValueError,
2104 "field name is required for alias");
2107 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2117 ast2obj_mod(void* _o)
2119 mod_ty o = (mod_ty)_o;
2120 PyObject *result = NULL, *value = NULL;
2128 result = PyType_GenericNew(Module_type, NULL, NULL);
2129 if (!result) goto failed;
2130 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "body", value) == -1)
2136 case Interactive_kind:
2137 result = PyType_GenericNew(Interactive_type, NULL, NULL);
2138 if (!result) goto failed;
2139 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2140 if (!value) goto failed;
2141 if (PyObject_SetAttrString(result, "body", value) == -1)
2145 case Expression_kind:
2146 result = PyType_GenericNew(Expression_type, NULL, NULL);
2147 if (!result) goto failed;
2148 value = ast2obj_expr(o->v.Expression.body);
2149 if (!value) goto failed;
2150 if (PyObject_SetAttrString(result, "body", value) == -1)
2155 result = PyType_GenericNew(Suite_type, NULL, NULL);
2156 if (!result) goto failed;
2157 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2158 if (!value) goto failed;
2159 if (PyObject_SetAttrString(result, "body", value) == -1)
2172 ast2obj_stmt(void* _o)
2174 stmt_ty o = (stmt_ty)_o;
2175 PyObject *result = NULL, *value = NULL;
2182 case FunctionDef_kind:
2183 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2184 if (!result) goto failed;
2185 value = ast2obj_identifier(o->v.FunctionDef.name);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "name", value) == -1)
2190 value = ast2obj_arguments(o->v.FunctionDef.args);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "args", value) == -1)
2195 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "body", value) == -1)
2200 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2202 if (!value) goto failed;
2203 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2209 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2210 if (!result) goto failed;
2211 value = ast2obj_identifier(o->v.ClassDef.name);
2212 if (!value) goto failed;
2213 if (PyObject_SetAttrString(result, "name", value) == -1)
2216 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2217 if (!value) goto failed;
2218 if (PyObject_SetAttrString(result, "bases", value) == -1)
2221 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2222 if (!value) goto failed;
2223 if (PyObject_SetAttrString(result, "body", value) == -1)
2226 value = ast2obj_list(o->v.ClassDef.decorator_list,
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2235 result = PyType_GenericNew(Return_type, NULL, NULL);
2236 if (!result) goto failed;
2237 value = ast2obj_expr(o->v.Return.value);
2238 if (!value) goto failed;
2239 if (PyObject_SetAttrString(result, "value", value) == -1)
2244 result = PyType_GenericNew(Delete_type, NULL, NULL);
2245 if (!result) goto failed;
2246 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "targets", value) == -1)
2253 result = PyType_GenericNew(Assign_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "targets", value) == -1)
2260 value = ast2obj_expr(o->v.Assign.value);
2261 if (!value) goto failed;
2262 if (PyObject_SetAttrString(result, "value", value) == -1)
2266 case AugAssign_kind:
2267 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2268 if (!result) goto failed;
2269 value = ast2obj_expr(o->v.AugAssign.target);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "target", value) == -1)
2274 value = ast2obj_operator(o->v.AugAssign.op);
2275 if (!value) goto failed;
2276 if (PyObject_SetAttrString(result, "op", value) == -1)
2279 value = ast2obj_expr(o->v.AugAssign.value);
2280 if (!value) goto failed;
2281 if (PyObject_SetAttrString(result, "value", value) == -1)
2286 result = PyType_GenericNew(Print_type, NULL, NULL);
2287 if (!result) goto failed;
2288 value = ast2obj_expr(o->v.Print.dest);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "dest", value) == -1)
2293 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2294 if (!value) goto failed;
2295 if (PyObject_SetAttrString(result, "values", value) == -1)
2298 value = ast2obj_bool(o->v.Print.nl);
2299 if (!value) goto failed;
2300 if (PyObject_SetAttrString(result, "nl", value) == -1)
2305 result = PyType_GenericNew(For_type, NULL, NULL);
2306 if (!result) goto failed;
2307 value = ast2obj_expr(o->v.For.target);
2308 if (!value) goto failed;
2309 if (PyObject_SetAttrString(result, "target", value) == -1)
2312 value = ast2obj_expr(o->v.For.iter);
2313 if (!value) goto failed;
2314 if (PyObject_SetAttrString(result, "iter", value) == -1)
2317 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2318 if (!value) goto failed;
2319 if (PyObject_SetAttrString(result, "body", value) == -1)
2322 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2323 if (!value) goto failed;
2324 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2329 result = PyType_GenericNew(While_type, NULL, NULL);
2330 if (!result) goto failed;
2331 value = ast2obj_expr(o->v.While.test);
2332 if (!value) goto failed;
2333 if (PyObject_SetAttrString(result, "test", value) == -1)
2336 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2337 if (!value) goto failed;
2338 if (PyObject_SetAttrString(result, "body", value) == -1)
2341 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2342 if (!value) goto failed;
2343 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2348 result = PyType_GenericNew(If_type, NULL, NULL);
2349 if (!result) goto failed;
2350 value = ast2obj_expr(o->v.If.test);
2351 if (!value) goto failed;
2352 if (PyObject_SetAttrString(result, "test", value) == -1)
2355 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2356 if (!value) goto failed;
2357 if (PyObject_SetAttrString(result, "body", value) == -1)
2360 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2367 result = PyType_GenericNew(With_type, NULL, NULL);
2368 if (!result) goto failed;
2369 value = ast2obj_expr(o->v.With.context_expr);
2370 if (!value) goto failed;
2371 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2374 value = ast2obj_expr(o->v.With.optional_vars);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2380 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "body", value) == -1)
2387 result = PyType_GenericNew(Raise_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_expr(o->v.Raise.type);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "type", value) == -1)
2394 value = ast2obj_expr(o->v.Raise.inst);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "inst", value) == -1)
2399 value = ast2obj_expr(o->v.Raise.tback);
2400 if (!value) goto failed;
2401 if (PyObject_SetAttrString(result, "tback", value) == -1)
2405 case TryExcept_kind:
2406 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2407 if (!result) goto failed;
2408 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2409 if (!value) goto failed;
2410 if (PyObject_SetAttrString(result, "body", value) == -1)
2413 value = ast2obj_list(o->v.TryExcept.handlers,
2414 ast2obj_excepthandler);
2415 if (!value) goto failed;
2416 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2419 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2420 if (!value) goto failed;
2421 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2425 case TryFinally_kind:
2426 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2427 if (!result) goto failed;
2428 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2429 if (!value) goto failed;
2430 if (PyObject_SetAttrString(result, "body", value) == -1)
2433 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2434 if (!value) goto failed;
2435 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2440 result = PyType_GenericNew(Assert_type, NULL, NULL);
2441 if (!result) goto failed;
2442 value = ast2obj_expr(o->v.Assert.test);
2443 if (!value) goto failed;
2444 if (PyObject_SetAttrString(result, "test", value) == -1)
2447 value = ast2obj_expr(o->v.Assert.msg);
2448 if (!value) goto failed;
2449 if (PyObject_SetAttrString(result, "msg", value) == -1)
2454 result = PyType_GenericNew(Import_type, NULL, NULL);
2455 if (!result) goto failed;
2456 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "names", value) == -1)
2462 case ImportFrom_kind:
2463 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_identifier(o->v.ImportFrom.module);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "module", value) == -1)
2470 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2471 if (!value) goto failed;
2472 if (PyObject_SetAttrString(result, "names", value) == -1)
2475 value = ast2obj_int(o->v.ImportFrom.level);
2476 if (!value) goto failed;
2477 if (PyObject_SetAttrString(result, "level", value) == -1)
2482 result = PyType_GenericNew(Exec_type, NULL, NULL);
2483 if (!result) goto failed;
2484 value = ast2obj_expr(o->v.Exec.body);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "body", value) == -1)
2489 value = ast2obj_expr(o->v.Exec.globals);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "globals", value) == -1)
2494 value = ast2obj_expr(o->v.Exec.locals);
2495 if (!value) goto failed;
2496 if (PyObject_SetAttrString(result, "locals", value) == -1)
2501 result = PyType_GenericNew(Global_type, NULL, NULL);
2502 if (!result) goto failed;
2503 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "names", value) == -1)
2510 result = PyType_GenericNew(Expr_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_expr(o->v.Expr.value);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "value", value) == -1)
2519 result = PyType_GenericNew(Pass_type, NULL, NULL);
2520 if (!result) goto failed;
2523 result = PyType_GenericNew(Break_type, NULL, NULL);
2524 if (!result) goto failed;
2527 result = PyType_GenericNew(Continue_type, NULL, NULL);
2528 if (!result) goto failed;
2531 value = ast2obj_int(o->lineno);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2536 value = ast2obj_int(o->col_offset);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2549 ast2obj_expr(void* _o)
2551 expr_ty o = (expr_ty)_o;
2552 PyObject *result = NULL, *value = NULL;
2560 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2561 if (!result) goto failed;
2562 value = ast2obj_boolop(o->v.BoolOp.op);
2563 if (!value) goto failed;
2564 if (PyObject_SetAttrString(result, "op", value) == -1)
2567 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2568 if (!value) goto failed;
2569 if (PyObject_SetAttrString(result, "values", value) == -1)
2574 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2575 if (!result) goto failed;
2576 value = ast2obj_expr(o->v.BinOp.left);
2577 if (!value) goto failed;
2578 if (PyObject_SetAttrString(result, "left", value) == -1)
2581 value = ast2obj_operator(o->v.BinOp.op);
2582 if (!value) goto failed;
2583 if (PyObject_SetAttrString(result, "op", value) == -1)
2586 value = ast2obj_expr(o->v.BinOp.right);
2587 if (!value) goto failed;
2588 if (PyObject_SetAttrString(result, "right", value) == -1)
2593 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2594 if (!result) goto failed;
2595 value = ast2obj_unaryop(o->v.UnaryOp.op);
2596 if (!value) goto failed;
2597 if (PyObject_SetAttrString(result, "op", value) == -1)
2600 value = ast2obj_expr(o->v.UnaryOp.operand);
2601 if (!value) goto failed;
2602 if (PyObject_SetAttrString(result, "operand", value) == -1)
2607 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2608 if (!result) goto failed;
2609 value = ast2obj_arguments(o->v.Lambda.args);
2610 if (!value) goto failed;
2611 if (PyObject_SetAttrString(result, "args", value) == -1)
2614 value = ast2obj_expr(o->v.Lambda.body);
2615 if (!value) goto failed;
2616 if (PyObject_SetAttrString(result, "body", value) == -1)
2621 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2622 if (!result) goto failed;
2623 value = ast2obj_expr(o->v.IfExp.test);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "test", value) == -1)
2628 value = ast2obj_expr(o->v.IfExp.body);
2629 if (!value) goto failed;
2630 if (PyObject_SetAttrString(result, "body", value) == -1)
2633 value = ast2obj_expr(o->v.IfExp.orelse);
2634 if (!value) goto failed;
2635 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2640 result = PyType_GenericNew(Dict_type, NULL, NULL);
2641 if (!result) goto failed;
2642 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2643 if (!value) goto failed;
2644 if (PyObject_SetAttrString(result, "keys", value) == -1)
2647 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2648 if (!value) goto failed;
2649 if (PyObject_SetAttrString(result, "values", value) == -1)
2654 result = PyType_GenericNew(Set_type, NULL, NULL);
2655 if (!result) goto failed;
2656 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2657 if (!value) goto failed;
2658 if (PyObject_SetAttrString(result, "elts", value) == -1)
2663 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2664 if (!result) goto failed;
2665 value = ast2obj_expr(o->v.ListComp.elt);
2666 if (!value) goto failed;
2667 if (PyObject_SetAttrString(result, "elt", value) == -1)
2670 value = ast2obj_list(o->v.ListComp.generators,
2671 ast2obj_comprehension);
2672 if (!value) goto failed;
2673 if (PyObject_SetAttrString(result, "generators", value) == -1)
2678 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2679 if (!result) goto failed;
2680 value = ast2obj_expr(o->v.SetComp.elt);
2681 if (!value) goto failed;
2682 if (PyObject_SetAttrString(result, "elt", value) == -1)
2685 value = ast2obj_list(o->v.SetComp.generators,
2686 ast2obj_comprehension);
2687 if (!value) goto failed;
2688 if (PyObject_SetAttrString(result, "generators", value) == -1)
2693 result = PyType_GenericNew(DictComp_type, NULL, NULL);
2694 if (!result) goto failed;
2695 value = ast2obj_expr(o->v.DictComp.key);
2696 if (!value) goto failed;
2697 if (PyObject_SetAttrString(result, "key", value) == -1)
2700 value = ast2obj_expr(o->v.DictComp.value);
2701 if (!value) goto failed;
2702 if (PyObject_SetAttrString(result, "value", value) == -1)
2705 value = ast2obj_list(o->v.DictComp.generators,
2706 ast2obj_comprehension);
2707 if (!value) goto failed;
2708 if (PyObject_SetAttrString(result, "generators", value) == -1)
2712 case GeneratorExp_kind:
2713 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2714 if (!result) goto failed;
2715 value = ast2obj_expr(o->v.GeneratorExp.elt);
2716 if (!value) goto failed;
2717 if (PyObject_SetAttrString(result, "elt", value) == -1)
2720 value = ast2obj_list(o->v.GeneratorExp.generators,
2721 ast2obj_comprehension);
2722 if (!value) goto failed;
2723 if (PyObject_SetAttrString(result, "generators", value) == -1)
2728 result = PyType_GenericNew(Yield_type, NULL, NULL);
2729 if (!result) goto failed;
2730 value = ast2obj_expr(o->v.Yield.value);
2731 if (!value) goto failed;
2732 if (PyObject_SetAttrString(result, "value", value) == -1)
2737 result = PyType_GenericNew(Compare_type, NULL, NULL);
2738 if (!result) goto failed;
2739 value = ast2obj_expr(o->v.Compare.left);
2740 if (!value) goto failed;
2741 if (PyObject_SetAttrString(result, "left", value) == -1)
2745 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2746 value = PyList_New(n);
2747 if (!value) goto failed;
2748 for(i = 0; i < n; i++)
2749 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2751 if (!value) goto failed;
2752 if (PyObject_SetAttrString(result, "ops", value) == -1)
2755 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2756 if (!value) goto failed;
2757 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2762 result = PyType_GenericNew(Call_type, NULL, NULL);
2763 if (!result) goto failed;
2764 value = ast2obj_expr(o->v.Call.func);
2765 if (!value) goto failed;
2766 if (PyObject_SetAttrString(result, "func", value) == -1)
2769 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2770 if (!value) goto failed;
2771 if (PyObject_SetAttrString(result, "args", value) == -1)
2774 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2775 if (!value) goto failed;
2776 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2779 value = ast2obj_expr(o->v.Call.starargs);
2780 if (!value) goto failed;
2781 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2784 value = ast2obj_expr(o->v.Call.kwargs);
2785 if (!value) goto failed;
2786 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2791 result = PyType_GenericNew(Repr_type, NULL, NULL);
2792 if (!result) goto failed;
2793 value = ast2obj_expr(o->v.Repr.value);
2794 if (!value) goto failed;
2795 if (PyObject_SetAttrString(result, "value", value) == -1)
2800 result = PyType_GenericNew(Num_type, NULL, NULL);
2801 if (!result) goto failed;
2802 value = ast2obj_object(o->v.Num.n);
2803 if (!value) goto failed;
2804 if (PyObject_SetAttrString(result, "n", value) == -1)
2809 result = PyType_GenericNew(Str_type, NULL, NULL);
2810 if (!result) goto failed;
2811 value = ast2obj_string(o->v.Str.s);
2812 if (!value) goto failed;
2813 if (PyObject_SetAttrString(result, "s", value) == -1)
2817 case Attribute_kind:
2818 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2819 if (!result) goto failed;
2820 value = ast2obj_expr(o->v.Attribute.value);
2821 if (!value) goto failed;
2822 if (PyObject_SetAttrString(result, "value", value) == -1)
2825 value = ast2obj_identifier(o->v.Attribute.attr);
2826 if (!value) goto failed;
2827 if (PyObject_SetAttrString(result, "attr", value) == -1)
2830 value = ast2obj_expr_context(o->v.Attribute.ctx);
2831 if (!value) goto failed;
2832 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2836 case Subscript_kind:
2837 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2838 if (!result) goto failed;
2839 value = ast2obj_expr(o->v.Subscript.value);
2840 if (!value) goto failed;
2841 if (PyObject_SetAttrString(result, "value", value) == -1)
2844 value = ast2obj_slice(o->v.Subscript.slice);
2845 if (!value) goto failed;
2846 if (PyObject_SetAttrString(result, "slice", value) == -1)
2849 value = ast2obj_expr_context(o->v.Subscript.ctx);
2850 if (!value) goto failed;
2851 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2856 result = PyType_GenericNew(Name_type, NULL, NULL);
2857 if (!result) goto failed;
2858 value = ast2obj_identifier(o->v.Name.id);
2859 if (!value) goto failed;
2860 if (PyObject_SetAttrString(result, "id", value) == -1)
2863 value = ast2obj_expr_context(o->v.Name.ctx);
2864 if (!value) goto failed;
2865 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2870 result = PyType_GenericNew(List_type, NULL, NULL);
2871 if (!result) goto failed;
2872 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2873 if (!value) goto failed;
2874 if (PyObject_SetAttrString(result, "elts", value) == -1)
2877 value = ast2obj_expr_context(o->v.List.ctx);
2878 if (!value) goto failed;
2879 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2884 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2885 if (!result) goto failed;
2886 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2887 if (!value) goto failed;
2888 if (PyObject_SetAttrString(result, "elts", value) == -1)
2891 value = ast2obj_expr_context(o->v.Tuple.ctx);
2892 if (!value) goto failed;
2893 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2898 value = ast2obj_int(o->lineno);
2899 if (!value) goto failed;
2900 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2903 value = ast2obj_int(o->col_offset);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2915 PyObject* ast2obj_expr_context(expr_context_ty o)
2919 Py_INCREF(Load_singleton);
2920 return Load_singleton;
2922 Py_INCREF(Store_singleton);
2923 return Store_singleton;
2925 Py_INCREF(Del_singleton);
2926 return Del_singleton;
2928 Py_INCREF(AugLoad_singleton);
2929 return AugLoad_singleton;
2931 Py_INCREF(AugStore_singleton);
2932 return AugStore_singleton;
2934 Py_INCREF(Param_singleton);
2935 return Param_singleton;
2937 /* should never happen, but just in case ... */
2938 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
2943 ast2obj_slice(void* _o)
2945 slice_ty o = (slice_ty)_o;
2946 PyObject *result = NULL, *value = NULL;
2954 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2955 if (!result) goto failed;
2958 result = PyType_GenericNew(Slice_type, NULL, NULL);
2959 if (!result) goto failed;
2960 value = ast2obj_expr(o->v.Slice.lower);
2961 if (!value) goto failed;
2962 if (PyObject_SetAttrString(result, "lower", value) == -1)
2965 value = ast2obj_expr(o->v.Slice.upper);
2966 if (!value) goto failed;
2967 if (PyObject_SetAttrString(result, "upper", value) == -1)
2970 value = ast2obj_expr(o->v.Slice.step);
2971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "step", value) == -1)
2977 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2978 if (!result) goto failed;
2979 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2980 if (!value) goto failed;
2981 if (PyObject_SetAttrString(result, "dims", value) == -1)
2986 result = PyType_GenericNew(Index_type, NULL, NULL);
2987 if (!result) goto failed;
2988 value = ast2obj_expr(o->v.Index.value);
2989 if (!value) goto failed;
2990 if (PyObject_SetAttrString(result, "value", value) == -1)
3002 PyObject* ast2obj_boolop(boolop_ty o)
3006 Py_INCREF(And_singleton);
3007 return And_singleton;
3009 Py_INCREF(Or_singleton);
3010 return Or_singleton;
3012 /* should never happen, but just in case ... */
3013 PyErr_Format(PyExc_SystemError, "unknown boolop found");
3017 PyObject* ast2obj_operator(operator_ty o)
3021 Py_INCREF(Add_singleton);
3022 return Add_singleton;
3024 Py_INCREF(Sub_singleton);
3025 return Sub_singleton;
3027 Py_INCREF(Mult_singleton);
3028 return Mult_singleton;
3030 Py_INCREF(Div_singleton);
3031 return Div_singleton;
3033 Py_INCREF(Mod_singleton);
3034 return Mod_singleton;
3036 Py_INCREF(Pow_singleton);
3037 return Pow_singleton;
3039 Py_INCREF(LShift_singleton);
3040 return LShift_singleton;
3042 Py_INCREF(RShift_singleton);
3043 return RShift_singleton;
3045 Py_INCREF(BitOr_singleton);
3046 return BitOr_singleton;
3048 Py_INCREF(BitXor_singleton);
3049 return BitXor_singleton;
3051 Py_INCREF(BitAnd_singleton);
3052 return BitAnd_singleton;
3054 Py_INCREF(FloorDiv_singleton);
3055 return FloorDiv_singleton;
3057 /* should never happen, but just in case ... */
3058 PyErr_Format(PyExc_SystemError, "unknown operator found");
3062 PyObject* ast2obj_unaryop(unaryop_ty o)
3066 Py_INCREF(Invert_singleton);
3067 return Invert_singleton;
3069 Py_INCREF(Not_singleton);
3070 return Not_singleton;
3072 Py_INCREF(UAdd_singleton);
3073 return UAdd_singleton;
3075 Py_INCREF(USub_singleton);
3076 return USub_singleton;
3078 /* should never happen, but just in case ... */
3079 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
3083 PyObject* ast2obj_cmpop(cmpop_ty o)
3087 Py_INCREF(Eq_singleton);
3088 return Eq_singleton;
3090 Py_INCREF(NotEq_singleton);
3091 return NotEq_singleton;
3093 Py_INCREF(Lt_singleton);
3094 return Lt_singleton;
3096 Py_INCREF(LtE_singleton);
3097 return LtE_singleton;
3099 Py_INCREF(Gt_singleton);
3100 return Gt_singleton;
3102 Py_INCREF(GtE_singleton);
3103 return GtE_singleton;
3105 Py_INCREF(Is_singleton);
3106 return Is_singleton;
3108 Py_INCREF(IsNot_singleton);
3109 return IsNot_singleton;
3111 Py_INCREF(In_singleton);
3112 return In_singleton;
3114 Py_INCREF(NotIn_singleton);
3115 return NotIn_singleton;
3117 /* should never happen, but just in case ... */
3118 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
3123 ast2obj_comprehension(void* _o)
3125 comprehension_ty o = (comprehension_ty)_o;
3126 PyObject *result = NULL, *value = NULL;
3132 result = PyType_GenericNew(comprehension_type, NULL, NULL);
3133 if (!result) return NULL;
3134 value = ast2obj_expr(o->target);
3135 if (!value) goto failed;
3136 if (PyObject_SetAttrString(result, "target", value) == -1)
3139 value = ast2obj_expr(o->iter);
3140 if (!value) goto failed;
3141 if (PyObject_SetAttrString(result, "iter", value) == -1)
3144 value = ast2obj_list(o->ifs, ast2obj_expr);
3145 if (!value) goto failed;
3146 if (PyObject_SetAttrString(result, "ifs", value) == -1)
3157 ast2obj_excepthandler(void* _o)
3159 excepthandler_ty o = (excepthandler_ty)_o;
3160 PyObject *result = NULL, *value = NULL;
3167 case ExceptHandler_kind:
3168 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3169 if (!result) goto failed;
3170 value = ast2obj_expr(o->v.ExceptHandler.type);
3171 if (!value) goto failed;
3172 if (PyObject_SetAttrString(result, "type", value) == -1)
3175 value = ast2obj_expr(o->v.ExceptHandler.name);
3176 if (!value) goto failed;
3177 if (PyObject_SetAttrString(result, "name", value) == -1)
3180 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3181 if (!value) goto failed;
3182 if (PyObject_SetAttrString(result, "body", value) == -1)
3187 value = ast2obj_int(o->lineno);
3188 if (!value) goto failed;
3189 if (PyObject_SetAttrString(result, "lineno", value) < 0)
3192 value = ast2obj_int(o->col_offset);
3193 if (!value) goto failed;
3194 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
3205 ast2obj_arguments(void* _o)
3207 arguments_ty o = (arguments_ty)_o;
3208 PyObject *result = NULL, *value = NULL;
3214 result = PyType_GenericNew(arguments_type, NULL, NULL);
3215 if (!result) return NULL;
3216 value = ast2obj_list(o->args, ast2obj_expr);
3217 if (!value) goto failed;
3218 if (PyObject_SetAttrString(result, "args", value) == -1)
3221 value = ast2obj_identifier(o->vararg);
3222 if (!value) goto failed;
3223 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3226 value = ast2obj_identifier(o->kwarg);
3227 if (!value) goto failed;
3228 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3231 value = ast2obj_list(o->defaults, ast2obj_expr);
3232 if (!value) goto failed;
3233 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3244 ast2obj_keyword(void* _o)
3246 keyword_ty o = (keyword_ty)_o;
3247 PyObject *result = NULL, *value = NULL;
3253 result = PyType_GenericNew(keyword_type, NULL, NULL);
3254 if (!result) return NULL;
3255 value = ast2obj_identifier(o->arg);
3256 if (!value) goto failed;
3257 if (PyObject_SetAttrString(result, "arg", value) == -1)
3260 value = ast2obj_expr(o->value);
3261 if (!value) goto failed;
3262 if (PyObject_SetAttrString(result, "value", value) == -1)
3273 ast2obj_alias(void* _o)
3275 alias_ty o = (alias_ty)_o;
3276 PyObject *result = NULL, *value = NULL;
3282 result = PyType_GenericNew(alias_type, NULL, NULL);
3283 if (!result) return NULL;
3284 value = ast2obj_identifier(o->name);
3285 if (!value) goto failed;
3286 if (PyObject_SetAttrString(result, "name", value) == -1)
3289 value = ast2obj_identifier(o->asname);
3290 if (!value) goto failed;
3291 if (PyObject_SetAttrString(result, "asname", value) == -1)
3303 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3305 PyObject* tmp = NULL;
3309 if (obj == Py_None) {
3313 isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
3314 if (isinstance == -1) {
3320 if (PyObject_HasAttrString(obj, "body")) {
3324 tmp = PyObject_GetAttrString(obj, "body");
3325 if (tmp == NULL) goto failed;
3326 if (!PyList_Check(tmp)) {
3327 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3330 len = PyList_GET_SIZE(tmp);
3331 body = asdl_seq_new(len, arena);
3332 if (body == NULL) goto failed;
3333 for (i = 0; i < len; i++) {
3335 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3336 if (res != 0) goto failed;
3337 asdl_seq_SET(body, i, value);
3342 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
3345 *out = Module(body, arena);
3346 if (*out == NULL) goto failed;
3349 isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
3350 if (isinstance == -1) {
3356 if (PyObject_HasAttrString(obj, "body")) {
3360 tmp = PyObject_GetAttrString(obj, "body");
3361 if (tmp == NULL) goto failed;
3362 if (!PyList_Check(tmp)) {
3363 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3366 len = PyList_GET_SIZE(tmp);
3367 body = asdl_seq_new(len, arena);
3368 if (body == NULL) goto failed;
3369 for (i = 0; i < len; i++) {
3371 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3372 if (res != 0) goto failed;
3373 asdl_seq_SET(body, i, value);
3378 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
3381 *out = Interactive(body, arena);
3382 if (*out == NULL) goto failed;
3385 isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
3386 if (isinstance == -1) {
3392 if (PyObject_HasAttrString(obj, "body")) {
3394 tmp = PyObject_GetAttrString(obj, "body");
3395 if (tmp == NULL) goto failed;
3396 res = obj2ast_expr(tmp, &body, arena);
3397 if (res != 0) goto failed;
3401 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
3404 *out = Expression(body, arena);
3405 if (*out == NULL) goto failed;
3408 isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
3409 if (isinstance == -1) {
3415 if (PyObject_HasAttrString(obj, "body")) {
3419 tmp = PyObject_GetAttrString(obj, "body");
3420 if (tmp == NULL) goto failed;
3421 if (!PyList_Check(tmp)) {
3422 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3425 len = PyList_GET_SIZE(tmp);
3426 body = asdl_seq_new(len, arena);
3427 if (body == NULL) goto failed;
3428 for (i = 0; i < len; i++) {
3430 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3431 if (res != 0) goto failed;
3432 asdl_seq_SET(body, i, value);
3437 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
3440 *out = Suite(body, arena);
3441 if (*out == NULL) goto failed;
3445 tmp = PyObject_Repr(obj);
3446 if (tmp == NULL) goto failed;
3447 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
3454 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
3456 PyObject* tmp = NULL;
3462 if (obj == Py_None) {
3466 if (PyObject_HasAttrString(obj, "lineno")) {
3468 tmp = PyObject_GetAttrString(obj, "lineno");
3469 if (tmp == NULL) goto failed;
3470 res = obj2ast_int(tmp, &lineno, arena);
3471 if (res != 0) goto failed;
3475 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
3478 if (PyObject_HasAttrString(obj, "col_offset")) {
3480 tmp = PyObject_GetAttrString(obj, "col_offset");
3481 if (tmp == NULL) goto failed;
3482 res = obj2ast_int(tmp, &col_offset, arena);
3483 if (res != 0) goto failed;
3487 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
3490 isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
3491 if (isinstance == -1) {
3498 asdl_seq* decorator_list;
3500 if (PyObject_HasAttrString(obj, "name")) {
3502 tmp = PyObject_GetAttrString(obj, "name");
3503 if (tmp == NULL) goto failed;
3504 res = obj2ast_identifier(tmp, &name, arena);
3505 if (res != 0) goto failed;
3509 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
3512 if (PyObject_HasAttrString(obj, "args")) {
3514 tmp = PyObject_GetAttrString(obj, "args");
3515 if (tmp == NULL) goto failed;
3516 res = obj2ast_arguments(tmp, &args, arena);
3517 if (res != 0) goto failed;
3521 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
3524 if (PyObject_HasAttrString(obj, "body")) {
3528 tmp = PyObject_GetAttrString(obj, "body");
3529 if (tmp == NULL) goto failed;
3530 if (!PyList_Check(tmp)) {
3531 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3534 len = PyList_GET_SIZE(tmp);
3535 body = asdl_seq_new(len, arena);
3536 if (body == NULL) goto failed;
3537 for (i = 0; i < len; i++) {
3539 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3540 if (res != 0) goto failed;
3541 asdl_seq_SET(body, i, value);
3546 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
3549 if (PyObject_HasAttrString(obj, "decorator_list")) {
3553 tmp = PyObject_GetAttrString(obj, "decorator_list");
3554 if (tmp == NULL) goto failed;
3555 if (!PyList_Check(tmp)) {
3556 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3559 len = PyList_GET_SIZE(tmp);
3560 decorator_list = asdl_seq_new(len, arena);
3561 if (decorator_list == NULL) goto failed;
3562 for (i = 0; i < len; i++) {
3564 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3565 if (res != 0) goto failed;
3566 asdl_seq_SET(decorator_list, i, value);
3571 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
3574 *out = FunctionDef(name, args, body, decorator_list, lineno,
3576 if (*out == NULL) goto failed;
3579 isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
3580 if (isinstance == -1) {
3587 asdl_seq* decorator_list;
3589 if (PyObject_HasAttrString(obj, "name")) {
3591 tmp = PyObject_GetAttrString(obj, "name");
3592 if (tmp == NULL) goto failed;
3593 res = obj2ast_identifier(tmp, &name, arena);
3594 if (res != 0) goto failed;
3598 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
3601 if (PyObject_HasAttrString(obj, "bases")) {
3605 tmp = PyObject_GetAttrString(obj, "bases");
3606 if (tmp == NULL) goto failed;
3607 if (!PyList_Check(tmp)) {
3608 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3611 len = PyList_GET_SIZE(tmp);
3612 bases = asdl_seq_new(len, arena);
3613 if (bases == NULL) goto failed;
3614 for (i = 0; i < len; i++) {
3616 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3617 if (res != 0) goto failed;
3618 asdl_seq_SET(bases, i, value);
3623 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
3626 if (PyObject_HasAttrString(obj, "body")) {
3630 tmp = PyObject_GetAttrString(obj, "body");
3631 if (tmp == NULL) goto failed;
3632 if (!PyList_Check(tmp)) {
3633 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3636 len = PyList_GET_SIZE(tmp);
3637 body = asdl_seq_new(len, arena);
3638 if (body == NULL) goto failed;
3639 for (i = 0; i < len; i++) {
3641 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3642 if (res != 0) goto failed;
3643 asdl_seq_SET(body, i, value);
3648 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
3651 if (PyObject_HasAttrString(obj, "decorator_list")) {
3655 tmp = PyObject_GetAttrString(obj, "decorator_list");
3656 if (tmp == NULL) goto failed;
3657 if (!PyList_Check(tmp)) {
3658 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3661 len = PyList_GET_SIZE(tmp);
3662 decorator_list = asdl_seq_new(len, arena);
3663 if (decorator_list == NULL) goto failed;
3664 for (i = 0; i < len; i++) {
3666 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3667 if (res != 0) goto failed;
3668 asdl_seq_SET(decorator_list, i, value);
3673 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
3676 *out = ClassDef(name, bases, body, decorator_list, lineno,
3678 if (*out == NULL) goto failed;
3681 isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
3682 if (isinstance == -1) {
3688 if (PyObject_HasAttrString(obj, "value")) {
3690 tmp = PyObject_GetAttrString(obj, "value");
3691 if (tmp == NULL) goto failed;
3692 res = obj2ast_expr(tmp, &value, arena);
3693 if (res != 0) goto failed;
3699 *out = Return(value, lineno, col_offset, arena);
3700 if (*out == NULL) goto failed;
3703 isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
3704 if (isinstance == -1) {
3710 if (PyObject_HasAttrString(obj, "targets")) {
3714 tmp = PyObject_GetAttrString(obj, "targets");
3715 if (tmp == NULL) goto failed;
3716 if (!PyList_Check(tmp)) {
3717 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3720 len = PyList_GET_SIZE(tmp);
3721 targets = asdl_seq_new(len, arena);
3722 if (targets == NULL) goto failed;
3723 for (i = 0; i < len; i++) {
3725 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3726 if (res != 0) goto failed;
3727 asdl_seq_SET(targets, i, value);
3732 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
3735 *out = Delete(targets, lineno, col_offset, arena);
3736 if (*out == NULL) goto failed;
3739 isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
3740 if (isinstance == -1) {
3747 if (PyObject_HasAttrString(obj, "targets")) {
3751 tmp = PyObject_GetAttrString(obj, "targets");
3752 if (tmp == NULL) goto failed;
3753 if (!PyList_Check(tmp)) {
3754 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3757 len = PyList_GET_SIZE(tmp);
3758 targets = asdl_seq_new(len, arena);
3759 if (targets == NULL) goto failed;
3760 for (i = 0; i < len; i++) {
3762 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3763 if (res != 0) goto failed;
3764 asdl_seq_SET(targets, i, value);
3769 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
3772 if (PyObject_HasAttrString(obj, "value")) {
3774 tmp = PyObject_GetAttrString(obj, "value");
3775 if (tmp == NULL) goto failed;
3776 res = obj2ast_expr(tmp, &value, arena);
3777 if (res != 0) goto failed;
3781 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
3784 *out = Assign(targets, value, lineno, col_offset, arena);
3785 if (*out == NULL) goto failed;
3788 isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
3789 if (isinstance == -1) {
3797 if (PyObject_HasAttrString(obj, "target")) {
3799 tmp = PyObject_GetAttrString(obj, "target");
3800 if (tmp == NULL) goto failed;
3801 res = obj2ast_expr(tmp, &target, arena);
3802 if (res != 0) goto failed;
3806 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
3809 if (PyObject_HasAttrString(obj, "op")) {
3811 tmp = PyObject_GetAttrString(obj, "op");
3812 if (tmp == NULL) goto failed;
3813 res = obj2ast_operator(tmp, &op, arena);
3814 if (res != 0) goto failed;
3818 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
3821 if (PyObject_HasAttrString(obj, "value")) {
3823 tmp = PyObject_GetAttrString(obj, "value");
3824 if (tmp == NULL) goto failed;
3825 res = obj2ast_expr(tmp, &value, arena);
3826 if (res != 0) goto failed;
3830 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
3833 *out = AugAssign(target, op, value, lineno, col_offset, arena);
3834 if (*out == NULL) goto failed;
3837 isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
3838 if (isinstance == -1) {
3846 if (PyObject_HasAttrString(obj, "dest")) {
3848 tmp = PyObject_GetAttrString(obj, "dest");
3849 if (tmp == NULL) goto failed;
3850 res = obj2ast_expr(tmp, &dest, arena);
3851 if (res != 0) goto failed;
3857 if (PyObject_HasAttrString(obj, "values")) {
3861 tmp = PyObject_GetAttrString(obj, "values");
3862 if (tmp == NULL) goto failed;
3863 if (!PyList_Check(tmp)) {
3864 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3867 len = PyList_GET_SIZE(tmp);
3868 values = asdl_seq_new(len, arena);
3869 if (values == NULL) goto failed;
3870 for (i = 0; i < len; i++) {
3872 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3873 if (res != 0) goto failed;
3874 asdl_seq_SET(values, i, value);
3879 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
3882 if (PyObject_HasAttrString(obj, "nl")) {
3884 tmp = PyObject_GetAttrString(obj, "nl");
3885 if (tmp == NULL) goto failed;
3886 res = obj2ast_bool(tmp, &nl, arena);
3887 if (res != 0) goto failed;
3891 PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
3894 *out = Print(dest, values, nl, lineno, col_offset, arena);
3895 if (*out == NULL) goto failed;
3898 isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
3899 if (isinstance == -1) {
3908 if (PyObject_HasAttrString(obj, "target")) {
3910 tmp = PyObject_GetAttrString(obj, "target");
3911 if (tmp == NULL) goto failed;
3912 res = obj2ast_expr(tmp, &target, arena);
3913 if (res != 0) goto failed;
3917 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
3920 if (PyObject_HasAttrString(obj, "iter")) {
3922 tmp = PyObject_GetAttrString(obj, "iter");
3923 if (tmp == NULL) goto failed;
3924 res = obj2ast_expr(tmp, &iter, arena);
3925 if (res != 0) goto failed;
3929 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
3932 if (PyObject_HasAttrString(obj, "body")) {
3936 tmp = PyObject_GetAttrString(obj, "body");
3937 if (tmp == NULL) goto failed;
3938 if (!PyList_Check(tmp)) {
3939 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3942 len = PyList_GET_SIZE(tmp);
3943 body = asdl_seq_new(len, arena);
3944 if (body == NULL) goto failed;
3945 for (i = 0; i < len; i++) {
3947 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3948 if (res != 0) goto failed;
3949 asdl_seq_SET(body, i, value);
3954 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
3957 if (PyObject_HasAttrString(obj, "orelse")) {
3961 tmp = PyObject_GetAttrString(obj, "orelse");
3962 if (tmp == NULL) goto failed;
3963 if (!PyList_Check(tmp)) {
3964 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3967 len = PyList_GET_SIZE(tmp);
3968 orelse = asdl_seq_new(len, arena);
3969 if (orelse == NULL) goto failed;
3970 for (i = 0; i < len; i++) {
3972 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3973 if (res != 0) goto failed;
3974 asdl_seq_SET(orelse, i, value);
3979 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
3982 *out = For(target, iter, body, orelse, lineno, col_offset,
3984 if (*out == NULL) goto failed;
3987 isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
3988 if (isinstance == -1) {
3996 if (PyObject_HasAttrString(obj, "test")) {
3998 tmp = PyObject_GetAttrString(obj, "test");
3999 if (tmp == NULL) goto failed;
4000 res = obj2ast_expr(tmp, &test, arena);
4001 if (res != 0) goto failed;
4005 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
4008 if (PyObject_HasAttrString(obj, "body")) {
4012 tmp = PyObject_GetAttrString(obj, "body");
4013 if (tmp == NULL) goto failed;
4014 if (!PyList_Check(tmp)) {
4015 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4018 len = PyList_GET_SIZE(tmp);
4019 body = asdl_seq_new(len, arena);
4020 if (body == NULL) goto failed;
4021 for (i = 0; i < len; i++) {
4023 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4024 if (res != 0) goto failed;
4025 asdl_seq_SET(body, i, value);
4030 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
4033 if (PyObject_HasAttrString(obj, "orelse")) {
4037 tmp = PyObject_GetAttrString(obj, "orelse");
4038 if (tmp == NULL) goto failed;
4039 if (!PyList_Check(tmp)) {
4040 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4043 len = PyList_GET_SIZE(tmp);
4044 orelse = asdl_seq_new(len, arena);
4045 if (orelse == NULL) goto failed;
4046 for (i = 0; i < len; i++) {
4048 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4049 if (res != 0) goto failed;
4050 asdl_seq_SET(orelse, i, value);
4055 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
4058 *out = While(test, body, orelse, lineno, col_offset, arena);
4059 if (*out == NULL) goto failed;
4062 isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
4063 if (isinstance == -1) {
4071 if (PyObject_HasAttrString(obj, "test")) {
4073 tmp = PyObject_GetAttrString(obj, "test");
4074 if (tmp == NULL) goto failed;
4075 res = obj2ast_expr(tmp, &test, arena);
4076 if (res != 0) goto failed;
4080 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
4083 if (PyObject_HasAttrString(obj, "body")) {
4087 tmp = PyObject_GetAttrString(obj, "body");
4088 if (tmp == NULL) goto failed;
4089 if (!PyList_Check(tmp)) {
4090 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4093 len = PyList_GET_SIZE(tmp);
4094 body = asdl_seq_new(len, arena);
4095 if (body == NULL) goto failed;
4096 for (i = 0; i < len; i++) {
4098 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4099 if (res != 0) goto failed;
4100 asdl_seq_SET(body, i, value);
4105 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
4108 if (PyObject_HasAttrString(obj, "orelse")) {
4112 tmp = PyObject_GetAttrString(obj, "orelse");
4113 if (tmp == NULL) goto failed;
4114 if (!PyList_Check(tmp)) {
4115 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4118 len = PyList_GET_SIZE(tmp);
4119 orelse = asdl_seq_new(len, arena);
4120 if (orelse == NULL) goto failed;
4121 for (i = 0; i < len; i++) {
4123 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4124 if (res != 0) goto failed;
4125 asdl_seq_SET(orelse, i, value);
4130 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
4133 *out = If(test, body, orelse, lineno, col_offset, arena);
4134 if (*out == NULL) goto failed;
4137 isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
4138 if (isinstance == -1) {
4142 expr_ty context_expr;
4143 expr_ty optional_vars;
4146 if (PyObject_HasAttrString(obj, "context_expr")) {
4148 tmp = PyObject_GetAttrString(obj, "context_expr");
4149 if (tmp == NULL) goto failed;
4150 res = obj2ast_expr(tmp, &context_expr, arena);
4151 if (res != 0) goto failed;
4155 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
4158 if (PyObject_HasAttrString(obj, "optional_vars")) {
4160 tmp = PyObject_GetAttrString(obj, "optional_vars");
4161 if (tmp == NULL) goto failed;
4162 res = obj2ast_expr(tmp, &optional_vars, arena);
4163 if (res != 0) goto failed;
4167 optional_vars = NULL;
4169 if (PyObject_HasAttrString(obj, "body")) {
4173 tmp = PyObject_GetAttrString(obj, "body");
4174 if (tmp == NULL) goto failed;
4175 if (!PyList_Check(tmp)) {
4176 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4179 len = PyList_GET_SIZE(tmp);
4180 body = asdl_seq_new(len, arena);
4181 if (body == NULL) goto failed;
4182 for (i = 0; i < len; i++) {
4184 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4185 if (res != 0) goto failed;
4186 asdl_seq_SET(body, i, value);
4191 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
4194 *out = With(context_expr, optional_vars, body, lineno,
4196 if (*out == NULL) goto failed;
4199 isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
4200 if (isinstance == -1) {
4208 if (PyObject_HasAttrString(obj, "type")) {
4210 tmp = PyObject_GetAttrString(obj, "type");
4211 if (tmp == NULL) goto failed;
4212 res = obj2ast_expr(tmp, &type, arena);
4213 if (res != 0) goto failed;
4219 if (PyObject_HasAttrString(obj, "inst")) {
4221 tmp = PyObject_GetAttrString(obj, "inst");
4222 if (tmp == NULL) goto failed;
4223 res = obj2ast_expr(tmp, &inst, arena);
4224 if (res != 0) goto failed;
4230 if (PyObject_HasAttrString(obj, "tback")) {
4232 tmp = PyObject_GetAttrString(obj, "tback");
4233 if (tmp == NULL) goto failed;
4234 res = obj2ast_expr(tmp, &tback, arena);
4235 if (res != 0) goto failed;
4241 *out = Raise(type, inst, tback, lineno, col_offset, arena);
4242 if (*out == NULL) goto failed;
4245 isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
4246 if (isinstance == -1) {
4254 if (PyObject_HasAttrString(obj, "body")) {
4258 tmp = PyObject_GetAttrString(obj, "body");
4259 if (tmp == NULL) goto failed;
4260 if (!PyList_Check(tmp)) {
4261 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4264 len = PyList_GET_SIZE(tmp);
4265 body = asdl_seq_new(len, arena);
4266 if (body == NULL) goto failed;
4267 for (i = 0; i < len; i++) {
4269 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4270 if (res != 0) goto failed;
4271 asdl_seq_SET(body, i, value);
4276 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
4279 if (PyObject_HasAttrString(obj, "handlers")) {
4283 tmp = PyObject_GetAttrString(obj, "handlers");
4284 if (tmp == NULL) goto failed;
4285 if (!PyList_Check(tmp)) {
4286 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4289 len = PyList_GET_SIZE(tmp);
4290 handlers = asdl_seq_new(len, arena);
4291 if (handlers == NULL) goto failed;
4292 for (i = 0; i < len; i++) {
4293 excepthandler_ty value;
4294 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
4295 if (res != 0) goto failed;
4296 asdl_seq_SET(handlers, i, value);
4301 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
4304 if (PyObject_HasAttrString(obj, "orelse")) {
4308 tmp = PyObject_GetAttrString(obj, "orelse");
4309 if (tmp == NULL) goto failed;
4310 if (!PyList_Check(tmp)) {
4311 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4314 len = PyList_GET_SIZE(tmp);
4315 orelse = asdl_seq_new(len, arena);
4316 if (orelse == NULL) goto failed;
4317 for (i = 0; i < len; i++) {
4319 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4320 if (res != 0) goto failed;
4321 asdl_seq_SET(orelse, i, value);
4326 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
4329 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
4331 if (*out == NULL) goto failed;
4334 isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
4335 if (isinstance == -1) {
4340 asdl_seq* finalbody;
4342 if (PyObject_HasAttrString(obj, "body")) {
4346 tmp = PyObject_GetAttrString(obj, "body");
4347 if (tmp == NULL) goto failed;
4348 if (!PyList_Check(tmp)) {
4349 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4352 len = PyList_GET_SIZE(tmp);
4353 body = asdl_seq_new(len, arena);
4354 if (body == NULL) goto failed;
4355 for (i = 0; i < len; i++) {
4357 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4358 if (res != 0) goto failed;
4359 asdl_seq_SET(body, i, value);
4364 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
4367 if (PyObject_HasAttrString(obj, "finalbody")) {
4371 tmp = PyObject_GetAttrString(obj, "finalbody");
4372 if (tmp == NULL) goto failed;
4373 if (!PyList_Check(tmp)) {
4374 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4377 len = PyList_GET_SIZE(tmp);
4378 finalbody = asdl_seq_new(len, arena);
4379 if (finalbody == NULL) goto failed;
4380 for (i = 0; i < len; i++) {
4382 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4383 if (res != 0) goto failed;
4384 asdl_seq_SET(finalbody, i, value);
4389 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
4392 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
4393 if (*out == NULL) goto failed;
4396 isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
4397 if (isinstance == -1) {
4404 if (PyObject_HasAttrString(obj, "test")) {
4406 tmp = PyObject_GetAttrString(obj, "test");
4407 if (tmp == NULL) goto failed;
4408 res = obj2ast_expr(tmp, &test, arena);
4409 if (res != 0) goto failed;
4413 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
4416 if (PyObject_HasAttrString(obj, "msg")) {
4418 tmp = PyObject_GetAttrString(obj, "msg");
4419 if (tmp == NULL) goto failed;
4420 res = obj2ast_expr(tmp, &msg, arena);
4421 if (res != 0) goto failed;
4427 *out = Assert(test, msg, lineno, col_offset, arena);
4428 if (*out == NULL) goto failed;
4431 isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
4432 if (isinstance == -1) {
4438 if (PyObject_HasAttrString(obj, "names")) {
4442 tmp = PyObject_GetAttrString(obj, "names");
4443 if (tmp == NULL) goto failed;
4444 if (!PyList_Check(tmp)) {
4445 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4448 len = PyList_GET_SIZE(tmp);
4449 names = asdl_seq_new(len, arena);
4450 if (names == NULL) goto failed;
4451 for (i = 0; i < len; i++) {
4453 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4454 if (res != 0) goto failed;
4455 asdl_seq_SET(names, i, value);
4460 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
4463 *out = Import(names, lineno, col_offset, arena);
4464 if (*out == NULL) goto failed;
4467 isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
4468 if (isinstance == -1) {
4476 if (PyObject_HasAttrString(obj, "module")) {
4478 tmp = PyObject_GetAttrString(obj, "module");
4479 if (tmp == NULL) goto failed;
4480 res = obj2ast_identifier(tmp, &module, arena);
4481 if (res != 0) goto failed;
4487 if (PyObject_HasAttrString(obj, "names")) {
4491 tmp = PyObject_GetAttrString(obj, "names");
4492 if (tmp == NULL) goto failed;
4493 if (!PyList_Check(tmp)) {
4494 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4497 len = PyList_GET_SIZE(tmp);
4498 names = asdl_seq_new(len, arena);
4499 if (names == NULL) goto failed;
4500 for (i = 0; i < len; i++) {
4502 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4503 if (res != 0) goto failed;
4504 asdl_seq_SET(names, i, value);
4509 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
4512 if (PyObject_HasAttrString(obj, "level")) {
4514 tmp = PyObject_GetAttrString(obj, "level");
4515 if (tmp == NULL) goto failed;
4516 res = obj2ast_int(tmp, &level, arena);
4517 if (res != 0) goto failed;
4523 *out = ImportFrom(module, names, level, lineno, col_offset,
4525 if (*out == NULL) goto failed;
4528 isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
4529 if (isinstance == -1) {
4537 if (PyObject_HasAttrString(obj, "body")) {
4539 tmp = PyObject_GetAttrString(obj, "body");
4540 if (tmp == NULL) goto failed;
4541 res = obj2ast_expr(tmp, &body, arena);
4542 if (res != 0) goto failed;
4546 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
4549 if (PyObject_HasAttrString(obj, "globals")) {
4551 tmp = PyObject_GetAttrString(obj, "globals");
4552 if (tmp == NULL) goto failed;
4553 res = obj2ast_expr(tmp, &globals, arena);
4554 if (res != 0) goto failed;
4560 if (PyObject_HasAttrString(obj, "locals")) {
4562 tmp = PyObject_GetAttrString(obj, "locals");
4563 if (tmp == NULL) goto failed;
4564 res = obj2ast_expr(tmp, &locals, arena);
4565 if (res != 0) goto failed;
4571 *out = Exec(body, globals, locals, lineno, col_offset, arena);
4572 if (*out == NULL) goto failed;
4575 isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
4576 if (isinstance == -1) {
4582 if (PyObject_HasAttrString(obj, "names")) {
4586 tmp = PyObject_GetAttrString(obj, "names");
4587 if (tmp == NULL) goto failed;
4588 if (!PyList_Check(tmp)) {
4589 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4592 len = PyList_GET_SIZE(tmp);
4593 names = asdl_seq_new(len, arena);
4594 if (names == NULL) goto failed;
4595 for (i = 0; i < len; i++) {
4597 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
4598 if (res != 0) goto failed;
4599 asdl_seq_SET(names, i, value);
4604 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
4607 *out = Global(names, lineno, col_offset, arena);
4608 if (*out == NULL) goto failed;
4611 isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
4612 if (isinstance == -1) {
4618 if (PyObject_HasAttrString(obj, "value")) {
4620 tmp = PyObject_GetAttrString(obj, "value");
4621 if (tmp == NULL) goto failed;
4622 res = obj2ast_expr(tmp, &value, arena);
4623 if (res != 0) goto failed;
4627 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
4630 *out = Expr(value, lineno, col_offset, arena);
4631 if (*out == NULL) goto failed;
4634 isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
4635 if (isinstance == -1) {
4640 *out = Pass(lineno, col_offset, arena);
4641 if (*out == NULL) goto failed;
4644 isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
4645 if (isinstance == -1) {
4650 *out = Break(lineno, col_offset, arena);
4651 if (*out == NULL) goto failed;
4654 isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
4655 if (isinstance == -1) {
4660 *out = Continue(lineno, col_offset, arena);
4661 if (*out == NULL) goto failed;
4665 tmp = PyObject_Repr(obj);
4666 if (tmp == NULL) goto failed;
4667 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
4674 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
4676 PyObject* tmp = NULL;
4682 if (obj == Py_None) {
4686 if (PyObject_HasAttrString(obj, "lineno")) {
4688 tmp = PyObject_GetAttrString(obj, "lineno");
4689 if (tmp == NULL) goto failed;
4690 res = obj2ast_int(tmp, &lineno, arena);
4691 if (res != 0) goto failed;
4695 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
4698 if (PyObject_HasAttrString(obj, "col_offset")) {
4700 tmp = PyObject_GetAttrString(obj, "col_offset");
4701 if (tmp == NULL) goto failed;
4702 res = obj2ast_int(tmp, &col_offset, arena);
4703 if (res != 0) goto failed;
4707 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
4710 isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
4711 if (isinstance == -1) {
4718 if (PyObject_HasAttrString(obj, "op")) {
4720 tmp = PyObject_GetAttrString(obj, "op");
4721 if (tmp == NULL) goto failed;
4722 res = obj2ast_boolop(tmp, &op, arena);
4723 if (res != 0) goto failed;
4727 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
4730 if (PyObject_HasAttrString(obj, "values")) {
4734 tmp = PyObject_GetAttrString(obj, "values");
4735 if (tmp == NULL) goto failed;
4736 if (!PyList_Check(tmp)) {
4737 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4740 len = PyList_GET_SIZE(tmp);
4741 values = asdl_seq_new(len, arena);
4742 if (values == NULL) goto failed;
4743 for (i = 0; i < len; i++) {
4745 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4746 if (res != 0) goto failed;
4747 asdl_seq_SET(values, i, value);
4752 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
4755 *out = BoolOp(op, values, lineno, col_offset, arena);
4756 if (*out == NULL) goto failed;
4759 isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
4760 if (isinstance == -1) {
4768 if (PyObject_HasAttrString(obj, "left")) {
4770 tmp = PyObject_GetAttrString(obj, "left");
4771 if (tmp == NULL) goto failed;
4772 res = obj2ast_expr(tmp, &left, arena);
4773 if (res != 0) goto failed;
4777 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
4780 if (PyObject_HasAttrString(obj, "op")) {
4782 tmp = PyObject_GetAttrString(obj, "op");
4783 if (tmp == NULL) goto failed;
4784 res = obj2ast_operator(tmp, &op, arena);
4785 if (res != 0) goto failed;
4789 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
4792 if (PyObject_HasAttrString(obj, "right")) {
4794 tmp = PyObject_GetAttrString(obj, "right");
4795 if (tmp == NULL) goto failed;
4796 res = obj2ast_expr(tmp, &right, arena);
4797 if (res != 0) goto failed;
4801 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
4804 *out = BinOp(left, op, right, lineno, col_offset, arena);
4805 if (*out == NULL) goto failed;
4808 isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
4809 if (isinstance == -1) {
4816 if (PyObject_HasAttrString(obj, "op")) {
4818 tmp = PyObject_GetAttrString(obj, "op");
4819 if (tmp == NULL) goto failed;
4820 res = obj2ast_unaryop(tmp, &op, arena);
4821 if (res != 0) goto failed;
4825 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
4828 if (PyObject_HasAttrString(obj, "operand")) {
4830 tmp = PyObject_GetAttrString(obj, "operand");
4831 if (tmp == NULL) goto failed;
4832 res = obj2ast_expr(tmp, &operand, arena);
4833 if (res != 0) goto failed;
4837 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
4840 *out = UnaryOp(op, operand, lineno, col_offset, arena);
4841 if (*out == NULL) goto failed;
4844 isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
4845 if (isinstance == -1) {
4852 if (PyObject_HasAttrString(obj, "args")) {
4854 tmp = PyObject_GetAttrString(obj, "args");
4855 if (tmp == NULL) goto failed;
4856 res = obj2ast_arguments(tmp, &args, arena);
4857 if (res != 0) goto failed;
4861 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
4864 if (PyObject_HasAttrString(obj, "body")) {
4866 tmp = PyObject_GetAttrString(obj, "body");
4867 if (tmp == NULL) goto failed;
4868 res = obj2ast_expr(tmp, &body, arena);
4869 if (res != 0) goto failed;
4873 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
4876 *out = Lambda(args, body, lineno, col_offset, arena);
4877 if (*out == NULL) goto failed;
4880 isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
4881 if (isinstance == -1) {
4889 if (PyObject_HasAttrString(obj, "test")) {
4891 tmp = PyObject_GetAttrString(obj, "test");
4892 if (tmp == NULL) goto failed;
4893 res = obj2ast_expr(tmp, &test, arena);
4894 if (res != 0) goto failed;
4898 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
4901 if (PyObject_HasAttrString(obj, "body")) {
4903 tmp = PyObject_GetAttrString(obj, "body");
4904 if (tmp == NULL) goto failed;
4905 res = obj2ast_expr(tmp, &body, arena);
4906 if (res != 0) goto failed;
4910 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
4913 if (PyObject_HasAttrString(obj, "orelse")) {
4915 tmp = PyObject_GetAttrString(obj, "orelse");
4916 if (tmp == NULL) goto failed;
4917 res = obj2ast_expr(tmp, &orelse, arena);
4918 if (res != 0) goto failed;
4922 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
4925 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
4926 if (*out == NULL) goto failed;
4929 isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
4930 if (isinstance == -1) {
4937 if (PyObject_HasAttrString(obj, "keys")) {
4941 tmp = PyObject_GetAttrString(obj, "keys");
4942 if (tmp == NULL) goto failed;
4943 if (!PyList_Check(tmp)) {
4944 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4947 len = PyList_GET_SIZE(tmp);
4948 keys = asdl_seq_new(len, arena);
4949 if (keys == NULL) goto failed;
4950 for (i = 0; i < len; i++) {
4952 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4953 if (res != 0) goto failed;
4954 asdl_seq_SET(keys, i, value);
4959 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
4962 if (PyObject_HasAttrString(obj, "values")) {
4966 tmp = PyObject_GetAttrString(obj, "values");
4967 if (tmp == NULL) goto failed;
4968 if (!PyList_Check(tmp)) {
4969 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4972 len = PyList_GET_SIZE(tmp);
4973 values = asdl_seq_new(len, arena);
4974 if (values == NULL) goto failed;
4975 for (i = 0; i < len; i++) {
4977 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4978 if (res != 0) goto failed;
4979 asdl_seq_SET(values, i, value);
4984 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
4987 *out = Dict(keys, values, lineno, col_offset, arena);
4988 if (*out == NULL) goto failed;
4991 isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
4992 if (isinstance == -1) {
4998 if (PyObject_HasAttrString(obj, "elts")) {
5002 tmp = PyObject_GetAttrString(obj, "elts");
5003 if (tmp == NULL) goto failed;
5004 if (!PyList_Check(tmp)) {
5005 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5008 len = PyList_GET_SIZE(tmp);
5009 elts = asdl_seq_new(len, arena);
5010 if (elts == NULL) goto failed;
5011 for (i = 0; i < len; i++) {
5013 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5014 if (res != 0) goto failed;
5015 asdl_seq_SET(elts, i, value);
5020 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
5023 *out = Set(elts, lineno, col_offset, arena);
5024 if (*out == NULL) goto failed;
5027 isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
5028 if (isinstance == -1) {
5033 asdl_seq* generators;
5035 if (PyObject_HasAttrString(obj, "elt")) {
5037 tmp = PyObject_GetAttrString(obj, "elt");
5038 if (tmp == NULL) goto failed;
5039 res = obj2ast_expr(tmp, &elt, arena);
5040 if (res != 0) goto failed;
5044 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
5047 if (PyObject_HasAttrString(obj, "generators")) {
5051 tmp = PyObject_GetAttrString(obj, "generators");
5052 if (tmp == NULL) goto failed;
5053 if (!PyList_Check(tmp)) {
5054 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5057 len = PyList_GET_SIZE(tmp);
5058 generators = asdl_seq_new(len, arena);
5059 if (generators == NULL) goto failed;
5060 for (i = 0; i < len; i++) {
5061 comprehension_ty value;
5062 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5063 if (res != 0) goto failed;
5064 asdl_seq_SET(generators, i, value);
5069 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
5072 *out = ListComp(elt, generators, lineno, col_offset, arena);
5073 if (*out == NULL) goto failed;
5076 isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
5077 if (isinstance == -1) {
5082 asdl_seq* generators;
5084 if (PyObject_HasAttrString(obj, "elt")) {
5086 tmp = PyObject_GetAttrString(obj, "elt");
5087 if (tmp == NULL) goto failed;
5088 res = obj2ast_expr(tmp, &elt, arena);
5089 if (res != 0) goto failed;
5093 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
5096 if (PyObject_HasAttrString(obj, "generators")) {
5100 tmp = PyObject_GetAttrString(obj, "generators");
5101 if (tmp == NULL) goto failed;
5102 if (!PyList_Check(tmp)) {
5103 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5106 len = PyList_GET_SIZE(tmp);
5107 generators = asdl_seq_new(len, arena);
5108 if (generators == NULL) goto failed;
5109 for (i = 0; i < len; i++) {
5110 comprehension_ty value;
5111 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5112 if (res != 0) goto failed;
5113 asdl_seq_SET(generators, i, value);
5118 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
5121 *out = SetComp(elt, generators, lineno, col_offset, arena);
5122 if (*out == NULL) goto failed;
5125 isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
5126 if (isinstance == -1) {
5132 asdl_seq* generators;
5134 if (PyObject_HasAttrString(obj, "key")) {
5136 tmp = PyObject_GetAttrString(obj, "key");
5137 if (tmp == NULL) goto failed;
5138 res = obj2ast_expr(tmp, &key, arena);
5139 if (res != 0) goto failed;
5143 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
5146 if (PyObject_HasAttrString(obj, "value")) {
5148 tmp = PyObject_GetAttrString(obj, "value");
5149 if (tmp == NULL) goto failed;
5150 res = obj2ast_expr(tmp, &value, arena);
5151 if (res != 0) goto failed;
5155 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
5158 if (PyObject_HasAttrString(obj, "generators")) {
5162 tmp = PyObject_GetAttrString(obj, "generators");
5163 if (tmp == NULL) goto failed;
5164 if (!PyList_Check(tmp)) {
5165 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5168 len = PyList_GET_SIZE(tmp);
5169 generators = asdl_seq_new(len, arena);
5170 if (generators == NULL) goto failed;
5171 for (i = 0; i < len; i++) {
5172 comprehension_ty value;
5173 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5174 if (res != 0) goto failed;
5175 asdl_seq_SET(generators, i, value);
5180 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
5183 *out = DictComp(key, value, generators, lineno, col_offset,
5185 if (*out == NULL) goto failed;
5188 isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
5189 if (isinstance == -1) {
5194 asdl_seq* generators;
5196 if (PyObject_HasAttrString(obj, "elt")) {
5198 tmp = PyObject_GetAttrString(obj, "elt");
5199 if (tmp == NULL) goto failed;
5200 res = obj2ast_expr(tmp, &elt, arena);
5201 if (res != 0) goto failed;
5205 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
5208 if (PyObject_HasAttrString(obj, "generators")) {
5212 tmp = PyObject_GetAttrString(obj, "generators");
5213 if (tmp == NULL) goto failed;
5214 if (!PyList_Check(tmp)) {
5215 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5218 len = PyList_GET_SIZE(tmp);
5219 generators = asdl_seq_new(len, arena);
5220 if (generators == NULL) goto failed;
5221 for (i = 0; i < len; i++) {
5222 comprehension_ty value;
5223 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5224 if (res != 0) goto failed;
5225 asdl_seq_SET(generators, i, value);
5230 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
5233 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
5234 if (*out == NULL) goto failed;
5237 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
5238 if (isinstance == -1) {
5244 if (PyObject_HasAttrString(obj, "value")) {
5246 tmp = PyObject_GetAttrString(obj, "value");
5247 if (tmp == NULL) goto failed;
5248 res = obj2ast_expr(tmp, &value, arena);
5249 if (res != 0) goto failed;
5255 *out = Yield(value, lineno, col_offset, arena);
5256 if (*out == NULL) goto failed;
5259 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
5260 if (isinstance == -1) {
5266 asdl_seq* comparators;
5268 if (PyObject_HasAttrString(obj, "left")) {
5270 tmp = PyObject_GetAttrString(obj, "left");
5271 if (tmp == NULL) goto failed;
5272 res = obj2ast_expr(tmp, &left, arena);
5273 if (res != 0) goto failed;
5277 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
5280 if (PyObject_HasAttrString(obj, "ops")) {
5284 tmp = PyObject_GetAttrString(obj, "ops");
5285 if (tmp == NULL) goto failed;
5286 if (!PyList_Check(tmp)) {
5287 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5290 len = PyList_GET_SIZE(tmp);
5291 ops = asdl_int_seq_new(len, arena);
5292 if (ops == NULL) goto failed;
5293 for (i = 0; i < len; i++) {
5295 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
5296 if (res != 0) goto failed;
5297 asdl_seq_SET(ops, i, value);
5302 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
5305 if (PyObject_HasAttrString(obj, "comparators")) {
5309 tmp = PyObject_GetAttrString(obj, "comparators");
5310 if (tmp == NULL) goto failed;
5311 if (!PyList_Check(tmp)) {
5312 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5315 len = PyList_GET_SIZE(tmp);
5316 comparators = asdl_seq_new(len, arena);
5317 if (comparators == NULL) goto failed;
5318 for (i = 0; i < len; i++) {
5320 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5321 if (res != 0) goto failed;
5322 asdl_seq_SET(comparators, i, value);
5327 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
5330 *out = Compare(left, ops, comparators, lineno, col_offset,
5332 if (*out == NULL) goto failed;
5335 isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
5336 if (isinstance == -1) {
5346 if (PyObject_HasAttrString(obj, "func")) {
5348 tmp = PyObject_GetAttrString(obj, "func");
5349 if (tmp == NULL) goto failed;
5350 res = obj2ast_expr(tmp, &func, arena);
5351 if (res != 0) goto failed;
5355 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
5358 if (PyObject_HasAttrString(obj, "args")) {
5362 tmp = PyObject_GetAttrString(obj, "args");
5363 if (tmp == NULL) goto failed;
5364 if (!PyList_Check(tmp)) {
5365 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5368 len = PyList_GET_SIZE(tmp);
5369 args = asdl_seq_new(len, arena);
5370 if (args == NULL) goto failed;
5371 for (i = 0; i < len; i++) {
5373 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5374 if (res != 0) goto failed;
5375 asdl_seq_SET(args, i, value);
5380 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
5383 if (PyObject_HasAttrString(obj, "keywords")) {
5387 tmp = PyObject_GetAttrString(obj, "keywords");
5388 if (tmp == NULL) goto failed;
5389 if (!PyList_Check(tmp)) {
5390 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5393 len = PyList_GET_SIZE(tmp);
5394 keywords = asdl_seq_new(len, arena);
5395 if (keywords == NULL) goto failed;
5396 for (i = 0; i < len; i++) {
5398 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
5399 if (res != 0) goto failed;
5400 asdl_seq_SET(keywords, i, value);
5405 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
5408 if (PyObject_HasAttrString(obj, "starargs")) {
5410 tmp = PyObject_GetAttrString(obj, "starargs");
5411 if (tmp == NULL) goto failed;
5412 res = obj2ast_expr(tmp, &starargs, arena);
5413 if (res != 0) goto failed;
5419 if (PyObject_HasAttrString(obj, "kwargs")) {
5421 tmp = PyObject_GetAttrString(obj, "kwargs");
5422 if (tmp == NULL) goto failed;
5423 res = obj2ast_expr(tmp, &kwargs, arena);
5424 if (res != 0) goto failed;
5430 *out = Call(func, args, keywords, starargs, kwargs, lineno,
5432 if (*out == NULL) goto failed;
5435 isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
5436 if (isinstance == -1) {
5442 if (PyObject_HasAttrString(obj, "value")) {
5444 tmp = PyObject_GetAttrString(obj, "value");
5445 if (tmp == NULL) goto failed;
5446 res = obj2ast_expr(tmp, &value, arena);
5447 if (res != 0) goto failed;
5451 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
5454 *out = Repr(value, lineno, col_offset, arena);
5455 if (*out == NULL) goto failed;
5458 isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
5459 if (isinstance == -1) {
5465 if (PyObject_HasAttrString(obj, "n")) {
5467 tmp = PyObject_GetAttrString(obj, "n");
5468 if (tmp == NULL) goto failed;
5469 res = obj2ast_object(tmp, &n, arena);
5470 if (res != 0) goto failed;
5474 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
5477 *out = Num(n, lineno, col_offset, arena);
5478 if (*out == NULL) goto failed;
5481 isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
5482 if (isinstance == -1) {
5488 if (PyObject_HasAttrString(obj, "s")) {
5490 tmp = PyObject_GetAttrString(obj, "s");
5491 if (tmp == NULL) goto failed;
5492 res = obj2ast_string(tmp, &s, arena);
5493 if (res != 0) goto failed;
5497 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
5500 *out = Str(s, lineno, col_offset, arena);
5501 if (*out == NULL) goto failed;
5504 isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
5505 if (isinstance == -1) {
5511 expr_context_ty ctx;
5513 if (PyObject_HasAttrString(obj, "value")) {
5515 tmp = PyObject_GetAttrString(obj, "value");
5516 if (tmp == NULL) goto failed;
5517 res = obj2ast_expr(tmp, &value, arena);
5518 if (res != 0) goto failed;
5522 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
5525 if (PyObject_HasAttrString(obj, "attr")) {
5527 tmp = PyObject_GetAttrString(obj, "attr");
5528 if (tmp == NULL) goto failed;
5529 res = obj2ast_identifier(tmp, &attr, arena);
5530 if (res != 0) goto failed;
5534 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
5537 if (PyObject_HasAttrString(obj, "ctx")) {
5539 tmp = PyObject_GetAttrString(obj, "ctx");
5540 if (tmp == NULL) goto failed;
5541 res = obj2ast_expr_context(tmp, &ctx, arena);
5542 if (res != 0) goto failed;
5546 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
5549 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
5550 if (*out == NULL) goto failed;
5553 isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
5554 if (isinstance == -1) {
5560 expr_context_ty ctx;
5562 if (PyObject_HasAttrString(obj, "value")) {
5564 tmp = PyObject_GetAttrString(obj, "value");
5565 if (tmp == NULL) goto failed;
5566 res = obj2ast_expr(tmp, &value, arena);
5567 if (res != 0) goto failed;
5571 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
5574 if (PyObject_HasAttrString(obj, "slice")) {
5576 tmp = PyObject_GetAttrString(obj, "slice");
5577 if (tmp == NULL) goto failed;
5578 res = obj2ast_slice(tmp, &slice, arena);
5579 if (res != 0) goto failed;
5583 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
5586 if (PyObject_HasAttrString(obj, "ctx")) {
5588 tmp = PyObject_GetAttrString(obj, "ctx");
5589 if (tmp == NULL) goto failed;
5590 res = obj2ast_expr_context(tmp, &ctx, arena);
5591 if (res != 0) goto failed;
5595 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
5598 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
5599 if (*out == NULL) goto failed;
5602 isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
5603 if (isinstance == -1) {
5608 expr_context_ty ctx;
5610 if (PyObject_HasAttrString(obj, "id")) {
5612 tmp = PyObject_GetAttrString(obj, "id");
5613 if (tmp == NULL) goto failed;
5614 res = obj2ast_identifier(tmp, &id, arena);
5615 if (res != 0) goto failed;
5619 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
5622 if (PyObject_HasAttrString(obj, "ctx")) {
5624 tmp = PyObject_GetAttrString(obj, "ctx");
5625 if (tmp == NULL) goto failed;
5626 res = obj2ast_expr_context(tmp, &ctx, arena);
5627 if (res != 0) goto failed;
5631 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
5634 *out = Name(id, ctx, lineno, col_offset, arena);
5635 if (*out == NULL) goto failed;
5638 isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
5639 if (isinstance == -1) {
5644 expr_context_ty ctx;
5646 if (PyObject_HasAttrString(obj, "elts")) {
5650 tmp = PyObject_GetAttrString(obj, "elts");
5651 if (tmp == NULL) goto failed;
5652 if (!PyList_Check(tmp)) {
5653 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5656 len = PyList_GET_SIZE(tmp);
5657 elts = asdl_seq_new(len, arena);
5658 if (elts == NULL) goto failed;
5659 for (i = 0; i < len; i++) {
5661 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5662 if (res != 0) goto failed;
5663 asdl_seq_SET(elts, i, value);
5668 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
5671 if (PyObject_HasAttrString(obj, "ctx")) {
5673 tmp = PyObject_GetAttrString(obj, "ctx");
5674 if (tmp == NULL) goto failed;
5675 res = obj2ast_expr_context(tmp, &ctx, arena);
5676 if (res != 0) goto failed;
5680 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
5683 *out = List(elts, ctx, lineno, col_offset, arena);
5684 if (*out == NULL) goto failed;
5687 isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
5688 if (isinstance == -1) {
5693 expr_context_ty ctx;
5695 if (PyObject_HasAttrString(obj, "elts")) {
5699 tmp = PyObject_GetAttrString(obj, "elts");
5700 if (tmp == NULL) goto failed;
5701 if (!PyList_Check(tmp)) {
5702 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5705 len = PyList_GET_SIZE(tmp);
5706 elts = asdl_seq_new(len, arena);
5707 if (elts == NULL) goto failed;
5708 for (i = 0; i < len; i++) {
5710 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5711 if (res != 0) goto failed;
5712 asdl_seq_SET(elts, i, value);
5717 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
5720 if (PyObject_HasAttrString(obj, "ctx")) {
5722 tmp = PyObject_GetAttrString(obj, "ctx");
5723 if (tmp == NULL) goto failed;
5724 res = obj2ast_expr_context(tmp, &ctx, arena);
5725 if (res != 0) goto failed;
5729 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
5732 *out = Tuple(elts, ctx, lineno, col_offset, arena);
5733 if (*out == NULL) goto failed;
5737 tmp = PyObject_Repr(obj);
5738 if (tmp == NULL) goto failed;
5739 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
5746 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
5748 PyObject* tmp = NULL;
5751 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
5752 if (isinstance == -1) {
5759 isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
5760 if (isinstance == -1) {
5767 isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
5768 if (isinstance == -1) {
5775 isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
5776 if (isinstance == -1) {
5783 isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
5784 if (isinstance == -1) {
5791 isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
5792 if (isinstance == -1) {
5800 tmp = PyObject_Repr(obj);
5801 if (tmp == NULL) goto failed;
5802 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
5809 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
5811 PyObject* tmp = NULL;
5815 if (obj == Py_None) {
5819 isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
5820 if (isinstance == -1) {
5825 *out = Ellipsis(arena);
5826 if (*out == NULL) goto failed;
5829 isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
5830 if (isinstance == -1) {
5838 if (PyObject_HasAttrString(obj, "lower")) {
5840 tmp = PyObject_GetAttrString(obj, "lower");
5841 if (tmp == NULL) goto failed;
5842 res = obj2ast_expr(tmp, &lower, arena);
5843 if (res != 0) goto failed;
5849 if (PyObject_HasAttrString(obj, "upper")) {
5851 tmp = PyObject_GetAttrString(obj, "upper");
5852 if (tmp == NULL) goto failed;
5853 res = obj2ast_expr(tmp, &upper, arena);
5854 if (res != 0) goto failed;
5860 if (PyObject_HasAttrString(obj, "step")) {
5862 tmp = PyObject_GetAttrString(obj, "step");
5863 if (tmp == NULL) goto failed;
5864 res = obj2ast_expr(tmp, &step, arena);
5865 if (res != 0) goto failed;
5871 *out = Slice(lower, upper, step, arena);
5872 if (*out == NULL) goto failed;
5875 isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
5876 if (isinstance == -1) {
5882 if (PyObject_HasAttrString(obj, "dims")) {
5886 tmp = PyObject_GetAttrString(obj, "dims");
5887 if (tmp == NULL) goto failed;
5888 if (!PyList_Check(tmp)) {
5889 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5892 len = PyList_GET_SIZE(tmp);
5893 dims = asdl_seq_new(len, arena);
5894 if (dims == NULL) goto failed;
5895 for (i = 0; i < len; i++) {
5897 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
5898 if (res != 0) goto failed;
5899 asdl_seq_SET(dims, i, value);
5904 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
5907 *out = ExtSlice(dims, arena);
5908 if (*out == NULL) goto failed;
5911 isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
5912 if (isinstance == -1) {
5918 if (PyObject_HasAttrString(obj, "value")) {
5920 tmp = PyObject_GetAttrString(obj, "value");
5921 if (tmp == NULL) goto failed;
5922 res = obj2ast_expr(tmp, &value, arena);
5923 if (res != 0) goto failed;
5927 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
5930 *out = Index(value, arena);
5931 if (*out == NULL) goto failed;
5935 tmp = PyObject_Repr(obj);
5936 if (tmp == NULL) goto failed;
5937 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
5944 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
5946 PyObject* tmp = NULL;
5949 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
5950 if (isinstance == -1) {
5957 isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
5958 if (isinstance == -1) {
5966 tmp = PyObject_Repr(obj);
5967 if (tmp == NULL) goto failed;
5968 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
5975 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
5977 PyObject* tmp = NULL;
5980 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
5981 if (isinstance == -1) {
5988 isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
5989 if (isinstance == -1) {
5996 isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
5997 if (isinstance == -1) {
6004 isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
6005 if (isinstance == -1) {
6012 isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
6013 if (isinstance == -1) {
6020 isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
6021 if (isinstance == -1) {
6028 isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
6029 if (isinstance == -1) {
6036 isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
6037 if (isinstance == -1) {
6044 isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
6045 if (isinstance == -1) {
6052 isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
6053 if (isinstance == -1) {
6060 isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
6061 if (isinstance == -1) {
6068 isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
6069 if (isinstance == -1) {
6077 tmp = PyObject_Repr(obj);
6078 if (tmp == NULL) goto failed;
6079 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
6086 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
6088 PyObject* tmp = NULL;
6091 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
6092 if (isinstance == -1) {
6099 isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
6100 if (isinstance == -1) {
6107 isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
6108 if (isinstance == -1) {
6115 isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
6116 if (isinstance == -1) {
6124 tmp = PyObject_Repr(obj);
6125 if (tmp == NULL) goto failed;
6126 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
6133 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
6135 PyObject* tmp = NULL;
6138 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
6139 if (isinstance == -1) {
6146 isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
6147 if (isinstance == -1) {
6154 isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
6155 if (isinstance == -1) {
6162 isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
6163 if (isinstance == -1) {
6170 isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
6171 if (isinstance == -1) {
6178 isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
6179 if (isinstance == -1) {
6186 isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
6187 if (isinstance == -1) {
6194 isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
6195 if (isinstance == -1) {
6202 isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
6203 if (isinstance == -1) {
6210 isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
6211 if (isinstance == -1) {
6219 tmp = PyObject_Repr(obj);
6220 if (tmp == NULL) goto failed;
6221 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
6228 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
6230 PyObject* tmp = NULL;
6235 if (PyObject_HasAttrString(obj, "target")) {
6237 tmp = PyObject_GetAttrString(obj, "target");
6238 if (tmp == NULL) goto failed;
6239 res = obj2ast_expr(tmp, &target, arena);
6240 if (res != 0) goto failed;
6244 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
6247 if (PyObject_HasAttrString(obj, "iter")) {
6249 tmp = PyObject_GetAttrString(obj, "iter");
6250 if (tmp == NULL) goto failed;
6251 res = obj2ast_expr(tmp, &iter, arena);
6252 if (res != 0) goto failed;
6256 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
6259 if (PyObject_HasAttrString(obj, "ifs")) {
6263 tmp = PyObject_GetAttrString(obj, "ifs");
6264 if (tmp == NULL) goto failed;
6265 if (!PyList_Check(tmp)) {
6266 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6269 len = PyList_GET_SIZE(tmp);
6270 ifs = asdl_seq_new(len, arena);
6271 if (ifs == NULL) goto failed;
6272 for (i = 0; i < len; i++) {
6274 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6275 if (res != 0) goto failed;
6276 asdl_seq_SET(ifs, i, value);
6281 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
6284 *out = comprehension(target, iter, ifs, arena);
6292 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
6294 PyObject* tmp = NULL;
6300 if (obj == Py_None) {
6304 if (PyObject_HasAttrString(obj, "lineno")) {
6306 tmp = PyObject_GetAttrString(obj, "lineno");
6307 if (tmp == NULL) goto failed;
6308 res = obj2ast_int(tmp, &lineno, arena);
6309 if (res != 0) goto failed;
6313 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
6316 if (PyObject_HasAttrString(obj, "col_offset")) {
6318 tmp = PyObject_GetAttrString(obj, "col_offset");
6319 if (tmp == NULL) goto failed;
6320 res = obj2ast_int(tmp, &col_offset, arena);
6321 if (res != 0) goto failed;
6325 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
6328 isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
6329 if (isinstance == -1) {
6337 if (PyObject_HasAttrString(obj, "type")) {
6339 tmp = PyObject_GetAttrString(obj, "type");
6340 if (tmp == NULL) goto failed;
6341 res = obj2ast_expr(tmp, &type, arena);
6342 if (res != 0) goto failed;
6348 if (PyObject_HasAttrString(obj, "name")) {
6350 tmp = PyObject_GetAttrString(obj, "name");
6351 if (tmp == NULL) goto failed;
6352 res = obj2ast_expr(tmp, &name, arena);
6353 if (res != 0) goto failed;
6359 if (PyObject_HasAttrString(obj, "body")) {
6363 tmp = PyObject_GetAttrString(obj, "body");
6364 if (tmp == NULL) goto failed;
6365 if (!PyList_Check(tmp)) {
6366 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6369 len = PyList_GET_SIZE(tmp);
6370 body = asdl_seq_new(len, arena);
6371 if (body == NULL) goto failed;
6372 for (i = 0; i < len; i++) {
6374 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
6375 if (res != 0) goto failed;
6376 asdl_seq_SET(body, i, value);
6381 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
6384 *out = ExceptHandler(type, name, body, lineno, col_offset,
6386 if (*out == NULL) goto failed;
6390 tmp = PyObject_Repr(obj);
6391 if (tmp == NULL) goto failed;
6392 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
6399 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
6401 PyObject* tmp = NULL;
6407 if (PyObject_HasAttrString(obj, "args")) {
6411 tmp = PyObject_GetAttrString(obj, "args");
6412 if (tmp == NULL) goto failed;
6413 if (!PyList_Check(tmp)) {
6414 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6417 len = PyList_GET_SIZE(tmp);
6418 args = asdl_seq_new(len, arena);
6419 if (args == NULL) goto failed;
6420 for (i = 0; i < len; i++) {
6422 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6423 if (res != 0) goto failed;
6424 asdl_seq_SET(args, i, value);
6429 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
6432 if (PyObject_HasAttrString(obj, "vararg")) {
6434 tmp = PyObject_GetAttrString(obj, "vararg");
6435 if (tmp == NULL) goto failed;
6436 res = obj2ast_identifier(tmp, &vararg, arena);
6437 if (res != 0) goto failed;
6443 if (PyObject_HasAttrString(obj, "kwarg")) {
6445 tmp = PyObject_GetAttrString(obj, "kwarg");
6446 if (tmp == NULL) goto failed;
6447 res = obj2ast_identifier(tmp, &kwarg, arena);
6448 if (res != 0) goto failed;
6454 if (PyObject_HasAttrString(obj, "defaults")) {
6458 tmp = PyObject_GetAttrString(obj, "defaults");
6459 if (tmp == NULL) goto failed;
6460 if (!PyList_Check(tmp)) {
6461 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6464 len = PyList_GET_SIZE(tmp);
6465 defaults = asdl_seq_new(len, arena);
6466 if (defaults == NULL) goto failed;
6467 for (i = 0; i < len; i++) {
6469 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6470 if (res != 0) goto failed;
6471 asdl_seq_SET(defaults, i, value);
6476 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
6479 *out = arguments(args, vararg, kwarg, defaults, arena);
6487 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
6489 PyObject* tmp = NULL;
6493 if (PyObject_HasAttrString(obj, "arg")) {
6495 tmp = PyObject_GetAttrString(obj, "arg");
6496 if (tmp == NULL) goto failed;
6497 res = obj2ast_identifier(tmp, &arg, arena);
6498 if (res != 0) goto failed;
6502 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
6505 if (PyObject_HasAttrString(obj, "value")) {
6507 tmp = PyObject_GetAttrString(obj, "value");
6508 if (tmp == NULL) goto failed;
6509 res = obj2ast_expr(tmp, &value, arena);
6510 if (res != 0) goto failed;
6514 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
6517 *out = keyword(arg, value, arena);
6525 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
6527 PyObject* tmp = NULL;
6531 if (PyObject_HasAttrString(obj, "name")) {
6533 tmp = PyObject_GetAttrString(obj, "name");
6534 if (tmp == NULL) goto failed;
6535 res = obj2ast_identifier(tmp, &name, arena);
6536 if (res != 0) goto failed;
6540 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
6543 if (PyObject_HasAttrString(obj, "asname")) {
6545 tmp = PyObject_GetAttrString(obj, "asname");
6546 if (tmp == NULL) goto failed;
6547 res = obj2ast_identifier(tmp, &asname, arena);
6548 if (res != 0) goto failed;
6554 *out = alias(name, asname, arena);
6566 if (!init_types()) return;
6567 m = Py_InitModule3("_ast", NULL, NULL);
6569 d = PyModule_GetDict(m);
6570 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
6571 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
6573 if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)
6575 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
6576 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
6578 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
6580 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
6582 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
6583 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
6584 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
6586 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
6588 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
6590 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
6592 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
6594 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
6596 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
6597 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
6598 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
6599 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
6600 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
6601 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
6602 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
6604 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
6606 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
6608 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
6610 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
6612 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
6613 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
6615 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
6616 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
6617 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
6618 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
6620 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
6621 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
6623 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
6624 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
6626 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
6628 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
6629 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
6630 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
6631 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
6633 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
6635 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
6637 if (PyDict_SetItemString(d, "GeneratorExp",
6638 (PyObject*)GeneratorExp_type) < 0) return;
6639 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
6640 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
6642 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
6643 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
6644 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
6645 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
6646 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
6648 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
6650 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
6651 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
6652 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
6653 if (PyDict_SetItemString(d, "expr_context",
6654 (PyObject*)expr_context_type) < 0) return;
6655 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
6656 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
6657 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
6658 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
6660 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
6662 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
6663 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
6664 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
6666 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
6667 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
6669 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
6670 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
6672 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
6673 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
6674 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
6676 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
6677 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
6678 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
6679 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
6680 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
6681 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
6682 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
6684 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
6686 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
6687 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
6689 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
6691 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
6693 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
6695 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
6697 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
6698 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
6699 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
6700 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
6701 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
6702 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
6703 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
6704 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
6705 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
6706 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
6707 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
6708 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
6709 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
6710 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
6711 if (PyDict_SetItemString(d, "comprehension",
6712 (PyObject*)comprehension_type) < 0) return;
6713 if (PyDict_SetItemString(d, "excepthandler",
6714 (PyObject*)excepthandler_type) < 0) return;
6715 if (PyDict_SetItemString(d, "ExceptHandler",
6716 (PyObject*)ExceptHandler_type) < 0) return;
6717 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
6719 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
6721 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
6725 PyObject* PyAST_mod2obj(mod_ty t)
6728 return ast2obj_mod(t);
6731 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6732 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
6735 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
6736 (PyObject*)Interactive_type};
6737 char *req_name[] = {"Module", "Expression", "Interactive"};
6739 assert(0 <= mode && mode <= 2);
6743 isinstance = PyObject_IsInstance(ast, req_type[mode]);
6744 if (isinstance == -1)
6747 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
6748 req_name[mode], Py_TYPE(ast)->tp_name);
6751 if (obj2ast_mod(ast, &res, arena) != 0)
6757 int PyAST_Check(PyObject* obj)
6760 return PyObject_IsInstance(obj, (PyObject*)&AST_type);