+/* File automatically generated by Parser/asdl_c.py. */\r
+\r
+\r
+/*\r
+ __version__ 82160.\r
+\r
+ This module must be committed separately after each AST grammar change;\r
+ The __version__ number is set to the revision number of the commit\r
+ containing the grammar change.\r
+*/\r
+\r
+#include "Python.h"\r
+#include "Python-ast.h"\r
+\r
+static PyTypeObject AST_type;\r
+static PyTypeObject *mod_type;\r
+static PyObject* ast2obj_mod(void*);\r
+static PyTypeObject *Module_type;\r
+static char *Module_fields[]={\r
+ "body",\r
+};\r
+static PyTypeObject *Interactive_type;\r
+static char *Interactive_fields[]={\r
+ "body",\r
+};\r
+static PyTypeObject *Expression_type;\r
+static char *Expression_fields[]={\r
+ "body",\r
+};\r
+static PyTypeObject *Suite_type;\r
+static char *Suite_fields[]={\r
+ "body",\r
+};\r
+static PyTypeObject *stmt_type;\r
+static char *stmt_attributes[] = {\r
+ "lineno",\r
+ "col_offset",\r
+};\r
+static PyObject* ast2obj_stmt(void*);\r
+static PyTypeObject *FunctionDef_type;\r
+static char *FunctionDef_fields[]={\r
+ "name",\r
+ "args",\r
+ "body",\r
+ "decorator_list",\r
+};\r
+static PyTypeObject *ClassDef_type;\r
+static char *ClassDef_fields[]={\r
+ "name",\r
+ "bases",\r
+ "body",\r
+ "decorator_list",\r
+};\r
+static PyTypeObject *Return_type;\r
+static char *Return_fields[]={\r
+ "value",\r
+};\r
+static PyTypeObject *Delete_type;\r
+static char *Delete_fields[]={\r
+ "targets",\r
+};\r
+static PyTypeObject *Assign_type;\r
+static char *Assign_fields[]={\r
+ "targets",\r
+ "value",\r
+};\r
+static PyTypeObject *AugAssign_type;\r
+static char *AugAssign_fields[]={\r
+ "target",\r
+ "op",\r
+ "value",\r
+};\r
+static PyTypeObject *Print_type;\r
+static char *Print_fields[]={\r
+ "dest",\r
+ "values",\r
+ "nl",\r
+};\r
+static PyTypeObject *For_type;\r
+static char *For_fields[]={\r
+ "target",\r
+ "iter",\r
+ "body",\r
+ "orelse",\r
+};\r
+static PyTypeObject *While_type;\r
+static char *While_fields[]={\r
+ "test",\r
+ "body",\r
+ "orelse",\r
+};\r
+static PyTypeObject *If_type;\r
+static char *If_fields[]={\r
+ "test",\r
+ "body",\r
+ "orelse",\r
+};\r
+static PyTypeObject *With_type;\r
+static char *With_fields[]={\r
+ "context_expr",\r
+ "optional_vars",\r
+ "body",\r
+};\r
+static PyTypeObject *Raise_type;\r
+static char *Raise_fields[]={\r
+ "type",\r
+ "inst",\r
+ "tback",\r
+};\r
+static PyTypeObject *TryExcept_type;\r
+static char *TryExcept_fields[]={\r
+ "body",\r
+ "handlers",\r
+ "orelse",\r
+};\r
+static PyTypeObject *TryFinally_type;\r
+static char *TryFinally_fields[]={\r
+ "body",\r
+ "finalbody",\r
+};\r
+static PyTypeObject *Assert_type;\r
+static char *Assert_fields[]={\r
+ "test",\r
+ "msg",\r
+};\r
+static PyTypeObject *Import_type;\r
+static char *Import_fields[]={\r
+ "names",\r
+};\r
+static PyTypeObject *ImportFrom_type;\r
+static char *ImportFrom_fields[]={\r
+ "module",\r
+ "names",\r
+ "level",\r
+};\r
+static PyTypeObject *Exec_type;\r
+static char *Exec_fields[]={\r
+ "body",\r
+ "globals",\r
+ "locals",\r
+};\r
+static PyTypeObject *Global_type;\r
+static char *Global_fields[]={\r
+ "names",\r
+};\r
+static PyTypeObject *Expr_type;\r
+static char *Expr_fields[]={\r
+ "value",\r
+};\r
+static PyTypeObject *Pass_type;\r
+static PyTypeObject *Break_type;\r
+static PyTypeObject *Continue_type;\r
+static PyTypeObject *expr_type;\r
+static char *expr_attributes[] = {\r
+ "lineno",\r
+ "col_offset",\r
+};\r
+static PyObject* ast2obj_expr(void*);\r
+static PyTypeObject *BoolOp_type;\r
+static char *BoolOp_fields[]={\r
+ "op",\r
+ "values",\r
+};\r
+static PyTypeObject *BinOp_type;\r
+static char *BinOp_fields[]={\r
+ "left",\r
+ "op",\r
+ "right",\r
+};\r
+static PyTypeObject *UnaryOp_type;\r
+static char *UnaryOp_fields[]={\r
+ "op",\r
+ "operand",\r
+};\r
+static PyTypeObject *Lambda_type;\r
+static char *Lambda_fields[]={\r
+ "args",\r
+ "body",\r
+};\r
+static PyTypeObject *IfExp_type;\r
+static char *IfExp_fields[]={\r
+ "test",\r
+ "body",\r
+ "orelse",\r
+};\r
+static PyTypeObject *Dict_type;\r
+static char *Dict_fields[]={\r
+ "keys",\r
+ "values",\r
+};\r
+static PyTypeObject *Set_type;\r
+static char *Set_fields[]={\r
+ "elts",\r
+};\r
+static PyTypeObject *ListComp_type;\r
+static char *ListComp_fields[]={\r
+ "elt",\r
+ "generators",\r
+};\r
+static PyTypeObject *SetComp_type;\r
+static char *SetComp_fields[]={\r
+ "elt",\r
+ "generators",\r
+};\r
+static PyTypeObject *DictComp_type;\r
+static char *DictComp_fields[]={\r
+ "key",\r
+ "value",\r
+ "generators",\r
+};\r
+static PyTypeObject *GeneratorExp_type;\r
+static char *GeneratorExp_fields[]={\r
+ "elt",\r
+ "generators",\r
+};\r
+static PyTypeObject *Yield_type;\r
+static char *Yield_fields[]={\r
+ "value",\r
+};\r
+static PyTypeObject *Compare_type;\r
+static char *Compare_fields[]={\r
+ "left",\r
+ "ops",\r
+ "comparators",\r
+};\r
+static PyTypeObject *Call_type;\r
+static char *Call_fields[]={\r
+ "func",\r
+ "args",\r
+ "keywords",\r
+ "starargs",\r
+ "kwargs",\r
+};\r
+static PyTypeObject *Repr_type;\r
+static char *Repr_fields[]={\r
+ "value",\r
+};\r
+static PyTypeObject *Num_type;\r
+static char *Num_fields[]={\r
+ "n",\r
+};\r
+static PyTypeObject *Str_type;\r
+static char *Str_fields[]={\r
+ "s",\r
+};\r
+static PyTypeObject *Attribute_type;\r
+static char *Attribute_fields[]={\r
+ "value",\r
+ "attr",\r
+ "ctx",\r
+};\r
+static PyTypeObject *Subscript_type;\r
+static char *Subscript_fields[]={\r
+ "value",\r
+ "slice",\r
+ "ctx",\r
+};\r
+static PyTypeObject *Name_type;\r
+static char *Name_fields[]={\r
+ "id",\r
+ "ctx",\r
+};\r
+static PyTypeObject *List_type;\r
+static char *List_fields[]={\r
+ "elts",\r
+ "ctx",\r
+};\r
+static PyTypeObject *Tuple_type;\r
+static char *Tuple_fields[]={\r
+ "elts",\r
+ "ctx",\r
+};\r
+static PyTypeObject *expr_context_type;\r
+static PyObject *Load_singleton, *Store_singleton, *Del_singleton,\r
+*AugLoad_singleton, *AugStore_singleton, *Param_singleton;\r
+static PyObject* ast2obj_expr_context(expr_context_ty);\r
+static PyTypeObject *Load_type;\r
+static PyTypeObject *Store_type;\r
+static PyTypeObject *Del_type;\r
+static PyTypeObject *AugLoad_type;\r
+static PyTypeObject *AugStore_type;\r
+static PyTypeObject *Param_type;\r
+static PyTypeObject *slice_type;\r
+static PyObject* ast2obj_slice(void*);\r
+static PyTypeObject *Ellipsis_type;\r
+static PyTypeObject *Slice_type;\r
+static char *Slice_fields[]={\r
+ "lower",\r
+ "upper",\r
+ "step",\r
+};\r
+static PyTypeObject *ExtSlice_type;\r
+static char *ExtSlice_fields[]={\r
+ "dims",\r
+};\r
+static PyTypeObject *Index_type;\r
+static char *Index_fields[]={\r
+ "value",\r
+};\r
+static PyTypeObject *boolop_type;\r
+static PyObject *And_singleton, *Or_singleton;\r
+static PyObject* ast2obj_boolop(boolop_ty);\r
+static PyTypeObject *And_type;\r
+static PyTypeObject *Or_type;\r
+static PyTypeObject *operator_type;\r
+static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,\r
+*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,\r
+*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,\r
+*FloorDiv_singleton;\r
+static PyObject* ast2obj_operator(operator_ty);\r
+static PyTypeObject *Add_type;\r
+static PyTypeObject *Sub_type;\r
+static PyTypeObject *Mult_type;\r
+static PyTypeObject *Div_type;\r
+static PyTypeObject *Mod_type;\r
+static PyTypeObject *Pow_type;\r
+static PyTypeObject *LShift_type;\r
+static PyTypeObject *RShift_type;\r
+static PyTypeObject *BitOr_type;\r
+static PyTypeObject *BitXor_type;\r
+static PyTypeObject *BitAnd_type;\r
+static PyTypeObject *FloorDiv_type;\r
+static PyTypeObject *unaryop_type;\r
+static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,\r
+*USub_singleton;\r
+static PyObject* ast2obj_unaryop(unaryop_ty);\r
+static PyTypeObject *Invert_type;\r
+static PyTypeObject *Not_type;\r
+static PyTypeObject *UAdd_type;\r
+static PyTypeObject *USub_type;\r
+static PyTypeObject *cmpop_type;\r
+static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,\r
+*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,\r
+*NotIn_singleton;\r
+static PyObject* ast2obj_cmpop(cmpop_ty);\r
+static PyTypeObject *Eq_type;\r
+static PyTypeObject *NotEq_type;\r
+static PyTypeObject *Lt_type;\r
+static PyTypeObject *LtE_type;\r
+static PyTypeObject *Gt_type;\r
+static PyTypeObject *GtE_type;\r
+static PyTypeObject *Is_type;\r
+static PyTypeObject *IsNot_type;\r
+static PyTypeObject *In_type;\r
+static PyTypeObject *NotIn_type;\r
+static PyTypeObject *comprehension_type;\r
+static PyObject* ast2obj_comprehension(void*);\r
+static char *comprehension_fields[]={\r
+ "target",\r
+ "iter",\r
+ "ifs",\r
+};\r
+static PyTypeObject *excepthandler_type;\r
+static char *excepthandler_attributes[] = {\r
+ "lineno",\r
+ "col_offset",\r
+};\r
+static PyObject* ast2obj_excepthandler(void*);\r
+static PyTypeObject *ExceptHandler_type;\r
+static char *ExceptHandler_fields[]={\r
+ "type",\r
+ "name",\r
+ "body",\r
+};\r
+static PyTypeObject *arguments_type;\r
+static PyObject* ast2obj_arguments(void*);\r
+static char *arguments_fields[]={\r
+ "args",\r
+ "vararg",\r
+ "kwarg",\r
+ "defaults",\r
+};\r
+static PyTypeObject *keyword_type;\r
+static PyObject* ast2obj_keyword(void*);\r
+static char *keyword_fields[]={\r
+ "arg",\r
+ "value",\r
+};\r
+static PyTypeObject *alias_type;\r
+static PyObject* ast2obj_alias(void*);\r
+static char *alias_fields[]={\r
+ "name",\r
+ "asname",\r
+};\r
+\r
+\r
+static int\r
+ast_type_init(PyObject *self, PyObject *args, PyObject *kw)\r
+{\r
+ Py_ssize_t i, numfields = 0;\r
+ int res = -1;\r
+ PyObject *key, *value, *fields;\r
+ fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");\r
+ if (!fields)\r
+ PyErr_Clear();\r
+ if (fields) {\r
+ numfields = PySequence_Size(fields);\r
+ if (numfields == -1)\r
+ goto cleanup;\r
+ }\r
+ res = 0; /* if no error occurs, this stays 0 to the end */\r
+ if (PyTuple_GET_SIZE(args) > 0) {\r
+ if (numfields != PyTuple_GET_SIZE(args)) {\r
+ PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"\r
+ "%zd positional argument%s",\r
+ Py_TYPE(self)->tp_name,\r
+ numfields == 0 ? "" : "either 0 or ",\r
+ numfields, numfields == 1 ? "" : "s");\r
+ res = -1;\r
+ goto cleanup;\r
+ }\r
+ for (i = 0; i < PyTuple_GET_SIZE(args); i++) {\r
+ /* cannot be reached when fields is NULL */\r
+ PyObject *name = PySequence_GetItem(fields, i);\r
+ if (!name) {\r
+ res = -1;\r
+ goto cleanup;\r
+ }\r
+ res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));\r
+ Py_DECREF(name);\r
+ if (res < 0)\r
+ goto cleanup;\r
+ }\r
+ }\r
+ if (kw) {\r
+ i = 0; /* needed by PyDict_Next */\r
+ while (PyDict_Next(kw, &i, &key, &value)) {\r
+ res = PyObject_SetAttr(self, key, value);\r
+ if (res < 0)\r
+ goto cleanup;\r
+ }\r
+ }\r
+ cleanup:\r
+ Py_XDECREF(fields);\r
+ return res;\r
+}\r
+\r
+/* Pickling support */\r
+static PyObject *\r
+ast_type_reduce(PyObject *self, PyObject *unused)\r
+{\r
+ PyObject *res;\r
+ PyObject *dict = PyObject_GetAttrString(self, "__dict__");\r
+ if (dict == NULL) {\r
+ if (PyErr_ExceptionMatches(PyExc_AttributeError))\r
+ PyErr_Clear();\r
+ else\r
+ return NULL;\r
+ }\r
+ if (dict) {\r
+ res = Py_BuildValue("O()O", Py_TYPE(self), dict);\r
+ Py_DECREF(dict);\r
+ return res;\r
+ }\r
+ return Py_BuildValue("O()", Py_TYPE(self));\r
+}\r
+\r
+static PyMethodDef ast_type_methods[] = {\r
+ {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},\r
+ {NULL}\r
+};\r
+\r
+static PyTypeObject AST_type = {\r
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)\r
+ "_ast.AST",\r
+ sizeof(PyObject),\r
+ 0,\r
+ 0, /* tp_dealloc */\r
+ 0, /* tp_print */\r
+ 0, /* tp_getattr */\r
+ 0, /* tp_setattr */\r
+ 0, /* tp_compare */\r
+ 0, /* tp_repr */\r
+ 0, /* tp_as_number */\r
+ 0, /* tp_as_sequence */\r
+ 0, /* tp_as_mapping */\r
+ 0, /* tp_hash */\r
+ 0, /* tp_call */\r
+ 0, /* tp_str */\r
+ PyObject_GenericGetAttr, /* tp_getattro */\r
+ PyObject_GenericSetAttr, /* tp_setattro */\r
+ 0, /* tp_as_buffer */\r
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */\r
+ 0, /* tp_doc */\r
+ 0, /* tp_traverse */\r
+ 0, /* tp_clear */\r
+ 0, /* tp_richcompare */\r
+ 0, /* tp_weaklistoffset */\r
+ 0, /* tp_iter */\r
+ 0, /* tp_iternext */\r
+ ast_type_methods, /* tp_methods */\r
+ 0, /* tp_members */\r
+ 0, /* tp_getset */\r
+ 0, /* tp_base */\r
+ 0, /* tp_dict */\r
+ 0, /* tp_descr_get */\r
+ 0, /* tp_descr_set */\r
+ 0, /* tp_dictoffset */\r
+ (initproc)ast_type_init, /* tp_init */\r
+ PyType_GenericAlloc, /* tp_alloc */\r
+ PyType_GenericNew, /* tp_new */\r
+ PyObject_Del, /* tp_free */\r
+};\r
+\r
+\r
+static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)\r
+{\r
+ PyObject *fnames, *result;\r
+ int i;\r
+ fnames = PyTuple_New(num_fields);\r
+ if (!fnames) return NULL;\r
+ for (i = 0; i < num_fields; i++) {\r
+ PyObject *field = PyString_FromString(fields[i]);\r
+ if (!field) {\r
+ Py_DECREF(fnames);\r
+ return NULL;\r
+ }\r
+ PyTuple_SET_ITEM(fnames, i, field);\r
+ }\r
+ result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",\r
+ type, base, "_fields", fnames, "__module__", "_ast");\r
+ Py_DECREF(fnames);\r
+ return (PyTypeObject*)result;\r
+}\r
+\r
+static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)\r
+{\r
+ int i, result;\r
+ PyObject *s, *l = PyTuple_New(num_fields);\r
+ if (!l)\r
+ return 0;\r
+ for (i = 0; i < num_fields; i++) {\r
+ s = PyString_FromString(attrs[i]);\r
+ if (!s) {\r
+ Py_DECREF(l);\r
+ return 0;\r
+ }\r
+ PyTuple_SET_ITEM(l, i, s);\r
+ }\r
+ result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;\r
+ Py_DECREF(l);\r
+ return result;\r
+}\r
+\r
+/* Conversion AST -> Python */\r
+\r
+static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))\r
+{\r
+ int i, n = asdl_seq_LEN(seq);\r
+ PyObject *result = PyList_New(n);\r
+ PyObject *value;\r
+ if (!result)\r
+ return NULL;\r
+ for (i = 0; i < n; i++) {\r
+ value = func(asdl_seq_GET(seq, i));\r
+ if (!value) {\r
+ Py_DECREF(result);\r
+ return NULL;\r
+ }\r
+ PyList_SET_ITEM(result, i, value);\r
+ }\r
+ return result;\r
+}\r
+\r
+static PyObject* ast2obj_object(void *o)\r
+{\r
+ if (!o)\r
+ o = Py_None;\r
+ Py_INCREF((PyObject*)o);\r
+ return (PyObject*)o;\r
+}\r
+#define ast2obj_identifier ast2obj_object\r
+#define ast2obj_string ast2obj_object\r
+static PyObject* ast2obj_bool(bool b)\r
+{\r
+ return PyBool_FromLong(b);\r
+}\r
+\r
+static PyObject* ast2obj_int(long b)\r
+{\r
+ return PyInt_FromLong(b);\r
+}\r
+\r
+/* Conversion Python -> AST */\r
+\r
+static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+ if (obj == Py_None)\r
+ obj = NULL;\r
+ if (obj)\r
+ PyArena_AddPyObject(arena, obj);\r
+ Py_XINCREF(obj);\r
+ *out = obj;\r
+ return 0;\r
+}\r
+\r
+static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+ if (!PyString_CheckExact(obj) && obj != Py_None) {\r
+ PyErr_Format(PyExc_TypeError,\r
+ "AST identifier must be of type str");\r
+ return 1;\r
+ }\r
+ return obj2ast_object(obj, out, arena);\r
+}\r
+\r
+static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+ if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {\r
+ PyErr_SetString(PyExc_TypeError,\r
+ "AST string must be of type str or unicode");\r
+ return 1;\r
+ }\r
+ return obj2ast_object(obj, out, arena);\r
+}\r
+\r
+static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)\r
+{\r
+ int i;\r
+ if (!PyInt_Check(obj) && !PyLong_Check(obj)) {\r
+ PyObject *s = PyObject_Repr(obj);\r
+ if (s == NULL) return 1;\r
+ PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",\r
+ PyString_AS_STRING(s));\r
+ Py_DECREF(s);\r
+ return 1;\r
+ }\r
+\r
+ i = (int)PyLong_AsLong(obj);\r
+ if (i == -1 && PyErr_Occurred())\r
+ return 1;\r
+ *out = i;\r
+ return 0;\r
+}\r
+\r
+static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)\r
+{\r
+ if (!PyBool_Check(obj)) {\r
+ PyObject *s = PyObject_Repr(obj);\r
+ if (s == NULL) return 1;\r
+ PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",\r
+ PyString_AS_STRING(s));\r
+ Py_DECREF(s);\r
+ return 1;\r
+ }\r
+\r
+ *out = (obj == Py_True);\r
+ return 0;\r
+}\r
+\r
+static int add_ast_fields(void)\r
+{\r
+ PyObject *empty_tuple, *d;\r
+ if (PyType_Ready(&AST_type) < 0)\r
+ return -1;\r
+ d = AST_type.tp_dict;\r
+ empty_tuple = PyTuple_New(0);\r
+ if (!empty_tuple ||\r
+ PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||\r
+ PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {\r
+ Py_XDECREF(empty_tuple);\r
+ return -1;\r
+ }\r
+ Py_DECREF(empty_tuple);\r
+ return 0;\r
+}\r
+\r
+\r
+static int init_types(void)\r
+{\r
+ static int initialized;\r
+ if (initialized) return 1;\r
+ if (add_ast_fields() < 0) return 0;\r
+ mod_type = make_type("mod", &AST_type, NULL, 0);\r
+ if (!mod_type) return 0;\r
+ if (!add_attributes(mod_type, NULL, 0)) return 0;\r
+ Module_type = make_type("Module", mod_type, Module_fields, 1);\r
+ if (!Module_type) return 0;\r
+ Interactive_type = make_type("Interactive", mod_type,\r
+ Interactive_fields, 1);\r
+ if (!Interactive_type) return 0;\r
+ Expression_type = make_type("Expression", mod_type, Expression_fields,\r
+ 1);\r
+ if (!Expression_type) return 0;\r
+ Suite_type = make_type("Suite", mod_type, Suite_fields, 1);\r
+ if (!Suite_type) return 0;\r
+ stmt_type = make_type("stmt", &AST_type, NULL, 0);\r
+ if (!stmt_type) return 0;\r
+ if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;\r
+ FunctionDef_type = make_type("FunctionDef", stmt_type,\r
+ FunctionDef_fields, 4);\r
+ if (!FunctionDef_type) return 0;\r
+ ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);\r
+ if (!ClassDef_type) return 0;\r
+ Return_type = make_type("Return", stmt_type, Return_fields, 1);\r
+ if (!Return_type) return 0;\r
+ Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);\r
+ if (!Delete_type) return 0;\r
+ Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);\r
+ if (!Assign_type) return 0;\r
+ AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);\r
+ if (!AugAssign_type) return 0;\r
+ Print_type = make_type("Print", stmt_type, Print_fields, 3);\r
+ if (!Print_type) return 0;\r
+ For_type = make_type("For", stmt_type, For_fields, 4);\r
+ if (!For_type) return 0;\r
+ While_type = make_type("While", stmt_type, While_fields, 3);\r
+ if (!While_type) return 0;\r
+ If_type = make_type("If", stmt_type, If_fields, 3);\r
+ if (!If_type) return 0;\r
+ With_type = make_type("With", stmt_type, With_fields, 3);\r
+ if (!With_type) return 0;\r
+ Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);\r
+ if (!Raise_type) return 0;\r
+ TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);\r
+ if (!TryExcept_type) return 0;\r
+ TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,\r
+ 2);\r
+ if (!TryFinally_type) return 0;\r
+ Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);\r
+ if (!Assert_type) return 0;\r
+ Import_type = make_type("Import", stmt_type, Import_fields, 1);\r
+ if (!Import_type) return 0;\r
+ ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,\r
+ 3);\r
+ if (!ImportFrom_type) return 0;\r
+ Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);\r
+ if (!Exec_type) return 0;\r
+ Global_type = make_type("Global", stmt_type, Global_fields, 1);\r
+ if (!Global_type) return 0;\r
+ Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);\r
+ if (!Expr_type) return 0;\r
+ Pass_type = make_type("Pass", stmt_type, NULL, 0);\r
+ if (!Pass_type) return 0;\r
+ Break_type = make_type("Break", stmt_type, NULL, 0);\r
+ if (!Break_type) return 0;\r
+ Continue_type = make_type("Continue", stmt_type, NULL, 0);\r
+ if (!Continue_type) return 0;\r
+ expr_type = make_type("expr", &AST_type, NULL, 0);\r
+ if (!expr_type) return 0;\r
+ if (!add_attributes(expr_type, expr_attributes, 2)) return 0;\r
+ BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);\r
+ if (!BoolOp_type) return 0;\r
+ BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);\r
+ if (!BinOp_type) return 0;\r
+ UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);\r
+ if (!UnaryOp_type) return 0;\r
+ Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);\r
+ if (!Lambda_type) return 0;\r
+ IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);\r
+ if (!IfExp_type) return 0;\r
+ Dict_type = make_type("Dict", expr_type, Dict_fields, 2);\r
+ if (!Dict_type) return 0;\r
+ Set_type = make_type("Set", expr_type, Set_fields, 1);\r
+ if (!Set_type) return 0;\r
+ ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);\r
+ if (!ListComp_type) return 0;\r
+ SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);\r
+ if (!SetComp_type) return 0;\r
+ DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);\r
+ if (!DictComp_type) return 0;\r
+ GeneratorExp_type = make_type("GeneratorExp", expr_type,\r
+ GeneratorExp_fields, 2);\r
+ if (!GeneratorExp_type) return 0;\r
+ Yield_type = make_type("Yield", expr_type, Yield_fields, 1);\r
+ if (!Yield_type) return 0;\r
+ Compare_type = make_type("Compare", expr_type, Compare_fields, 3);\r
+ if (!Compare_type) return 0;\r
+ Call_type = make_type("Call", expr_type, Call_fields, 5);\r
+ if (!Call_type) return 0;\r
+ Repr_type = make_type("Repr", expr_type, Repr_fields, 1);\r
+ if (!Repr_type) return 0;\r
+ Num_type = make_type("Num", expr_type, Num_fields, 1);\r
+ if (!Num_type) return 0;\r
+ Str_type = make_type("Str", expr_type, Str_fields, 1);\r
+ if (!Str_type) return 0;\r
+ Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);\r
+ if (!Attribute_type) return 0;\r
+ Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);\r
+ if (!Subscript_type) return 0;\r
+ Name_type = make_type("Name", expr_type, Name_fields, 2);\r
+ if (!Name_type) return 0;\r
+ List_type = make_type("List", expr_type, List_fields, 2);\r
+ if (!List_type) return 0;\r
+ Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);\r
+ if (!Tuple_type) return 0;\r
+ expr_context_type = make_type("expr_context", &AST_type, NULL, 0);\r
+ if (!expr_context_type) return 0;\r
+ if (!add_attributes(expr_context_type, NULL, 0)) return 0;\r
+ Load_type = make_type("Load", expr_context_type, NULL, 0);\r
+ if (!Load_type) return 0;\r
+ Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);\r
+ if (!Load_singleton) return 0;\r
+ Store_type = make_type("Store", expr_context_type, NULL, 0);\r
+ if (!Store_type) return 0;\r
+ Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);\r
+ if (!Store_singleton) return 0;\r
+ Del_type = make_type("Del", expr_context_type, NULL, 0);\r
+ if (!Del_type) return 0;\r
+ Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);\r
+ if (!Del_singleton) return 0;\r
+ AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);\r
+ if (!AugLoad_type) return 0;\r
+ AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);\r
+ if (!AugLoad_singleton) return 0;\r
+ AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);\r
+ if (!AugStore_type) return 0;\r
+ AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);\r
+ if (!AugStore_singleton) return 0;\r
+ Param_type = make_type("Param", expr_context_type, NULL, 0);\r
+ if (!Param_type) return 0;\r
+ Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);\r
+ if (!Param_singleton) return 0;\r
+ slice_type = make_type("slice", &AST_type, NULL, 0);\r
+ if (!slice_type) return 0;\r
+ if (!add_attributes(slice_type, NULL, 0)) return 0;\r
+ Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);\r
+ if (!Ellipsis_type) return 0;\r
+ Slice_type = make_type("Slice", slice_type, Slice_fields, 3);\r
+ if (!Slice_type) return 0;\r
+ ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);\r
+ if (!ExtSlice_type) return 0;\r
+ Index_type = make_type("Index", slice_type, Index_fields, 1);\r
+ if (!Index_type) return 0;\r
+ boolop_type = make_type("boolop", &AST_type, NULL, 0);\r
+ if (!boolop_type) return 0;\r
+ if (!add_attributes(boolop_type, NULL, 0)) return 0;\r
+ And_type = make_type("And", boolop_type, NULL, 0);\r
+ if (!And_type) return 0;\r
+ And_singleton = PyType_GenericNew(And_type, NULL, NULL);\r
+ if (!And_singleton) return 0;\r
+ Or_type = make_type("Or", boolop_type, NULL, 0);\r
+ if (!Or_type) return 0;\r
+ Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);\r
+ if (!Or_singleton) return 0;\r
+ operator_type = make_type("operator", &AST_type, NULL, 0);\r
+ if (!operator_type) return 0;\r
+ if (!add_attributes(operator_type, NULL, 0)) return 0;\r
+ Add_type = make_type("Add", operator_type, NULL, 0);\r
+ if (!Add_type) return 0;\r
+ Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);\r
+ if (!Add_singleton) return 0;\r
+ Sub_type = make_type("Sub", operator_type, NULL, 0);\r
+ if (!Sub_type) return 0;\r
+ Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);\r
+ if (!Sub_singleton) return 0;\r
+ Mult_type = make_type("Mult", operator_type, NULL, 0);\r
+ if (!Mult_type) return 0;\r
+ Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);\r
+ if (!Mult_singleton) return 0;\r
+ Div_type = make_type("Div", operator_type, NULL, 0);\r
+ if (!Div_type) return 0;\r
+ Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);\r
+ if (!Div_singleton) return 0;\r
+ Mod_type = make_type("Mod", operator_type, NULL, 0);\r
+ if (!Mod_type) return 0;\r
+ Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);\r
+ if (!Mod_singleton) return 0;\r
+ Pow_type = make_type("Pow", operator_type, NULL, 0);\r
+ if (!Pow_type) return 0;\r
+ Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);\r
+ if (!Pow_singleton) return 0;\r
+ LShift_type = make_type("LShift", operator_type, NULL, 0);\r
+ if (!LShift_type) return 0;\r
+ LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);\r
+ if (!LShift_singleton) return 0;\r
+ RShift_type = make_type("RShift", operator_type, NULL, 0);\r
+ if (!RShift_type) return 0;\r
+ RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);\r
+ if (!RShift_singleton) return 0;\r
+ BitOr_type = make_type("BitOr", operator_type, NULL, 0);\r
+ if (!BitOr_type) return 0;\r
+ BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);\r
+ if (!BitOr_singleton) return 0;\r
+ BitXor_type = make_type("BitXor", operator_type, NULL, 0);\r
+ if (!BitXor_type) return 0;\r
+ BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);\r
+ if (!BitXor_singleton) return 0;\r
+ BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);\r
+ if (!BitAnd_type) return 0;\r
+ BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);\r
+ if (!BitAnd_singleton) return 0;\r
+ FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);\r
+ if (!FloorDiv_type) return 0;\r
+ FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);\r
+ if (!FloorDiv_singleton) return 0;\r
+ unaryop_type = make_type("unaryop", &AST_type, NULL, 0);\r
+ if (!unaryop_type) return 0;\r
+ if (!add_attributes(unaryop_type, NULL, 0)) return 0;\r
+ Invert_type = make_type("Invert", unaryop_type, NULL, 0);\r
+ if (!Invert_type) return 0;\r
+ Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);\r
+ if (!Invert_singleton) return 0;\r
+ Not_type = make_type("Not", unaryop_type, NULL, 0);\r
+ if (!Not_type) return 0;\r
+ Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);\r
+ if (!Not_singleton) return 0;\r
+ UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);\r
+ if (!UAdd_type) return 0;\r
+ UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);\r
+ if (!UAdd_singleton) return 0;\r
+ USub_type = make_type("USub", unaryop_type, NULL, 0);\r
+ if (!USub_type) return 0;\r
+ USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);\r
+ if (!USub_singleton) return 0;\r
+ cmpop_type = make_type("cmpop", &AST_type, NULL, 0);\r
+ if (!cmpop_type) return 0;\r
+ if (!add_attributes(cmpop_type, NULL, 0)) return 0;\r
+ Eq_type = make_type("Eq", cmpop_type, NULL, 0);\r
+ if (!Eq_type) return 0;\r
+ Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);\r
+ if (!Eq_singleton) return 0;\r
+ NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);\r
+ if (!NotEq_type) return 0;\r
+ NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);\r
+ if (!NotEq_singleton) return 0;\r
+ Lt_type = make_type("Lt", cmpop_type, NULL, 0);\r
+ if (!Lt_type) return 0;\r
+ Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);\r
+ if (!Lt_singleton) return 0;\r
+ LtE_type = make_type("LtE", cmpop_type, NULL, 0);\r
+ if (!LtE_type) return 0;\r
+ LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);\r
+ if (!LtE_singleton) return 0;\r
+ Gt_type = make_type("Gt", cmpop_type, NULL, 0);\r
+ if (!Gt_type) return 0;\r
+ Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);\r
+ if (!Gt_singleton) return 0;\r
+ GtE_type = make_type("GtE", cmpop_type, NULL, 0);\r
+ if (!GtE_type) return 0;\r
+ GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);\r
+ if (!GtE_singleton) return 0;\r
+ Is_type = make_type("Is", cmpop_type, NULL, 0);\r
+ if (!Is_type) return 0;\r
+ Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);\r
+ if (!Is_singleton) return 0;\r
+ IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);\r
+ if (!IsNot_type) return 0;\r
+ IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);\r
+ if (!IsNot_singleton) return 0;\r
+ In_type = make_type("In", cmpop_type, NULL, 0);\r
+ if (!In_type) return 0;\r
+ In_singleton = PyType_GenericNew(In_type, NULL, NULL);\r
+ if (!In_singleton) return 0;\r
+ NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);\r
+ if (!NotIn_type) return 0;\r
+ NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);\r
+ if (!NotIn_singleton) return 0;\r
+ comprehension_type = make_type("comprehension", &AST_type,\r
+ comprehension_fields, 3);\r
+ if (!comprehension_type) return 0;\r
+ excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);\r
+ if (!excepthandler_type) return 0;\r
+ if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))\r
+ return 0;\r
+ ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,\r
+ ExceptHandler_fields, 3);\r
+ if (!ExceptHandler_type) return 0;\r
+ arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);\r
+ if (!arguments_type) return 0;\r
+ keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);\r
+ if (!keyword_type) return 0;\r
+ alias_type = make_type("alias", &AST_type, alias_fields, 2);\r
+ if (!alias_type) return 0;\r
+ initialized = 1;\r
+ return 1;\r
+}\r
+\r
+static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);\r
+static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);\r
+static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);\r
+static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*\r
+ arena);\r
+static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);\r
+static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);\r
+static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);\r
+static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);\r
+static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);\r
+static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*\r
+ arena);\r
+static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*\r
+ arena);\r
+static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);\r
+static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);\r
+static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);\r
+\r
+mod_ty\r
+Module(asdl_seq * body, PyArena *arena)\r
+{\r
+ mod_ty p;\r
+ p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Module_kind;\r
+ p->v.Module.body = body;\r
+ return p;\r
+}\r
+\r
+mod_ty\r
+Interactive(asdl_seq * body, PyArena *arena)\r
+{\r
+ mod_ty p;\r
+ p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Interactive_kind;\r
+ p->v.Interactive.body = body;\r
+ return p;\r
+}\r
+\r
+mod_ty\r
+Expression(expr_ty body, PyArena *arena)\r
+{\r
+ mod_ty p;\r
+ if (!body) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field body is required for Expression");\r
+ return NULL;\r
+ }\r
+ p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Expression_kind;\r
+ p->v.Expression.body = body;\r
+ return p;\r
+}\r
+\r
+mod_ty\r
+Suite(asdl_seq * body, PyArena *arena)\r
+{\r
+ mod_ty p;\r
+ p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Suite_kind;\r
+ p->v.Suite.body = body;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *\r
+ decorator_list, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!name) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field name is required for FunctionDef");\r
+ return NULL;\r
+ }\r
+ if (!args) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field args is required for FunctionDef");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = FunctionDef_kind;\r
+ p->v.FunctionDef.name = name;\r
+ p->v.FunctionDef.args = args;\r
+ p->v.FunctionDef.body = body;\r
+ p->v.FunctionDef.decorator_list = decorator_list;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *\r
+ decorator_list, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!name) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field name is required for ClassDef");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = ClassDef_kind;\r
+ p->v.ClassDef.name = name;\r
+ p->v.ClassDef.bases = bases;\r
+ p->v.ClassDef.body = body;\r
+ p->v.ClassDef.decorator_list = decorator_list;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Return(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Return_kind;\r
+ p->v.Return.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Delete_kind;\r
+ p->v.Delete.targets = targets;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Assign");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Assign_kind;\r
+ p->v.Assign.targets = targets;\r
+ p->v.Assign.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!target) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field target is required for AugAssign");\r
+ return NULL;\r
+ }\r
+ if (!op) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field op is required for AugAssign");\r
+ return NULL;\r
+ }\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for AugAssign");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = AugAssign_kind;\r
+ p->v.AugAssign.target = target;\r
+ p->v.AugAssign.op = op;\r
+ p->v.AugAssign.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Print_kind;\r
+ p->v.Print.dest = dest;\r
+ p->v.Print.values = values;\r
+ p->v.Print.nl = nl;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int\r
+ lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!target) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field target is required for For");\r
+ return NULL;\r
+ }\r
+ if (!iter) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field iter is required for For");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = For_kind;\r
+ p->v.For.target = target;\r
+ p->v.For.iter = iter;\r
+ p->v.For.body = body;\r
+ p->v.For.orelse = orelse;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!test) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field test is required for While");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = While_kind;\r
+ p->v.While.test = test;\r
+ p->v.While.body = body;\r
+ p->v.While.orelse = orelse;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!test) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field test is required for If");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = If_kind;\r
+ p->v.If.test = test;\r
+ p->v.If.body = body;\r
+ p->v.If.orelse = orelse;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,\r
+ int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!context_expr) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field context_expr is required for With");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = With_kind;\r
+ p->v.With.context_expr = context_expr;\r
+ p->v.With.optional_vars = optional_vars;\r
+ p->v.With.body = body;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Raise_kind;\r
+ p->v.Raise.type = type;\r
+ p->v.Raise.inst = inst;\r
+ p->v.Raise.tback = tback;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,\r
+ int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = TryExcept_kind;\r
+ p->v.TryExcept.body = body;\r
+ p->v.TryExcept.handlers = handlers;\r
+ p->v.TryExcept.orelse = orelse;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = TryFinally_kind;\r
+ p->v.TryFinally.body = body;\r
+ p->v.TryFinally.finalbody = finalbody;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!test) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field test is required for Assert");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Assert_kind;\r
+ p->v.Assert.test = test;\r
+ p->v.Assert.msg = msg;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Import_kind;\r
+ p->v.Import.names = names;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = ImportFrom_kind;\r
+ p->v.ImportFrom.module = module;\r
+ p->v.ImportFrom.names = names;\r
+ p->v.ImportFrom.level = level;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!body) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field body is required for Exec");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Exec_kind;\r
+ p->v.Exec.body = body;\r
+ p->v.Exec.globals = globals;\r
+ p->v.Exec.locals = locals;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Global_kind;\r
+ p->v.Global.names = names;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Expr");\r
+ return NULL;\r
+ }\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Expr_kind;\r
+ p->v.Expr.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Pass(int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Pass_kind;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Break(int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Break_kind;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+stmt_ty\r
+Continue(int lineno, int col_offset, PyArena *arena)\r
+{\r
+ stmt_ty p;\r
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Continue_kind;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!op) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field op is required for BoolOp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = BoolOp_kind;\r
+ p->v.BoolOp.op = op;\r
+ p->v.BoolOp.values = values;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!left) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field left is required for BinOp");\r
+ return NULL;\r
+ }\r
+ if (!op) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field op is required for BinOp");\r
+ return NULL;\r
+ }\r
+ if (!right) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field right is required for BinOp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = BinOp_kind;\r
+ p->v.BinOp.left = left;\r
+ p->v.BinOp.op = op;\r
+ p->v.BinOp.right = right;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!op) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field op is required for UnaryOp");\r
+ return NULL;\r
+ }\r
+ if (!operand) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field operand is required for UnaryOp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = UnaryOp_kind;\r
+ p->v.UnaryOp.op = op;\r
+ p->v.UnaryOp.operand = operand;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!args) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field args is required for Lambda");\r
+ return NULL;\r
+ }\r
+ if (!body) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field body is required for Lambda");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Lambda_kind;\r
+ p->v.Lambda.args = args;\r
+ p->v.Lambda.body = body;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!test) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field test is required for IfExp");\r
+ return NULL;\r
+ }\r
+ if (!body) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field body is required for IfExp");\r
+ return NULL;\r
+ }\r
+ if (!orelse) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field orelse is required for IfExp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = IfExp_kind;\r
+ p->v.IfExp.test = test;\r
+ p->v.IfExp.body = body;\r
+ p->v.IfExp.orelse = orelse;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Dict_kind;\r
+ p->v.Dict.keys = keys;\r
+ p->v.Dict.values = values;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Set_kind;\r
+ p->v.Set.elts = elts;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!elt) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field elt is required for ListComp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = ListComp_kind;\r
+ p->v.ListComp.elt = elt;\r
+ p->v.ListComp.generators = generators;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!elt) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field elt is required for SetComp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = SetComp_kind;\r
+ p->v.SetComp.elt = elt;\r
+ p->v.SetComp.generators = generators;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!key) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field key is required for DictComp");\r
+ return NULL;\r
+ }\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for DictComp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = DictComp_kind;\r
+ p->v.DictComp.key = key;\r
+ p->v.DictComp.value = value;\r
+ p->v.DictComp.generators = generators;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r
+ PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!elt) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field elt is required for GeneratorExp");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = GeneratorExp_kind;\r
+ p->v.GeneratorExp.elt = elt;\r
+ p->v.GeneratorExp.generators = generators;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Yield_kind;\r
+ p->v.Yield.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,\r
+ int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!left) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field left is required for Compare");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Compare_kind;\r
+ p->v.Compare.left = left;\r
+ p->v.Compare.ops = ops;\r
+ p->v.Compare.comparators = comparators;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,\r
+ expr_ty kwargs, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!func) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field func is required for Call");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Call_kind;\r
+ p->v.Call.func = func;\r
+ p->v.Call.args = args;\r
+ p->v.Call.keywords = keywords;\r
+ p->v.Call.starargs = starargs;\r
+ p->v.Call.kwargs = kwargs;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Repr");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Repr_kind;\r
+ p->v.Repr.value = value;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Num(object n, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!n) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field n is required for Num");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Num_kind;\r
+ p->v.Num.n = n;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Str(string s, int lineno, int col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!s) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field s is required for Str");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Str_kind;\r
+ p->v.Str.s = s;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Attribute");\r
+ return NULL;\r
+ }\r
+ if (!attr) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field attr is required for Attribute");\r
+ return NULL;\r
+ }\r
+ if (!ctx) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field ctx is required for Attribute");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Attribute_kind;\r
+ p->v.Attribute.value = value;\r
+ p->v.Attribute.attr = attr;\r
+ p->v.Attribute.ctx = ctx;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ expr_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Subscript");\r
+ return NULL;\r
+ }\r
+ if (!slice) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field slice is required for Subscript");\r
+ return NULL;\r
+ }\r
+ if (!ctx) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field ctx is required for Subscript");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Subscript_kind;\r
+ p->v.Subscript.value = value;\r
+ p->v.Subscript.slice = slice;\r
+ p->v.Subscript.ctx = ctx;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!id) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field id is required for Name");\r
+ return NULL;\r
+ }\r
+ if (!ctx) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field ctx is required for Name");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Name_kind;\r
+ p->v.Name.id = id;\r
+ p->v.Name.ctx = ctx;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!ctx) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field ctx is required for List");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = List_kind;\r
+ p->v.List.elts = elts;\r
+ p->v.List.ctx = ctx;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+expr_ty\r
+Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+ *arena)\r
+{\r
+ expr_ty p;\r
+ if (!ctx) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field ctx is required for Tuple");\r
+ return NULL;\r
+ }\r
+ p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Tuple_kind;\r
+ p->v.Tuple.elts = elts;\r
+ p->v.Tuple.ctx = ctx;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+slice_ty\r
+Ellipsis(PyArena *arena)\r
+{\r
+ slice_ty p;\r
+ p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Ellipsis_kind;\r
+ return p;\r
+}\r
+\r
+slice_ty\r
+Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)\r
+{\r
+ slice_ty p;\r
+ p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Slice_kind;\r
+ p->v.Slice.lower = lower;\r
+ p->v.Slice.upper = upper;\r
+ p->v.Slice.step = step;\r
+ return p;\r
+}\r
+\r
+slice_ty\r
+ExtSlice(asdl_seq * dims, PyArena *arena)\r
+{\r
+ slice_ty p;\r
+ p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = ExtSlice_kind;\r
+ p->v.ExtSlice.dims = dims;\r
+ return p;\r
+}\r
+\r
+slice_ty\r
+Index(expr_ty value, PyArena *arena)\r
+{\r
+ slice_ty p;\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for Index");\r
+ return NULL;\r
+ }\r
+ p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = Index_kind;\r
+ p->v.Index.value = value;\r
+ return p;\r
+}\r
+\r
+comprehension_ty\r
+comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)\r
+{\r
+ comprehension_ty p;\r
+ if (!target) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field target is required for comprehension");\r
+ return NULL;\r
+ }\r
+ if (!iter) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field iter is required for comprehension");\r
+ return NULL;\r
+ }\r
+ p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->target = target;\r
+ p->iter = iter;\r
+ p->ifs = ifs;\r
+ return p;\r
+}\r
+\r
+excepthandler_ty\r
+ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int\r
+ col_offset, PyArena *arena)\r
+{\r
+ excepthandler_ty p;\r
+ p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->kind = ExceptHandler_kind;\r
+ p->v.ExceptHandler.type = type;\r
+ p->v.ExceptHandler.name = name;\r
+ p->v.ExceptHandler.body = body;\r
+ p->lineno = lineno;\r
+ p->col_offset = col_offset;\r
+ return p;\r
+}\r
+\r
+arguments_ty\r
+arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *\r
+ defaults, PyArena *arena)\r
+{\r
+ arguments_ty p;\r
+ p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->args = args;\r
+ p->vararg = vararg;\r
+ p->kwarg = kwarg;\r
+ p->defaults = defaults;\r
+ return p;\r
+}\r
+\r
+keyword_ty\r
+keyword(identifier arg, expr_ty value, PyArena *arena)\r
+{\r
+ keyword_ty p;\r
+ if (!arg) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field arg is required for keyword");\r
+ return NULL;\r
+ }\r
+ if (!value) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field value is required for keyword");\r
+ return NULL;\r
+ }\r
+ p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->arg = arg;\r
+ p->value = value;\r
+ return p;\r
+}\r
+\r
+alias_ty\r
+alias(identifier name, identifier asname, PyArena *arena)\r
+{\r
+ alias_ty p;\r
+ if (!name) {\r
+ PyErr_SetString(PyExc_ValueError,\r
+ "field name is required for alias");\r
+ return NULL;\r
+ }\r
+ p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));\r
+ if (!p)\r
+ return NULL;\r
+ p->name = name;\r
+ p->asname = asname;\r
+ return p;\r
+}\r
+\r
+\r
+PyObject*\r
+ast2obj_mod(void* _o)\r
+{\r
+ mod_ty o = (mod_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ switch (o->kind) {\r
+ case Module_kind:\r
+ result = PyType_GenericNew(Module_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Module.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Interactive_kind:\r
+ result = PyType_GenericNew(Interactive_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Expression_kind:\r
+ result = PyType_GenericNew(Expression_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Expression.body);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Suite_kind:\r
+ result = PyType_GenericNew(Suite_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ }\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_stmt(void* _o)\r
+{\r
+ stmt_ty o = (stmt_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ switch (o->kind) {\r
+ case FunctionDef_kind:\r
+ result = PyType_GenericNew(FunctionDef_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_identifier(o->v.FunctionDef.name);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "name", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_arguments(o->v.FunctionDef.args);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "args", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.FunctionDef.decorator_list,\r
+ ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "decorator_list", value) ==\r
+ -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case ClassDef_kind:\r
+ result = PyType_GenericNew(ClassDef_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_identifier(o->v.ClassDef.name);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "name", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "bases", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ClassDef.decorator_list,\r
+ ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "decorator_list", value) ==\r
+ -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Return_kind:\r
+ result = PyType_GenericNew(Return_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Return.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Delete_kind:\r
+ result = PyType_GenericNew(Delete_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "targets", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Assign_kind:\r
+ result = PyType_GenericNew(Assign_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "targets", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Assign.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case AugAssign_kind:\r
+ result = PyType_GenericNew(AugAssign_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.AugAssign.target);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "target", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_operator(o->v.AugAssign.op);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "op", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.AugAssign.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Print_kind:\r
+ result = PyType_GenericNew(Print_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Print.dest);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "dest", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.Print.values, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "values", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_bool(o->v.Print.nl);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "nl", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case For_kind:\r
+ result = PyType_GenericNew(For_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.For.target);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "target", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.For.iter);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "iter", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.For.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case While_kind:\r
+ result = PyType_GenericNew(While_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.While.test);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "test", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.While.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case If_kind:\r
+ result = PyType_GenericNew(If_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.If.test);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "test", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.If.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case With_kind:\r
+ result = PyType_GenericNew(With_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.With.context_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "context_expr", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.With.optional_vars);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "optional_vars", value) ==\r
+ -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.With.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Raise_kind:\r
+ result = PyType_GenericNew(Raise_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Raise.type);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "type", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Raise.inst);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "inst", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Raise.tback);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "tback", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case TryExcept_kind:\r
+ result = PyType_GenericNew(TryExcept_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.TryExcept.handlers,\r
+ ast2obj_excepthandler);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "handlers", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case TryFinally_kind:\r
+ result = PyType_GenericNew(TryFinally_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "finalbody", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Assert_kind:\r
+ result = PyType_GenericNew(Assert_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Assert.test);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "test", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Assert.msg);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "msg", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Import_kind:\r
+ result = PyType_GenericNew(Import_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Import.names, ast2obj_alias);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "names", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case ImportFrom_kind:\r
+ result = PyType_GenericNew(ImportFrom_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_identifier(o->v.ImportFrom.module);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "module", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "names", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_int(o->v.ImportFrom.level);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "level", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Exec_kind:\r
+ result = PyType_GenericNew(Exec_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Exec.body);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Exec.globals);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "globals", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Exec.locals);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "locals", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Global_kind:\r
+ result = PyType_GenericNew(Global_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Global.names, ast2obj_identifier);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "names", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Expr_kind:\r
+ result = PyType_GenericNew(Expr_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Expr.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Pass_kind:\r
+ result = PyType_GenericNew(Pass_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ break;\r
+ case Break_kind:\r
+ result = PyType_GenericNew(Break_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ break;\r
+ case Continue_kind:\r
+ result = PyType_GenericNew(Continue_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ break;\r
+ }\r
+ value = ast2obj_int(o->lineno);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_int(o->col_offset);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_expr(void* _o)\r
+{\r
+ expr_ty o = (expr_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ switch (o->kind) {\r
+ case BoolOp_kind:\r
+ result = PyType_GenericNew(BoolOp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_boolop(o->v.BoolOp.op);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "op", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "values", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case BinOp_kind:\r
+ result = PyType_GenericNew(BinOp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.BinOp.left);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "left", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_operator(o->v.BinOp.op);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "op", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.BinOp.right);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "right", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case UnaryOp_kind:\r
+ result = PyType_GenericNew(UnaryOp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_unaryop(o->v.UnaryOp.op);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "op", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.UnaryOp.operand);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "operand", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Lambda_kind:\r
+ result = PyType_GenericNew(Lambda_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_arguments(o->v.Lambda.args);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "args", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Lambda.body);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case IfExp_kind:\r
+ result = PyType_GenericNew(IfExp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.IfExp.test);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "test", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.IfExp.body);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.IfExp.orelse);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Dict_kind:\r
+ result = PyType_GenericNew(Dict_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "keys", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.Dict.values, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "values", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Set_kind:\r
+ result = PyType_GenericNew(Set_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Set.elts, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case ListComp_kind:\r
+ result = PyType_GenericNew(ListComp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.ListComp.elt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ListComp.generators,\r
+ ast2obj_comprehension);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case SetComp_kind:\r
+ result = PyType_GenericNew(SetComp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.SetComp.elt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.SetComp.generators,\r
+ ast2obj_comprehension);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case DictComp_kind:\r
+ result = PyType_GenericNew(DictComp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.DictComp.key);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "key", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.DictComp.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.DictComp.generators,\r
+ ast2obj_comprehension);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case GeneratorExp_kind:\r
+ result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.GeneratorExp.elt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.GeneratorExp.generators,\r
+ ast2obj_comprehension);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Yield_kind:\r
+ result = PyType_GenericNew(Yield_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Yield.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Compare_kind:\r
+ result = PyType_GenericNew(Compare_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Compare.left);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "left", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ {\r
+ int i, n = asdl_seq_LEN(o->v.Compare.ops);\r
+ value = PyList_New(n);\r
+ if (!value) goto failed;\r
+ for(i = 0; i < n; i++)\r
+ PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));\r
+ }\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ops", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "comparators", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Call_kind:\r
+ result = PyType_GenericNew(Call_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Call.func);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "func", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.Call.args, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "args", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "keywords", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Call.starargs);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "starargs", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Call.kwargs);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "kwargs", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Repr_kind:\r
+ result = PyType_GenericNew(Repr_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Repr.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Num_kind:\r
+ result = PyType_GenericNew(Num_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_object(o->v.Num.n);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "n", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Str_kind:\r
+ result = PyType_GenericNew(Str_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_string(o->v.Str.s);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "s", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Attribute_kind:\r
+ result = PyType_GenericNew(Attribute_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Attribute.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_identifier(o->v.Attribute.attr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "attr", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr_context(o->v.Attribute.ctx);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Subscript_kind:\r
+ result = PyType_GenericNew(Subscript_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Subscript.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_slice(o->v.Subscript.slice);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "slice", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr_context(o->v.Subscript.ctx);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Name_kind:\r
+ result = PyType_GenericNew(Name_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_identifier(o->v.Name.id);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "id", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr_context(o->v.Name.ctx);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case List_kind:\r
+ result = PyType_GenericNew(List_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.List.elts, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr_context(o->v.List.ctx);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Tuple_kind:\r
+ result = PyType_GenericNew(Tuple_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr_context(o->v.Tuple.ctx);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ }\r
+ value = ast2obj_int(o->lineno);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_int(o->col_offset);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject* ast2obj_expr_context(expr_context_ty o)\r
+{\r
+ switch(o) {\r
+ case Load:\r
+ Py_INCREF(Load_singleton);\r
+ return Load_singleton;\r
+ case Store:\r
+ Py_INCREF(Store_singleton);\r
+ return Store_singleton;\r
+ case Del:\r
+ Py_INCREF(Del_singleton);\r
+ return Del_singleton;\r
+ case AugLoad:\r
+ Py_INCREF(AugLoad_singleton);\r
+ return AugLoad_singleton;\r
+ case AugStore:\r
+ Py_INCREF(AugStore_singleton);\r
+ return AugStore_singleton;\r
+ case Param:\r
+ Py_INCREF(Param_singleton);\r
+ return Param_singleton;\r
+ default:\r
+ /* should never happen, but just in case ... */\r
+ PyErr_Format(PyExc_SystemError, "unknown expr_context found");\r
+ return NULL;\r
+ }\r
+}\r
+PyObject*\r
+ast2obj_slice(void* _o)\r
+{\r
+ slice_ty o = (slice_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ switch (o->kind) {\r
+ case Ellipsis_kind:\r
+ result = PyType_GenericNew(Ellipsis_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ break;\r
+ case Slice_kind:\r
+ result = PyType_GenericNew(Slice_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Slice.lower);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "lower", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Slice.upper);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "upper", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.Slice.step);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "step", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case ExtSlice_kind:\r
+ result = PyType_GenericNew(ExtSlice_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "dims", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ case Index_kind:\r
+ result = PyType_GenericNew(Index_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.Index.value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ }\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject* ast2obj_boolop(boolop_ty o)\r
+{\r
+ switch(o) {\r
+ case And:\r
+ Py_INCREF(And_singleton);\r
+ return And_singleton;\r
+ case Or:\r
+ Py_INCREF(Or_singleton);\r
+ return Or_singleton;\r
+ default:\r
+ /* should never happen, but just in case ... */\r
+ PyErr_Format(PyExc_SystemError, "unknown boolop found");\r
+ return NULL;\r
+ }\r
+}\r
+PyObject* ast2obj_operator(operator_ty o)\r
+{\r
+ switch(o) {\r
+ case Add:\r
+ Py_INCREF(Add_singleton);\r
+ return Add_singleton;\r
+ case Sub:\r
+ Py_INCREF(Sub_singleton);\r
+ return Sub_singleton;\r
+ case Mult:\r
+ Py_INCREF(Mult_singleton);\r
+ return Mult_singleton;\r
+ case Div:\r
+ Py_INCREF(Div_singleton);\r
+ return Div_singleton;\r
+ case Mod:\r
+ Py_INCREF(Mod_singleton);\r
+ return Mod_singleton;\r
+ case Pow:\r
+ Py_INCREF(Pow_singleton);\r
+ return Pow_singleton;\r
+ case LShift:\r
+ Py_INCREF(LShift_singleton);\r
+ return LShift_singleton;\r
+ case RShift:\r
+ Py_INCREF(RShift_singleton);\r
+ return RShift_singleton;\r
+ case BitOr:\r
+ Py_INCREF(BitOr_singleton);\r
+ return BitOr_singleton;\r
+ case BitXor:\r
+ Py_INCREF(BitXor_singleton);\r
+ return BitXor_singleton;\r
+ case BitAnd:\r
+ Py_INCREF(BitAnd_singleton);\r
+ return BitAnd_singleton;\r
+ case FloorDiv:\r
+ Py_INCREF(FloorDiv_singleton);\r
+ return FloorDiv_singleton;\r
+ default:\r
+ /* should never happen, but just in case ... */\r
+ PyErr_Format(PyExc_SystemError, "unknown operator found");\r
+ return NULL;\r
+ }\r
+}\r
+PyObject* ast2obj_unaryop(unaryop_ty o)\r
+{\r
+ switch(o) {\r
+ case Invert:\r
+ Py_INCREF(Invert_singleton);\r
+ return Invert_singleton;\r
+ case Not:\r
+ Py_INCREF(Not_singleton);\r
+ return Not_singleton;\r
+ case UAdd:\r
+ Py_INCREF(UAdd_singleton);\r
+ return UAdd_singleton;\r
+ case USub:\r
+ Py_INCREF(USub_singleton);\r
+ return USub_singleton;\r
+ default:\r
+ /* should never happen, but just in case ... */\r
+ PyErr_Format(PyExc_SystemError, "unknown unaryop found");\r
+ return NULL;\r
+ }\r
+}\r
+PyObject* ast2obj_cmpop(cmpop_ty o)\r
+{\r
+ switch(o) {\r
+ case Eq:\r
+ Py_INCREF(Eq_singleton);\r
+ return Eq_singleton;\r
+ case NotEq:\r
+ Py_INCREF(NotEq_singleton);\r
+ return NotEq_singleton;\r
+ case Lt:\r
+ Py_INCREF(Lt_singleton);\r
+ return Lt_singleton;\r
+ case LtE:\r
+ Py_INCREF(LtE_singleton);\r
+ return LtE_singleton;\r
+ case Gt:\r
+ Py_INCREF(Gt_singleton);\r
+ return Gt_singleton;\r
+ case GtE:\r
+ Py_INCREF(GtE_singleton);\r
+ return GtE_singleton;\r
+ case Is:\r
+ Py_INCREF(Is_singleton);\r
+ return Is_singleton;\r
+ case IsNot:\r
+ Py_INCREF(IsNot_singleton);\r
+ return IsNot_singleton;\r
+ case In:\r
+ Py_INCREF(In_singleton);\r
+ return In_singleton;\r
+ case NotIn:\r
+ Py_INCREF(NotIn_singleton);\r
+ return NotIn_singleton;\r
+ default:\r
+ /* should never happen, but just in case ... */\r
+ PyErr_Format(PyExc_SystemError, "unknown cmpop found");\r
+ return NULL;\r
+ }\r
+}\r
+PyObject*\r
+ast2obj_comprehension(void* _o)\r
+{\r
+ comprehension_ty o = (comprehension_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ result = PyType_GenericNew(comprehension_type, NULL, NULL);\r
+ if (!result) return NULL;\r
+ value = ast2obj_expr(o->target);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "target", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->iter);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "iter", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->ifs, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "ifs", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_excepthandler(void* _o)\r
+{\r
+ excepthandler_ty o = (excepthandler_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ switch (o->kind) {\r
+ case ExceptHandler_kind:\r
+ result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);\r
+ if (!result) goto failed;\r
+ value = ast2obj_expr(o->v.ExceptHandler.type);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "type", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->v.ExceptHandler.name);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "name", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "body", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ break;\r
+ }\r
+ value = ast2obj_int(o->lineno);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_int(o->col_offset);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_arguments(void* _o)\r
+{\r
+ arguments_ty o = (arguments_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ result = PyType_GenericNew(arguments_type, NULL, NULL);\r
+ if (!result) return NULL;\r
+ value = ast2obj_list(o->args, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "args", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_identifier(o->vararg);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "vararg", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_identifier(o->kwarg);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "kwarg", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_list(o->defaults, ast2obj_expr);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "defaults", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_keyword(void* _o)\r
+{\r
+ keyword_ty o = (keyword_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ result = PyType_GenericNew(keyword_type, NULL, NULL);\r
+ if (!result) return NULL;\r
+ value = ast2obj_identifier(o->arg);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "arg", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_expr(o->value);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "value", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_alias(void* _o)\r
+{\r
+ alias_ty o = (alias_ty)_o;\r
+ PyObject *result = NULL, *value = NULL;\r
+ if (!o) {\r
+ Py_INCREF(Py_None);\r
+ return Py_None;\r
+ }\r
+\r
+ result = PyType_GenericNew(alias_type, NULL, NULL);\r
+ if (!result) return NULL;\r
+ value = ast2obj_identifier(o->name);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "name", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ value = ast2obj_identifier(o->asname);\r
+ if (!value) goto failed;\r
+ if (PyObject_SetAttrString(result, "asname", value) == -1)\r
+ goto failed;\r
+ Py_DECREF(value);\r
+ return result;\r
+failed:\r
+ Py_XDECREF(value);\r
+ Py_XDECREF(result);\r
+ return NULL;\r
+}\r
+\r
+\r
+int\r
+obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+\r
+ if (obj == Py_None) {\r
+ *out = NULL;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* body;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");\r
+ return 1;\r
+ }\r
+ *out = Module(body, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* body;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");\r
+ return 1;\r
+ }\r
+ *out = Interactive(body, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty body;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &body, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");\r
+ return 1;\r
+ }\r
+ *out = Expression(body, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* body;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");\r
+ return 1;\r
+ }\r
+ *out = Suite(body, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ int lineno;\r
+ int col_offset;\r
+\r
+ if (obj == Py_None) {\r
+ *out = NULL;\r
+ return 0;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "lineno")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "lineno");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &lineno, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "col_offset")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "col_offset");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &col_offset, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");\r
+ return 1;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ identifier name;\r
+ arguments_ty args;\r
+ asdl_seq* body;\r
+ asdl_seq* decorator_list;\r
+\r
+ if (PyObject_HasAttrString(obj, "name")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "name");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &name, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "args")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "args");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_arguments(tmp, &args, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "decorator_list")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "decorator_list");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ decorator_list = asdl_seq_new(len, arena);\r
+ if (decorator_list == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(decorator_list, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");\r
+ return 1;\r
+ }\r
+ *out = FunctionDef(name, args, body, decorator_list, lineno,\r
+ col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ identifier name;\r
+ asdl_seq* bases;\r
+ asdl_seq* body;\r
+ asdl_seq* decorator_list;\r
+\r
+ if (PyObject_HasAttrString(obj, "name")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "name");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &name, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "bases")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "bases");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ bases = asdl_seq_new(len, arena);\r
+ if (bases == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(bases, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "decorator_list")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "decorator_list");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ decorator_list = asdl_seq_new(len, arena);\r
+ if (decorator_list == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(decorator_list, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");\r
+ return 1;\r
+ }\r
+ *out = ClassDef(name, bases, body, decorator_list, lineno,\r
+ col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ value = NULL;\r
+ }\r
+ *out = Return(value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* targets;\r
+\r
+ if (PyObject_HasAttrString(obj, "targets")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "targets");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ targets = asdl_seq_new(len, arena);\r
+ if (targets == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(targets, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");\r
+ return 1;\r
+ }\r
+ *out = Delete(targets, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* targets;\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "targets")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "targets");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ targets = asdl_seq_new(len, arena);\r
+ if (targets == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(targets, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");\r
+ return 1;\r
+ }\r
+ *out = Assign(targets, value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty target;\r
+ operator_ty op;\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "target")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "target");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &target, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "op")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "op");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_operator(tmp, &op, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");\r
+ return 1;\r
+ }\r
+ *out = AugAssign(target, op, value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty dest;\r
+ asdl_seq* values;\r
+ bool nl;\r
+\r
+ if (PyObject_HasAttrString(obj, "dest")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "dest");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &dest, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ dest = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "values")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "values");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ values = asdl_seq_new(len, arena);\r
+ if (values == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(values, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "nl")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "nl");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_bool(tmp, &nl, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");\r
+ return 1;\r
+ }\r
+ *out = Print(dest, values, nl, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty target;\r
+ expr_ty iter;\r
+ asdl_seq* body;\r
+ asdl_seq* orelse;\r
+\r
+ if (PyObject_HasAttrString(obj, "target")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "target");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &target, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "iter")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "iter");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &iter, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "orelse")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "orelse");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ orelse = asdl_seq_new(len, arena);\r
+ if (orelse == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(orelse, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");\r
+ return 1;\r
+ }\r
+ *out = For(target, iter, body, orelse, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty test;\r
+ asdl_seq* body;\r
+ asdl_seq* orelse;\r
+\r
+ if (PyObject_HasAttrString(obj, "test")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "test");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &test, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "orelse")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "orelse");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ orelse = asdl_seq_new(len, arena);\r
+ if (orelse == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(orelse, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");\r
+ return 1;\r
+ }\r
+ *out = While(test, body, orelse, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty test;\r
+ asdl_seq* body;\r
+ asdl_seq* orelse;\r
+\r
+ if (PyObject_HasAttrString(obj, "test")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "test");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &test, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "orelse")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "orelse");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ orelse = asdl_seq_new(len, arena);\r
+ if (orelse == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(orelse, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");\r
+ return 1;\r
+ }\r
+ *out = If(test, body, orelse, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty context_expr;\r
+ expr_ty optional_vars;\r
+ asdl_seq* body;\r
+\r
+ if (PyObject_HasAttrString(obj, "context_expr")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "context_expr");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &context_expr, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "optional_vars")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "optional_vars");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &optional_vars, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ optional_vars = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");\r
+ return 1;\r
+ }\r
+ *out = With(context_expr, optional_vars, body, lineno,\r
+ col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty type;\r
+ expr_ty inst;\r
+ expr_ty tback;\r
+\r
+ if (PyObject_HasAttrString(obj, "type")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "type");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &type, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ type = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "inst")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "inst");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &inst, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ inst = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "tback")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "tback");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &tback, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ tback = NULL;\r
+ }\r
+ *out = Raise(type, inst, tback, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* body;\r
+ asdl_seq* handlers;\r
+ asdl_seq* orelse;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "handlers")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "handlers");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ handlers = asdl_seq_new(len, arena);\r
+ if (handlers == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ excepthandler_ty value;\r
+ res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(handlers, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "orelse")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "orelse");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ orelse = asdl_seq_new(len, arena);\r
+ if (orelse == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(orelse, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");\r
+ return 1;\r
+ }\r
+ *out = TryExcept(body, handlers, orelse, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* body;\r
+ asdl_seq* finalbody;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "finalbody")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "finalbody");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ finalbody = asdl_seq_new(len, arena);\r
+ if (finalbody == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(finalbody, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");\r
+ return 1;\r
+ }\r
+ *out = TryFinally(body, finalbody, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty test;\r
+ expr_ty msg;\r
+\r
+ if (PyObject_HasAttrString(obj, "test")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "test");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &test, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "msg")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "msg");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &msg, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ msg = NULL;\r
+ }\r
+ *out = Assert(test, msg, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* names;\r
+\r
+ if (PyObject_HasAttrString(obj, "names")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "names");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ names = asdl_seq_new(len, arena);\r
+ if (names == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ alias_ty value;\r
+ res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(names, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");\r
+ return 1;\r
+ }\r
+ *out = Import(names, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ identifier module;\r
+ asdl_seq* names;\r
+ int level;\r
+\r
+ if (PyObject_HasAttrString(obj, "module")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "module");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &module, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ module = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "names")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "names");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ names = asdl_seq_new(len, arena);\r
+ if (names == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ alias_ty value;\r
+ res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(names, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "level")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "level");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &level, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ level = 0;\r
+ }\r
+ *out = ImportFrom(module, names, level, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty body;\r
+ expr_ty globals;\r
+ expr_ty locals;\r
+\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &body, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "globals")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "globals");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &globals, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ globals = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "locals")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "locals");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &locals, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ locals = NULL;\r
+ }\r
+ *out = Exec(body, globals, locals, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* names;\r
+\r
+ if (PyObject_HasAttrString(obj, "names")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "names");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ names = asdl_seq_new(len, arena);\r
+ if (names == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ identifier value;\r
+ res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(names, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");\r
+ return 1;\r
+ }\r
+ *out = Global(names, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");\r
+ return 1;\r
+ }\r
+ *out = Expr(value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+\r
+ *out = Pass(lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+\r
+ *out = Break(lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+\r
+ *out = Continue(lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ int lineno;\r
+ int col_offset;\r
+\r
+ if (obj == Py_None) {\r
+ *out = NULL;\r
+ return 0;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "lineno")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "lineno");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &lineno, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "col_offset")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "col_offset");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &col_offset, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");\r
+ return 1;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ boolop_ty op;\r
+ asdl_seq* values;\r
+\r
+ if (PyObject_HasAttrString(obj, "op")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "op");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_boolop(tmp, &op, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "values")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "values");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ values = asdl_seq_new(len, arena);\r
+ if (values == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(values, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");\r
+ return 1;\r
+ }\r
+ *out = BoolOp(op, values, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty left;\r
+ operator_ty op;\r
+ expr_ty right;\r
+\r
+ if (PyObject_HasAttrString(obj, "left")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "left");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &left, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "op")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "op");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_operator(tmp, &op, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "right")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "right");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &right, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");\r
+ return 1;\r
+ }\r
+ *out = BinOp(left, op, right, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ unaryop_ty op;\r
+ expr_ty operand;\r
+\r
+ if (PyObject_HasAttrString(obj, "op")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "op");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_unaryop(tmp, &op, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "operand")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "operand");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &operand, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");\r
+ return 1;\r
+ }\r
+ *out = UnaryOp(op, operand, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ arguments_ty args;\r
+ expr_ty body;\r
+\r
+ if (PyObject_HasAttrString(obj, "args")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "args");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_arguments(tmp, &args, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &body, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");\r
+ return 1;\r
+ }\r
+ *out = Lambda(args, body, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty test;\r
+ expr_ty body;\r
+ expr_ty orelse;\r
+\r
+ if (PyObject_HasAttrString(obj, "test")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "test");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &test, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &body, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "orelse")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "orelse");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &orelse, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");\r
+ return 1;\r
+ }\r
+ *out = IfExp(test, body, orelse, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* keys;\r
+ asdl_seq* values;\r
+\r
+ if (PyObject_HasAttrString(obj, "keys")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "keys");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ keys = asdl_seq_new(len, arena);\r
+ if (keys == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(keys, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "values")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "values");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ values = asdl_seq_new(len, arena);\r
+ if (values == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(values, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");\r
+ return 1;\r
+ }\r
+ *out = Dict(keys, values, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* elts;\r
+\r
+ if (PyObject_HasAttrString(obj, "elts")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "elts");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ elts = asdl_seq_new(len, arena);\r
+ if (elts == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(elts, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");\r
+ return 1;\r
+ }\r
+ *out = Set(elts, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty elt;\r
+ asdl_seq* generators;\r
+\r
+ if (PyObject_HasAttrString(obj, "elt")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "elt");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &elt, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "generators")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "generators");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ generators = asdl_seq_new(len, arena);\r
+ if (generators == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ comprehension_ty value;\r
+ res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(generators, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");\r
+ return 1;\r
+ }\r
+ *out = ListComp(elt, generators, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty elt;\r
+ asdl_seq* generators;\r
+\r
+ if (PyObject_HasAttrString(obj, "elt")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "elt");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &elt, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "generators")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "generators");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ generators = asdl_seq_new(len, arena);\r
+ if (generators == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ comprehension_ty value;\r
+ res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(generators, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");\r
+ return 1;\r
+ }\r
+ *out = SetComp(elt, generators, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty key;\r
+ expr_ty value;\r
+ asdl_seq* generators;\r
+\r
+ if (PyObject_HasAttrString(obj, "key")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "key");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &key, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "generators")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "generators");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ generators = asdl_seq_new(len, arena);\r
+ if (generators == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ comprehension_ty value;\r
+ res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(generators, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");\r
+ return 1;\r
+ }\r
+ *out = DictComp(key, value, generators, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty elt;\r
+ asdl_seq* generators;\r
+\r
+ if (PyObject_HasAttrString(obj, "elt")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "elt");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &elt, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "generators")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "generators");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ generators = asdl_seq_new(len, arena);\r
+ if (generators == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ comprehension_ty value;\r
+ res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(generators, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");\r
+ return 1;\r
+ }\r
+ *out = GeneratorExp(elt, generators, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ value = NULL;\r
+ }\r
+ *out = Yield(value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty left;\r
+ asdl_int_seq* ops;\r
+ asdl_seq* comparators;\r
+\r
+ if (PyObject_HasAttrString(obj, "left")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "left");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &left, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ops")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "ops");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ ops = asdl_int_seq_new(len, arena);\r
+ if (ops == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ cmpop_ty value;\r
+ res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(ops, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "comparators")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "comparators");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ comparators = asdl_seq_new(len, arena);\r
+ if (comparators == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(comparators, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");\r
+ return 1;\r
+ }\r
+ *out = Compare(left, ops, comparators, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty func;\r
+ asdl_seq* args;\r
+ asdl_seq* keywords;\r
+ expr_ty starargs;\r
+ expr_ty kwargs;\r
+\r
+ if (PyObject_HasAttrString(obj, "func")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "func");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &func, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "args")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "args");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ args = asdl_seq_new(len, arena);\r
+ if (args == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(args, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "keywords")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "keywords");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ keywords = asdl_seq_new(len, arena);\r
+ if (keywords == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ keyword_ty value;\r
+ res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(keywords, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "starargs")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "starargs");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &starargs, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ starargs = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "kwargs")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "kwargs");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &kwargs, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ kwargs = NULL;\r
+ }\r
+ *out = Call(func, args, keywords, starargs, kwargs, lineno,\r
+ col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");\r
+ return 1;\r
+ }\r
+ *out = Repr(value, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ object n;\r
+\r
+ if (PyObject_HasAttrString(obj, "n")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "n");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_object(tmp, &n, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");\r
+ return 1;\r
+ }\r
+ *out = Num(n, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ string s;\r
+\r
+ if (PyObject_HasAttrString(obj, "s")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "s");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_string(tmp, &s, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");\r
+ return 1;\r
+ }\r
+ *out = Str(s, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+ identifier attr;\r
+ expr_context_ty ctx;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "attr")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "attr");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &attr, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ctx")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "ctx");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr_context(tmp, &ctx, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");\r
+ return 1;\r
+ }\r
+ *out = Attribute(value, attr, ctx, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+ slice_ty slice;\r
+ expr_context_ty ctx;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "slice")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "slice");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_slice(tmp, &slice, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ctx")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "ctx");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr_context(tmp, &ctx, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");\r
+ return 1;\r
+ }\r
+ *out = Subscript(value, slice, ctx, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ identifier id;\r
+ expr_context_ty ctx;\r
+\r
+ if (PyObject_HasAttrString(obj, "id")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "id");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &id, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ctx")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "ctx");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr_context(tmp, &ctx, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");\r
+ return 1;\r
+ }\r
+ *out = Name(id, ctx, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* elts;\r
+ expr_context_ty ctx;\r
+\r
+ if (PyObject_HasAttrString(obj, "elts")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "elts");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ elts = asdl_seq_new(len, arena);\r
+ if (elts == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(elts, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ctx")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "ctx");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr_context(tmp, &ctx, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");\r
+ return 1;\r
+ }\r
+ *out = List(elts, ctx, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* elts;\r
+ expr_context_ty ctx;\r
+\r
+ if (PyObject_HasAttrString(obj, "elts")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "elts");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ elts = asdl_seq_new(len, arena);\r
+ if (elts == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(elts, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ctx")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "ctx");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr_context(tmp, &ctx, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");\r
+ return 1;\r
+ }\r
+ *out = Tuple(elts, ctx, lineno, col_offset, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Load;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Store;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Del;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = AugLoad;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = AugStore;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Param;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+\r
+ if (obj == Py_None) {\r
+ *out = NULL;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+\r
+ *out = Ellipsis(arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty lower;\r
+ expr_ty upper;\r
+ expr_ty step;\r
+\r
+ if (PyObject_HasAttrString(obj, "lower")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "lower");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &lower, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ lower = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "upper")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "upper");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &upper, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ upper = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "step")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "step");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &step, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ step = NULL;\r
+ }\r
+ *out = Slice(lower, upper, step, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ asdl_seq* dims;\r
+\r
+ if (PyObject_HasAttrString(obj, "dims")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "dims");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ dims = asdl_seq_new(len, arena);\r
+ if (dims == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ slice_ty value;\r
+ res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(dims, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");\r
+ return 1;\r
+ }\r
+ *out = ExtSlice(dims, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");\r
+ return 1;\r
+ }\r
+ *out = Index(value, arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = And;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Or;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Add;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Sub;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Mult;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Div;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Mod;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Pow;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = LShift;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = RShift;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = BitOr;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = BitXor;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = BitAnd;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = FloorDiv;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Invert;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Not;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = UAdd;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = USub;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Eq;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = NotEq;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Lt;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = LtE;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Gt;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = GtE;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = Is;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = IsNot;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = In;\r
+ return 0;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ *out = NotIn;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ expr_ty target;\r
+ expr_ty iter;\r
+ asdl_seq* ifs;\r
+\r
+ if (PyObject_HasAttrString(obj, "target")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "target");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &target, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "iter")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "iter");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &iter, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "ifs")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "ifs");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ ifs = asdl_seq_new(len, arena);\r
+ if (ifs == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(ifs, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");\r
+ return 1;\r
+ }\r
+ *out = comprehension(target, iter, ifs, arena);\r
+ return 0;\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ int isinstance;\r
+\r
+ int lineno;\r
+ int col_offset;\r
+\r
+ if (obj == Py_None) {\r
+ *out = NULL;\r
+ return 0;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "lineno")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "lineno");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &lineno, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "col_offset")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "col_offset");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_int(tmp, &col_offset, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");\r
+ return 1;\r
+ }\r
+ isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);\r
+ if (isinstance == -1) {\r
+ return 1;\r
+ }\r
+ if (isinstance) {\r
+ expr_ty type;\r
+ expr_ty name;\r
+ asdl_seq* body;\r
+\r
+ if (PyObject_HasAttrString(obj, "type")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "type");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &type, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ type = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "name")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "name");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &name, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ name = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "body")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "body");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ body = asdl_seq_new(len, arena);\r
+ if (body == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ stmt_ty value;\r
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(body, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");\r
+ return 1;\r
+ }\r
+ *out = ExceptHandler(type, name, body, lineno, col_offset,\r
+ arena);\r
+ if (*out == NULL) goto failed;\r
+ return 0;\r
+ }\r
+\r
+ tmp = PyObject_Repr(obj);\r
+ if (tmp == NULL) goto failed;\r
+ PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ asdl_seq* args;\r
+ identifier vararg;\r
+ identifier kwarg;\r
+ asdl_seq* defaults;\r
+\r
+ if (PyObject_HasAttrString(obj, "args")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "args");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ args = asdl_seq_new(len, arena);\r
+ if (args == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(args, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "vararg")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "vararg");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &vararg, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ vararg = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "kwarg")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "kwarg");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &kwarg, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ kwarg = NULL;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "defaults")) {\r
+ int res;\r
+ Py_ssize_t len;\r
+ Py_ssize_t i;\r
+ tmp = PyObject_GetAttrString(obj, "defaults");\r
+ if (tmp == NULL) goto failed;\r
+ if (!PyList_Check(tmp)) {\r
+ PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+ goto failed;\r
+ }\r
+ len = PyList_GET_SIZE(tmp);\r
+ defaults = asdl_seq_new(len, arena);\r
+ if (defaults == NULL) goto failed;\r
+ for (i = 0; i < len; i++) {\r
+ expr_ty value;\r
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+ if (res != 0) goto failed;\r
+ asdl_seq_SET(defaults, i, value);\r
+ }\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");\r
+ return 1;\r
+ }\r
+ *out = arguments(args, vararg, kwarg, defaults, arena);\r
+ return 0;\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ identifier arg;\r
+ expr_ty value;\r
+\r
+ if (PyObject_HasAttrString(obj, "arg")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "arg");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &arg, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "value")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "value");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_expr(tmp, &value, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");\r
+ return 1;\r
+ }\r
+ *out = keyword(arg, value, arena);\r
+ return 0;\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+int\r
+obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)\r
+{\r
+ PyObject* tmp = NULL;\r
+ identifier name;\r
+ identifier asname;\r
+\r
+ if (PyObject_HasAttrString(obj, "name")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "name");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &name, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");\r
+ return 1;\r
+ }\r
+ if (PyObject_HasAttrString(obj, "asname")) {\r
+ int res;\r
+ tmp = PyObject_GetAttrString(obj, "asname");\r
+ if (tmp == NULL) goto failed;\r
+ res = obj2ast_identifier(tmp, &asname, arena);\r
+ if (res != 0) goto failed;\r
+ Py_XDECREF(tmp);\r
+ tmp = NULL;\r
+ } else {\r
+ asname = NULL;\r
+ }\r
+ *out = alias(name, asname, arena);\r
+ return 0;\r
+failed:\r
+ Py_XDECREF(tmp);\r
+ return 1;\r
+}\r
+\r
+\r
+PyMODINIT_FUNC\r
+init_ast(void)\r
+{\r
+ PyObject *m, *d;\r
+ if (!init_types()) return;\r
+ m = Py_InitModule3("_ast", NULL, NULL);\r
+ if (!m) return;\r
+ d = PyModule_GetDict(m);\r
+ if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;\r
+ if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)\r
+ return;\r
+ if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)\r
+ < 0) return;\r
+ if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)\r
+ < 0) return;\r
+ if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "GeneratorExp",\r
+ (PyObject*)GeneratorExp_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "expr_context",\r
+ (PyObject*)expr_context_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "comprehension",\r
+ (PyObject*)comprehension_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "excepthandler",\r
+ (PyObject*)excepthandler_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "ExceptHandler",\r
+ (PyObject*)ExceptHandler_type) < 0) return;\r
+ if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <\r
+ 0) return;\r
+ if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)\r
+ return;\r
+ if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;\r
+}\r
+\r
+\r
+PyObject* PyAST_mod2obj(mod_ty t)\r
+{\r
+ init_types();\r
+ return ast2obj_mod(t);\r
+}\r
+\r
+/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */\r
+mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)\r
+{\r
+ mod_ty res;\r
+ PyObject *req_type[3];\r
+ char *req_name[3];\r
+ int isinstance;\r
+\r
+ req_type[0] = (PyObject*)Module_type;\r
+ req_type[1] = (PyObject*)Expression_type;\r
+ req_type[2] = (PyObject*)Interactive_type;\r
+\r
+ req_name[0] = "Module";\r
+ req_name[1] = "Expression";\r
+ req_name[2] = "Interactive";\r
+\r
+ assert(0 <= mode && mode <= 2);\r
+\r
+ init_types();\r
+\r
+ isinstance = PyObject_IsInstance(ast, req_type[mode]);\r
+ if (isinstance == -1)\r
+ return NULL;\r
+ if (!isinstance) {\r
+ PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",\r
+ req_name[mode], Py_TYPE(ast)->tp_name);\r
+ return NULL;\r
+ }\r
+ if (obj2ast_mod(ast, &res, arena) != 0)\r
+ return NULL;\r
+ else\r
+ return res;\r
+}\r
+\r
+int PyAST_Check(PyObject* obj)\r
+{\r
+ init_types();\r
+ return PyObject_IsInstance(obj, (PyObject*)&AST_type);\r
+}\r
+\r
+\r