Home | History | Annotate | Download | only in Python
      1 /* File automatically generated by Parser/asdl_c.py. */
      2 
      3 
      4 /*
      5    __version__ 82160.
      6 
      7    This module must be committed separately after each AST grammar change;
      8    The __version__ number is set to the revision number of the commit
      9    containing the grammar change.
     10 */
     11 
     12 #include "Python.h"
     13 #include "Python-ast.h"
     14 
     15 static PyTypeObject AST_type;
     16 static PyTypeObject *mod_type;
     17 static PyObject* ast2obj_mod(void*);
     18 static PyTypeObject *Module_type;
     19 static char *Module_fields[]={
     20         "body",
     21 };
     22 static PyTypeObject *Interactive_type;
     23 static char *Interactive_fields[]={
     24         "body",
     25 };
     26 static PyTypeObject *Expression_type;
     27 static char *Expression_fields[]={
     28         "body",
     29 };
     30 static PyTypeObject *Suite_type;
     31 static char *Suite_fields[]={
     32         "body",
     33 };
     34 static PyTypeObject *stmt_type;
     35 static char *stmt_attributes[] = {
     36         "lineno",
     37         "col_offset",
     38 };
     39 static PyObject* ast2obj_stmt(void*);
     40 static PyTypeObject *FunctionDef_type;
     41 static char *FunctionDef_fields[]={
     42         "name",
     43         "args",
     44         "body",
     45         "decorator_list",
     46 };
     47 static PyTypeObject *ClassDef_type;
     48 static char *ClassDef_fields[]={
     49         "name",
     50         "bases",
     51         "body",
     52         "decorator_list",
     53 };
     54 static PyTypeObject *Return_type;
     55 static char *Return_fields[]={
     56         "value",
     57 };
     58 static PyTypeObject *Delete_type;
     59 static char *Delete_fields[]={
     60         "targets",
     61 };
     62 static PyTypeObject *Assign_type;
     63 static char *Assign_fields[]={
     64         "targets",
     65         "value",
     66 };
     67 static PyTypeObject *AugAssign_type;
     68 static char *AugAssign_fields[]={
     69         "target",
     70         "op",
     71         "value",
     72 };
     73 static PyTypeObject *Print_type;
     74 static char *Print_fields[]={
     75         "dest",
     76         "values",
     77         "nl",
     78 };
     79 static PyTypeObject *For_type;
     80 static char *For_fields[]={
     81         "target",
     82         "iter",
     83         "body",
     84         "orelse",
     85 };
     86 static PyTypeObject *While_type;
     87 static char *While_fields[]={
     88         "test",
     89         "body",
     90         "orelse",
     91 };
     92 static PyTypeObject *If_type;
     93 static char *If_fields[]={
     94         "test",
     95         "body",
     96         "orelse",
     97 };
     98 static PyTypeObject *With_type;
     99 static char *With_fields[]={
    100         "context_expr",
    101         "optional_vars",
    102         "body",
    103 };
    104 static PyTypeObject *Raise_type;
    105 static char *Raise_fields[]={
    106         "type",
    107         "inst",
    108         "tback",
    109 };
    110 static PyTypeObject *TryExcept_type;
    111 static char *TryExcept_fields[]={
    112         "body",
    113         "handlers",
    114         "orelse",
    115 };
    116 static PyTypeObject *TryFinally_type;
    117 static char *TryFinally_fields[]={
    118         "body",
    119         "finalbody",
    120 };
    121 static PyTypeObject *Assert_type;
    122 static char *Assert_fields[]={
    123         "test",
    124         "msg",
    125 };
    126 static PyTypeObject *Import_type;
    127 static char *Import_fields[]={
    128         "names",
    129 };
    130 static PyTypeObject *ImportFrom_type;
    131 static char *ImportFrom_fields[]={
    132         "module",
    133         "names",
    134         "level",
    135 };
    136 static PyTypeObject *Exec_type;
    137 static char *Exec_fields[]={
    138         "body",
    139         "globals",
    140         "locals",
    141 };
    142 static PyTypeObject *Global_type;
    143 static char *Global_fields[]={
    144         "names",
    145 };
    146 static PyTypeObject *Expr_type;
    147 static char *Expr_fields[]={
    148         "value",
    149 };
    150 static PyTypeObject *Pass_type;
    151 static PyTypeObject *Break_type;
    152 static PyTypeObject *Continue_type;
    153 static PyTypeObject *expr_type;
    154 static char *expr_attributes[] = {
    155         "lineno",
    156         "col_offset",
    157 };
    158 static PyObject* ast2obj_expr(void*);
    159 static PyTypeObject *BoolOp_type;
    160 static char *BoolOp_fields[]={
    161         "op",
    162         "values",
    163 };
    164 static PyTypeObject *BinOp_type;
    165 static char *BinOp_fields[]={
    166         "left",
    167         "op",
    168         "right",
    169 };
    170 static PyTypeObject *UnaryOp_type;
    171 static char *UnaryOp_fields[]={
    172         "op",
    173         "operand",
    174 };
    175 static PyTypeObject *Lambda_type;
    176 static char *Lambda_fields[]={
    177         "args",
    178         "body",
    179 };
    180 static PyTypeObject *IfExp_type;
    181 static char *IfExp_fields[]={
    182         "test",
    183         "body",
    184         "orelse",
    185 };
    186 static PyTypeObject *Dict_type;
    187 static char *Dict_fields[]={
    188         "keys",
    189         "values",
    190 };
    191 static PyTypeObject *Set_type;
    192 static char *Set_fields[]={
    193         "elts",
    194 };
    195 static PyTypeObject *ListComp_type;
    196 static char *ListComp_fields[]={
    197         "elt",
    198         "generators",
    199 };
    200 static PyTypeObject *SetComp_type;
    201 static char *SetComp_fields[]={
    202         "elt",
    203         "generators",
    204 };
    205 static PyTypeObject *DictComp_type;
    206 static char *DictComp_fields[]={
    207         "key",
    208         "value",
    209         "generators",
    210 };
    211 static PyTypeObject *GeneratorExp_type;
    212 static char *GeneratorExp_fields[]={
    213         "elt",
    214         "generators",
    215 };
    216 static PyTypeObject *Yield_type;
    217 static char *Yield_fields[]={
    218         "value",
    219 };
    220 static PyTypeObject *Compare_type;
    221 static char *Compare_fields[]={
    222         "left",
    223         "ops",
    224         "comparators",
    225 };
    226 static PyTypeObject *Call_type;
    227 static char *Call_fields[]={
    228         "func",
    229         "args",
    230         "keywords",
    231         "starargs",
    232         "kwargs",
    233 };
    234 static PyTypeObject *Repr_type;
    235 static char *Repr_fields[]={
    236         "value",
    237 };
    238 static PyTypeObject *Num_type;
    239 static char *Num_fields[]={
    240         "n",
    241 };
    242 static PyTypeObject *Str_type;
    243 static char *Str_fields[]={
    244         "s",
    245 };
    246 static PyTypeObject *Attribute_type;
    247 static char *Attribute_fields[]={
    248         "value",
    249         "attr",
    250         "ctx",
    251 };
    252 static PyTypeObject *Subscript_type;
    253 static char *Subscript_fields[]={
    254         "value",
    255         "slice",
    256         "ctx",
    257 };
    258 static PyTypeObject *Name_type;
    259 static char *Name_fields[]={
    260         "id",
    261         "ctx",
    262 };
    263 static PyTypeObject *List_type;
    264 static char *List_fields[]={
    265         "elts",
    266         "ctx",
    267 };
    268 static PyTypeObject *Tuple_type;
    269 static char *Tuple_fields[]={
    270         "elts",
    271         "ctx",
    272 };
    273 static PyTypeObject *expr_context_type;
    274 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
    275 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
    276 static PyObject* ast2obj_expr_context(expr_context_ty);
    277 static PyTypeObject *Load_type;
    278 static PyTypeObject *Store_type;
    279 static PyTypeObject *Del_type;
    280 static PyTypeObject *AugLoad_type;
    281 static PyTypeObject *AugStore_type;
    282 static PyTypeObject *Param_type;
    283 static PyTypeObject *slice_type;
    284 static PyObject* ast2obj_slice(void*);
    285 static PyTypeObject *Ellipsis_type;
    286 static PyTypeObject *Slice_type;
    287 static char *Slice_fields[]={
    288         "lower",
    289         "upper",
    290         "step",
    291 };
    292 static PyTypeObject *ExtSlice_type;
    293 static char *ExtSlice_fields[]={
    294         "dims",
    295 };
    296 static PyTypeObject *Index_type;
    297 static char *Index_fields[]={
    298         "value",
    299 };
    300 static PyTypeObject *boolop_type;
    301 static PyObject *And_singleton, *Or_singleton;
    302 static PyObject* ast2obj_boolop(boolop_ty);
    303 static PyTypeObject *And_type;
    304 static PyTypeObject *Or_type;
    305 static PyTypeObject *operator_type;
    306 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
    307 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
    308 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
    309 *FloorDiv_singleton;
    310 static PyObject* ast2obj_operator(operator_ty);
    311 static PyTypeObject *Add_type;
    312 static PyTypeObject *Sub_type;
    313 static PyTypeObject *Mult_type;
    314 static PyTypeObject *Div_type;
    315 static PyTypeObject *Mod_type;
    316 static PyTypeObject *Pow_type;
    317 static PyTypeObject *LShift_type;
    318 static PyTypeObject *RShift_type;
    319 static PyTypeObject *BitOr_type;
    320 static PyTypeObject *BitXor_type;
    321 static PyTypeObject *BitAnd_type;
    322 static PyTypeObject *FloorDiv_type;
    323 static PyTypeObject *unaryop_type;
    324 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
    325 *USub_singleton;
    326 static PyObject* ast2obj_unaryop(unaryop_ty);
    327 static PyTypeObject *Invert_type;
    328 static PyTypeObject *Not_type;
    329 static PyTypeObject *UAdd_type;
    330 static PyTypeObject *USub_type;
    331 static PyTypeObject *cmpop_type;
    332 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
    333 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
    334 *NotIn_singleton;
    335 static PyObject* ast2obj_cmpop(cmpop_ty);
    336 static PyTypeObject *Eq_type;
    337 static PyTypeObject *NotEq_type;
    338 static PyTypeObject *Lt_type;
    339 static PyTypeObject *LtE_type;
    340 static PyTypeObject *Gt_type;
    341 static PyTypeObject *GtE_type;
    342 static PyTypeObject *Is_type;
    343 static PyTypeObject *IsNot_type;
    344 static PyTypeObject *In_type;
    345 static PyTypeObject *NotIn_type;
    346 static PyTypeObject *comprehension_type;
    347 static PyObject* ast2obj_comprehension(void*);
    348 static char *comprehension_fields[]={
    349         "target",
    350         "iter",
    351         "ifs",
    352 };
    353 static PyTypeObject *excepthandler_type;
    354 static char *excepthandler_attributes[] = {
    355         "lineno",
    356         "col_offset",
    357 };
    358 static PyObject* ast2obj_excepthandler(void*);
    359 static PyTypeObject *ExceptHandler_type;
    360 static char *ExceptHandler_fields[]={
    361         "type",
    362         "name",
    363         "body",
    364 };
    365 static PyTypeObject *arguments_type;
    366 static PyObject* ast2obj_arguments(void*);
    367 static char *arguments_fields[]={
    368         "args",
    369         "vararg",
    370         "kwarg",
    371         "defaults",
    372 };
    373 static PyTypeObject *keyword_type;
    374 static PyObject* ast2obj_keyword(void*);
    375 static char *keyword_fields[]={
    376         "arg",
    377         "value",
    378 };
    379 static PyTypeObject *alias_type;
    380 static PyObject* ast2obj_alias(void*);
    381 static char *alias_fields[]={
    382         "name",
    383         "asname",
    384 };
    385 
    386 
    387 static int
    388 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
    389 {
    390     Py_ssize_t i, numfields = 0;
    391     int res = -1;
    392     PyObject *key, *value, *fields;
    393     fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
    394     if (!fields)
    395         PyErr_Clear();
    396     if (fields) {
    397         numfields = PySequence_Size(fields);
    398         if (numfields == -1)
    399             goto cleanup;
    400     }
    401     res = 0; /* if no error occurs, this stays 0 to the end */
    402     if (PyTuple_GET_SIZE(args) > 0) {
    403         if (numfields != PyTuple_GET_SIZE(args)) {
    404             PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
    405                          "%zd positional argument%s",
    406                          Py_TYPE(self)->tp_name,
    407                          numfields == 0 ? "" : "either 0 or ",
    408                          numfields, numfields == 1 ? "" : "s");
    409             res = -1;
    410             goto cleanup;
    411         }
    412         for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
    413             /* cannot be reached when fields is NULL */
    414             PyObject *name = PySequence_GetItem(fields, i);
    415             if (!name) {
    416                 res = -1;
    417                 goto cleanup;
    418             }
    419             res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
    420             Py_DECREF(name);
    421             if (res < 0)
    422                 goto cleanup;
    423         }
    424     }
    425     if (kw) {
    426         i = 0;  /* needed by PyDict_Next */
    427         while (PyDict_Next(kw, &i, &key, &value)) {
    428             res = PyObject_SetAttr(self, key, value);
    429             if (res < 0)
    430                 goto cleanup;
    431         }
    432     }
    433   cleanup:
    434     Py_XDECREF(fields);
    435     return res;
    436 }
    437 
    438 /* Pickling support */
    439 static PyObject *
    440 ast_type_reduce(PyObject *self, PyObject *unused)
    441 {
    442     PyObject *res;
    443     PyObject *dict = PyObject_GetAttrString(self, "__dict__");
    444     if (dict == NULL) {
    445         if (PyErr_ExceptionMatches(PyExc_AttributeError))
    446             PyErr_Clear();
    447         else
    448             return NULL;
    449     }
    450     if (dict) {
    451         res = Py_BuildValue("O()O", Py_TYPE(self), dict);
    452         Py_DECREF(dict);
    453         return res;
    454     }
    455     return Py_BuildValue("O()", Py_TYPE(self));
    456 }
    457 
    458 static PyMethodDef ast_type_methods[] = {
    459     {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
    460     {NULL}
    461 };
    462 
    463 static PyTypeObject AST_type = {
    464     PyVarObject_HEAD_INIT(&PyType_Type, 0)
    465     "_ast.AST",
    466     sizeof(PyObject),
    467     0,
    468     0,                       /* tp_dealloc */
    469     0,                       /* tp_print */
    470     0,                       /* tp_getattr */
    471     0,                       /* tp_setattr */
    472     0,                       /* tp_compare */
    473     0,                       /* tp_repr */
    474     0,                       /* tp_as_number */
    475     0,                       /* tp_as_sequence */
    476     0,                       /* tp_as_mapping */
    477     0,                       /* tp_hash */
    478     0,                       /* tp_call */
    479     0,                       /* tp_str */
    480     PyObject_GenericGetAttr, /* tp_getattro */
    481     PyObject_GenericSetAttr, /* tp_setattro */
    482     0,                       /* tp_as_buffer */
    483     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
    484     0,                       /* tp_doc */
    485     0,                       /* tp_traverse */
    486     0,                       /* tp_clear */
    487     0,                       /* tp_richcompare */
    488     0,                       /* tp_weaklistoffset */
    489     0,                       /* tp_iter */
    490     0,                       /* tp_iternext */
    491     ast_type_methods,        /* tp_methods */
    492     0,                       /* tp_members */
    493     0,                       /* tp_getset */
    494     0,                       /* tp_base */
    495     0,                       /* tp_dict */
    496     0,                       /* tp_descr_get */
    497     0,                       /* tp_descr_set */
    498     0,                       /* tp_dictoffset */
    499     (initproc)ast_type_init, /* tp_init */
    500     PyType_GenericAlloc,     /* tp_alloc */
    501     PyType_GenericNew,       /* tp_new */
    502     PyObject_Del,            /* tp_free */
    503 };
    504 
    505 
    506 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
    507 {
    508     PyObject *fnames, *result;
    509     int i;
    510     fnames = PyTuple_New(num_fields);
    511     if (!fnames) return NULL;
    512     for (i = 0; i < num_fields; i++) {
    513         PyObject *field = PyString_FromString(fields[i]);
    514         if (!field) {
    515             Py_DECREF(fnames);
    516             return NULL;
    517         }
    518         PyTuple_SET_ITEM(fnames, i, field);
    519     }
    520     result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
    521                     type, base, "_fields", fnames, "__module__", "_ast");
    522     Py_DECREF(fnames);
    523     return (PyTypeObject*)result;
    524 }
    525 
    526 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
    527 {
    528     int i, result;
    529     PyObject *s, *l = PyTuple_New(num_fields);
    530     if (!l)
    531         return 0;
    532     for (i = 0; i < num_fields; i++) {
    533         s = PyString_FromString(attrs[i]);
    534         if (!s) {
    535             Py_DECREF(l);
    536             return 0;
    537         }
    538         PyTuple_SET_ITEM(l, i, s);
    539     }
    540     result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
    541     Py_DECREF(l);
    542     return result;
    543 }
    544 
    545 /* Conversion AST -> Python */
    546 
    547 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
    548 {
    549     int i, n = asdl_seq_LEN(seq);
    550     PyObject *result = PyList_New(n);
    551     PyObject *value;
    552     if (!result)
    553         return NULL;
    554     for (i = 0; i < n; i++) {
    555         value = func(asdl_seq_GET(seq, i));
    556         if (!value) {
    557             Py_DECREF(result);
    558             return NULL;
    559         }
    560         PyList_SET_ITEM(result, i, value);
    561     }
    562     return result;
    563 }
    564 
    565 static PyObject* ast2obj_object(void *o)
    566 {
    567     if (!o)
    568         o = Py_None;
    569     Py_INCREF((PyObject*)o);
    570     return (PyObject*)o;
    571 }
    572 #define ast2obj_identifier ast2obj_object
    573 #define ast2obj_string ast2obj_object
    574 static PyObject* ast2obj_bool(bool b)
    575 {
    576     return PyBool_FromLong(b);
    577 }
    578 
    579 static PyObject* ast2obj_int(long b)
    580 {
    581     return PyInt_FromLong(b);
    582 }
    583 
    584 /* Conversion Python -> AST */
    585 
    586 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
    587 {
    588     if (obj == Py_None)
    589         obj = NULL;
    590     if (obj)
    591         PyArena_AddPyObject(arena, obj);
    592     Py_XINCREF(obj);
    593     *out = obj;
    594     return 0;
    595 }
    596 
    597 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
    598 {
    599     if (!PyString_CheckExact(obj) && obj != Py_None) {
    600         PyErr_Format(PyExc_TypeError,
    601                     "AST identifier must be of type str");
    602         return 1;
    603     }
    604     return obj2ast_object(obj, out, arena);
    605 }
    606 
    607 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
    608 {
    609     if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {
    610         PyErr_SetString(PyExc_TypeError,
    611                        "AST string must be of type str or unicode");
    612         return 1;
    613     }
    614     return obj2ast_object(obj, out, arena);
    615 }
    616 
    617 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
    618 {
    619     int i;
    620     if (!_PyAnyInt_Check(obj)) {
    621         PyObject *s = PyObject_Repr(obj);
    622         if (s == NULL) return 1;
    623         PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
    624                      PyString_AS_STRING(s));
    625         Py_DECREF(s);
    626         return 1;
    627     }
    628 
    629     i = (int)PyLong_AsLong(obj);
    630     if (i == -1 && PyErr_Occurred())
    631         return 1;
    632     *out = i;
    633     return 0;
    634 }
    635 
    636 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
    637 {
    638     if (!PyBool_Check(obj)) {
    639         PyObject *s = PyObject_Repr(obj);
    640         if (s == NULL) return 1;
    641         PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
    642                      PyString_AS_STRING(s));
    643         Py_DECREF(s);
    644         return 1;
    645     }
    646 
    647     *out = (obj == Py_True);
    648     return 0;
    649 }
    650 
    651 static int add_ast_fields(void)
    652 {
    653     PyObject *empty_tuple, *d;
    654     if (PyType_Ready(&AST_type) < 0)
    655         return -1;
    656     d = AST_type.tp_dict;
    657     empty_tuple = PyTuple_New(0);
    658     if (!empty_tuple ||
    659         PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
    660         PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
    661         Py_XDECREF(empty_tuple);
    662         return -1;
    663     }
    664     Py_DECREF(empty_tuple);
    665     return 0;
    666 }
    667 
    668 
    669 static int init_types(void)
    670 {
    671         static int initialized;
    672         if (initialized) return 1;
    673         if (add_ast_fields() < 0) return 0;
    674         mod_type = make_type("mod", &AST_type, NULL, 0);
    675         if (!mod_type) return 0;
    676         if (!add_attributes(mod_type, NULL, 0)) return 0;
    677         Module_type = make_type("Module", mod_type, Module_fields, 1);
    678         if (!Module_type) return 0;
    679         Interactive_type = make_type("Interactive", mod_type,
    680                                      Interactive_fields, 1);
    681         if (!Interactive_type) return 0;
    682         Expression_type = make_type("Expression", mod_type, Expression_fields,
    683                                     1);
    684         if (!Expression_type) return 0;
    685         Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
    686         if (!Suite_type) return 0;
    687         stmt_type = make_type("stmt", &AST_type, NULL, 0);
    688         if (!stmt_type) return 0;
    689         if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
    690         FunctionDef_type = make_type("FunctionDef", stmt_type,
    691                                      FunctionDef_fields, 4);
    692         if (!FunctionDef_type) return 0;
    693         ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
    694         if (!ClassDef_type) return 0;
    695         Return_type = make_type("Return", stmt_type, Return_fields, 1);
    696         if (!Return_type) return 0;
    697         Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
    698         if (!Delete_type) return 0;
    699         Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
    700         if (!Assign_type) return 0;
    701         AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
    702         if (!AugAssign_type) return 0;
    703         Print_type = make_type("Print", stmt_type, Print_fields, 3);
    704         if (!Print_type) return 0;
    705         For_type = make_type("For", stmt_type, For_fields, 4);
    706         if (!For_type) return 0;
    707         While_type = make_type("While", stmt_type, While_fields, 3);
    708         if (!While_type) return 0;
    709         If_type = make_type("If", stmt_type, If_fields, 3);
    710         if (!If_type) return 0;
    711         With_type = make_type("With", stmt_type, With_fields, 3);
    712         if (!With_type) return 0;
    713         Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
    714         if (!Raise_type) return 0;
    715         TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
    716         if (!TryExcept_type) return 0;
    717         TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
    718                                     2);
    719         if (!TryFinally_type) return 0;
    720         Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
    721         if (!Assert_type) return 0;
    722         Import_type = make_type("Import", stmt_type, Import_fields, 1);
    723         if (!Import_type) return 0;
    724         ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
    725                                     3);
    726         if (!ImportFrom_type) return 0;
    727         Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
    728         if (!Exec_type) return 0;
    729         Global_type = make_type("Global", stmt_type, Global_fields, 1);
    730         if (!Global_type) return 0;
    731         Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
    732         if (!Expr_type) return 0;
    733         Pass_type = make_type("Pass", stmt_type, NULL, 0);
    734         if (!Pass_type) return 0;
    735         Break_type = make_type("Break", stmt_type, NULL, 0);
    736         if (!Break_type) return 0;
    737         Continue_type = make_type("Continue", stmt_type, NULL, 0);
    738         if (!Continue_type) return 0;
    739         expr_type = make_type("expr", &AST_type, NULL, 0);
    740         if (!expr_type) return 0;
    741         if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
    742         BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
    743         if (!BoolOp_type) return 0;
    744         BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
    745         if (!BinOp_type) return 0;
    746         UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
    747         if (!UnaryOp_type) return 0;
    748         Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
    749         if (!Lambda_type) return 0;
    750         IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
    751         if (!IfExp_type) return 0;
    752         Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
    753         if (!Dict_type) return 0;
    754         Set_type = make_type("Set", expr_type, Set_fields, 1);
    755         if (!Set_type) return 0;
    756         ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
    757         if (!ListComp_type) return 0;
    758         SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
    759         if (!SetComp_type) return 0;
    760         DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
    761         if (!DictComp_type) return 0;
    762         GeneratorExp_type = make_type("GeneratorExp", expr_type,
    763                                       GeneratorExp_fields, 2);
    764         if (!GeneratorExp_type) return 0;
    765         Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
    766         if (!Yield_type) return 0;
    767         Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
    768         if (!Compare_type) return 0;
    769         Call_type = make_type("Call", expr_type, Call_fields, 5);
    770         if (!Call_type) return 0;
    771         Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
    772         if (!Repr_type) return 0;
    773         Num_type = make_type("Num", expr_type, Num_fields, 1);
    774         if (!Num_type) return 0;
    775         Str_type = make_type("Str", expr_type, Str_fields, 1);
    776         if (!Str_type) return 0;
    777         Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
    778         if (!Attribute_type) return 0;
    779         Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
    780         if (!Subscript_type) return 0;
    781         Name_type = make_type("Name", expr_type, Name_fields, 2);
    782         if (!Name_type) return 0;
    783         List_type = make_type("List", expr_type, List_fields, 2);
    784         if (!List_type) return 0;
    785         Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
    786         if (!Tuple_type) return 0;
    787         expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
    788         if (!expr_context_type) return 0;
    789         if (!add_attributes(expr_context_type, NULL, 0)) return 0;
    790         Load_type = make_type("Load", expr_context_type, NULL, 0);
    791         if (!Load_type) return 0;
    792         Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
    793         if (!Load_singleton) return 0;
    794         Store_type = make_type("Store", expr_context_type, NULL, 0);
    795         if (!Store_type) return 0;
    796         Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
    797         if (!Store_singleton) return 0;
    798         Del_type = make_type("Del", expr_context_type, NULL, 0);
    799         if (!Del_type) return 0;
    800         Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
    801         if (!Del_singleton) return 0;
    802         AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
    803         if (!AugLoad_type) return 0;
    804         AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
    805         if (!AugLoad_singleton) return 0;
    806         AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
    807         if (!AugStore_type) return 0;
    808         AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
    809         if (!AugStore_singleton) return 0;
    810         Param_type = make_type("Param", expr_context_type, NULL, 0);
    811         if (!Param_type) return 0;
    812         Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
    813         if (!Param_singleton) return 0;
    814         slice_type = make_type("slice", &AST_type, NULL, 0);
    815         if (!slice_type) return 0;
    816         if (!add_attributes(slice_type, NULL, 0)) return 0;
    817         Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
    818         if (!Ellipsis_type) return 0;
    819         Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
    820         if (!Slice_type) return 0;
    821         ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
    822         if (!ExtSlice_type) return 0;
    823         Index_type = make_type("Index", slice_type, Index_fields, 1);
    824         if (!Index_type) return 0;
    825         boolop_type = make_type("boolop", &AST_type, NULL, 0);
    826         if (!boolop_type) return 0;
    827         if (!add_attributes(boolop_type, NULL, 0)) return 0;
    828         And_type = make_type("And", boolop_type, NULL, 0);
    829         if (!And_type) return 0;
    830         And_singleton = PyType_GenericNew(And_type, NULL, NULL);
    831         if (!And_singleton) return 0;
    832         Or_type = make_type("Or", boolop_type, NULL, 0);
    833         if (!Or_type) return 0;
    834         Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
    835         if (!Or_singleton) return 0;
    836         operator_type = make_type("operator", &AST_type, NULL, 0);
    837         if (!operator_type) return 0;
    838         if (!add_attributes(operator_type, NULL, 0)) return 0;
    839         Add_type = make_type("Add", operator_type, NULL, 0);
    840         if (!Add_type) return 0;
    841         Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
    842         if (!Add_singleton) return 0;
    843         Sub_type = make_type("Sub", operator_type, NULL, 0);
    844         if (!Sub_type) return 0;
    845         Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
    846         if (!Sub_singleton) return 0;
    847         Mult_type = make_type("Mult", operator_type, NULL, 0);
    848         if (!Mult_type) return 0;
    849         Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
    850         if (!Mult_singleton) return 0;
    851         Div_type = make_type("Div", operator_type, NULL, 0);
    852         if (!Div_type) return 0;
    853         Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
    854         if (!Div_singleton) return 0;
    855         Mod_type = make_type("Mod", operator_type, NULL, 0);
    856         if (!Mod_type) return 0;
    857         Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
    858         if (!Mod_singleton) return 0;
    859         Pow_type = make_type("Pow", operator_type, NULL, 0);
    860         if (!Pow_type) return 0;
    861         Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
    862         if (!Pow_singleton) return 0;
    863         LShift_type = make_type("LShift", operator_type, NULL, 0);
    864         if (!LShift_type) return 0;
    865         LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
    866         if (!LShift_singleton) return 0;
    867         RShift_type = make_type("RShift", operator_type, NULL, 0);
    868         if (!RShift_type) return 0;
    869         RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
    870         if (!RShift_singleton) return 0;
    871         BitOr_type = make_type("BitOr", operator_type, NULL, 0);
    872         if (!BitOr_type) return 0;
    873         BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
    874         if (!BitOr_singleton) return 0;
    875         BitXor_type = make_type("BitXor", operator_type, NULL, 0);
    876         if (!BitXor_type) return 0;
    877         BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
    878         if (!BitXor_singleton) return 0;
    879         BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
    880         if (!BitAnd_type) return 0;
    881         BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
    882         if (!BitAnd_singleton) return 0;
    883         FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
    884         if (!FloorDiv_type) return 0;
    885         FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
    886         if (!FloorDiv_singleton) return 0;
    887         unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
    888         if (!unaryop_type) return 0;
    889         if (!add_attributes(unaryop_type, NULL, 0)) return 0;
    890         Invert_type = make_type("Invert", unaryop_type, NULL, 0);
    891         if (!Invert_type) return 0;
    892         Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
    893         if (!Invert_singleton) return 0;
    894         Not_type = make_type("Not", unaryop_type, NULL, 0);
    895         if (!Not_type) return 0;
    896         Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
    897         if (!Not_singleton) return 0;
    898         UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
    899         if (!UAdd_type) return 0;
    900         UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
    901         if (!UAdd_singleton) return 0;
    902         USub_type = make_type("USub", unaryop_type, NULL, 0);
    903         if (!USub_type) return 0;
    904         USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
    905         if (!USub_singleton) return 0;
    906         cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
    907         if (!cmpop_type) return 0;
    908         if (!add_attributes(cmpop_type, NULL, 0)) return 0;
    909         Eq_type = make_type("Eq", cmpop_type, NULL, 0);
    910         if (!Eq_type) return 0;
    911         Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
    912         if (!Eq_singleton) return 0;
    913         NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
    914         if (!NotEq_type) return 0;
    915         NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
    916         if (!NotEq_singleton) return 0;
    917         Lt_type = make_type("Lt", cmpop_type, NULL, 0);
    918         if (!Lt_type) return 0;
    919         Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
    920         if (!Lt_singleton) return 0;
    921         LtE_type = make_type("LtE", cmpop_type, NULL, 0);
    922         if (!LtE_type) return 0;
    923         LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
    924         if (!LtE_singleton) return 0;
    925         Gt_type = make_type("Gt", cmpop_type, NULL, 0);
    926         if (!Gt_type) return 0;
    927         Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
    928         if (!Gt_singleton) return 0;
    929         GtE_type = make_type("GtE", cmpop_type, NULL, 0);
    930         if (!GtE_type) return 0;
    931         GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
    932         if (!GtE_singleton) return 0;
    933         Is_type = make_type("Is", cmpop_type, NULL, 0);
    934         if (!Is_type) return 0;
    935         Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
    936         if (!Is_singleton) return 0;
    937         IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
    938         if (!IsNot_type) return 0;
    939         IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
    940         if (!IsNot_singleton) return 0;
    941         In_type = make_type("In", cmpop_type, NULL, 0);
    942         if (!In_type) return 0;
    943         In_singleton = PyType_GenericNew(In_type, NULL, NULL);
    944         if (!In_singleton) return 0;
    945         NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
    946         if (!NotIn_type) return 0;
    947         NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
    948         if (!NotIn_singleton) return 0;
    949         comprehension_type = make_type("comprehension", &AST_type,
    950                                        comprehension_fields, 3);
    951         if (!comprehension_type) return 0;
    952         excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
    953         if (!excepthandler_type) return 0;
    954         if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
    955             return 0;
    956         ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
    957                                        ExceptHandler_fields, 3);
    958         if (!ExceptHandler_type) return 0;
    959         arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
    960         if (!arguments_type) return 0;
    961         keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
    962         if (!keyword_type) return 0;
    963         alias_type = make_type("alias", &AST_type, alias_fields, 2);
    964         if (!alias_type) return 0;
    965         initialized = 1;
    966         return 1;
    967 }
    968 
    969 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
    970 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
    971 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
    972 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
    973                                 arena);
    974 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
    975 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
    976 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
    977 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
    978 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
    979 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
    980                                  arena);
    981 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
    982                                  arena);
    983 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
    984 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
    985 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
    986 
    987 mod_ty
    988 Module(asdl_seq * body, PyArena *arena)
    989 {
    990         mod_ty p;
    991         p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
    992         if (!p)
    993                 return NULL;
    994         p->kind = Module_kind;
    995         p->v.Module.body = body;
    996         return p;
    997 }
    998 
    999 mod_ty
   1000 Interactive(asdl_seq * body, PyArena *arena)
   1001 {
   1002         mod_ty p;
   1003         p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
   1004         if (!p)
   1005                 return NULL;
   1006         p->kind = Interactive_kind;
   1007         p->v.Interactive.body = body;
   1008         return p;
   1009 }
   1010 
   1011 mod_ty
   1012 Expression(expr_ty body, PyArena *arena)
   1013 {
   1014         mod_ty p;
   1015         if (!body) {
   1016                 PyErr_SetString(PyExc_ValueError,
   1017                                 "field body is required for Expression");
   1018                 return NULL;
   1019         }
   1020         p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
   1021         if (!p)
   1022                 return NULL;
   1023         p->kind = Expression_kind;
   1024         p->v.Expression.body = body;
   1025         return p;
   1026 }
   1027 
   1028 mod_ty
   1029 Suite(asdl_seq * body, PyArena *arena)
   1030 {
   1031         mod_ty p;
   1032         p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
   1033         if (!p)
   1034                 return NULL;
   1035         p->kind = Suite_kind;
   1036         p->v.Suite.body = body;
   1037         return p;
   1038 }
   1039 
   1040 stmt_ty
   1041 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
   1042             decorator_list, int lineno, int col_offset, PyArena *arena)
   1043 {
   1044         stmt_ty p;
   1045         if (!name) {
   1046                 PyErr_SetString(PyExc_ValueError,
   1047                                 "field name is required for FunctionDef");
   1048                 return NULL;
   1049         }
   1050         if (!args) {
   1051                 PyErr_SetString(PyExc_ValueError,
   1052                                 "field args is required for FunctionDef");
   1053                 return NULL;
   1054         }
   1055         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1056         if (!p)
   1057                 return NULL;
   1058         p->kind = FunctionDef_kind;
   1059         p->v.FunctionDef.name = name;
   1060         p->v.FunctionDef.args = args;
   1061         p->v.FunctionDef.body = body;
   1062         p->v.FunctionDef.decorator_list = decorator_list;
   1063         p->lineno = lineno;
   1064         p->col_offset = col_offset;
   1065         return p;
   1066 }
   1067 
   1068 stmt_ty
   1069 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
   1070          decorator_list, int lineno, int col_offset, PyArena *arena)
   1071 {
   1072         stmt_ty p;
   1073         if (!name) {
   1074                 PyErr_SetString(PyExc_ValueError,
   1075                                 "field name is required for ClassDef");
   1076                 return NULL;
   1077         }
   1078         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1079         if (!p)
   1080                 return NULL;
   1081         p->kind = ClassDef_kind;
   1082         p->v.ClassDef.name = name;
   1083         p->v.ClassDef.bases = bases;
   1084         p->v.ClassDef.body = body;
   1085         p->v.ClassDef.decorator_list = decorator_list;
   1086         p->lineno = lineno;
   1087         p->col_offset = col_offset;
   1088         return p;
   1089 }
   1090 
   1091 stmt_ty
   1092 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
   1093 {
   1094         stmt_ty p;
   1095         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1096         if (!p)
   1097                 return NULL;
   1098         p->kind = Return_kind;
   1099         p->v.Return.value = value;
   1100         p->lineno = lineno;
   1101         p->col_offset = col_offset;
   1102         return p;
   1103 }
   1104 
   1105 stmt_ty
   1106 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
   1107 {
   1108         stmt_ty p;
   1109         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1110         if (!p)
   1111                 return NULL;
   1112         p->kind = Delete_kind;
   1113         p->v.Delete.targets = targets;
   1114         p->lineno = lineno;
   1115         p->col_offset = col_offset;
   1116         return p;
   1117 }
   1118 
   1119 stmt_ty
   1120 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
   1121        *arena)
   1122 {
   1123         stmt_ty p;
   1124         if (!value) {
   1125                 PyErr_SetString(PyExc_ValueError,
   1126                                 "field value is required for Assign");
   1127                 return NULL;
   1128         }
   1129         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1130         if (!p)
   1131                 return NULL;
   1132         p->kind = Assign_kind;
   1133         p->v.Assign.targets = targets;
   1134         p->v.Assign.value = value;
   1135         p->lineno = lineno;
   1136         p->col_offset = col_offset;
   1137         return p;
   1138 }
   1139 
   1140 stmt_ty
   1141 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
   1142           col_offset, PyArena *arena)
   1143 {
   1144         stmt_ty p;
   1145         if (!target) {
   1146                 PyErr_SetString(PyExc_ValueError,
   1147                                 "field target is required for AugAssign");
   1148                 return NULL;
   1149         }
   1150         if (!op) {
   1151                 PyErr_SetString(PyExc_ValueError,
   1152                                 "field op is required for AugAssign");
   1153                 return NULL;
   1154         }
   1155         if (!value) {
   1156                 PyErr_SetString(PyExc_ValueError,
   1157                                 "field value is required for AugAssign");
   1158                 return NULL;
   1159         }
   1160         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1161         if (!p)
   1162                 return NULL;
   1163         p->kind = AugAssign_kind;
   1164         p->v.AugAssign.target = target;
   1165         p->v.AugAssign.op = op;
   1166         p->v.AugAssign.value = value;
   1167         p->lineno = lineno;
   1168         p->col_offset = col_offset;
   1169         return p;
   1170 }
   1171 
   1172 stmt_ty
   1173 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
   1174       PyArena *arena)
   1175 {
   1176         stmt_ty p;
   1177         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1178         if (!p)
   1179                 return NULL;
   1180         p->kind = Print_kind;
   1181         p->v.Print.dest = dest;
   1182         p->v.Print.values = values;
   1183         p->v.Print.nl = nl;
   1184         p->lineno = lineno;
   1185         p->col_offset = col_offset;
   1186         return p;
   1187 }
   1188 
   1189 stmt_ty
   1190 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
   1191     lineno, int col_offset, PyArena *arena)
   1192 {
   1193         stmt_ty p;
   1194         if (!target) {
   1195                 PyErr_SetString(PyExc_ValueError,
   1196                                 "field target is required for For");
   1197                 return NULL;
   1198         }
   1199         if (!iter) {
   1200                 PyErr_SetString(PyExc_ValueError,
   1201                                 "field iter is required for For");
   1202                 return NULL;
   1203         }
   1204         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1205         if (!p)
   1206                 return NULL;
   1207         p->kind = For_kind;
   1208         p->v.For.target = target;
   1209         p->v.For.iter = iter;
   1210         p->v.For.body = body;
   1211         p->v.For.orelse = orelse;
   1212         p->lineno = lineno;
   1213         p->col_offset = col_offset;
   1214         return p;
   1215 }
   1216 
   1217 stmt_ty
   1218 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
   1219       col_offset, PyArena *arena)
   1220 {
   1221         stmt_ty p;
   1222         if (!test) {
   1223                 PyErr_SetString(PyExc_ValueError,
   1224                                 "field test is required for While");
   1225                 return NULL;
   1226         }
   1227         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1228         if (!p)
   1229                 return NULL;
   1230         p->kind = While_kind;
   1231         p->v.While.test = test;
   1232         p->v.While.body = body;
   1233         p->v.While.orelse = orelse;
   1234         p->lineno = lineno;
   1235         p->col_offset = col_offset;
   1236         return p;
   1237 }
   1238 
   1239 stmt_ty
   1240 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
   1241    col_offset, PyArena *arena)
   1242 {
   1243         stmt_ty p;
   1244         if (!test) {
   1245                 PyErr_SetString(PyExc_ValueError,
   1246                                 "field test is required for If");
   1247                 return NULL;
   1248         }
   1249         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1250         if (!p)
   1251                 return NULL;
   1252         p->kind = If_kind;
   1253         p->v.If.test = test;
   1254         p->v.If.body = body;
   1255         p->v.If.orelse = orelse;
   1256         p->lineno = lineno;
   1257         p->col_offset = col_offset;
   1258         return p;
   1259 }
   1260 
   1261 stmt_ty
   1262 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
   1263      int col_offset, PyArena *arena)
   1264 {
   1265         stmt_ty p;
   1266         if (!context_expr) {
   1267                 PyErr_SetString(PyExc_ValueError,
   1268                                 "field context_expr is required for With");
   1269                 return NULL;
   1270         }
   1271         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1272         if (!p)
   1273                 return NULL;
   1274         p->kind = With_kind;
   1275         p->v.With.context_expr = context_expr;
   1276         p->v.With.optional_vars = optional_vars;
   1277         p->v.With.body = body;
   1278         p->lineno = lineno;
   1279         p->col_offset = col_offset;
   1280         return p;
   1281 }
   1282 
   1283 stmt_ty
   1284 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
   1285       PyArena *arena)
   1286 {
   1287         stmt_ty p;
   1288         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1289         if (!p)
   1290                 return NULL;
   1291         p->kind = Raise_kind;
   1292         p->v.Raise.type = type;
   1293         p->v.Raise.inst = inst;
   1294         p->v.Raise.tback = tback;
   1295         p->lineno = lineno;
   1296         p->col_offset = col_offset;
   1297         return p;
   1298 }
   1299 
   1300 stmt_ty
   1301 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
   1302           int col_offset, PyArena *arena)
   1303 {
   1304         stmt_ty p;
   1305         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1306         if (!p)
   1307                 return NULL;
   1308         p->kind = TryExcept_kind;
   1309         p->v.TryExcept.body = body;
   1310         p->v.TryExcept.handlers = handlers;
   1311         p->v.TryExcept.orelse = orelse;
   1312         p->lineno = lineno;
   1313         p->col_offset = col_offset;
   1314         return p;
   1315 }
   1316 
   1317 stmt_ty
   1318 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
   1319            PyArena *arena)
   1320 {
   1321         stmt_ty p;
   1322         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1323         if (!p)
   1324                 return NULL;
   1325         p->kind = TryFinally_kind;
   1326         p->v.TryFinally.body = body;
   1327         p->v.TryFinally.finalbody = finalbody;
   1328         p->lineno = lineno;
   1329         p->col_offset = col_offset;
   1330         return p;
   1331 }
   1332 
   1333 stmt_ty
   1334 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
   1335 {
   1336         stmt_ty p;
   1337         if (!test) {
   1338                 PyErr_SetString(PyExc_ValueError,
   1339                                 "field test is required for Assert");
   1340                 return NULL;
   1341         }
   1342         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1343         if (!p)
   1344                 return NULL;
   1345         p->kind = Assert_kind;
   1346         p->v.Assert.test = test;
   1347         p->v.Assert.msg = msg;
   1348         p->lineno = lineno;
   1349         p->col_offset = col_offset;
   1350         return p;
   1351 }
   1352 
   1353 stmt_ty
   1354 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
   1355 {
   1356         stmt_ty p;
   1357         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1358         if (!p)
   1359                 return NULL;
   1360         p->kind = Import_kind;
   1361         p->v.Import.names = names;
   1362         p->lineno = lineno;
   1363         p->col_offset = col_offset;
   1364         return p;
   1365 }
   1366 
   1367 stmt_ty
   1368 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
   1369            col_offset, PyArena *arena)
   1370 {
   1371         stmt_ty p;
   1372         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1373         if (!p)
   1374                 return NULL;
   1375         p->kind = ImportFrom_kind;
   1376         p->v.ImportFrom.module = module;
   1377         p->v.ImportFrom.names = names;
   1378         p->v.ImportFrom.level = level;
   1379         p->lineno = lineno;
   1380         p->col_offset = col_offset;
   1381         return p;
   1382 }
   1383 
   1384 stmt_ty
   1385 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
   1386      PyArena *arena)
   1387 {
   1388         stmt_ty p;
   1389         if (!body) {
   1390                 PyErr_SetString(PyExc_ValueError,
   1391                                 "field body is required for Exec");
   1392                 return NULL;
   1393         }
   1394         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1395         if (!p)
   1396                 return NULL;
   1397         p->kind = Exec_kind;
   1398         p->v.Exec.body = body;
   1399         p->v.Exec.globals = globals;
   1400         p->v.Exec.locals = locals;
   1401         p->lineno = lineno;
   1402         p->col_offset = col_offset;
   1403         return p;
   1404 }
   1405 
   1406 stmt_ty
   1407 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
   1408 {
   1409         stmt_ty p;
   1410         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1411         if (!p)
   1412                 return NULL;
   1413         p->kind = Global_kind;
   1414         p->v.Global.names = names;
   1415         p->lineno = lineno;
   1416         p->col_offset = col_offset;
   1417         return p;
   1418 }
   1419 
   1420 stmt_ty
   1421 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
   1422 {
   1423         stmt_ty p;
   1424         if (!value) {
   1425                 PyErr_SetString(PyExc_ValueError,
   1426                                 "field value is required for Expr");
   1427                 return NULL;
   1428         }
   1429         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1430         if (!p)
   1431                 return NULL;
   1432         p->kind = Expr_kind;
   1433         p->v.Expr.value = value;
   1434         p->lineno = lineno;
   1435         p->col_offset = col_offset;
   1436         return p;
   1437 }
   1438 
   1439 stmt_ty
   1440 Pass(int lineno, int col_offset, PyArena *arena)
   1441 {
   1442         stmt_ty p;
   1443         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1444         if (!p)
   1445                 return NULL;
   1446         p->kind = Pass_kind;
   1447         p->lineno = lineno;
   1448         p->col_offset = col_offset;
   1449         return p;
   1450 }
   1451 
   1452 stmt_ty
   1453 Break(int lineno, int col_offset, PyArena *arena)
   1454 {
   1455         stmt_ty p;
   1456         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1457         if (!p)
   1458                 return NULL;
   1459         p->kind = Break_kind;
   1460         p->lineno = lineno;
   1461         p->col_offset = col_offset;
   1462         return p;
   1463 }
   1464 
   1465 stmt_ty
   1466 Continue(int lineno, int col_offset, PyArena *arena)
   1467 {
   1468         stmt_ty p;
   1469         p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
   1470         if (!p)
   1471                 return NULL;
   1472         p->kind = Continue_kind;
   1473         p->lineno = lineno;
   1474         p->col_offset = col_offset;
   1475         return p;
   1476 }
   1477 
   1478 expr_ty
   1479 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
   1480        *arena)
   1481 {
   1482         expr_ty p;
   1483         if (!op) {
   1484                 PyErr_SetString(PyExc_ValueError,
   1485                                 "field op is required for BoolOp");
   1486                 return NULL;
   1487         }
   1488         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1489         if (!p)
   1490                 return NULL;
   1491         p->kind = BoolOp_kind;
   1492         p->v.BoolOp.op = op;
   1493         p->v.BoolOp.values = values;
   1494         p->lineno = lineno;
   1495         p->col_offset = col_offset;
   1496         return p;
   1497 }
   1498 
   1499 expr_ty
   1500 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
   1501       PyArena *arena)
   1502 {
   1503         expr_ty p;
   1504         if (!left) {
   1505                 PyErr_SetString(PyExc_ValueError,
   1506                                 "field left is required for BinOp");
   1507                 return NULL;
   1508         }
   1509         if (!op) {
   1510                 PyErr_SetString(PyExc_ValueError,
   1511                                 "field op is required for BinOp");
   1512                 return NULL;
   1513         }
   1514         if (!right) {
   1515                 PyErr_SetString(PyExc_ValueError,
   1516                                 "field right is required for BinOp");
   1517                 return NULL;
   1518         }
   1519         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1520         if (!p)
   1521                 return NULL;
   1522         p->kind = BinOp_kind;
   1523         p->v.BinOp.left = left;
   1524         p->v.BinOp.op = op;
   1525         p->v.BinOp.right = right;
   1526         p->lineno = lineno;
   1527         p->col_offset = col_offset;
   1528         return p;
   1529 }
   1530 
   1531 expr_ty
   1532 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
   1533         *arena)
   1534 {
   1535         expr_ty p;
   1536         if (!op) {
   1537                 PyErr_SetString(PyExc_ValueError,
   1538                                 "field op is required for UnaryOp");
   1539                 return NULL;
   1540         }
   1541         if (!operand) {
   1542                 PyErr_SetString(PyExc_ValueError,
   1543                                 "field operand is required for UnaryOp");
   1544                 return NULL;
   1545         }
   1546         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1547         if (!p)
   1548                 return NULL;
   1549         p->kind = UnaryOp_kind;
   1550         p->v.UnaryOp.op = op;
   1551         p->v.UnaryOp.operand = operand;
   1552         p->lineno = lineno;
   1553         p->col_offset = col_offset;
   1554         return p;
   1555 }
   1556 
   1557 expr_ty
   1558 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
   1559        *arena)
   1560 {
   1561         expr_ty p;
   1562         if (!args) {
   1563                 PyErr_SetString(PyExc_ValueError,
   1564                                 "field args is required for Lambda");
   1565                 return NULL;
   1566         }
   1567         if (!body) {
   1568                 PyErr_SetString(PyExc_ValueError,
   1569                                 "field body is required for Lambda");
   1570                 return NULL;
   1571         }
   1572         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1573         if (!p)
   1574                 return NULL;
   1575         p->kind = Lambda_kind;
   1576         p->v.Lambda.args = args;
   1577         p->v.Lambda.body = body;
   1578         p->lineno = lineno;
   1579         p->col_offset = col_offset;
   1580         return p;
   1581 }
   1582 
   1583 expr_ty
   1584 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
   1585       PyArena *arena)
   1586 {
   1587         expr_ty p;
   1588         if (!test) {
   1589                 PyErr_SetString(PyExc_ValueError,
   1590                                 "field test is required for IfExp");
   1591                 return NULL;
   1592         }
   1593         if (!body) {
   1594                 PyErr_SetString(PyExc_ValueError,
   1595                                 "field body is required for IfExp");
   1596                 return NULL;
   1597         }
   1598         if (!orelse) {
   1599                 PyErr_SetString(PyExc_ValueError,
   1600                                 "field orelse is required for IfExp");
   1601                 return NULL;
   1602         }
   1603         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1604         if (!p)
   1605                 return NULL;
   1606         p->kind = IfExp_kind;
   1607         p->v.IfExp.test = test;
   1608         p->v.IfExp.body = body;
   1609         p->v.IfExp.orelse = orelse;
   1610         p->lineno = lineno;
   1611         p->col_offset = col_offset;
   1612         return p;
   1613 }
   1614 
   1615 expr_ty
   1616 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
   1617      *arena)
   1618 {
   1619         expr_ty p;
   1620         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1621         if (!p)
   1622                 return NULL;
   1623         p->kind = Dict_kind;
   1624         p->v.Dict.keys = keys;
   1625         p->v.Dict.values = values;
   1626         p->lineno = lineno;
   1627         p->col_offset = col_offset;
   1628         return p;
   1629 }
   1630 
   1631 expr_ty
   1632 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
   1633 {
   1634         expr_ty p;
   1635         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1636         if (!p)
   1637                 return NULL;
   1638         p->kind = Set_kind;
   1639         p->v.Set.elts = elts;
   1640         p->lineno = lineno;
   1641         p->col_offset = col_offset;
   1642         return p;
   1643 }
   1644 
   1645 expr_ty
   1646 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
   1647          PyArena *arena)
   1648 {
   1649         expr_ty p;
   1650         if (!elt) {
   1651                 PyErr_SetString(PyExc_ValueError,
   1652                                 "field elt is required for ListComp");
   1653                 return NULL;
   1654         }
   1655         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1656         if (!p)
   1657                 return NULL;
   1658         p->kind = ListComp_kind;
   1659         p->v.ListComp.elt = elt;
   1660         p->v.ListComp.generators = generators;
   1661         p->lineno = lineno;
   1662         p->col_offset = col_offset;
   1663         return p;
   1664 }
   1665 
   1666 expr_ty
   1667 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
   1668         *arena)
   1669 {
   1670         expr_ty p;
   1671         if (!elt) {
   1672                 PyErr_SetString(PyExc_ValueError,
   1673                                 "field elt is required for SetComp");
   1674                 return NULL;
   1675         }
   1676         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1677         if (!p)
   1678                 return NULL;
   1679         p->kind = SetComp_kind;
   1680         p->v.SetComp.elt = elt;
   1681         p->v.SetComp.generators = generators;
   1682         p->lineno = lineno;
   1683         p->col_offset = col_offset;
   1684         return p;
   1685 }
   1686 
   1687 expr_ty
   1688 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
   1689          col_offset, PyArena *arena)
   1690 {
   1691         expr_ty p;
   1692         if (!key) {
   1693                 PyErr_SetString(PyExc_ValueError,
   1694                                 "field key is required for DictComp");
   1695                 return NULL;
   1696         }
   1697         if (!value) {
   1698                 PyErr_SetString(PyExc_ValueError,
   1699                                 "field value is required for DictComp");
   1700                 return NULL;
   1701         }
   1702         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1703         if (!p)
   1704                 return NULL;
   1705         p->kind = DictComp_kind;
   1706         p->v.DictComp.key = key;
   1707         p->v.DictComp.value = value;
   1708         p->v.DictComp.generators = generators;
   1709         p->lineno = lineno;
   1710         p->col_offset = col_offset;
   1711         return p;
   1712 }
   1713 
   1714 expr_ty
   1715 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
   1716              PyArena *arena)
   1717 {
   1718         expr_ty p;
   1719         if (!elt) {
   1720                 PyErr_SetString(PyExc_ValueError,
   1721                                 "field elt is required for GeneratorExp");
   1722                 return NULL;
   1723         }
   1724         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1725         if (!p)
   1726                 return NULL;
   1727         p->kind = GeneratorExp_kind;
   1728         p->v.GeneratorExp.elt = elt;
   1729         p->v.GeneratorExp.generators = generators;
   1730         p->lineno = lineno;
   1731         p->col_offset = col_offset;
   1732         return p;
   1733 }
   1734 
   1735 expr_ty
   1736 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
   1737 {
   1738         expr_ty p;
   1739         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1740         if (!p)
   1741                 return NULL;
   1742         p->kind = Yield_kind;
   1743         p->v.Yield.value = value;
   1744         p->lineno = lineno;
   1745         p->col_offset = col_offset;
   1746         return p;
   1747 }
   1748 
   1749 expr_ty
   1750 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
   1751         int col_offset, PyArena *arena)
   1752 {
   1753         expr_ty p;
   1754         if (!left) {
   1755                 PyErr_SetString(PyExc_ValueError,
   1756                                 "field left is required for Compare");
   1757                 return NULL;
   1758         }
   1759         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1760         if (!p)
   1761                 return NULL;
   1762         p->kind = Compare_kind;
   1763         p->v.Compare.left = left;
   1764         p->v.Compare.ops = ops;
   1765         p->v.Compare.comparators = comparators;
   1766         p->lineno = lineno;
   1767         p->col_offset = col_offset;
   1768         return p;
   1769 }
   1770 
   1771 expr_ty
   1772 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
   1773      expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
   1774 {
   1775         expr_ty p;
   1776         if (!func) {
   1777                 PyErr_SetString(PyExc_ValueError,
   1778                                 "field func is required for Call");
   1779                 return NULL;
   1780         }
   1781         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1782         if (!p)
   1783                 return NULL;
   1784         p->kind = Call_kind;
   1785         p->v.Call.func = func;
   1786         p->v.Call.args = args;
   1787         p->v.Call.keywords = keywords;
   1788         p->v.Call.starargs = starargs;
   1789         p->v.Call.kwargs = kwargs;
   1790         p->lineno = lineno;
   1791         p->col_offset = col_offset;
   1792         return p;
   1793 }
   1794 
   1795 expr_ty
   1796 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
   1797 {
   1798         expr_ty p;
   1799         if (!value) {
   1800                 PyErr_SetString(PyExc_ValueError,
   1801                                 "field value is required for Repr");
   1802                 return NULL;
   1803         }
   1804         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1805         if (!p)
   1806                 return NULL;
   1807         p->kind = Repr_kind;
   1808         p->v.Repr.value = value;
   1809         p->lineno = lineno;
   1810         p->col_offset = col_offset;
   1811         return p;
   1812 }
   1813 
   1814 expr_ty
   1815 Num(object n, int lineno, int col_offset, PyArena *arena)
   1816 {
   1817         expr_ty p;
   1818         if (!n) {
   1819                 PyErr_SetString(PyExc_ValueError,
   1820                                 "field n is required for Num");
   1821                 return NULL;
   1822         }
   1823         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1824         if (!p)
   1825                 return NULL;
   1826         p->kind = Num_kind;
   1827         p->v.Num.n = n;
   1828         p->lineno = lineno;
   1829         p->col_offset = col_offset;
   1830         return p;
   1831 }
   1832 
   1833 expr_ty
   1834 Str(string s, int lineno, int col_offset, PyArena *arena)
   1835 {
   1836         expr_ty p;
   1837         if (!s) {
   1838                 PyErr_SetString(PyExc_ValueError,
   1839                                 "field s is required for Str");
   1840                 return NULL;
   1841         }
   1842         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1843         if (!p)
   1844                 return NULL;
   1845         p->kind = Str_kind;
   1846         p->v.Str.s = s;
   1847         p->lineno = lineno;
   1848         p->col_offset = col_offset;
   1849         return p;
   1850 }
   1851 
   1852 expr_ty
   1853 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
   1854           col_offset, PyArena *arena)
   1855 {
   1856         expr_ty p;
   1857         if (!value) {
   1858                 PyErr_SetString(PyExc_ValueError,
   1859                                 "field value is required for Attribute");
   1860                 return NULL;
   1861         }
   1862         if (!attr) {
   1863                 PyErr_SetString(PyExc_ValueError,
   1864                                 "field attr is required for Attribute");
   1865                 return NULL;
   1866         }
   1867         if (!ctx) {
   1868                 PyErr_SetString(PyExc_ValueError,
   1869                                 "field ctx is required for Attribute");
   1870                 return NULL;
   1871         }
   1872         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1873         if (!p)
   1874                 return NULL;
   1875         p->kind = Attribute_kind;
   1876         p->v.Attribute.value = value;
   1877         p->v.Attribute.attr = attr;
   1878         p->v.Attribute.ctx = ctx;
   1879         p->lineno = lineno;
   1880         p->col_offset = col_offset;
   1881         return p;
   1882 }
   1883 
   1884 expr_ty
   1885 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
   1886           col_offset, PyArena *arena)
   1887 {
   1888         expr_ty p;
   1889         if (!value) {
   1890                 PyErr_SetString(PyExc_ValueError,
   1891                                 "field value is required for Subscript");
   1892                 return NULL;
   1893         }
   1894         if (!slice) {
   1895                 PyErr_SetString(PyExc_ValueError,
   1896                                 "field slice is required for Subscript");
   1897                 return NULL;
   1898         }
   1899         if (!ctx) {
   1900                 PyErr_SetString(PyExc_ValueError,
   1901                                 "field ctx is required for Subscript");
   1902                 return NULL;
   1903         }
   1904         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1905         if (!p)
   1906                 return NULL;
   1907         p->kind = Subscript_kind;
   1908         p->v.Subscript.value = value;
   1909         p->v.Subscript.slice = slice;
   1910         p->v.Subscript.ctx = ctx;
   1911         p->lineno = lineno;
   1912         p->col_offset = col_offset;
   1913         return p;
   1914 }
   1915 
   1916 expr_ty
   1917 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
   1918      *arena)
   1919 {
   1920         expr_ty p;
   1921         if (!id) {
   1922                 PyErr_SetString(PyExc_ValueError,
   1923                                 "field id is required for Name");
   1924                 return NULL;
   1925         }
   1926         if (!ctx) {
   1927                 PyErr_SetString(PyExc_ValueError,
   1928                                 "field ctx is required for Name");
   1929                 return NULL;
   1930         }
   1931         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1932         if (!p)
   1933                 return NULL;
   1934         p->kind = Name_kind;
   1935         p->v.Name.id = id;
   1936         p->v.Name.ctx = ctx;
   1937         p->lineno = lineno;
   1938         p->col_offset = col_offset;
   1939         return p;
   1940 }
   1941 
   1942 expr_ty
   1943 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
   1944      *arena)
   1945 {
   1946         expr_ty p;
   1947         if (!ctx) {
   1948                 PyErr_SetString(PyExc_ValueError,
   1949                                 "field ctx is required for List");
   1950                 return NULL;
   1951         }
   1952         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1953         if (!p)
   1954                 return NULL;
   1955         p->kind = List_kind;
   1956         p->v.List.elts = elts;
   1957         p->v.List.ctx = ctx;
   1958         p->lineno = lineno;
   1959         p->col_offset = col_offset;
   1960         return p;
   1961 }
   1962 
   1963 expr_ty
   1964 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
   1965       *arena)
   1966 {
   1967         expr_ty p;
   1968         if (!ctx) {
   1969                 PyErr_SetString(PyExc_ValueError,
   1970                                 "field ctx is required for Tuple");
   1971                 return NULL;
   1972         }
   1973         p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
   1974         if (!p)
   1975                 return NULL;
   1976         p->kind = Tuple_kind;
   1977         p->v.Tuple.elts = elts;
   1978         p->v.Tuple.ctx = ctx;
   1979         p->lineno = lineno;
   1980         p->col_offset = col_offset;
   1981         return p;
   1982 }
   1983 
   1984 slice_ty
   1985 Ellipsis(PyArena *arena)
   1986 {
   1987         slice_ty p;
   1988         p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
   1989         if (!p)
   1990                 return NULL;
   1991         p->kind = Ellipsis_kind;
   1992         return p;
   1993 }
   1994 
   1995 slice_ty
   1996 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
   1997 {
   1998         slice_ty p;
   1999         p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
   2000         if (!p)
   2001                 return NULL;
   2002         p->kind = Slice_kind;
   2003         p->v.Slice.lower = lower;
   2004         p->v.Slice.upper = upper;
   2005         p->v.Slice.step = step;
   2006         return p;
   2007 }
   2008 
   2009 slice_ty
   2010 ExtSlice(asdl_seq * dims, PyArena *arena)
   2011 {
   2012         slice_ty p;
   2013         p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
   2014         if (!p)
   2015                 return NULL;
   2016         p->kind = ExtSlice_kind;
   2017         p->v.ExtSlice.dims = dims;
   2018         return p;
   2019 }
   2020 
   2021 slice_ty
   2022 Index(expr_ty value, PyArena *arena)
   2023 {
   2024         slice_ty p;
   2025         if (!value) {
   2026                 PyErr_SetString(PyExc_ValueError,
   2027                                 "field value is required for Index");
   2028                 return NULL;
   2029         }
   2030         p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
   2031         if (!p)
   2032                 return NULL;
   2033         p->kind = Index_kind;
   2034         p->v.Index.value = value;
   2035         return p;
   2036 }
   2037 
   2038 comprehension_ty
   2039 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
   2040 {
   2041         comprehension_ty p;
   2042         if (!target) {
   2043                 PyErr_SetString(PyExc_ValueError,
   2044                                 "field target is required for comprehension");
   2045                 return NULL;
   2046         }
   2047         if (!iter) {
   2048                 PyErr_SetString(PyExc_ValueError,
   2049                                 "field iter is required for comprehension");
   2050                 return NULL;
   2051         }
   2052         p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
   2053         if (!p)
   2054                 return NULL;
   2055         p->target = target;
   2056         p->iter = iter;
   2057         p->ifs = ifs;
   2058         return p;
   2059 }
   2060 
   2061 excepthandler_ty
   2062 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
   2063               col_offset, PyArena *arena)
   2064 {
   2065         excepthandler_ty p;
   2066         p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
   2067         if (!p)
   2068                 return NULL;
   2069         p->kind = ExceptHandler_kind;
   2070         p->v.ExceptHandler.type = type;
   2071         p->v.ExceptHandler.name = name;
   2072         p->v.ExceptHandler.body = body;
   2073         p->lineno = lineno;
   2074         p->col_offset = col_offset;
   2075         return p;
   2076 }
   2077 
   2078 arguments_ty
   2079 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
   2080           defaults, PyArena *arena)
   2081 {
   2082         arguments_ty p;
   2083         p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
   2084         if (!p)
   2085                 return NULL;
   2086         p->args = args;
   2087         p->vararg = vararg;
   2088         p->kwarg = kwarg;
   2089         p->defaults = defaults;
   2090         return p;
   2091 }
   2092 
   2093 keyword_ty
   2094 keyword(identifier arg, expr_ty value, PyArena *arena)
   2095 {
   2096         keyword_ty p;
   2097         if (!arg) {
   2098                 PyErr_SetString(PyExc_ValueError,
   2099                                 "field arg is required for keyword");
   2100                 return NULL;
   2101         }
   2102         if (!value) {
   2103                 PyErr_SetString(PyExc_ValueError,
   2104                                 "field value is required for keyword");
   2105                 return NULL;
   2106         }
   2107         p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
   2108         if (!p)
   2109                 return NULL;
   2110         p->arg = arg;
   2111         p->value = value;
   2112         return p;
   2113 }
   2114 
   2115 alias_ty
   2116 alias(identifier name, identifier asname, PyArena *arena)
   2117 {
   2118         alias_ty p;
   2119         if (!name) {
   2120                 PyErr_SetString(PyExc_ValueError,
   2121                                 "field name is required for alias");
   2122                 return NULL;
   2123         }
   2124         p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
   2125         if (!p)
   2126                 return NULL;
   2127         p->name = name;
   2128         p->asname = asname;
   2129         return p;
   2130 }
   2131 
   2132 
   2133 PyObject*
   2134 ast2obj_mod(void* _o)
   2135 {
   2136         mod_ty o = (mod_ty)_o;
   2137         PyObject *result = NULL, *value = NULL;
   2138         if (!o) {
   2139                 Py_INCREF(Py_None);
   2140                 return Py_None;
   2141         }
   2142 
   2143         switch (o->kind) {
   2144         case Module_kind:
   2145                 result = PyType_GenericNew(Module_type, NULL, NULL);
   2146                 if (!result) goto failed;
   2147                 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
   2148                 if (!value) goto failed;
   2149                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2150                         goto failed;
   2151                 Py_DECREF(value);
   2152                 break;
   2153         case Interactive_kind:
   2154                 result = PyType_GenericNew(Interactive_type, NULL, NULL);
   2155                 if (!result) goto failed;
   2156                 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
   2157                 if (!value) goto failed;
   2158                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2159                         goto failed;
   2160                 Py_DECREF(value);
   2161                 break;
   2162         case Expression_kind:
   2163                 result = PyType_GenericNew(Expression_type, NULL, NULL);
   2164                 if (!result) goto failed;
   2165                 value = ast2obj_expr(o->v.Expression.body);
   2166                 if (!value) goto failed;
   2167                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2168                         goto failed;
   2169                 Py_DECREF(value);
   2170                 break;
   2171         case Suite_kind:
   2172                 result = PyType_GenericNew(Suite_type, NULL, NULL);
   2173                 if (!result) goto failed;
   2174                 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
   2175                 if (!value) goto failed;
   2176                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2177                         goto failed;
   2178                 Py_DECREF(value);
   2179                 break;
   2180         }
   2181         return result;
   2182 failed:
   2183         Py_XDECREF(value);
   2184         Py_XDECREF(result);
   2185         return NULL;
   2186 }
   2187 
   2188 PyObject*
   2189 ast2obj_stmt(void* _o)
   2190 {
   2191         stmt_ty o = (stmt_ty)_o;
   2192         PyObject *result = NULL, *value = NULL;
   2193         if (!o) {
   2194                 Py_INCREF(Py_None);
   2195                 return Py_None;
   2196         }
   2197 
   2198         switch (o->kind) {
   2199         case FunctionDef_kind:
   2200                 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
   2201                 if (!result) goto failed;
   2202                 value = ast2obj_identifier(o->v.FunctionDef.name);
   2203                 if (!value) goto failed;
   2204                 if (PyObject_SetAttrString(result, "name", value) == -1)
   2205                         goto failed;
   2206                 Py_DECREF(value);
   2207                 value = ast2obj_arguments(o->v.FunctionDef.args);
   2208                 if (!value) goto failed;
   2209                 if (PyObject_SetAttrString(result, "args", value) == -1)
   2210                         goto failed;
   2211                 Py_DECREF(value);
   2212                 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
   2213                 if (!value) goto failed;
   2214                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2215                         goto failed;
   2216                 Py_DECREF(value);
   2217                 value = ast2obj_list(o->v.FunctionDef.decorator_list,
   2218                                      ast2obj_expr);
   2219                 if (!value) goto failed;
   2220                 if (PyObject_SetAttrString(result, "decorator_list", value) ==
   2221                     -1)
   2222                         goto failed;
   2223                 Py_DECREF(value);
   2224                 break;
   2225         case ClassDef_kind:
   2226                 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
   2227                 if (!result) goto failed;
   2228                 value = ast2obj_identifier(o->v.ClassDef.name);
   2229                 if (!value) goto failed;
   2230                 if (PyObject_SetAttrString(result, "name", value) == -1)
   2231                         goto failed;
   2232                 Py_DECREF(value);
   2233                 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
   2234                 if (!value) goto failed;
   2235                 if (PyObject_SetAttrString(result, "bases", value) == -1)
   2236                         goto failed;
   2237                 Py_DECREF(value);
   2238                 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
   2239                 if (!value) goto failed;
   2240                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2241                         goto failed;
   2242                 Py_DECREF(value);
   2243                 value = ast2obj_list(o->v.ClassDef.decorator_list,
   2244                                      ast2obj_expr);
   2245                 if (!value) goto failed;
   2246                 if (PyObject_SetAttrString(result, "decorator_list", value) ==
   2247                     -1)
   2248                         goto failed;
   2249                 Py_DECREF(value);
   2250                 break;
   2251         case Return_kind:
   2252                 result = PyType_GenericNew(Return_type, NULL, NULL);
   2253                 if (!result) goto failed;
   2254                 value = ast2obj_expr(o->v.Return.value);
   2255                 if (!value) goto failed;
   2256                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2257                         goto failed;
   2258                 Py_DECREF(value);
   2259                 break;
   2260         case Delete_kind:
   2261                 result = PyType_GenericNew(Delete_type, NULL, NULL);
   2262                 if (!result) goto failed;
   2263                 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
   2264                 if (!value) goto failed;
   2265                 if (PyObject_SetAttrString(result, "targets", value) == -1)
   2266                         goto failed;
   2267                 Py_DECREF(value);
   2268                 break;
   2269         case Assign_kind:
   2270                 result = PyType_GenericNew(Assign_type, NULL, NULL);
   2271                 if (!result) goto failed;
   2272                 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
   2273                 if (!value) goto failed;
   2274                 if (PyObject_SetAttrString(result, "targets", value) == -1)
   2275                         goto failed;
   2276                 Py_DECREF(value);
   2277                 value = ast2obj_expr(o->v.Assign.value);
   2278                 if (!value) goto failed;
   2279                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2280                         goto failed;
   2281                 Py_DECREF(value);
   2282                 break;
   2283         case AugAssign_kind:
   2284                 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
   2285                 if (!result) goto failed;
   2286                 value = ast2obj_expr(o->v.AugAssign.target);
   2287                 if (!value) goto failed;
   2288                 if (PyObject_SetAttrString(result, "target", value) == -1)
   2289                         goto failed;
   2290                 Py_DECREF(value);
   2291                 value = ast2obj_operator(o->v.AugAssign.op);
   2292                 if (!value) goto failed;
   2293                 if (PyObject_SetAttrString(result, "op", value) == -1)
   2294                         goto failed;
   2295                 Py_DECREF(value);
   2296                 value = ast2obj_expr(o->v.AugAssign.value);
   2297                 if (!value) goto failed;
   2298                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2299                         goto failed;
   2300                 Py_DECREF(value);
   2301                 break;
   2302         case Print_kind:
   2303                 result = PyType_GenericNew(Print_type, NULL, NULL);
   2304                 if (!result) goto failed;
   2305                 value = ast2obj_expr(o->v.Print.dest);
   2306                 if (!value) goto failed;
   2307                 if (PyObject_SetAttrString(result, "dest", value) == -1)
   2308                         goto failed;
   2309                 Py_DECREF(value);
   2310                 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
   2311                 if (!value) goto failed;
   2312                 if (PyObject_SetAttrString(result, "values", value) == -1)
   2313                         goto failed;
   2314                 Py_DECREF(value);
   2315                 value = ast2obj_bool(o->v.Print.nl);
   2316                 if (!value) goto failed;
   2317                 if (PyObject_SetAttrString(result, "nl", value) == -1)
   2318                         goto failed;
   2319                 Py_DECREF(value);
   2320                 break;
   2321         case For_kind:
   2322                 result = PyType_GenericNew(For_type, NULL, NULL);
   2323                 if (!result) goto failed;
   2324                 value = ast2obj_expr(o->v.For.target);
   2325                 if (!value) goto failed;
   2326                 if (PyObject_SetAttrString(result, "target", value) == -1)
   2327                         goto failed;
   2328                 Py_DECREF(value);
   2329                 value = ast2obj_expr(o->v.For.iter);
   2330                 if (!value) goto failed;
   2331                 if (PyObject_SetAttrString(result, "iter", value) == -1)
   2332                         goto failed;
   2333                 Py_DECREF(value);
   2334                 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
   2335                 if (!value) goto failed;
   2336                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2337                         goto failed;
   2338                 Py_DECREF(value);
   2339                 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
   2340                 if (!value) goto failed;
   2341                 if (PyObject_SetAttrString(result, "orelse", value) == -1)
   2342                         goto failed;
   2343                 Py_DECREF(value);
   2344                 break;
   2345         case While_kind:
   2346                 result = PyType_GenericNew(While_type, NULL, NULL);
   2347                 if (!result) goto failed;
   2348                 value = ast2obj_expr(o->v.While.test);
   2349                 if (!value) goto failed;
   2350                 if (PyObject_SetAttrString(result, "test", value) == -1)
   2351                         goto failed;
   2352                 Py_DECREF(value);
   2353                 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
   2354                 if (!value) goto failed;
   2355                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2356                         goto failed;
   2357                 Py_DECREF(value);
   2358                 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
   2359                 if (!value) goto failed;
   2360                 if (PyObject_SetAttrString(result, "orelse", value) == -1)
   2361                         goto failed;
   2362                 Py_DECREF(value);
   2363                 break;
   2364         case If_kind:
   2365                 result = PyType_GenericNew(If_type, NULL, NULL);
   2366                 if (!result) goto failed;
   2367                 value = ast2obj_expr(o->v.If.test);
   2368                 if (!value) goto failed;
   2369                 if (PyObject_SetAttrString(result, "test", value) == -1)
   2370                         goto failed;
   2371                 Py_DECREF(value);
   2372                 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
   2373                 if (!value) goto failed;
   2374                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2375                         goto failed;
   2376                 Py_DECREF(value);
   2377                 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
   2378                 if (!value) goto failed;
   2379                 if (PyObject_SetAttrString(result, "orelse", value) == -1)
   2380                         goto failed;
   2381                 Py_DECREF(value);
   2382                 break;
   2383         case With_kind:
   2384                 result = PyType_GenericNew(With_type, NULL, NULL);
   2385                 if (!result) goto failed;
   2386                 value = ast2obj_expr(o->v.With.context_expr);
   2387                 if (!value) goto failed;
   2388                 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
   2389                         goto failed;
   2390                 Py_DECREF(value);
   2391                 value = ast2obj_expr(o->v.With.optional_vars);
   2392                 if (!value) goto failed;
   2393                 if (PyObject_SetAttrString(result, "optional_vars", value) ==
   2394                     -1)
   2395                         goto failed;
   2396                 Py_DECREF(value);
   2397                 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
   2398                 if (!value) goto failed;
   2399                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2400                         goto failed;
   2401                 Py_DECREF(value);
   2402                 break;
   2403         case Raise_kind:
   2404                 result = PyType_GenericNew(Raise_type, NULL, NULL);
   2405                 if (!result) goto failed;
   2406                 value = ast2obj_expr(o->v.Raise.type);
   2407                 if (!value) goto failed;
   2408                 if (PyObject_SetAttrString(result, "type", value) == -1)
   2409                         goto failed;
   2410                 Py_DECREF(value);
   2411                 value = ast2obj_expr(o->v.Raise.inst);
   2412                 if (!value) goto failed;
   2413                 if (PyObject_SetAttrString(result, "inst", value) == -1)
   2414                         goto failed;
   2415                 Py_DECREF(value);
   2416                 value = ast2obj_expr(o->v.Raise.tback);
   2417                 if (!value) goto failed;
   2418                 if (PyObject_SetAttrString(result, "tback", value) == -1)
   2419                         goto failed;
   2420                 Py_DECREF(value);
   2421                 break;
   2422         case TryExcept_kind:
   2423                 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
   2424                 if (!result) goto failed;
   2425                 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
   2426                 if (!value) goto failed;
   2427                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2428                         goto failed;
   2429                 Py_DECREF(value);
   2430                 value = ast2obj_list(o->v.TryExcept.handlers,
   2431                                      ast2obj_excepthandler);
   2432                 if (!value) goto failed;
   2433                 if (PyObject_SetAttrString(result, "handlers", value) == -1)
   2434                         goto failed;
   2435                 Py_DECREF(value);
   2436                 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
   2437                 if (!value) goto failed;
   2438                 if (PyObject_SetAttrString(result, "orelse", value) == -1)
   2439                         goto failed;
   2440                 Py_DECREF(value);
   2441                 break;
   2442         case TryFinally_kind:
   2443                 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
   2444                 if (!result) goto failed;
   2445                 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
   2446                 if (!value) goto failed;
   2447                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2448                         goto failed;
   2449                 Py_DECREF(value);
   2450                 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
   2451                 if (!value) goto failed;
   2452                 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
   2453                         goto failed;
   2454                 Py_DECREF(value);
   2455                 break;
   2456         case Assert_kind:
   2457                 result = PyType_GenericNew(Assert_type, NULL, NULL);
   2458                 if (!result) goto failed;
   2459                 value = ast2obj_expr(o->v.Assert.test);
   2460                 if (!value) goto failed;
   2461                 if (PyObject_SetAttrString(result, "test", value) == -1)
   2462                         goto failed;
   2463                 Py_DECREF(value);
   2464                 value = ast2obj_expr(o->v.Assert.msg);
   2465                 if (!value) goto failed;
   2466                 if (PyObject_SetAttrString(result, "msg", value) == -1)
   2467                         goto failed;
   2468                 Py_DECREF(value);
   2469                 break;
   2470         case Import_kind:
   2471                 result = PyType_GenericNew(Import_type, NULL, NULL);
   2472                 if (!result) goto failed;
   2473                 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
   2474                 if (!value) goto failed;
   2475                 if (PyObject_SetAttrString(result, "names", value) == -1)
   2476                         goto failed;
   2477                 Py_DECREF(value);
   2478                 break;
   2479         case ImportFrom_kind:
   2480                 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
   2481                 if (!result) goto failed;
   2482                 value = ast2obj_identifier(o->v.ImportFrom.module);
   2483                 if (!value) goto failed;
   2484                 if (PyObject_SetAttrString(result, "module", value) == -1)
   2485                         goto failed;
   2486                 Py_DECREF(value);
   2487                 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
   2488                 if (!value) goto failed;
   2489                 if (PyObject_SetAttrString(result, "names", value) == -1)
   2490                         goto failed;
   2491                 Py_DECREF(value);
   2492                 value = ast2obj_int(o->v.ImportFrom.level);
   2493                 if (!value) goto failed;
   2494                 if (PyObject_SetAttrString(result, "level", value) == -1)
   2495                         goto failed;
   2496                 Py_DECREF(value);
   2497                 break;
   2498         case Exec_kind:
   2499                 result = PyType_GenericNew(Exec_type, NULL, NULL);
   2500                 if (!result) goto failed;
   2501                 value = ast2obj_expr(o->v.Exec.body);
   2502                 if (!value) goto failed;
   2503                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2504                         goto failed;
   2505                 Py_DECREF(value);
   2506                 value = ast2obj_expr(o->v.Exec.globals);
   2507                 if (!value) goto failed;
   2508                 if (PyObject_SetAttrString(result, "globals", value) == -1)
   2509                         goto failed;
   2510                 Py_DECREF(value);
   2511                 value = ast2obj_expr(o->v.Exec.locals);
   2512                 if (!value) goto failed;
   2513                 if (PyObject_SetAttrString(result, "locals", value) == -1)
   2514                         goto failed;
   2515                 Py_DECREF(value);
   2516                 break;
   2517         case Global_kind:
   2518                 result = PyType_GenericNew(Global_type, NULL, NULL);
   2519                 if (!result) goto failed;
   2520                 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
   2521                 if (!value) goto failed;
   2522                 if (PyObject_SetAttrString(result, "names", value) == -1)
   2523                         goto failed;
   2524                 Py_DECREF(value);
   2525                 break;
   2526         case Expr_kind:
   2527                 result = PyType_GenericNew(Expr_type, NULL, NULL);
   2528                 if (!result) goto failed;
   2529                 value = ast2obj_expr(o->v.Expr.value);
   2530                 if (!value) goto failed;
   2531                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2532                         goto failed;
   2533                 Py_DECREF(value);
   2534                 break;
   2535         case Pass_kind:
   2536                 result = PyType_GenericNew(Pass_type, NULL, NULL);
   2537                 if (!result) goto failed;
   2538                 break;
   2539         case Break_kind:
   2540                 result = PyType_GenericNew(Break_type, NULL, NULL);
   2541                 if (!result) goto failed;
   2542                 break;
   2543         case Continue_kind:
   2544                 result = PyType_GenericNew(Continue_type, NULL, NULL);
   2545                 if (!result) goto failed;
   2546                 break;
   2547         }
   2548         value = ast2obj_int(o->lineno);
   2549         if (!value) goto failed;
   2550         if (PyObject_SetAttrString(result, "lineno", value) < 0)
   2551                 goto failed;
   2552         Py_DECREF(value);
   2553         value = ast2obj_int(o->col_offset);
   2554         if (!value) goto failed;
   2555         if (PyObject_SetAttrString(result, "col_offset", value) < 0)
   2556                 goto failed;
   2557         Py_DECREF(value);
   2558         return result;
   2559 failed:
   2560         Py_XDECREF(value);
   2561         Py_XDECREF(result);
   2562         return NULL;
   2563 }
   2564 
   2565 PyObject*
   2566 ast2obj_expr(void* _o)
   2567 {
   2568         expr_ty o = (expr_ty)_o;
   2569         PyObject *result = NULL, *value = NULL;
   2570         if (!o) {
   2571                 Py_INCREF(Py_None);
   2572                 return Py_None;
   2573         }
   2574 
   2575         switch (o->kind) {
   2576         case BoolOp_kind:
   2577                 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
   2578                 if (!result) goto failed;
   2579                 value = ast2obj_boolop(o->v.BoolOp.op);
   2580                 if (!value) goto failed;
   2581                 if (PyObject_SetAttrString(result, "op", value) == -1)
   2582                         goto failed;
   2583                 Py_DECREF(value);
   2584                 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
   2585                 if (!value) goto failed;
   2586                 if (PyObject_SetAttrString(result, "values", value) == -1)
   2587                         goto failed;
   2588                 Py_DECREF(value);
   2589                 break;
   2590         case BinOp_kind:
   2591                 result = PyType_GenericNew(BinOp_type, NULL, NULL);
   2592                 if (!result) goto failed;
   2593                 value = ast2obj_expr(o->v.BinOp.left);
   2594                 if (!value) goto failed;
   2595                 if (PyObject_SetAttrString(result, "left", value) == -1)
   2596                         goto failed;
   2597                 Py_DECREF(value);
   2598                 value = ast2obj_operator(o->v.BinOp.op);
   2599                 if (!value) goto failed;
   2600                 if (PyObject_SetAttrString(result, "op", value) == -1)
   2601                         goto failed;
   2602                 Py_DECREF(value);
   2603                 value = ast2obj_expr(o->v.BinOp.right);
   2604                 if (!value) goto failed;
   2605                 if (PyObject_SetAttrString(result, "right", value) == -1)
   2606                         goto failed;
   2607                 Py_DECREF(value);
   2608                 break;
   2609         case UnaryOp_kind:
   2610                 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
   2611                 if (!result) goto failed;
   2612                 value = ast2obj_unaryop(o->v.UnaryOp.op);
   2613                 if (!value) goto failed;
   2614                 if (PyObject_SetAttrString(result, "op", value) == -1)
   2615                         goto failed;
   2616                 Py_DECREF(value);
   2617                 value = ast2obj_expr(o->v.UnaryOp.operand);
   2618                 if (!value) goto failed;
   2619                 if (PyObject_SetAttrString(result, "operand", value) == -1)
   2620                         goto failed;
   2621                 Py_DECREF(value);
   2622                 break;
   2623         case Lambda_kind:
   2624                 result = PyType_GenericNew(Lambda_type, NULL, NULL);
   2625                 if (!result) goto failed;
   2626                 value = ast2obj_arguments(o->v.Lambda.args);
   2627                 if (!value) goto failed;
   2628                 if (PyObject_SetAttrString(result, "args", value) == -1)
   2629                         goto failed;
   2630                 Py_DECREF(value);
   2631                 value = ast2obj_expr(o->v.Lambda.body);
   2632                 if (!value) goto failed;
   2633                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2634                         goto failed;
   2635                 Py_DECREF(value);
   2636                 break;
   2637         case IfExp_kind:
   2638                 result = PyType_GenericNew(IfExp_type, NULL, NULL);
   2639                 if (!result) goto failed;
   2640                 value = ast2obj_expr(o->v.IfExp.test);
   2641                 if (!value) goto failed;
   2642                 if (PyObject_SetAttrString(result, "test", value) == -1)
   2643                         goto failed;
   2644                 Py_DECREF(value);
   2645                 value = ast2obj_expr(o->v.IfExp.body);
   2646                 if (!value) goto failed;
   2647                 if (PyObject_SetAttrString(result, "body", value) == -1)
   2648                         goto failed;
   2649                 Py_DECREF(value);
   2650                 value = ast2obj_expr(o->v.IfExp.orelse);
   2651                 if (!value) goto failed;
   2652                 if (PyObject_SetAttrString(result, "orelse", value) == -1)
   2653                         goto failed;
   2654                 Py_DECREF(value);
   2655                 break;
   2656         case Dict_kind:
   2657                 result = PyType_GenericNew(Dict_type, NULL, NULL);
   2658                 if (!result) goto failed;
   2659                 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
   2660                 if (!value) goto failed;
   2661                 if (PyObject_SetAttrString(result, "keys", value) == -1)
   2662                         goto failed;
   2663                 Py_DECREF(value);
   2664                 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
   2665                 if (!value) goto failed;
   2666                 if (PyObject_SetAttrString(result, "values", value) == -1)
   2667                         goto failed;
   2668                 Py_DECREF(value);
   2669                 break;
   2670         case Set_kind:
   2671                 result = PyType_GenericNew(Set_type, NULL, NULL);
   2672                 if (!result) goto failed;
   2673                 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
   2674                 if (!value) goto failed;
   2675                 if (PyObject_SetAttrString(result, "elts", value) == -1)
   2676                         goto failed;
   2677                 Py_DECREF(value);
   2678                 break;
   2679         case ListComp_kind:
   2680                 result = PyType_GenericNew(ListComp_type, NULL, NULL);
   2681                 if (!result) goto failed;
   2682                 value = ast2obj_expr(o->v.ListComp.elt);
   2683                 if (!value) goto failed;
   2684                 if (PyObject_SetAttrString(result, "elt", value) == -1)
   2685                         goto failed;
   2686                 Py_DECREF(value);
   2687                 value = ast2obj_list(o->v.ListComp.generators,
   2688                                      ast2obj_comprehension);
   2689                 if (!value) goto failed;
   2690                 if (PyObject_SetAttrString(result, "generators", value) == -1)
   2691                         goto failed;
   2692                 Py_DECREF(value);
   2693                 break;
   2694         case SetComp_kind:
   2695                 result = PyType_GenericNew(SetComp_type, NULL, NULL);
   2696                 if (!result) goto failed;
   2697                 value = ast2obj_expr(o->v.SetComp.elt);
   2698                 if (!value) goto failed;
   2699                 if (PyObject_SetAttrString(result, "elt", value) == -1)
   2700                         goto failed;
   2701                 Py_DECREF(value);
   2702                 value = ast2obj_list(o->v.SetComp.generators,
   2703                                      ast2obj_comprehension);
   2704                 if (!value) goto failed;
   2705                 if (PyObject_SetAttrString(result, "generators", value) == -1)
   2706                         goto failed;
   2707                 Py_DECREF(value);
   2708                 break;
   2709         case DictComp_kind:
   2710                 result = PyType_GenericNew(DictComp_type, NULL, NULL);
   2711                 if (!result) goto failed;
   2712                 value = ast2obj_expr(o->v.DictComp.key);
   2713                 if (!value) goto failed;
   2714                 if (PyObject_SetAttrString(result, "key", value) == -1)
   2715                         goto failed;
   2716                 Py_DECREF(value);
   2717                 value = ast2obj_expr(o->v.DictComp.value);
   2718                 if (!value) goto failed;
   2719                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2720                         goto failed;
   2721                 Py_DECREF(value);
   2722                 value = ast2obj_list(o->v.DictComp.generators,
   2723                                      ast2obj_comprehension);
   2724                 if (!value) goto failed;
   2725                 if (PyObject_SetAttrString(result, "generators", value) == -1)
   2726                         goto failed;
   2727                 Py_DECREF(value);
   2728                 break;
   2729         case GeneratorExp_kind:
   2730                 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
   2731                 if (!result) goto failed;
   2732                 value = ast2obj_expr(o->v.GeneratorExp.elt);
   2733                 if (!value) goto failed;
   2734                 if (PyObject_SetAttrString(result, "elt", value) == -1)
   2735                         goto failed;
   2736                 Py_DECREF(value);
   2737                 value = ast2obj_list(o->v.GeneratorExp.generators,
   2738                                      ast2obj_comprehension);
   2739                 if (!value) goto failed;
   2740                 if (PyObject_SetAttrString(result, "generators", value) == -1)
   2741                         goto failed;
   2742                 Py_DECREF(value);
   2743                 break;
   2744         case Yield_kind:
   2745                 result = PyType_GenericNew(Yield_type, NULL, NULL);
   2746                 if (!result) goto failed;
   2747                 value = ast2obj_expr(o->v.Yield.value);
   2748                 if (!value) goto failed;
   2749                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2750                         goto failed;
   2751                 Py_DECREF(value);
   2752                 break;
   2753         case Compare_kind:
   2754                 result = PyType_GenericNew(Compare_type, NULL, NULL);
   2755                 if (!result) goto failed;
   2756                 value = ast2obj_expr(o->v.Compare.left);
   2757                 if (!value) goto failed;
   2758                 if (PyObject_SetAttrString(result, "left", value) == -1)
   2759                         goto failed;
   2760                 Py_DECREF(value);
   2761                 {
   2762                         int i, n = asdl_seq_LEN(o->v.Compare.ops);
   2763                         value = PyList_New(n);
   2764                         if (!value) goto failed;
   2765                         for(i = 0; i < n; i++)
   2766                                 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
   2767                 }
   2768                 if (!value) goto failed;
   2769                 if (PyObject_SetAttrString(result, "ops", value) == -1)
   2770                         goto failed;
   2771                 Py_DECREF(value);
   2772                 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
   2773                 if (!value) goto failed;
   2774                 if (PyObject_SetAttrString(result, "comparators", value) == -1)
   2775                         goto failed;
   2776                 Py_DECREF(value);
   2777                 break;
   2778         case Call_kind:
   2779                 result = PyType_GenericNew(Call_type, NULL, NULL);
   2780                 if (!result) goto failed;
   2781                 value = ast2obj_expr(o->v.Call.func);
   2782                 if (!value) goto failed;
   2783                 if (PyObject_SetAttrString(result, "func", value) == -1)
   2784                         goto failed;
   2785                 Py_DECREF(value);
   2786                 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
   2787                 if (!value) goto failed;
   2788                 if (PyObject_SetAttrString(result, "args", value) == -1)
   2789                         goto failed;
   2790                 Py_DECREF(value);
   2791                 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
   2792                 if (!value) goto failed;
   2793                 if (PyObject_SetAttrString(result, "keywords", value) == -1)
   2794                         goto failed;
   2795                 Py_DECREF(value);
   2796                 value = ast2obj_expr(o->v.Call.starargs);
   2797                 if (!value) goto failed;
   2798                 if (PyObject_SetAttrString(result, "starargs", value) == -1)
   2799                         goto failed;
   2800                 Py_DECREF(value);
   2801                 value = ast2obj_expr(o->v.Call.kwargs);
   2802                 if (!value) goto failed;
   2803                 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
   2804                         goto failed;
   2805                 Py_DECREF(value);
   2806                 break;
   2807         case Repr_kind:
   2808                 result = PyType_GenericNew(Repr_type, NULL, NULL);
   2809                 if (!result) goto failed;
   2810                 value = ast2obj_expr(o->v.Repr.value);
   2811                 if (!value) goto failed;
   2812                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2813                         goto failed;
   2814                 Py_DECREF(value);
   2815                 break;
   2816         case Num_kind:
   2817                 result = PyType_GenericNew(Num_type, NULL, NULL);
   2818                 if (!result) goto failed;
   2819                 value = ast2obj_object(o->v.Num.n);
   2820                 if (!value) goto failed;
   2821                 if (PyObject_SetAttrString(result, "n", value) == -1)
   2822                         goto failed;
   2823                 Py_DECREF(value);
   2824                 break;
   2825         case Str_kind:
   2826                 result = PyType_GenericNew(Str_type, NULL, NULL);
   2827                 if (!result) goto failed;
   2828                 value = ast2obj_string(o->v.Str.s);
   2829                 if (!value) goto failed;
   2830                 if (PyObject_SetAttrString(result, "s", value) == -1)
   2831                         goto failed;
   2832                 Py_DECREF(value);
   2833                 break;
   2834         case Attribute_kind:
   2835                 result = PyType_GenericNew(Attribute_type, NULL, NULL);
   2836                 if (!result) goto failed;
   2837                 value = ast2obj_expr(o->v.Attribute.value);
   2838                 if (!value) goto failed;
   2839                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2840                         goto failed;
   2841                 Py_DECREF(value);
   2842                 value = ast2obj_identifier(o->v.Attribute.attr);
   2843                 if (!value) goto failed;
   2844                 if (PyObject_SetAttrString(result, "attr", value) == -1)
   2845                         goto failed;
   2846                 Py_DECREF(value);
   2847                 value = ast2obj_expr_context(o->v.Attribute.ctx);
   2848                 if (!value) goto failed;
   2849                 if (PyObject_SetAttrString(result, "ctx", value) == -1)
   2850                         goto failed;
   2851                 Py_DECREF(value);
   2852                 break;
   2853         case Subscript_kind:
   2854                 result = PyType_GenericNew(Subscript_type, NULL, NULL);
   2855                 if (!result) goto failed;
   2856                 value = ast2obj_expr(o->v.Subscript.value);
   2857                 if (!value) goto failed;
   2858                 if (PyObject_SetAttrString(result, "value", value) == -1)
   2859                         goto failed;
   2860                 Py_DECREF(value);
   2861                 value = ast2obj_slice(o->v.Subscript.slice);
   2862                 if (!value) goto failed;
   2863                 if (PyObject_SetAttrString(result, "slice", value) == -1)
   2864                         goto failed;
   2865                 Py_DECREF(value);
   2866                 value = ast2obj_expr_context(o->v.Subscript.ctx);
   2867                 if (!value) goto failed;
   2868                 if (PyObject_SetAttrString(result, "ctx", value) == -1)
   2869                         goto failed;
   2870                 Py_DECREF(value);
   2871                 break;
   2872         case Name_kind:
   2873                 result = PyType_GenericNew(Name_type, NULL, NULL);
   2874                 if (!result) goto failed;
   2875                 value = ast2obj_identifier(o->v.Name.id);
   2876                 if (!value) goto failed;
   2877                 if (PyObject_SetAttrString(result, "id", value) == -1)
   2878                         goto failed;
   2879                 Py_DECREF(value);
   2880                 value = ast2obj_expr_context(o->v.Name.ctx);
   2881                 if (!value) goto failed;
   2882                 if (PyObject_SetAttrString(result, "ctx", value) == -1)
   2883                         goto failed;
   2884                 Py_DECREF(value);
   2885                 break;
   2886         case List_kind:
   2887                 result = PyType_GenericNew(List_type, NULL, NULL);
   2888                 if (!result) goto failed;
   2889                 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
   2890                 if (!value) goto failed;
   2891                 if (PyObject_SetAttrString(result, "elts", value) == -1)
   2892                         goto failed;
   2893                 Py_DECREF(value);
   2894                 value = ast2obj_expr_context(o->v.List.ctx);
   2895                 if (!value) goto failed;
   2896                 if (PyObject_SetAttrString(result, "ctx", value) == -1)
   2897                         goto failed;
   2898                 Py_DECREF(value);
   2899                 break;
   2900         case Tuple_kind:
   2901                 result = PyType_GenericNew(Tuple_type, NULL, NULL);
   2902                 if (!result) goto failed;
   2903                 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
   2904                 if (!value) goto failed;
   2905                 if (PyObject_SetAttrString(result, "elts", value) == -1)
   2906                         goto failed;
   2907                 Py_DECREF(value);
   2908                 value = ast2obj_expr_context(o->v.Tuple.ctx);
   2909                 if (!value) goto failed;
   2910                 if (PyObject_SetAttrString(result, "ctx", value) == -1)
   2911                         goto failed;
   2912                 Py_DECREF(value);
   2913                 break;
   2914         }
   2915         value = ast2obj_int(o->lineno);
   2916         if (!value) goto failed;
   2917         if (PyObject_SetAttrString(result, "lineno", value) < 0)
   2918                 goto failed;
   2919         Py_DECREF(value);
   2920         value = ast2obj_int(o->col_offset);
   2921         if (!value) goto failed;
   2922         if (PyObject_SetAttrString(result, "col_offset", value) < 0)
   2923                 goto failed;
   2924         Py_DECREF(value);
   2925         return result;
   2926 failed:
   2927         Py_XDECREF(value);
   2928         Py_XDECREF(result);
   2929         return NULL;
   2930 }
   2931 
   2932 PyObject* ast2obj_expr_context(expr_context_ty o)
   2933 {
   2934         switch(o) {
   2935                 case Load:
   2936                         Py_INCREF(Load_singleton);
   2937                         return Load_singleton;
   2938                 case Store:
   2939                         Py_INCREF(Store_singleton);
   2940                         return Store_singleton;
   2941                 case Del:
   2942                         Py_INCREF(Del_singleton);
   2943                         return Del_singleton;
   2944                 case AugLoad:
   2945                         Py_INCREF(AugLoad_singleton);
   2946                         return AugLoad_singleton;
   2947                 case AugStore:
   2948                         Py_INCREF(AugStore_singleton);
   2949                         return AugStore_singleton;
   2950                 case Param:
   2951                         Py_INCREF(Param_singleton);
   2952                         return Param_singleton;
   2953                 default:
   2954                         /* should never happen, but just in case ... */
   2955                         PyErr_Format(PyExc_SystemError, "unknown expr_context found");
   2956                         return NULL;
   2957         }
   2958 }
   2959 PyObject*
   2960 ast2obj_slice(void* _o)
   2961 {
   2962         slice_ty o = (slice_ty)_o;
   2963         PyObject *result = NULL, *value = NULL;
   2964         if (!o) {
   2965                 Py_INCREF(Py_None);
   2966                 return Py_None;
   2967         }
   2968 
   2969         switch (o->kind) {
   2970         case Ellipsis_kind:
   2971                 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
   2972                 if (!result) goto failed;
   2973                 break;
   2974         case Slice_kind:
   2975                 result = PyType_GenericNew(Slice_type, NULL, NULL);
   2976                 if (!result) goto failed;
   2977                 value = ast2obj_expr(o->v.Slice.lower);
   2978                 if (!value) goto failed;
   2979                 if (PyObject_SetAttrString(result, "lower", value) == -1)
   2980                         goto failed;
   2981                 Py_DECREF(value);
   2982                 value = ast2obj_expr(o->v.Slice.upper);
   2983                 if (!value) goto failed;
   2984                 if (PyObject_SetAttrString(result, "upper", value) == -1)
   2985                         goto failed;
   2986                 Py_DECREF(value);
   2987                 value = ast2obj_expr(o->v.Slice.step);
   2988                 if (!value) goto failed;
   2989                 if (PyObject_SetAttrString(result, "step", value) == -1)
   2990                         goto failed;
   2991                 Py_DECREF(value);
   2992                 break;
   2993         case ExtSlice_kind:
   2994                 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
   2995                 if (!result) goto failed;
   2996                 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
   2997                 if (!value) goto failed;
   2998                 if (PyObject_SetAttrString(result, "dims", value) == -1)
   2999                         goto failed;
   3000                 Py_DECREF(value);
   3001                 break;
   3002         case Index_kind:
   3003                 result = PyType_GenericNew(Index_type, NULL, NULL);
   3004                 if (!result) goto failed;
   3005                 value = ast2obj_expr(o->v.Index.value);
   3006                 if (!value) goto failed;
   3007                 if (PyObject_SetAttrString(result, "value", value) == -1)
   3008                         goto failed;
   3009                 Py_DECREF(value);
   3010                 break;
   3011         }
   3012         return result;
   3013 failed:
   3014         Py_XDECREF(value);
   3015         Py_XDECREF(result);
   3016         return NULL;
   3017 }
   3018 
   3019 PyObject* ast2obj_boolop(boolop_ty o)
   3020 {
   3021         switch(o) {
   3022                 case And:
   3023                         Py_INCREF(And_singleton);
   3024                         return And_singleton;
   3025                 case Or:
   3026                         Py_INCREF(Or_singleton);
   3027                         return Or_singleton;
   3028                 default:
   3029                         /* should never happen, but just in case ... */
   3030                         PyErr_Format(PyExc_SystemError, "unknown boolop found");
   3031                         return NULL;
   3032         }
   3033 }
   3034 PyObject* ast2obj_operator(operator_ty o)
   3035 {
   3036         switch(o) {
   3037                 case Add:
   3038                         Py_INCREF(Add_singleton);
   3039                         return Add_singleton;
   3040                 case Sub:
   3041                         Py_INCREF(Sub_singleton);
   3042                         return Sub_singleton;
   3043                 case Mult:
   3044                         Py_INCREF(Mult_singleton);
   3045                         return Mult_singleton;
   3046                 case Div:
   3047                         Py_INCREF(Div_singleton);
   3048                         return Div_singleton;
   3049                 case Mod:
   3050                         Py_INCREF(Mod_singleton);
   3051                         return Mod_singleton;
   3052                 case Pow:
   3053                         Py_INCREF(Pow_singleton);
   3054                         return Pow_singleton;
   3055                 case LShift:
   3056                         Py_INCREF(LShift_singleton);
   3057                         return LShift_singleton;
   3058                 case RShift:
   3059                         Py_INCREF(RShift_singleton);
   3060                         return RShift_singleton;
   3061                 case BitOr:
   3062                         Py_INCREF(BitOr_singleton);
   3063                         return BitOr_singleton;
   3064                 case BitXor:
   3065                         Py_INCREF(BitXor_singleton);
   3066                         return BitXor_singleton;
   3067                 case BitAnd:
   3068                         Py_INCREF(BitAnd_singleton);
   3069                         return BitAnd_singleton;
   3070                 case FloorDiv:
   3071                         Py_INCREF(FloorDiv_singleton);
   3072                         return FloorDiv_singleton;
   3073                 default:
   3074                         /* should never happen, but just in case ... */
   3075                         PyErr_Format(PyExc_SystemError, "unknown operator found");
   3076                         return NULL;
   3077         }
   3078 }
   3079 PyObject* ast2obj_unaryop(unaryop_ty o)
   3080 {
   3081         switch(o) {
   3082                 case Invert:
   3083                         Py_INCREF(Invert_singleton);
   3084                         return Invert_singleton;
   3085                 case Not:
   3086                         Py_INCREF(Not_singleton);
   3087                         return Not_singleton;
   3088                 case UAdd:
   3089                         Py_INCREF(UAdd_singleton);
   3090                         return UAdd_singleton;
   3091                 case USub:
   3092                         Py_INCREF(USub_singleton);
   3093                         return USub_singleton;
   3094                 default:
   3095                         /* should never happen, but just in case ... */
   3096                         PyErr_Format(PyExc_SystemError, "unknown unaryop found");
   3097                         return NULL;
   3098         }
   3099 }
   3100 PyObject* ast2obj_cmpop(cmpop_ty o)
   3101 {
   3102         switch(o) {
   3103                 case Eq:
   3104                         Py_INCREF(Eq_singleton);
   3105                         return Eq_singleton;
   3106                 case NotEq:
   3107                         Py_INCREF(NotEq_singleton);
   3108                         return NotEq_singleton;
   3109                 case Lt:
   3110                         Py_INCREF(Lt_singleton);
   3111                         return Lt_singleton;
   3112                 case LtE:
   3113                         Py_INCREF(LtE_singleton);
   3114                         return LtE_singleton;
   3115                 case Gt:
   3116                         Py_INCREF(Gt_singleton);
   3117                         return Gt_singleton;
   3118                 case GtE:
   3119                         Py_INCREF(GtE_singleton);
   3120                         return GtE_singleton;
   3121                 case Is:
   3122                         Py_INCREF(Is_singleton);
   3123                         return Is_singleton;
   3124                 case IsNot:
   3125                         Py_INCREF(IsNot_singleton);
   3126                         return IsNot_singleton;
   3127                 case In:
   3128                         Py_INCREF(In_singleton);
   3129                         return In_singleton;
   3130                 case NotIn:
   3131                         Py_INCREF(NotIn_singleton);
   3132                         return NotIn_singleton;
   3133                 default:
   3134                         /* should never happen, but just in case ... */
   3135                         PyErr_Format(PyExc_SystemError, "unknown cmpop found");
   3136                         return NULL;
   3137         }
   3138 }
   3139 PyObject*
   3140 ast2obj_comprehension(void* _o)
   3141 {
   3142         comprehension_ty o = (comprehension_ty)_o;
   3143         PyObject *result = NULL, *value = NULL;
   3144         if (!o) {
   3145                 Py_INCREF(Py_None);
   3146                 return Py_None;
   3147         }
   3148 
   3149         result = PyType_GenericNew(comprehension_type, NULL, NULL);
   3150         if (!result) return NULL;
   3151         value = ast2obj_expr(o->target);
   3152         if (!value) goto failed;
   3153         if (PyObject_SetAttrString(result, "target", value) == -1)
   3154                 goto failed;
   3155         Py_DECREF(value);
   3156         value = ast2obj_expr(o->iter);
   3157         if (!value) goto failed;
   3158         if (PyObject_SetAttrString(result, "iter", value) == -1)
   3159                 goto failed;
   3160         Py_DECREF(value);
   3161         value = ast2obj_list(o->ifs, ast2obj_expr);
   3162         if (!value) goto failed;
   3163         if (PyObject_SetAttrString(result, "ifs", value) == -1)
   3164                 goto failed;
   3165         Py_DECREF(value);
   3166         return result;
   3167 failed:
   3168         Py_XDECREF(value);
   3169         Py_XDECREF(result);
   3170         return NULL;
   3171 }
   3172 
   3173 PyObject*
   3174 ast2obj_excepthandler(void* _o)
   3175 {
   3176         excepthandler_ty o = (excepthandler_ty)_o;
   3177         PyObject *result = NULL, *value = NULL;
   3178         if (!o) {
   3179                 Py_INCREF(Py_None);
   3180                 return Py_None;
   3181         }
   3182 
   3183         switch (o->kind) {
   3184         case ExceptHandler_kind:
   3185                 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
   3186                 if (!result) goto failed;
   3187                 value = ast2obj_expr(o->v.ExceptHandler.type);
   3188                 if (!value) goto failed;
   3189                 if (PyObject_SetAttrString(result, "type", value) == -1)
   3190                         goto failed;
   3191                 Py_DECREF(value);
   3192                 value = ast2obj_expr(o->v.ExceptHandler.name);
   3193                 if (!value) goto failed;
   3194                 if (PyObject_SetAttrString(result, "name", value) == -1)
   3195                         goto failed;
   3196                 Py_DECREF(value);
   3197                 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
   3198                 if (!value) goto failed;
   3199                 if (PyObject_SetAttrString(result, "body", value) == -1)
   3200                         goto failed;
   3201                 Py_DECREF(value);
   3202                 break;
   3203         }
   3204         value = ast2obj_int(o->lineno);
   3205         if (!value) goto failed;
   3206         if (PyObject_SetAttrString(result, "lineno", value) < 0)
   3207                 goto failed;
   3208         Py_DECREF(value);
   3209         value = ast2obj_int(o->col_offset);
   3210         if (!value) goto failed;
   3211         if (PyObject_SetAttrString(result, "col_offset", value) < 0)
   3212                 goto failed;
   3213         Py_DECREF(value);
   3214         return result;
   3215 failed:
   3216         Py_XDECREF(value);
   3217         Py_XDECREF(result);
   3218         return NULL;
   3219 }
   3220 
   3221 PyObject*
   3222 ast2obj_arguments(void* _o)
   3223 {
   3224         arguments_ty o = (arguments_ty)_o;
   3225         PyObject *result = NULL, *value = NULL;
   3226         if (!o) {
   3227                 Py_INCREF(Py_None);
   3228                 return Py_None;
   3229         }
   3230 
   3231         result = PyType_GenericNew(arguments_type, NULL, NULL);
   3232         if (!result) return NULL;
   3233         value = ast2obj_list(o->args, ast2obj_expr);
   3234         if (!value) goto failed;
   3235         if (PyObject_SetAttrString(result, "args", value) == -1)
   3236                 goto failed;
   3237         Py_DECREF(value);
   3238         value = ast2obj_identifier(o->vararg);
   3239         if (!value) goto failed;
   3240         if (PyObject_SetAttrString(result, "vararg", value) == -1)
   3241                 goto failed;
   3242         Py_DECREF(value);
   3243         value = ast2obj_identifier(o->kwarg);
   3244         if (!value) goto failed;
   3245         if (PyObject_SetAttrString(result, "kwarg", value) == -1)
   3246                 goto failed;
   3247         Py_DECREF(value);
   3248         value = ast2obj_list(o->defaults, ast2obj_expr);
   3249         if (!value) goto failed;
   3250         if (PyObject_SetAttrString(result, "defaults", value) == -1)
   3251                 goto failed;
   3252         Py_DECREF(value);
   3253         return result;
   3254 failed:
   3255         Py_XDECREF(value);
   3256         Py_XDECREF(result);
   3257         return NULL;
   3258 }
   3259 
   3260 PyObject*
   3261 ast2obj_keyword(void* _o)
   3262 {
   3263         keyword_ty o = (keyword_ty)_o;
   3264         PyObject *result = NULL, *value = NULL;
   3265         if (!o) {
   3266                 Py_INCREF(Py_None);
   3267                 return Py_None;
   3268         }
   3269 
   3270         result = PyType_GenericNew(keyword_type, NULL, NULL);
   3271         if (!result) return NULL;
   3272         value = ast2obj_identifier(o->arg);
   3273         if (!value) goto failed;
   3274         if (PyObject_SetAttrString(result, "arg", value) == -1)
   3275                 goto failed;
   3276         Py_DECREF(value);
   3277         value = ast2obj_expr(o->value);
   3278         if (!value) goto failed;
   3279         if (PyObject_SetAttrString(result, "value", value) == -1)
   3280                 goto failed;
   3281         Py_DECREF(value);
   3282         return result;
   3283 failed:
   3284         Py_XDECREF(value);
   3285         Py_XDECREF(result);
   3286         return NULL;
   3287 }
   3288 
   3289 PyObject*
   3290 ast2obj_alias(void* _o)
   3291 {
   3292         alias_ty o = (alias_ty)_o;
   3293         PyObject *result = NULL, *value = NULL;
   3294         if (!o) {
   3295                 Py_INCREF(Py_None);
   3296                 return Py_None;
   3297         }
   3298 
   3299         result = PyType_GenericNew(alias_type, NULL, NULL);
   3300         if (!result) return NULL;
   3301         value = ast2obj_identifier(o->name);
   3302         if (!value) goto failed;
   3303         if (PyObject_SetAttrString(result, "name", value) == -1)
   3304                 goto failed;
   3305         Py_DECREF(value);
   3306         value = ast2obj_identifier(o->asname);
   3307         if (!value) goto failed;
   3308         if (PyObject_SetAttrString(result, "asname", value) == -1)
   3309                 goto failed;
   3310         Py_DECREF(value);
   3311         return result;
   3312 failed:
   3313         Py_XDECREF(value);
   3314         Py_XDECREF(result);
   3315         return NULL;
   3316 }
   3317 
   3318 
   3319 int
   3320 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
   3321 {
   3322         PyObject* tmp = NULL;
   3323         int isinstance;
   3324 
   3325 
   3326         if (obj == Py_None) {
   3327                 *out = NULL;
   3328                 return 0;
   3329         }
   3330         isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
   3331         if (isinstance == -1) {
   3332                 return 1;
   3333         }
   3334         if (isinstance) {
   3335                 asdl_seq* body;
   3336 
   3337                 if (PyObject_HasAttrString(obj, "body")) {
   3338                         int res;
   3339                         Py_ssize_t len;
   3340                         Py_ssize_t i;
   3341                         tmp = PyObject_GetAttrString(obj, "body");
   3342                         if (tmp == NULL) goto failed;
   3343                         if (!PyList_Check(tmp)) {
   3344                                 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3345                                 goto failed;
   3346                         }
   3347                         len = PyList_GET_SIZE(tmp);
   3348                         body = asdl_seq_new(len, arena);
   3349                         if (body == NULL) goto failed;
   3350                         for (i = 0; i < len; i++) {
   3351                                 stmt_ty val;
   3352                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   3353                                 if (res != 0) goto failed;
   3354                                 if (len != PyList_GET_SIZE(tmp)) {
   3355                                         PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
   3356                                         goto failed;
   3357                                 }
   3358                                 asdl_seq_SET(body, i, val);
   3359                         }
   3360                         Py_XDECREF(tmp);
   3361                         tmp = NULL;
   3362                 } else {
   3363                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
   3364                         return 1;
   3365                 }
   3366                 *out = Module(body, arena);
   3367                 if (*out == NULL) goto failed;
   3368                 return 0;
   3369         }
   3370         isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
   3371         if (isinstance == -1) {
   3372                 return 1;
   3373         }
   3374         if (isinstance) {
   3375                 asdl_seq* body;
   3376 
   3377                 if (PyObject_HasAttrString(obj, "body")) {
   3378                         int res;
   3379                         Py_ssize_t len;
   3380                         Py_ssize_t i;
   3381                         tmp = PyObject_GetAttrString(obj, "body");
   3382                         if (tmp == NULL) goto failed;
   3383                         if (!PyList_Check(tmp)) {
   3384                                 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3385                                 goto failed;
   3386                         }
   3387                         len = PyList_GET_SIZE(tmp);
   3388                         body = asdl_seq_new(len, arena);
   3389                         if (body == NULL) goto failed;
   3390                         for (i = 0; i < len; i++) {
   3391                                 stmt_ty val;
   3392                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   3393                                 if (res != 0) goto failed;
   3394                                 if (len != PyList_GET_SIZE(tmp)) {
   3395                                         PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
   3396                                         goto failed;
   3397                                 }
   3398                                 asdl_seq_SET(body, i, val);
   3399                         }
   3400                         Py_XDECREF(tmp);
   3401                         tmp = NULL;
   3402                 } else {
   3403                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
   3404                         return 1;
   3405                 }
   3406                 *out = Interactive(body, arena);
   3407                 if (*out == NULL) goto failed;
   3408                 return 0;
   3409         }
   3410         isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
   3411         if (isinstance == -1) {
   3412                 return 1;
   3413         }
   3414         if (isinstance) {
   3415                 expr_ty body;
   3416 
   3417                 if (PyObject_HasAttrString(obj, "body")) {
   3418                         int res;
   3419                         tmp = PyObject_GetAttrString(obj, "body");
   3420                         if (tmp == NULL) goto failed;
   3421                         res = obj2ast_expr(tmp, &body, arena);
   3422                         if (res != 0) goto failed;
   3423                         Py_XDECREF(tmp);
   3424                         tmp = NULL;
   3425                 } else {
   3426                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
   3427                         return 1;
   3428                 }
   3429                 *out = Expression(body, arena);
   3430                 if (*out == NULL) goto failed;
   3431                 return 0;
   3432         }
   3433         isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
   3434         if (isinstance == -1) {
   3435                 return 1;
   3436         }
   3437         if (isinstance) {
   3438                 asdl_seq* body;
   3439 
   3440                 if (PyObject_HasAttrString(obj, "body")) {
   3441                         int res;
   3442                         Py_ssize_t len;
   3443                         Py_ssize_t i;
   3444                         tmp = PyObject_GetAttrString(obj, "body");
   3445                         if (tmp == NULL) goto failed;
   3446                         if (!PyList_Check(tmp)) {
   3447                                 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3448                                 goto failed;
   3449                         }
   3450                         len = PyList_GET_SIZE(tmp);
   3451                         body = asdl_seq_new(len, arena);
   3452                         if (body == NULL) goto failed;
   3453                         for (i = 0; i < len; i++) {
   3454                                 stmt_ty val;
   3455                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   3456                                 if (res != 0) goto failed;
   3457                                 if (len != PyList_GET_SIZE(tmp)) {
   3458                                         PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
   3459                                         goto failed;
   3460                                 }
   3461                                 asdl_seq_SET(body, i, val);
   3462                         }
   3463                         Py_XDECREF(tmp);
   3464                         tmp = NULL;
   3465                 } else {
   3466                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
   3467                         return 1;
   3468                 }
   3469                 *out = Suite(body, arena);
   3470                 if (*out == NULL) goto failed;
   3471                 return 0;
   3472         }
   3473 
   3474         tmp = PyObject_Repr(obj);
   3475         if (tmp == NULL) goto failed;
   3476         PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
   3477 failed:
   3478         Py_XDECREF(tmp);
   3479         return 1;
   3480 }
   3481 
   3482 int
   3483 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
   3484 {
   3485         PyObject* tmp = NULL;
   3486         int isinstance;
   3487 
   3488         int lineno;
   3489         int col_offset;
   3490 
   3491         if (obj == Py_None) {
   3492                 *out = NULL;
   3493                 return 0;
   3494         }
   3495         if (PyObject_HasAttrString(obj, "lineno")) {
   3496                 int res;
   3497                 tmp = PyObject_GetAttrString(obj, "lineno");
   3498                 if (tmp == NULL) goto failed;
   3499                 res = obj2ast_int(tmp, &lineno, arena);
   3500                 if (res != 0) goto failed;
   3501                 Py_XDECREF(tmp);
   3502                 tmp = NULL;
   3503         } else {
   3504                 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
   3505                 return 1;
   3506         }
   3507         if (PyObject_HasAttrString(obj, "col_offset")) {
   3508                 int res;
   3509                 tmp = PyObject_GetAttrString(obj, "col_offset");
   3510                 if (tmp == NULL) goto failed;
   3511                 res = obj2ast_int(tmp, &col_offset, arena);
   3512                 if (res != 0) goto failed;
   3513                 Py_XDECREF(tmp);
   3514                 tmp = NULL;
   3515         } else {
   3516                 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
   3517                 return 1;
   3518         }
   3519         isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
   3520         if (isinstance == -1) {
   3521                 return 1;
   3522         }
   3523         if (isinstance) {
   3524                 identifier name;
   3525                 arguments_ty args;
   3526                 asdl_seq* body;
   3527                 asdl_seq* decorator_list;
   3528 
   3529                 if (PyObject_HasAttrString(obj, "name")) {
   3530                         int res;
   3531                         tmp = PyObject_GetAttrString(obj, "name");
   3532                         if (tmp == NULL) goto failed;
   3533                         res = obj2ast_identifier(tmp, &name, arena);
   3534                         if (res != 0) goto failed;
   3535                         Py_XDECREF(tmp);
   3536                         tmp = NULL;
   3537                 } else {
   3538                         PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
   3539                         return 1;
   3540                 }
   3541                 if (PyObject_HasAttrString(obj, "args")) {
   3542                         int res;
   3543                         tmp = PyObject_GetAttrString(obj, "args");
   3544                         if (tmp == NULL) goto failed;
   3545                         res = obj2ast_arguments(tmp, &args, arena);
   3546                         if (res != 0) goto failed;
   3547                         Py_XDECREF(tmp);
   3548                         tmp = NULL;
   3549                 } else {
   3550                         PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
   3551                         return 1;
   3552                 }
   3553                 if (PyObject_HasAttrString(obj, "body")) {
   3554                         int res;
   3555                         Py_ssize_t len;
   3556                         Py_ssize_t i;
   3557                         tmp = PyObject_GetAttrString(obj, "body");
   3558                         if (tmp == NULL) goto failed;
   3559                         if (!PyList_Check(tmp)) {
   3560                                 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3561                                 goto failed;
   3562                         }
   3563                         len = PyList_GET_SIZE(tmp);
   3564                         body = asdl_seq_new(len, arena);
   3565                         if (body == NULL) goto failed;
   3566                         for (i = 0; i < len; i++) {
   3567                                 stmt_ty val;
   3568                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   3569                                 if (res != 0) goto failed;
   3570                                 if (len != PyList_GET_SIZE(tmp)) {
   3571                                         PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
   3572                                         goto failed;
   3573                                 }
   3574                                 asdl_seq_SET(body, i, val);
   3575                         }
   3576                         Py_XDECREF(tmp);
   3577                         tmp = NULL;
   3578                 } else {
   3579                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
   3580                         return 1;
   3581                 }
   3582                 if (PyObject_HasAttrString(obj, "decorator_list")) {
   3583                         int res;
   3584                         Py_ssize_t len;
   3585                         Py_ssize_t i;
   3586                         tmp = PyObject_GetAttrString(obj, "decorator_list");
   3587                         if (tmp == NULL) goto failed;
   3588                         if (!PyList_Check(tmp)) {
   3589                                 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3590                                 goto failed;
   3591                         }
   3592                         len = PyList_GET_SIZE(tmp);
   3593                         decorator_list = asdl_seq_new(len, arena);
   3594                         if (decorator_list == NULL) goto failed;
   3595                         for (i = 0; i < len; i++) {
   3596                                 expr_ty val;
   3597                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3598                                 if (res != 0) goto failed;
   3599                                 if (len != PyList_GET_SIZE(tmp)) {
   3600                                         PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
   3601                                         goto failed;
   3602                                 }
   3603                                 asdl_seq_SET(decorator_list, i, val);
   3604                         }
   3605                         Py_XDECREF(tmp);
   3606                         tmp = NULL;
   3607                 } else {
   3608                         PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
   3609                         return 1;
   3610                 }
   3611                 *out = FunctionDef(name, args, body, decorator_list, lineno,
   3612                                    col_offset, arena);
   3613                 if (*out == NULL) goto failed;
   3614                 return 0;
   3615         }
   3616         isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
   3617         if (isinstance == -1) {
   3618                 return 1;
   3619         }
   3620         if (isinstance) {
   3621                 identifier name;
   3622                 asdl_seq* bases;
   3623                 asdl_seq* body;
   3624                 asdl_seq* decorator_list;
   3625 
   3626                 if (PyObject_HasAttrString(obj, "name")) {
   3627                         int res;
   3628                         tmp = PyObject_GetAttrString(obj, "name");
   3629                         if (tmp == NULL) goto failed;
   3630                         res = obj2ast_identifier(tmp, &name, arena);
   3631                         if (res != 0) goto failed;
   3632                         Py_XDECREF(tmp);
   3633                         tmp = NULL;
   3634                 } else {
   3635                         PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
   3636                         return 1;
   3637                 }
   3638                 if (PyObject_HasAttrString(obj, "bases")) {
   3639                         int res;
   3640                         Py_ssize_t len;
   3641                         Py_ssize_t i;
   3642                         tmp = PyObject_GetAttrString(obj, "bases");
   3643                         if (tmp == NULL) goto failed;
   3644                         if (!PyList_Check(tmp)) {
   3645                                 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3646                                 goto failed;
   3647                         }
   3648                         len = PyList_GET_SIZE(tmp);
   3649                         bases = asdl_seq_new(len, arena);
   3650                         if (bases == NULL) goto failed;
   3651                         for (i = 0; i < len; i++) {
   3652                                 expr_ty val;
   3653                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3654                                 if (res != 0) goto failed;
   3655                                 if (len != PyList_GET_SIZE(tmp)) {
   3656                                         PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
   3657                                         goto failed;
   3658                                 }
   3659                                 asdl_seq_SET(bases, i, val);
   3660                         }
   3661                         Py_XDECREF(tmp);
   3662                         tmp = NULL;
   3663                 } else {
   3664                         PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
   3665                         return 1;
   3666                 }
   3667                 if (PyObject_HasAttrString(obj, "body")) {
   3668                         int res;
   3669                         Py_ssize_t len;
   3670                         Py_ssize_t i;
   3671                         tmp = PyObject_GetAttrString(obj, "body");
   3672                         if (tmp == NULL) goto failed;
   3673                         if (!PyList_Check(tmp)) {
   3674                                 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3675                                 goto failed;
   3676                         }
   3677                         len = PyList_GET_SIZE(tmp);
   3678                         body = asdl_seq_new(len, arena);
   3679                         if (body == NULL) goto failed;
   3680                         for (i = 0; i < len; i++) {
   3681                                 stmt_ty val;
   3682                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   3683                                 if (res != 0) goto failed;
   3684                                 if (len != PyList_GET_SIZE(tmp)) {
   3685                                         PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
   3686                                         goto failed;
   3687                                 }
   3688                                 asdl_seq_SET(body, i, val);
   3689                         }
   3690                         Py_XDECREF(tmp);
   3691                         tmp = NULL;
   3692                 } else {
   3693                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
   3694                         return 1;
   3695                 }
   3696                 if (PyObject_HasAttrString(obj, "decorator_list")) {
   3697                         int res;
   3698                         Py_ssize_t len;
   3699                         Py_ssize_t i;
   3700                         tmp = PyObject_GetAttrString(obj, "decorator_list");
   3701                         if (tmp == NULL) goto failed;
   3702                         if (!PyList_Check(tmp)) {
   3703                                 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3704                                 goto failed;
   3705                         }
   3706                         len = PyList_GET_SIZE(tmp);
   3707                         decorator_list = asdl_seq_new(len, arena);
   3708                         if (decorator_list == NULL) goto failed;
   3709                         for (i = 0; i < len; i++) {
   3710                                 expr_ty val;
   3711                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3712                                 if (res != 0) goto failed;
   3713                                 if (len != PyList_GET_SIZE(tmp)) {
   3714                                         PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
   3715                                         goto failed;
   3716                                 }
   3717                                 asdl_seq_SET(decorator_list, i, val);
   3718                         }
   3719                         Py_XDECREF(tmp);
   3720                         tmp = NULL;
   3721                 } else {
   3722                         PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
   3723                         return 1;
   3724                 }
   3725                 *out = ClassDef(name, bases, body, decorator_list, lineno,
   3726                                 col_offset, arena);
   3727                 if (*out == NULL) goto failed;
   3728                 return 0;
   3729         }
   3730         isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
   3731         if (isinstance == -1) {
   3732                 return 1;
   3733         }
   3734         if (isinstance) {
   3735                 expr_ty value;
   3736 
   3737                 if (PyObject_HasAttrString(obj, "value")) {
   3738                         int res;
   3739                         tmp = PyObject_GetAttrString(obj, "value");
   3740                         if (tmp == NULL) goto failed;
   3741                         res = obj2ast_expr(tmp, &value, arena);
   3742                         if (res != 0) goto failed;
   3743                         Py_XDECREF(tmp);
   3744                         tmp = NULL;
   3745                 } else {
   3746                         value = NULL;
   3747                 }
   3748                 *out = Return(value, lineno, col_offset, arena);
   3749                 if (*out == NULL) goto failed;
   3750                 return 0;
   3751         }
   3752         isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
   3753         if (isinstance == -1) {
   3754                 return 1;
   3755         }
   3756         if (isinstance) {
   3757                 asdl_seq* targets;
   3758 
   3759                 if (PyObject_HasAttrString(obj, "targets")) {
   3760                         int res;
   3761                         Py_ssize_t len;
   3762                         Py_ssize_t i;
   3763                         tmp = PyObject_GetAttrString(obj, "targets");
   3764                         if (tmp == NULL) goto failed;
   3765                         if (!PyList_Check(tmp)) {
   3766                                 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3767                                 goto failed;
   3768                         }
   3769                         len = PyList_GET_SIZE(tmp);
   3770                         targets = asdl_seq_new(len, arena);
   3771                         if (targets == NULL) goto failed;
   3772                         for (i = 0; i < len; i++) {
   3773                                 expr_ty val;
   3774                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3775                                 if (res != 0) goto failed;
   3776                                 if (len != PyList_GET_SIZE(tmp)) {
   3777                                         PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
   3778                                         goto failed;
   3779                                 }
   3780                                 asdl_seq_SET(targets, i, val);
   3781                         }
   3782                         Py_XDECREF(tmp);
   3783                         tmp = NULL;
   3784                 } else {
   3785                         PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
   3786                         return 1;
   3787                 }
   3788                 *out = Delete(targets, lineno, col_offset, arena);
   3789                 if (*out == NULL) goto failed;
   3790                 return 0;
   3791         }
   3792         isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
   3793         if (isinstance == -1) {
   3794                 return 1;
   3795         }
   3796         if (isinstance) {
   3797                 asdl_seq* targets;
   3798                 expr_ty value;
   3799 
   3800                 if (PyObject_HasAttrString(obj, "targets")) {
   3801                         int res;
   3802                         Py_ssize_t len;
   3803                         Py_ssize_t i;
   3804                         tmp = PyObject_GetAttrString(obj, "targets");
   3805                         if (tmp == NULL) goto failed;
   3806                         if (!PyList_Check(tmp)) {
   3807                                 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3808                                 goto failed;
   3809                         }
   3810                         len = PyList_GET_SIZE(tmp);
   3811                         targets = asdl_seq_new(len, arena);
   3812                         if (targets == NULL) goto failed;
   3813                         for (i = 0; i < len; i++) {
   3814                                 expr_ty val;
   3815                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3816                                 if (res != 0) goto failed;
   3817                                 if (len != PyList_GET_SIZE(tmp)) {
   3818                                         PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
   3819                                         goto failed;
   3820                                 }
   3821                                 asdl_seq_SET(targets, i, val);
   3822                         }
   3823                         Py_XDECREF(tmp);
   3824                         tmp = NULL;
   3825                 } else {
   3826                         PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
   3827                         return 1;
   3828                 }
   3829                 if (PyObject_HasAttrString(obj, "value")) {
   3830                         int res;
   3831                         tmp = PyObject_GetAttrString(obj, "value");
   3832                         if (tmp == NULL) goto failed;
   3833                         res = obj2ast_expr(tmp, &value, arena);
   3834                         if (res != 0) goto failed;
   3835                         Py_XDECREF(tmp);
   3836                         tmp = NULL;
   3837                 } else {
   3838                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
   3839                         return 1;
   3840                 }
   3841                 *out = Assign(targets, value, lineno, col_offset, arena);
   3842                 if (*out == NULL) goto failed;
   3843                 return 0;
   3844         }
   3845         isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
   3846         if (isinstance == -1) {
   3847                 return 1;
   3848         }
   3849         if (isinstance) {
   3850                 expr_ty target;
   3851                 operator_ty op;
   3852                 expr_ty value;
   3853 
   3854                 if (PyObject_HasAttrString(obj, "target")) {
   3855                         int res;
   3856                         tmp = PyObject_GetAttrString(obj, "target");
   3857                         if (tmp == NULL) goto failed;
   3858                         res = obj2ast_expr(tmp, &target, arena);
   3859                         if (res != 0) goto failed;
   3860                         Py_XDECREF(tmp);
   3861                         tmp = NULL;
   3862                 } else {
   3863                         PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
   3864                         return 1;
   3865                 }
   3866                 if (PyObject_HasAttrString(obj, "op")) {
   3867                         int res;
   3868                         tmp = PyObject_GetAttrString(obj, "op");
   3869                         if (tmp == NULL) goto failed;
   3870                         res = obj2ast_operator(tmp, &op, arena);
   3871                         if (res != 0) goto failed;
   3872                         Py_XDECREF(tmp);
   3873                         tmp = NULL;
   3874                 } else {
   3875                         PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
   3876                         return 1;
   3877                 }
   3878                 if (PyObject_HasAttrString(obj, "value")) {
   3879                         int res;
   3880                         tmp = PyObject_GetAttrString(obj, "value");
   3881                         if (tmp == NULL) goto failed;
   3882                         res = obj2ast_expr(tmp, &value, arena);
   3883                         if (res != 0) goto failed;
   3884                         Py_XDECREF(tmp);
   3885                         tmp = NULL;
   3886                 } else {
   3887                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
   3888                         return 1;
   3889                 }
   3890                 *out = AugAssign(target, op, value, lineno, col_offset, arena);
   3891                 if (*out == NULL) goto failed;
   3892                 return 0;
   3893         }
   3894         isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
   3895         if (isinstance == -1) {
   3896                 return 1;
   3897         }
   3898         if (isinstance) {
   3899                 expr_ty dest;
   3900                 asdl_seq* values;
   3901                 bool nl;
   3902 
   3903                 if (PyObject_HasAttrString(obj, "dest")) {
   3904                         int res;
   3905                         tmp = PyObject_GetAttrString(obj, "dest");
   3906                         if (tmp == NULL) goto failed;
   3907                         res = obj2ast_expr(tmp, &dest, arena);
   3908                         if (res != 0) goto failed;
   3909                         Py_XDECREF(tmp);
   3910                         tmp = NULL;
   3911                 } else {
   3912                         dest = NULL;
   3913                 }
   3914                 if (PyObject_HasAttrString(obj, "values")) {
   3915                         int res;
   3916                         Py_ssize_t len;
   3917                         Py_ssize_t i;
   3918                         tmp = PyObject_GetAttrString(obj, "values");
   3919                         if (tmp == NULL) goto failed;
   3920                         if (!PyList_Check(tmp)) {
   3921                                 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   3922                                 goto failed;
   3923                         }
   3924                         len = PyList_GET_SIZE(tmp);
   3925                         values = asdl_seq_new(len, arena);
   3926                         if (values == NULL) goto failed;
   3927                         for (i = 0; i < len; i++) {
   3928                                 expr_ty val;
   3929                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   3930                                 if (res != 0) goto failed;
   3931                                 if (len != PyList_GET_SIZE(tmp)) {
   3932                                         PyErr_SetString(PyExc_RuntimeError, "Print field \"values\" changed size during iteration");
   3933                                         goto failed;
   3934                                 }
   3935                                 asdl_seq_SET(values, i, val);
   3936                         }
   3937                         Py_XDECREF(tmp);
   3938                         tmp = NULL;
   3939                 } else {
   3940                         PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
   3941                         return 1;
   3942                 }
   3943                 if (PyObject_HasAttrString(obj, "nl")) {
   3944                         int res;
   3945                         tmp = PyObject_GetAttrString(obj, "nl");
   3946                         if (tmp == NULL) goto failed;
   3947                         res = obj2ast_bool(tmp, &nl, arena);
   3948                         if (res != 0) goto failed;
   3949                         Py_XDECREF(tmp);
   3950                         tmp = NULL;
   3951                 } else {
   3952                         PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
   3953                         return 1;
   3954                 }
   3955                 *out = Print(dest, values, nl, lineno, col_offset, arena);
   3956                 if (*out == NULL) goto failed;
   3957                 return 0;
   3958         }
   3959         isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
   3960         if (isinstance == -1) {
   3961                 return 1;
   3962         }
   3963         if (isinstance) {
   3964                 expr_ty target;
   3965                 expr_ty iter;
   3966                 asdl_seq* body;
   3967                 asdl_seq* orelse;
   3968 
   3969                 if (PyObject_HasAttrString(obj, "target")) {
   3970                         int res;
   3971                         tmp = PyObject_GetAttrString(obj, "target");
   3972                         if (tmp == NULL) goto failed;
   3973                         res = obj2ast_expr(tmp, &target, arena);
   3974                         if (res != 0) goto failed;
   3975                         Py_XDECREF(tmp);
   3976                         tmp = NULL;
   3977                 } else {
   3978                         PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
   3979                         return 1;
   3980                 }
   3981                 if (PyObject_HasAttrString(obj, "iter")) {
   3982                         int res;
   3983                         tmp = PyObject_GetAttrString(obj, "iter");
   3984                         if (tmp == NULL) goto failed;
   3985                         res = obj2ast_expr(tmp, &iter, arena);
   3986                         if (res != 0) goto failed;
   3987                         Py_XDECREF(tmp);
   3988                         tmp = NULL;
   3989                 } else {
   3990                         PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
   3991                         return 1;
   3992                 }
   3993                 if (PyObject_HasAttrString(obj, "body")) {
   3994                         int res;
   3995                         Py_ssize_t len;
   3996                         Py_ssize_t i;
   3997                         tmp = PyObject_GetAttrString(obj, "body");
   3998                         if (tmp == NULL) goto failed;
   3999                         if (!PyList_Check(tmp)) {
   4000                                 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4001                                 goto failed;
   4002                         }
   4003                         len = PyList_GET_SIZE(tmp);
   4004                         body = asdl_seq_new(len, arena);
   4005                         if (body == NULL) goto failed;
   4006                         for (i = 0; i < len; i++) {
   4007                                 stmt_ty val;
   4008                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4009                                 if (res != 0) goto failed;
   4010                                 if (len != PyList_GET_SIZE(tmp)) {
   4011                                         PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
   4012                                         goto failed;
   4013                                 }
   4014                                 asdl_seq_SET(body, i, val);
   4015                         }
   4016                         Py_XDECREF(tmp);
   4017                         tmp = NULL;
   4018                 } else {
   4019                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
   4020                         return 1;
   4021                 }
   4022                 if (PyObject_HasAttrString(obj, "orelse")) {
   4023                         int res;
   4024                         Py_ssize_t len;
   4025                         Py_ssize_t i;
   4026                         tmp = PyObject_GetAttrString(obj, "orelse");
   4027                         if (tmp == NULL) goto failed;
   4028                         if (!PyList_Check(tmp)) {
   4029                                 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4030                                 goto failed;
   4031                         }
   4032                         len = PyList_GET_SIZE(tmp);
   4033                         orelse = asdl_seq_new(len, arena);
   4034                         if (orelse == NULL) goto failed;
   4035                         for (i = 0; i < len; i++) {
   4036                                 stmt_ty val;
   4037                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4038                                 if (res != 0) goto failed;
   4039                                 if (len != PyList_GET_SIZE(tmp)) {
   4040                                         PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
   4041                                         goto failed;
   4042                                 }
   4043                                 asdl_seq_SET(orelse, i, val);
   4044                         }
   4045                         Py_XDECREF(tmp);
   4046                         tmp = NULL;
   4047                 } else {
   4048                         PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
   4049                         return 1;
   4050                 }
   4051                 *out = For(target, iter, body, orelse, lineno, col_offset,
   4052                            arena);
   4053                 if (*out == NULL) goto failed;
   4054                 return 0;
   4055         }
   4056         isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
   4057         if (isinstance == -1) {
   4058                 return 1;
   4059         }
   4060         if (isinstance) {
   4061                 expr_ty test;
   4062                 asdl_seq* body;
   4063                 asdl_seq* orelse;
   4064 
   4065                 if (PyObject_HasAttrString(obj, "test")) {
   4066                         int res;
   4067                         tmp = PyObject_GetAttrString(obj, "test");
   4068                         if (tmp == NULL) goto failed;
   4069                         res = obj2ast_expr(tmp, &test, arena);
   4070                         if (res != 0) goto failed;
   4071                         Py_XDECREF(tmp);
   4072                         tmp = NULL;
   4073                 } else {
   4074                         PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
   4075                         return 1;
   4076                 }
   4077                 if (PyObject_HasAttrString(obj, "body")) {
   4078                         int res;
   4079                         Py_ssize_t len;
   4080                         Py_ssize_t i;
   4081                         tmp = PyObject_GetAttrString(obj, "body");
   4082                         if (tmp == NULL) goto failed;
   4083                         if (!PyList_Check(tmp)) {
   4084                                 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4085                                 goto failed;
   4086                         }
   4087                         len = PyList_GET_SIZE(tmp);
   4088                         body = asdl_seq_new(len, arena);
   4089                         if (body == NULL) goto failed;
   4090                         for (i = 0; i < len; i++) {
   4091                                 stmt_ty val;
   4092                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4093                                 if (res != 0) goto failed;
   4094                                 if (len != PyList_GET_SIZE(tmp)) {
   4095                                         PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
   4096                                         goto failed;
   4097                                 }
   4098                                 asdl_seq_SET(body, i, val);
   4099                         }
   4100                         Py_XDECREF(tmp);
   4101                         tmp = NULL;
   4102                 } else {
   4103                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
   4104                         return 1;
   4105                 }
   4106                 if (PyObject_HasAttrString(obj, "orelse")) {
   4107                         int res;
   4108                         Py_ssize_t len;
   4109                         Py_ssize_t i;
   4110                         tmp = PyObject_GetAttrString(obj, "orelse");
   4111                         if (tmp == NULL) goto failed;
   4112                         if (!PyList_Check(tmp)) {
   4113                                 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4114                                 goto failed;
   4115                         }
   4116                         len = PyList_GET_SIZE(tmp);
   4117                         orelse = asdl_seq_new(len, arena);
   4118                         if (orelse == NULL) goto failed;
   4119                         for (i = 0; i < len; i++) {
   4120                                 stmt_ty val;
   4121                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4122                                 if (res != 0) goto failed;
   4123                                 if (len != PyList_GET_SIZE(tmp)) {
   4124                                         PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
   4125                                         goto failed;
   4126                                 }
   4127                                 asdl_seq_SET(orelse, i, val);
   4128                         }
   4129                         Py_XDECREF(tmp);
   4130                         tmp = NULL;
   4131                 } else {
   4132                         PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
   4133                         return 1;
   4134                 }
   4135                 *out = While(test, body, orelse, lineno, col_offset, arena);
   4136                 if (*out == NULL) goto failed;
   4137                 return 0;
   4138         }
   4139         isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
   4140         if (isinstance == -1) {
   4141                 return 1;
   4142         }
   4143         if (isinstance) {
   4144                 expr_ty test;
   4145                 asdl_seq* body;
   4146                 asdl_seq* orelse;
   4147 
   4148                 if (PyObject_HasAttrString(obj, "test")) {
   4149                         int res;
   4150                         tmp = PyObject_GetAttrString(obj, "test");
   4151                         if (tmp == NULL) goto failed;
   4152                         res = obj2ast_expr(tmp, &test, arena);
   4153                         if (res != 0) goto failed;
   4154                         Py_XDECREF(tmp);
   4155                         tmp = NULL;
   4156                 } else {
   4157                         PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
   4158                         return 1;
   4159                 }
   4160                 if (PyObject_HasAttrString(obj, "body")) {
   4161                         int res;
   4162                         Py_ssize_t len;
   4163                         Py_ssize_t i;
   4164                         tmp = PyObject_GetAttrString(obj, "body");
   4165                         if (tmp == NULL) goto failed;
   4166                         if (!PyList_Check(tmp)) {
   4167                                 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4168                                 goto failed;
   4169                         }
   4170                         len = PyList_GET_SIZE(tmp);
   4171                         body = asdl_seq_new(len, arena);
   4172                         if (body == NULL) goto failed;
   4173                         for (i = 0; i < len; i++) {
   4174                                 stmt_ty val;
   4175                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4176                                 if (res != 0) goto failed;
   4177                                 if (len != PyList_GET_SIZE(tmp)) {
   4178                                         PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
   4179                                         goto failed;
   4180                                 }
   4181                                 asdl_seq_SET(body, i, val);
   4182                         }
   4183                         Py_XDECREF(tmp);
   4184                         tmp = NULL;
   4185                 } else {
   4186                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
   4187                         return 1;
   4188                 }
   4189                 if (PyObject_HasAttrString(obj, "orelse")) {
   4190                         int res;
   4191                         Py_ssize_t len;
   4192                         Py_ssize_t i;
   4193                         tmp = PyObject_GetAttrString(obj, "orelse");
   4194                         if (tmp == NULL) goto failed;
   4195                         if (!PyList_Check(tmp)) {
   4196                                 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4197                                 goto failed;
   4198                         }
   4199                         len = PyList_GET_SIZE(tmp);
   4200                         orelse = asdl_seq_new(len, arena);
   4201                         if (orelse == NULL) goto failed;
   4202                         for (i = 0; i < len; i++) {
   4203                                 stmt_ty val;
   4204                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4205                                 if (res != 0) goto failed;
   4206                                 if (len != PyList_GET_SIZE(tmp)) {
   4207                                         PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
   4208                                         goto failed;
   4209                                 }
   4210                                 asdl_seq_SET(orelse, i, val);
   4211                         }
   4212                         Py_XDECREF(tmp);
   4213                         tmp = NULL;
   4214                 } else {
   4215                         PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
   4216                         return 1;
   4217                 }
   4218                 *out = If(test, body, orelse, lineno, col_offset, arena);
   4219                 if (*out == NULL) goto failed;
   4220                 return 0;
   4221         }
   4222         isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
   4223         if (isinstance == -1) {
   4224                 return 1;
   4225         }
   4226         if (isinstance) {
   4227                 expr_ty context_expr;
   4228                 expr_ty optional_vars;
   4229                 asdl_seq* body;
   4230 
   4231                 if (PyObject_HasAttrString(obj, "context_expr")) {
   4232                         int res;
   4233                         tmp = PyObject_GetAttrString(obj, "context_expr");
   4234                         if (tmp == NULL) goto failed;
   4235                         res = obj2ast_expr(tmp, &context_expr, arena);
   4236                         if (res != 0) goto failed;
   4237                         Py_XDECREF(tmp);
   4238                         tmp = NULL;
   4239                 } else {
   4240                         PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
   4241                         return 1;
   4242                 }
   4243                 if (PyObject_HasAttrString(obj, "optional_vars")) {
   4244                         int res;
   4245                         tmp = PyObject_GetAttrString(obj, "optional_vars");
   4246                         if (tmp == NULL) goto failed;
   4247                         res = obj2ast_expr(tmp, &optional_vars, arena);
   4248                         if (res != 0) goto failed;
   4249                         Py_XDECREF(tmp);
   4250                         tmp = NULL;
   4251                 } else {
   4252                         optional_vars = NULL;
   4253                 }
   4254                 if (PyObject_HasAttrString(obj, "body")) {
   4255                         int res;
   4256                         Py_ssize_t len;
   4257                         Py_ssize_t i;
   4258                         tmp = PyObject_GetAttrString(obj, "body");
   4259                         if (tmp == NULL) goto failed;
   4260                         if (!PyList_Check(tmp)) {
   4261                                 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4262                                 goto failed;
   4263                         }
   4264                         len = PyList_GET_SIZE(tmp);
   4265                         body = asdl_seq_new(len, arena);
   4266                         if (body == NULL) goto failed;
   4267                         for (i = 0; i < len; i++) {
   4268                                 stmt_ty val;
   4269                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4270                                 if (res != 0) goto failed;
   4271                                 if (len != PyList_GET_SIZE(tmp)) {
   4272                                         PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
   4273                                         goto failed;
   4274                                 }
   4275                                 asdl_seq_SET(body, i, val);
   4276                         }
   4277                         Py_XDECREF(tmp);
   4278                         tmp = NULL;
   4279                 } else {
   4280                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
   4281                         return 1;
   4282                 }
   4283                 *out = With(context_expr, optional_vars, body, lineno,
   4284                             col_offset, arena);
   4285                 if (*out == NULL) goto failed;
   4286                 return 0;
   4287         }
   4288         isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
   4289         if (isinstance == -1) {
   4290                 return 1;
   4291         }
   4292         if (isinstance) {
   4293                 expr_ty type;
   4294                 expr_ty inst;
   4295                 expr_ty tback;
   4296 
   4297                 if (PyObject_HasAttrString(obj, "type")) {
   4298                         int res;
   4299                         tmp = PyObject_GetAttrString(obj, "type");
   4300                         if (tmp == NULL) goto failed;
   4301                         res = obj2ast_expr(tmp, &type, arena);
   4302                         if (res != 0) goto failed;
   4303                         Py_XDECREF(tmp);
   4304                         tmp = NULL;
   4305                 } else {
   4306                         type = NULL;
   4307                 }
   4308                 if (PyObject_HasAttrString(obj, "inst")) {
   4309                         int res;
   4310                         tmp = PyObject_GetAttrString(obj, "inst");
   4311                         if (tmp == NULL) goto failed;
   4312                         res = obj2ast_expr(tmp, &inst, arena);
   4313                         if (res != 0) goto failed;
   4314                         Py_XDECREF(tmp);
   4315                         tmp = NULL;
   4316                 } else {
   4317                         inst = NULL;
   4318                 }
   4319                 if (PyObject_HasAttrString(obj, "tback")) {
   4320                         int res;
   4321                         tmp = PyObject_GetAttrString(obj, "tback");
   4322                         if (tmp == NULL) goto failed;
   4323                         res = obj2ast_expr(tmp, &tback, arena);
   4324                         if (res != 0) goto failed;
   4325                         Py_XDECREF(tmp);
   4326                         tmp = NULL;
   4327                 } else {
   4328                         tback = NULL;
   4329                 }
   4330                 *out = Raise(type, inst, tback, lineno, col_offset, arena);
   4331                 if (*out == NULL) goto failed;
   4332                 return 0;
   4333         }
   4334         isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
   4335         if (isinstance == -1) {
   4336                 return 1;
   4337         }
   4338         if (isinstance) {
   4339                 asdl_seq* body;
   4340                 asdl_seq* handlers;
   4341                 asdl_seq* orelse;
   4342 
   4343                 if (PyObject_HasAttrString(obj, "body")) {
   4344                         int res;
   4345                         Py_ssize_t len;
   4346                         Py_ssize_t i;
   4347                         tmp = PyObject_GetAttrString(obj, "body");
   4348                         if (tmp == NULL) goto failed;
   4349                         if (!PyList_Check(tmp)) {
   4350                                 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4351                                 goto failed;
   4352                         }
   4353                         len = PyList_GET_SIZE(tmp);
   4354                         body = asdl_seq_new(len, arena);
   4355                         if (body == NULL) goto failed;
   4356                         for (i = 0; i < len; i++) {
   4357                                 stmt_ty val;
   4358                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4359                                 if (res != 0) goto failed;
   4360                                 if (len != PyList_GET_SIZE(tmp)) {
   4361                                         PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"body\" changed size during iteration");
   4362                                         goto failed;
   4363                                 }
   4364                                 asdl_seq_SET(body, i, val);
   4365                         }
   4366                         Py_XDECREF(tmp);
   4367                         tmp = NULL;
   4368                 } else {
   4369                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
   4370                         return 1;
   4371                 }
   4372                 if (PyObject_HasAttrString(obj, "handlers")) {
   4373                         int res;
   4374                         Py_ssize_t len;
   4375                         Py_ssize_t i;
   4376                         tmp = PyObject_GetAttrString(obj, "handlers");
   4377                         if (tmp == NULL) goto failed;
   4378                         if (!PyList_Check(tmp)) {
   4379                                 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4380                                 goto failed;
   4381                         }
   4382                         len = PyList_GET_SIZE(tmp);
   4383                         handlers = asdl_seq_new(len, arena);
   4384                         if (handlers == NULL) goto failed;
   4385                         for (i = 0; i < len; i++) {
   4386                                 excepthandler_ty val;
   4387                                 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena);
   4388                                 if (res != 0) goto failed;
   4389                                 if (len != PyList_GET_SIZE(tmp)) {
   4390                                         PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"handlers\" changed size during iteration");
   4391                                         goto failed;
   4392                                 }
   4393                                 asdl_seq_SET(handlers, i, val);
   4394                         }
   4395                         Py_XDECREF(tmp);
   4396                         tmp = NULL;
   4397                 } else {
   4398                         PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
   4399                         return 1;
   4400                 }
   4401                 if (PyObject_HasAttrString(obj, "orelse")) {
   4402                         int res;
   4403                         Py_ssize_t len;
   4404                         Py_ssize_t i;
   4405                         tmp = PyObject_GetAttrString(obj, "orelse");
   4406                         if (tmp == NULL) goto failed;
   4407                         if (!PyList_Check(tmp)) {
   4408                                 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4409                                 goto failed;
   4410                         }
   4411                         len = PyList_GET_SIZE(tmp);
   4412                         orelse = asdl_seq_new(len, arena);
   4413                         if (orelse == NULL) goto failed;
   4414                         for (i = 0; i < len; i++) {
   4415                                 stmt_ty val;
   4416                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4417                                 if (res != 0) goto failed;
   4418                                 if (len != PyList_GET_SIZE(tmp)) {
   4419                                         PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"orelse\" changed size during iteration");
   4420                                         goto failed;
   4421                                 }
   4422                                 asdl_seq_SET(orelse, i, val);
   4423                         }
   4424                         Py_XDECREF(tmp);
   4425                         tmp = NULL;
   4426                 } else {
   4427                         PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
   4428                         return 1;
   4429                 }
   4430                 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
   4431                                  arena);
   4432                 if (*out == NULL) goto failed;
   4433                 return 0;
   4434         }
   4435         isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
   4436         if (isinstance == -1) {
   4437                 return 1;
   4438         }
   4439         if (isinstance) {
   4440                 asdl_seq* body;
   4441                 asdl_seq* finalbody;
   4442 
   4443                 if (PyObject_HasAttrString(obj, "body")) {
   4444                         int res;
   4445                         Py_ssize_t len;
   4446                         Py_ssize_t i;
   4447                         tmp = PyObject_GetAttrString(obj, "body");
   4448                         if (tmp == NULL) goto failed;
   4449                         if (!PyList_Check(tmp)) {
   4450                                 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4451                                 goto failed;
   4452                         }
   4453                         len = PyList_GET_SIZE(tmp);
   4454                         body = asdl_seq_new(len, arena);
   4455                         if (body == NULL) goto failed;
   4456                         for (i = 0; i < len; i++) {
   4457                                 stmt_ty val;
   4458                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4459                                 if (res != 0) goto failed;
   4460                                 if (len != PyList_GET_SIZE(tmp)) {
   4461                                         PyErr_SetString(PyExc_RuntimeError, "TryFinally field \"body\" changed size during iteration");
   4462                                         goto failed;
   4463                                 }
   4464                                 asdl_seq_SET(body, i, val);
   4465                         }
   4466                         Py_XDECREF(tmp);
   4467                         tmp = NULL;
   4468                 } else {
   4469                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
   4470                         return 1;
   4471                 }
   4472                 if (PyObject_HasAttrString(obj, "finalbody")) {
   4473                         int res;
   4474                         Py_ssize_t len;
   4475                         Py_ssize_t i;
   4476                         tmp = PyObject_GetAttrString(obj, "finalbody");
   4477                         if (tmp == NULL) goto failed;
   4478                         if (!PyList_Check(tmp)) {
   4479                                 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4480                                 goto failed;
   4481                         }
   4482                         len = PyList_GET_SIZE(tmp);
   4483                         finalbody = asdl_seq_new(len, arena);
   4484                         if (finalbody == NULL) goto failed;
   4485                         for (i = 0; i < len; i++) {
   4486                                 stmt_ty val;
   4487                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   4488                                 if (res != 0) goto failed;
   4489                                 if (len != PyList_GET_SIZE(tmp)) {
   4490                                         PyErr_SetString(PyExc_RuntimeError, "TryFinally field \"finalbody\" changed size during iteration");
   4491                                         goto failed;
   4492                                 }
   4493                                 asdl_seq_SET(finalbody, i, val);
   4494                         }
   4495                         Py_XDECREF(tmp);
   4496                         tmp = NULL;
   4497                 } else {
   4498                         PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
   4499                         return 1;
   4500                 }
   4501                 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
   4502                 if (*out == NULL) goto failed;
   4503                 return 0;
   4504         }
   4505         isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
   4506         if (isinstance == -1) {
   4507                 return 1;
   4508         }
   4509         if (isinstance) {
   4510                 expr_ty test;
   4511                 expr_ty msg;
   4512 
   4513                 if (PyObject_HasAttrString(obj, "test")) {
   4514                         int res;
   4515                         tmp = PyObject_GetAttrString(obj, "test");
   4516                         if (tmp == NULL) goto failed;
   4517                         res = obj2ast_expr(tmp, &test, arena);
   4518                         if (res != 0) goto failed;
   4519                         Py_XDECREF(tmp);
   4520                         tmp = NULL;
   4521                 } else {
   4522                         PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
   4523                         return 1;
   4524                 }
   4525                 if (PyObject_HasAttrString(obj, "msg")) {
   4526                         int res;
   4527                         tmp = PyObject_GetAttrString(obj, "msg");
   4528                         if (tmp == NULL) goto failed;
   4529                         res = obj2ast_expr(tmp, &msg, arena);
   4530                         if (res != 0) goto failed;
   4531                         Py_XDECREF(tmp);
   4532                         tmp = NULL;
   4533                 } else {
   4534                         msg = NULL;
   4535                 }
   4536                 *out = Assert(test, msg, lineno, col_offset, arena);
   4537                 if (*out == NULL) goto failed;
   4538                 return 0;
   4539         }
   4540         isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
   4541         if (isinstance == -1) {
   4542                 return 1;
   4543         }
   4544         if (isinstance) {
   4545                 asdl_seq* names;
   4546 
   4547                 if (PyObject_HasAttrString(obj, "names")) {
   4548                         int res;
   4549                         Py_ssize_t len;
   4550                         Py_ssize_t i;
   4551                         tmp = PyObject_GetAttrString(obj, "names");
   4552                         if (tmp == NULL) goto failed;
   4553                         if (!PyList_Check(tmp)) {
   4554                                 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4555                                 goto failed;
   4556                         }
   4557                         len = PyList_GET_SIZE(tmp);
   4558                         names = asdl_seq_new(len, arena);
   4559                         if (names == NULL) goto failed;
   4560                         for (i = 0; i < len; i++) {
   4561                                 alias_ty val;
   4562                                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
   4563                                 if (res != 0) goto failed;
   4564                                 if (len != PyList_GET_SIZE(tmp)) {
   4565                                         PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
   4566                                         goto failed;
   4567                                 }
   4568                                 asdl_seq_SET(names, i, val);
   4569                         }
   4570                         Py_XDECREF(tmp);
   4571                         tmp = NULL;
   4572                 } else {
   4573                         PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
   4574                         return 1;
   4575                 }
   4576                 *out = Import(names, lineno, col_offset, arena);
   4577                 if (*out == NULL) goto failed;
   4578                 return 0;
   4579         }
   4580         isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
   4581         if (isinstance == -1) {
   4582                 return 1;
   4583         }
   4584         if (isinstance) {
   4585                 identifier module;
   4586                 asdl_seq* names;
   4587                 int level;
   4588 
   4589                 if (PyObject_HasAttrString(obj, "module")) {
   4590                         int res;
   4591                         tmp = PyObject_GetAttrString(obj, "module");
   4592                         if (tmp == NULL) goto failed;
   4593                         res = obj2ast_identifier(tmp, &module, arena);
   4594                         if (res != 0) goto failed;
   4595                         Py_XDECREF(tmp);
   4596                         tmp = NULL;
   4597                 } else {
   4598                         module = NULL;
   4599                 }
   4600                 if (PyObject_HasAttrString(obj, "names")) {
   4601                         int res;
   4602                         Py_ssize_t len;
   4603                         Py_ssize_t i;
   4604                         tmp = PyObject_GetAttrString(obj, "names");
   4605                         if (tmp == NULL) goto failed;
   4606                         if (!PyList_Check(tmp)) {
   4607                                 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4608                                 goto failed;
   4609                         }
   4610                         len = PyList_GET_SIZE(tmp);
   4611                         names = asdl_seq_new(len, arena);
   4612                         if (names == NULL) goto failed;
   4613                         for (i = 0; i < len; i++) {
   4614                                 alias_ty val;
   4615                                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
   4616                                 if (res != 0) goto failed;
   4617                                 if (len != PyList_GET_SIZE(tmp)) {
   4618                                         PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
   4619                                         goto failed;
   4620                                 }
   4621                                 asdl_seq_SET(names, i, val);
   4622                         }
   4623                         Py_XDECREF(tmp);
   4624                         tmp = NULL;
   4625                 } else {
   4626                         PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
   4627                         return 1;
   4628                 }
   4629                 if (PyObject_HasAttrString(obj, "level")) {
   4630                         int res;
   4631                         tmp = PyObject_GetAttrString(obj, "level");
   4632                         if (tmp == NULL) goto failed;
   4633                         res = obj2ast_int(tmp, &level, arena);
   4634                         if (res != 0) goto failed;
   4635                         Py_XDECREF(tmp);
   4636                         tmp = NULL;
   4637                 } else {
   4638                         level = 0;
   4639                 }
   4640                 *out = ImportFrom(module, names, level, lineno, col_offset,
   4641                                   arena);
   4642                 if (*out == NULL) goto failed;
   4643                 return 0;
   4644         }
   4645         isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
   4646         if (isinstance == -1) {
   4647                 return 1;
   4648         }
   4649         if (isinstance) {
   4650                 expr_ty body;
   4651                 expr_ty globals;
   4652                 expr_ty locals;
   4653 
   4654                 if (PyObject_HasAttrString(obj, "body")) {
   4655                         int res;
   4656                         tmp = PyObject_GetAttrString(obj, "body");
   4657                         if (tmp == NULL) goto failed;
   4658                         res = obj2ast_expr(tmp, &body, arena);
   4659                         if (res != 0) goto failed;
   4660                         Py_XDECREF(tmp);
   4661                         tmp = NULL;
   4662                 } else {
   4663                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
   4664                         return 1;
   4665                 }
   4666                 if (PyObject_HasAttrString(obj, "globals")) {
   4667                         int res;
   4668                         tmp = PyObject_GetAttrString(obj, "globals");
   4669                         if (tmp == NULL) goto failed;
   4670                         res = obj2ast_expr(tmp, &globals, arena);
   4671                         if (res != 0) goto failed;
   4672                         Py_XDECREF(tmp);
   4673                         tmp = NULL;
   4674                 } else {
   4675                         globals = NULL;
   4676                 }
   4677                 if (PyObject_HasAttrString(obj, "locals")) {
   4678                         int res;
   4679                         tmp = PyObject_GetAttrString(obj, "locals");
   4680                         if (tmp == NULL) goto failed;
   4681                         res = obj2ast_expr(tmp, &locals, arena);
   4682                         if (res != 0) goto failed;
   4683                         Py_XDECREF(tmp);
   4684                         tmp = NULL;
   4685                 } else {
   4686                         locals = NULL;
   4687                 }
   4688                 *out = Exec(body, globals, locals, lineno, col_offset, arena);
   4689                 if (*out == NULL) goto failed;
   4690                 return 0;
   4691         }
   4692         isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
   4693         if (isinstance == -1) {
   4694                 return 1;
   4695         }
   4696         if (isinstance) {
   4697                 asdl_seq* names;
   4698 
   4699                 if (PyObject_HasAttrString(obj, "names")) {
   4700                         int res;
   4701                         Py_ssize_t len;
   4702                         Py_ssize_t i;
   4703                         tmp = PyObject_GetAttrString(obj, "names");
   4704                         if (tmp == NULL) goto failed;
   4705                         if (!PyList_Check(tmp)) {
   4706                                 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4707                                 goto failed;
   4708                         }
   4709                         len = PyList_GET_SIZE(tmp);
   4710                         names = asdl_seq_new(len, arena);
   4711                         if (names == NULL) goto failed;
   4712                         for (i = 0; i < len; i++) {
   4713                                 identifier val;
   4714                                 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
   4715                                 if (res != 0) goto failed;
   4716                                 if (len != PyList_GET_SIZE(tmp)) {
   4717                                         PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
   4718                                         goto failed;
   4719                                 }
   4720                                 asdl_seq_SET(names, i, val);
   4721                         }
   4722                         Py_XDECREF(tmp);
   4723                         tmp = NULL;
   4724                 } else {
   4725                         PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
   4726                         return 1;
   4727                 }
   4728                 *out = Global(names, lineno, col_offset, arena);
   4729                 if (*out == NULL) goto failed;
   4730                 return 0;
   4731         }
   4732         isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
   4733         if (isinstance == -1) {
   4734                 return 1;
   4735         }
   4736         if (isinstance) {
   4737                 expr_ty value;
   4738 
   4739                 if (PyObject_HasAttrString(obj, "value")) {
   4740                         int res;
   4741                         tmp = PyObject_GetAttrString(obj, "value");
   4742                         if (tmp == NULL) goto failed;
   4743                         res = obj2ast_expr(tmp, &value, arena);
   4744                         if (res != 0) goto failed;
   4745                         Py_XDECREF(tmp);
   4746                         tmp = NULL;
   4747                 } else {
   4748                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
   4749                         return 1;
   4750                 }
   4751                 *out = Expr(value, lineno, col_offset, arena);
   4752                 if (*out == NULL) goto failed;
   4753                 return 0;
   4754         }
   4755         isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
   4756         if (isinstance == -1) {
   4757                 return 1;
   4758         }
   4759         if (isinstance) {
   4760 
   4761                 *out = Pass(lineno, col_offset, arena);
   4762                 if (*out == NULL) goto failed;
   4763                 return 0;
   4764         }
   4765         isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
   4766         if (isinstance == -1) {
   4767                 return 1;
   4768         }
   4769         if (isinstance) {
   4770 
   4771                 *out = Break(lineno, col_offset, arena);
   4772                 if (*out == NULL) goto failed;
   4773                 return 0;
   4774         }
   4775         isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
   4776         if (isinstance == -1) {
   4777                 return 1;
   4778         }
   4779         if (isinstance) {
   4780 
   4781                 *out = Continue(lineno, col_offset, arena);
   4782                 if (*out == NULL) goto failed;
   4783                 return 0;
   4784         }
   4785 
   4786         tmp = PyObject_Repr(obj);
   4787         if (tmp == NULL) goto failed;
   4788         PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
   4789 failed:
   4790         Py_XDECREF(tmp);
   4791         return 1;
   4792 }
   4793 
   4794 int
   4795 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
   4796 {
   4797         PyObject* tmp = NULL;
   4798         int isinstance;
   4799 
   4800         int lineno;
   4801         int col_offset;
   4802 
   4803         if (obj == Py_None) {
   4804                 *out = NULL;
   4805                 return 0;
   4806         }
   4807         if (PyObject_HasAttrString(obj, "lineno")) {
   4808                 int res;
   4809                 tmp = PyObject_GetAttrString(obj, "lineno");
   4810                 if (tmp == NULL) goto failed;
   4811                 res = obj2ast_int(tmp, &lineno, arena);
   4812                 if (res != 0) goto failed;
   4813                 Py_XDECREF(tmp);
   4814                 tmp = NULL;
   4815         } else {
   4816                 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
   4817                 return 1;
   4818         }
   4819         if (PyObject_HasAttrString(obj, "col_offset")) {
   4820                 int res;
   4821                 tmp = PyObject_GetAttrString(obj, "col_offset");
   4822                 if (tmp == NULL) goto failed;
   4823                 res = obj2ast_int(tmp, &col_offset, arena);
   4824                 if (res != 0) goto failed;
   4825                 Py_XDECREF(tmp);
   4826                 tmp = NULL;
   4827         } else {
   4828                 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
   4829                 return 1;
   4830         }
   4831         isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
   4832         if (isinstance == -1) {
   4833                 return 1;
   4834         }
   4835         if (isinstance) {
   4836                 boolop_ty op;
   4837                 asdl_seq* values;
   4838 
   4839                 if (PyObject_HasAttrString(obj, "op")) {
   4840                         int res;
   4841                         tmp = PyObject_GetAttrString(obj, "op");
   4842                         if (tmp == NULL) goto failed;
   4843                         res = obj2ast_boolop(tmp, &op, arena);
   4844                         if (res != 0) goto failed;
   4845                         Py_XDECREF(tmp);
   4846                         tmp = NULL;
   4847                 } else {
   4848                         PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
   4849                         return 1;
   4850                 }
   4851                 if (PyObject_HasAttrString(obj, "values")) {
   4852                         int res;
   4853                         Py_ssize_t len;
   4854                         Py_ssize_t i;
   4855                         tmp = PyObject_GetAttrString(obj, "values");
   4856                         if (tmp == NULL) goto failed;
   4857                         if (!PyList_Check(tmp)) {
   4858                                 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   4859                                 goto failed;
   4860                         }
   4861                         len = PyList_GET_SIZE(tmp);
   4862                         values = asdl_seq_new(len, arena);
   4863                         if (values == NULL) goto failed;
   4864                         for (i = 0; i < len; i++) {
   4865                                 expr_ty val;
   4866                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   4867                                 if (res != 0) goto failed;
   4868                                 if (len != PyList_GET_SIZE(tmp)) {
   4869                                         PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
   4870                                         goto failed;
   4871                                 }
   4872                                 asdl_seq_SET(values, i, val);
   4873                         }
   4874                         Py_XDECREF(tmp);
   4875                         tmp = NULL;
   4876                 } else {
   4877                         PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
   4878                         return 1;
   4879                 }
   4880                 *out = BoolOp(op, values, lineno, col_offset, arena);
   4881                 if (*out == NULL) goto failed;
   4882                 return 0;
   4883         }
   4884         isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
   4885         if (isinstance == -1) {
   4886                 return 1;
   4887         }
   4888         if (isinstance) {
   4889                 expr_ty left;
   4890                 operator_ty op;
   4891                 expr_ty right;
   4892 
   4893                 if (PyObject_HasAttrString(obj, "left")) {
   4894                         int res;
   4895                         tmp = PyObject_GetAttrString(obj, "left");
   4896                         if (tmp == NULL) goto failed;
   4897                         res = obj2ast_expr(tmp, &left, arena);
   4898                         if (res != 0) goto failed;
   4899                         Py_XDECREF(tmp);
   4900                         tmp = NULL;
   4901                 } else {
   4902                         PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
   4903                         return 1;
   4904                 }
   4905                 if (PyObject_HasAttrString(obj, "op")) {
   4906                         int res;
   4907                         tmp = PyObject_GetAttrString(obj, "op");
   4908                         if (tmp == NULL) goto failed;
   4909                         res = obj2ast_operator(tmp, &op, arena);
   4910                         if (res != 0) goto failed;
   4911                         Py_XDECREF(tmp);
   4912                         tmp = NULL;
   4913                 } else {
   4914                         PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
   4915                         return 1;
   4916                 }
   4917                 if (PyObject_HasAttrString(obj, "right")) {
   4918                         int res;
   4919                         tmp = PyObject_GetAttrString(obj, "right");
   4920                         if (tmp == NULL) goto failed;
   4921                         res = obj2ast_expr(tmp, &right, arena);
   4922                         if (res != 0) goto failed;
   4923                         Py_XDECREF(tmp);
   4924                         tmp = NULL;
   4925                 } else {
   4926                         PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
   4927                         return 1;
   4928                 }
   4929                 *out = BinOp(left, op, right, lineno, col_offset, arena);
   4930                 if (*out == NULL) goto failed;
   4931                 return 0;
   4932         }
   4933         isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
   4934         if (isinstance == -1) {
   4935                 return 1;
   4936         }
   4937         if (isinstance) {
   4938                 unaryop_ty op;
   4939                 expr_ty operand;
   4940 
   4941                 if (PyObject_HasAttrString(obj, "op")) {
   4942                         int res;
   4943                         tmp = PyObject_GetAttrString(obj, "op");
   4944                         if (tmp == NULL) goto failed;
   4945                         res = obj2ast_unaryop(tmp, &op, arena);
   4946                         if (res != 0) goto failed;
   4947                         Py_XDECREF(tmp);
   4948                         tmp = NULL;
   4949                 } else {
   4950                         PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
   4951                         return 1;
   4952                 }
   4953                 if (PyObject_HasAttrString(obj, "operand")) {
   4954                         int res;
   4955                         tmp = PyObject_GetAttrString(obj, "operand");
   4956                         if (tmp == NULL) goto failed;
   4957                         res = obj2ast_expr(tmp, &operand, arena);
   4958                         if (res != 0) goto failed;
   4959                         Py_XDECREF(tmp);
   4960                         tmp = NULL;
   4961                 } else {
   4962                         PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
   4963                         return 1;
   4964                 }
   4965                 *out = UnaryOp(op, operand, lineno, col_offset, arena);
   4966                 if (*out == NULL) goto failed;
   4967                 return 0;
   4968         }
   4969         isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
   4970         if (isinstance == -1) {
   4971                 return 1;
   4972         }
   4973         if (isinstance) {
   4974                 arguments_ty args;
   4975                 expr_ty body;
   4976 
   4977                 if (PyObject_HasAttrString(obj, "args")) {
   4978                         int res;
   4979                         tmp = PyObject_GetAttrString(obj, "args");
   4980                         if (tmp == NULL) goto failed;
   4981                         res = obj2ast_arguments(tmp, &args, arena);
   4982                         if (res != 0) goto failed;
   4983                         Py_XDECREF(tmp);
   4984                         tmp = NULL;
   4985                 } else {
   4986                         PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
   4987                         return 1;
   4988                 }
   4989                 if (PyObject_HasAttrString(obj, "body")) {
   4990                         int res;
   4991                         tmp = PyObject_GetAttrString(obj, "body");
   4992                         if (tmp == NULL) goto failed;
   4993                         res = obj2ast_expr(tmp, &body, arena);
   4994                         if (res != 0) goto failed;
   4995                         Py_XDECREF(tmp);
   4996                         tmp = NULL;
   4997                 } else {
   4998                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
   4999                         return 1;
   5000                 }
   5001                 *out = Lambda(args, body, lineno, col_offset, arena);
   5002                 if (*out == NULL) goto failed;
   5003                 return 0;
   5004         }
   5005         isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
   5006         if (isinstance == -1) {
   5007                 return 1;
   5008         }
   5009         if (isinstance) {
   5010                 expr_ty test;
   5011                 expr_ty body;
   5012                 expr_ty orelse;
   5013 
   5014                 if (PyObject_HasAttrString(obj, "test")) {
   5015                         int res;
   5016                         tmp = PyObject_GetAttrString(obj, "test");
   5017                         if (tmp == NULL) goto failed;
   5018                         res = obj2ast_expr(tmp, &test, arena);
   5019                         if (res != 0) goto failed;
   5020                         Py_XDECREF(tmp);
   5021                         tmp = NULL;
   5022                 } else {
   5023                         PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
   5024                         return 1;
   5025                 }
   5026                 if (PyObject_HasAttrString(obj, "body")) {
   5027                         int res;
   5028                         tmp = PyObject_GetAttrString(obj, "body");
   5029                         if (tmp == NULL) goto failed;
   5030                         res = obj2ast_expr(tmp, &body, arena);
   5031                         if (res != 0) goto failed;
   5032                         Py_XDECREF(tmp);
   5033                         tmp = NULL;
   5034                 } else {
   5035                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
   5036                         return 1;
   5037                 }
   5038                 if (PyObject_HasAttrString(obj, "orelse")) {
   5039                         int res;
   5040                         tmp = PyObject_GetAttrString(obj, "orelse");
   5041                         if (tmp == NULL) goto failed;
   5042                         res = obj2ast_expr(tmp, &orelse, arena);
   5043                         if (res != 0) goto failed;
   5044                         Py_XDECREF(tmp);
   5045                         tmp = NULL;
   5046                 } else {
   5047                         PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
   5048                         return 1;
   5049                 }
   5050                 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
   5051                 if (*out == NULL) goto failed;
   5052                 return 0;
   5053         }
   5054         isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
   5055         if (isinstance == -1) {
   5056                 return 1;
   5057         }
   5058         if (isinstance) {
   5059                 asdl_seq* keys;
   5060                 asdl_seq* values;
   5061 
   5062                 if (PyObject_HasAttrString(obj, "keys")) {
   5063                         int res;
   5064                         Py_ssize_t len;
   5065                         Py_ssize_t i;
   5066                         tmp = PyObject_GetAttrString(obj, "keys");
   5067                         if (tmp == NULL) goto failed;
   5068                         if (!PyList_Check(tmp)) {
   5069                                 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5070                                 goto failed;
   5071                         }
   5072                         len = PyList_GET_SIZE(tmp);
   5073                         keys = asdl_seq_new(len, arena);
   5074                         if (keys == NULL) goto failed;
   5075                         for (i = 0; i < len; i++) {
   5076                                 expr_ty val;
   5077                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5078                                 if (res != 0) goto failed;
   5079                                 if (len != PyList_GET_SIZE(tmp)) {
   5080                                         PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
   5081                                         goto failed;
   5082                                 }
   5083                                 asdl_seq_SET(keys, i, val);
   5084                         }
   5085                         Py_XDECREF(tmp);
   5086                         tmp = NULL;
   5087                 } else {
   5088                         PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
   5089                         return 1;
   5090                 }
   5091                 if (PyObject_HasAttrString(obj, "values")) {
   5092                         int res;
   5093                         Py_ssize_t len;
   5094                         Py_ssize_t i;
   5095                         tmp = PyObject_GetAttrString(obj, "values");
   5096                         if (tmp == NULL) goto failed;
   5097                         if (!PyList_Check(tmp)) {
   5098                                 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5099                                 goto failed;
   5100                         }
   5101                         len = PyList_GET_SIZE(tmp);
   5102                         values = asdl_seq_new(len, arena);
   5103                         if (values == NULL) goto failed;
   5104                         for (i = 0; i < len; i++) {
   5105                                 expr_ty val;
   5106                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5107                                 if (res != 0) goto failed;
   5108                                 if (len != PyList_GET_SIZE(tmp)) {
   5109                                         PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
   5110                                         goto failed;
   5111                                 }
   5112                                 asdl_seq_SET(values, i, val);
   5113                         }
   5114                         Py_XDECREF(tmp);
   5115                         tmp = NULL;
   5116                 } else {
   5117                         PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
   5118                         return 1;
   5119                 }
   5120                 *out = Dict(keys, values, lineno, col_offset, arena);
   5121                 if (*out == NULL) goto failed;
   5122                 return 0;
   5123         }
   5124         isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
   5125         if (isinstance == -1) {
   5126                 return 1;
   5127         }
   5128         if (isinstance) {
   5129                 asdl_seq* elts;
   5130 
   5131                 if (PyObject_HasAttrString(obj, "elts")) {
   5132                         int res;
   5133                         Py_ssize_t len;
   5134                         Py_ssize_t i;
   5135                         tmp = PyObject_GetAttrString(obj, "elts");
   5136                         if (tmp == NULL) goto failed;
   5137                         if (!PyList_Check(tmp)) {
   5138                                 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5139                                 goto failed;
   5140                         }
   5141                         len = PyList_GET_SIZE(tmp);
   5142                         elts = asdl_seq_new(len, arena);
   5143                         if (elts == NULL) goto failed;
   5144                         for (i = 0; i < len; i++) {
   5145                                 expr_ty val;
   5146                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5147                                 if (res != 0) goto failed;
   5148                                 if (len != PyList_GET_SIZE(tmp)) {
   5149                                         PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
   5150                                         goto failed;
   5151                                 }
   5152                                 asdl_seq_SET(elts, i, val);
   5153                         }
   5154                         Py_XDECREF(tmp);
   5155                         tmp = NULL;
   5156                 } else {
   5157                         PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
   5158                         return 1;
   5159                 }
   5160                 *out = Set(elts, lineno, col_offset, arena);
   5161                 if (*out == NULL) goto failed;
   5162                 return 0;
   5163         }
   5164         isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
   5165         if (isinstance == -1) {
   5166                 return 1;
   5167         }
   5168         if (isinstance) {
   5169                 expr_ty elt;
   5170                 asdl_seq* generators;
   5171 
   5172                 if (PyObject_HasAttrString(obj, "elt")) {
   5173                         int res;
   5174                         tmp = PyObject_GetAttrString(obj, "elt");
   5175                         if (tmp == NULL) goto failed;
   5176                         res = obj2ast_expr(tmp, &elt, arena);
   5177                         if (res != 0) goto failed;
   5178                         Py_XDECREF(tmp);
   5179                         tmp = NULL;
   5180                 } else {
   5181                         PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
   5182                         return 1;
   5183                 }
   5184                 if (PyObject_HasAttrString(obj, "generators")) {
   5185                         int res;
   5186                         Py_ssize_t len;
   5187                         Py_ssize_t i;
   5188                         tmp = PyObject_GetAttrString(obj, "generators");
   5189                         if (tmp == NULL) goto failed;
   5190                         if (!PyList_Check(tmp)) {
   5191                                 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5192                                 goto failed;
   5193                         }
   5194                         len = PyList_GET_SIZE(tmp);
   5195                         generators = asdl_seq_new(len, arena);
   5196                         if (generators == NULL) goto failed;
   5197                         for (i = 0; i < len; i++) {
   5198                                 comprehension_ty val;
   5199                                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
   5200                                 if (res != 0) goto failed;
   5201                                 if (len != PyList_GET_SIZE(tmp)) {
   5202                                         PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
   5203                                         goto failed;
   5204                                 }
   5205                                 asdl_seq_SET(generators, i, val);
   5206                         }
   5207                         Py_XDECREF(tmp);
   5208                         tmp = NULL;
   5209                 } else {
   5210                         PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
   5211                         return 1;
   5212                 }
   5213                 *out = ListComp(elt, generators, lineno, col_offset, arena);
   5214                 if (*out == NULL) goto failed;
   5215                 return 0;
   5216         }
   5217         isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
   5218         if (isinstance == -1) {
   5219                 return 1;
   5220         }
   5221         if (isinstance) {
   5222                 expr_ty elt;
   5223                 asdl_seq* generators;
   5224 
   5225                 if (PyObject_HasAttrString(obj, "elt")) {
   5226                         int res;
   5227                         tmp = PyObject_GetAttrString(obj, "elt");
   5228                         if (tmp == NULL) goto failed;
   5229                         res = obj2ast_expr(tmp, &elt, arena);
   5230                         if (res != 0) goto failed;
   5231                         Py_XDECREF(tmp);
   5232                         tmp = NULL;
   5233                 } else {
   5234                         PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
   5235                         return 1;
   5236                 }
   5237                 if (PyObject_HasAttrString(obj, "generators")) {
   5238                         int res;
   5239                         Py_ssize_t len;
   5240                         Py_ssize_t i;
   5241                         tmp = PyObject_GetAttrString(obj, "generators");
   5242                         if (tmp == NULL) goto failed;
   5243                         if (!PyList_Check(tmp)) {
   5244                                 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5245                                 goto failed;
   5246                         }
   5247                         len = PyList_GET_SIZE(tmp);
   5248                         generators = asdl_seq_new(len, arena);
   5249                         if (generators == NULL) goto failed;
   5250                         for (i = 0; i < len; i++) {
   5251                                 comprehension_ty val;
   5252                                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
   5253                                 if (res != 0) goto failed;
   5254                                 if (len != PyList_GET_SIZE(tmp)) {
   5255                                         PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
   5256                                         goto failed;
   5257                                 }
   5258                                 asdl_seq_SET(generators, i, val);
   5259                         }
   5260                         Py_XDECREF(tmp);
   5261                         tmp = NULL;
   5262                 } else {
   5263                         PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
   5264                         return 1;
   5265                 }
   5266                 *out = SetComp(elt, generators, lineno, col_offset, arena);
   5267                 if (*out == NULL) goto failed;
   5268                 return 0;
   5269         }
   5270         isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
   5271         if (isinstance == -1) {
   5272                 return 1;
   5273         }
   5274         if (isinstance) {
   5275                 expr_ty key;
   5276                 expr_ty value;
   5277                 asdl_seq* generators;
   5278 
   5279                 if (PyObject_HasAttrString(obj, "key")) {
   5280                         int res;
   5281                         tmp = PyObject_GetAttrString(obj, "key");
   5282                         if (tmp == NULL) goto failed;
   5283                         res = obj2ast_expr(tmp, &key, arena);
   5284                         if (res != 0) goto failed;
   5285                         Py_XDECREF(tmp);
   5286                         tmp = NULL;
   5287                 } else {
   5288                         PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
   5289                         return 1;
   5290                 }
   5291                 if (PyObject_HasAttrString(obj, "value")) {
   5292                         int res;
   5293                         tmp = PyObject_GetAttrString(obj, "value");
   5294                         if (tmp == NULL) goto failed;
   5295                         res = obj2ast_expr(tmp, &value, arena);
   5296                         if (res != 0) goto failed;
   5297                         Py_XDECREF(tmp);
   5298                         tmp = NULL;
   5299                 } else {
   5300                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
   5301                         return 1;
   5302                 }
   5303                 if (PyObject_HasAttrString(obj, "generators")) {
   5304                         int res;
   5305                         Py_ssize_t len;
   5306                         Py_ssize_t i;
   5307                         tmp = PyObject_GetAttrString(obj, "generators");
   5308                         if (tmp == NULL) goto failed;
   5309                         if (!PyList_Check(tmp)) {
   5310                                 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5311                                 goto failed;
   5312                         }
   5313                         len = PyList_GET_SIZE(tmp);
   5314                         generators = asdl_seq_new(len, arena);
   5315                         if (generators == NULL) goto failed;
   5316                         for (i = 0; i < len; i++) {
   5317                                 comprehension_ty val;
   5318                                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
   5319                                 if (res != 0) goto failed;
   5320                                 if (len != PyList_GET_SIZE(tmp)) {
   5321                                         PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
   5322                                         goto failed;
   5323                                 }
   5324                                 asdl_seq_SET(generators, i, val);
   5325                         }
   5326                         Py_XDECREF(tmp);
   5327                         tmp = NULL;
   5328                 } else {
   5329                         PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
   5330                         return 1;
   5331                 }
   5332                 *out = DictComp(key, value, generators, lineno, col_offset,
   5333                                 arena);
   5334                 if (*out == NULL) goto failed;
   5335                 return 0;
   5336         }
   5337         isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
   5338         if (isinstance == -1) {
   5339                 return 1;
   5340         }
   5341         if (isinstance) {
   5342                 expr_ty elt;
   5343                 asdl_seq* generators;
   5344 
   5345                 if (PyObject_HasAttrString(obj, "elt")) {
   5346                         int res;
   5347                         tmp = PyObject_GetAttrString(obj, "elt");
   5348                         if (tmp == NULL) goto failed;
   5349                         res = obj2ast_expr(tmp, &elt, arena);
   5350                         if (res != 0) goto failed;
   5351                         Py_XDECREF(tmp);
   5352                         tmp = NULL;
   5353                 } else {
   5354                         PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
   5355                         return 1;
   5356                 }
   5357                 if (PyObject_HasAttrString(obj, "generators")) {
   5358                         int res;
   5359                         Py_ssize_t len;
   5360                         Py_ssize_t i;
   5361                         tmp = PyObject_GetAttrString(obj, "generators");
   5362                         if (tmp == NULL) goto failed;
   5363                         if (!PyList_Check(tmp)) {
   5364                                 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5365                                 goto failed;
   5366                         }
   5367                         len = PyList_GET_SIZE(tmp);
   5368                         generators = asdl_seq_new(len, arena);
   5369                         if (generators == NULL) goto failed;
   5370                         for (i = 0; i < len; i++) {
   5371                                 comprehension_ty val;
   5372                                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
   5373                                 if (res != 0) goto failed;
   5374                                 if (len != PyList_GET_SIZE(tmp)) {
   5375                                         PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
   5376                                         goto failed;
   5377                                 }
   5378                                 asdl_seq_SET(generators, i, val);
   5379                         }
   5380                         Py_XDECREF(tmp);
   5381                         tmp = NULL;
   5382                 } else {
   5383                         PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
   5384                         return 1;
   5385                 }
   5386                 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
   5387                 if (*out == NULL) goto failed;
   5388                 return 0;
   5389         }
   5390         isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
   5391         if (isinstance == -1) {
   5392                 return 1;
   5393         }
   5394         if (isinstance) {
   5395                 expr_ty value;
   5396 
   5397                 if (PyObject_HasAttrString(obj, "value")) {
   5398                         int res;
   5399                         tmp = PyObject_GetAttrString(obj, "value");
   5400                         if (tmp == NULL) goto failed;
   5401                         res = obj2ast_expr(tmp, &value, arena);
   5402                         if (res != 0) goto failed;
   5403                         Py_XDECREF(tmp);
   5404                         tmp = NULL;
   5405                 } else {
   5406                         value = NULL;
   5407                 }
   5408                 *out = Yield(value, lineno, col_offset, arena);
   5409                 if (*out == NULL) goto failed;
   5410                 return 0;
   5411         }
   5412         isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
   5413         if (isinstance == -1) {
   5414                 return 1;
   5415         }
   5416         if (isinstance) {
   5417                 expr_ty left;
   5418                 asdl_int_seq* ops;
   5419                 asdl_seq* comparators;
   5420 
   5421                 if (PyObject_HasAttrString(obj, "left")) {
   5422                         int res;
   5423                         tmp = PyObject_GetAttrString(obj, "left");
   5424                         if (tmp == NULL) goto failed;
   5425                         res = obj2ast_expr(tmp, &left, arena);
   5426                         if (res != 0) goto failed;
   5427                         Py_XDECREF(tmp);
   5428                         tmp = NULL;
   5429                 } else {
   5430                         PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
   5431                         return 1;
   5432                 }
   5433                 if (PyObject_HasAttrString(obj, "ops")) {
   5434                         int res;
   5435                         Py_ssize_t len;
   5436                         Py_ssize_t i;
   5437                         tmp = PyObject_GetAttrString(obj, "ops");
   5438                         if (tmp == NULL) goto failed;
   5439                         if (!PyList_Check(tmp)) {
   5440                                 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5441                                 goto failed;
   5442                         }
   5443                         len = PyList_GET_SIZE(tmp);
   5444                         ops = asdl_int_seq_new(len, arena);
   5445                         if (ops == NULL) goto failed;
   5446                         for (i = 0; i < len; i++) {
   5447                                 cmpop_ty val;
   5448                                 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena);
   5449                                 if (res != 0) goto failed;
   5450                                 if (len != PyList_GET_SIZE(tmp)) {
   5451                                         PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
   5452                                         goto failed;
   5453                                 }
   5454                                 asdl_seq_SET(ops, i, val);
   5455                         }
   5456                         Py_XDECREF(tmp);
   5457                         tmp = NULL;
   5458                 } else {
   5459                         PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
   5460                         return 1;
   5461                 }
   5462                 if (PyObject_HasAttrString(obj, "comparators")) {
   5463                         int res;
   5464                         Py_ssize_t len;
   5465                         Py_ssize_t i;
   5466                         tmp = PyObject_GetAttrString(obj, "comparators");
   5467                         if (tmp == NULL) goto failed;
   5468                         if (!PyList_Check(tmp)) {
   5469                                 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5470                                 goto failed;
   5471                         }
   5472                         len = PyList_GET_SIZE(tmp);
   5473                         comparators = asdl_seq_new(len, arena);
   5474                         if (comparators == NULL) goto failed;
   5475                         for (i = 0; i < len; i++) {
   5476                                 expr_ty val;
   5477                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5478                                 if (res != 0) goto failed;
   5479                                 if (len != PyList_GET_SIZE(tmp)) {
   5480                                         PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
   5481                                         goto failed;
   5482                                 }
   5483                                 asdl_seq_SET(comparators, i, val);
   5484                         }
   5485                         Py_XDECREF(tmp);
   5486                         tmp = NULL;
   5487                 } else {
   5488                         PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
   5489                         return 1;
   5490                 }
   5491                 *out = Compare(left, ops, comparators, lineno, col_offset,
   5492                                arena);
   5493                 if (*out == NULL) goto failed;
   5494                 return 0;
   5495         }
   5496         isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
   5497         if (isinstance == -1) {
   5498                 return 1;
   5499         }
   5500         if (isinstance) {
   5501                 expr_ty func;
   5502                 asdl_seq* args;
   5503                 asdl_seq* keywords;
   5504                 expr_ty starargs;
   5505                 expr_ty kwargs;
   5506 
   5507                 if (PyObject_HasAttrString(obj, "func")) {
   5508                         int res;
   5509                         tmp = PyObject_GetAttrString(obj, "func");
   5510                         if (tmp == NULL) goto failed;
   5511                         res = obj2ast_expr(tmp, &func, arena);
   5512                         if (res != 0) goto failed;
   5513                         Py_XDECREF(tmp);
   5514                         tmp = NULL;
   5515                 } else {
   5516                         PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
   5517                         return 1;
   5518                 }
   5519                 if (PyObject_HasAttrString(obj, "args")) {
   5520                         int res;
   5521                         Py_ssize_t len;
   5522                         Py_ssize_t i;
   5523                         tmp = PyObject_GetAttrString(obj, "args");
   5524                         if (tmp == NULL) goto failed;
   5525                         if (!PyList_Check(tmp)) {
   5526                                 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5527                                 goto failed;
   5528                         }
   5529                         len = PyList_GET_SIZE(tmp);
   5530                         args = asdl_seq_new(len, arena);
   5531                         if (args == NULL) goto failed;
   5532                         for (i = 0; i < len; i++) {
   5533                                 expr_ty val;
   5534                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5535                                 if (res != 0) goto failed;
   5536                                 if (len != PyList_GET_SIZE(tmp)) {
   5537                                         PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
   5538                                         goto failed;
   5539                                 }
   5540                                 asdl_seq_SET(args, i, val);
   5541                         }
   5542                         Py_XDECREF(tmp);
   5543                         tmp = NULL;
   5544                 } else {
   5545                         PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
   5546                         return 1;
   5547                 }
   5548                 if (PyObject_HasAttrString(obj, "keywords")) {
   5549                         int res;
   5550                         Py_ssize_t len;
   5551                         Py_ssize_t i;
   5552                         tmp = PyObject_GetAttrString(obj, "keywords");
   5553                         if (tmp == NULL) goto failed;
   5554                         if (!PyList_Check(tmp)) {
   5555                                 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5556                                 goto failed;
   5557                         }
   5558                         len = PyList_GET_SIZE(tmp);
   5559                         keywords = asdl_seq_new(len, arena);
   5560                         if (keywords == NULL) goto failed;
   5561                         for (i = 0; i < len; i++) {
   5562                                 keyword_ty val;
   5563                                 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
   5564                                 if (res != 0) goto failed;
   5565                                 if (len != PyList_GET_SIZE(tmp)) {
   5566                                         PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
   5567                                         goto failed;
   5568                                 }
   5569                                 asdl_seq_SET(keywords, i, val);
   5570                         }
   5571                         Py_XDECREF(tmp);
   5572                         tmp = NULL;
   5573                 } else {
   5574                         PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
   5575                         return 1;
   5576                 }
   5577                 if (PyObject_HasAttrString(obj, "starargs")) {
   5578                         int res;
   5579                         tmp = PyObject_GetAttrString(obj, "starargs");
   5580                         if (tmp == NULL) goto failed;
   5581                         res = obj2ast_expr(tmp, &starargs, arena);
   5582                         if (res != 0) goto failed;
   5583                         Py_XDECREF(tmp);
   5584                         tmp = NULL;
   5585                 } else {
   5586                         starargs = NULL;
   5587                 }
   5588                 if (PyObject_HasAttrString(obj, "kwargs")) {
   5589                         int res;
   5590                         tmp = PyObject_GetAttrString(obj, "kwargs");
   5591                         if (tmp == NULL) goto failed;
   5592                         res = obj2ast_expr(tmp, &kwargs, arena);
   5593                         if (res != 0) goto failed;
   5594                         Py_XDECREF(tmp);
   5595                         tmp = NULL;
   5596                 } else {
   5597                         kwargs = NULL;
   5598                 }
   5599                 *out = Call(func, args, keywords, starargs, kwargs, lineno,
   5600                             col_offset, arena);
   5601                 if (*out == NULL) goto failed;
   5602                 return 0;
   5603         }
   5604         isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
   5605         if (isinstance == -1) {
   5606                 return 1;
   5607         }
   5608         if (isinstance) {
   5609                 expr_ty value;
   5610 
   5611                 if (PyObject_HasAttrString(obj, "value")) {
   5612                         int res;
   5613                         tmp = PyObject_GetAttrString(obj, "value");
   5614                         if (tmp == NULL) goto failed;
   5615                         res = obj2ast_expr(tmp, &value, arena);
   5616                         if (res != 0) goto failed;
   5617                         Py_XDECREF(tmp);
   5618                         tmp = NULL;
   5619                 } else {
   5620                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
   5621                         return 1;
   5622                 }
   5623                 *out = Repr(value, lineno, col_offset, arena);
   5624                 if (*out == NULL) goto failed;
   5625                 return 0;
   5626         }
   5627         isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
   5628         if (isinstance == -1) {
   5629                 return 1;
   5630         }
   5631         if (isinstance) {
   5632                 object n;
   5633 
   5634                 if (PyObject_HasAttrString(obj, "n")) {
   5635                         int res;
   5636                         tmp = PyObject_GetAttrString(obj, "n");
   5637                         if (tmp == NULL) goto failed;
   5638                         res = obj2ast_object(tmp, &n, arena);
   5639                         if (res != 0) goto failed;
   5640                         Py_XDECREF(tmp);
   5641                         tmp = NULL;
   5642                 } else {
   5643                         PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
   5644                         return 1;
   5645                 }
   5646                 *out = Num(n, lineno, col_offset, arena);
   5647                 if (*out == NULL) goto failed;
   5648                 return 0;
   5649         }
   5650         isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
   5651         if (isinstance == -1) {
   5652                 return 1;
   5653         }
   5654         if (isinstance) {
   5655                 string s;
   5656 
   5657                 if (PyObject_HasAttrString(obj, "s")) {
   5658                         int res;
   5659                         tmp = PyObject_GetAttrString(obj, "s");
   5660                         if (tmp == NULL) goto failed;
   5661                         res = obj2ast_string(tmp, &s, arena);
   5662                         if (res != 0) goto failed;
   5663                         Py_XDECREF(tmp);
   5664                         tmp = NULL;
   5665                 } else {
   5666                         PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
   5667                         return 1;
   5668                 }
   5669                 *out = Str(s, lineno, col_offset, arena);
   5670                 if (*out == NULL) goto failed;
   5671                 return 0;
   5672         }
   5673         isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
   5674         if (isinstance == -1) {
   5675                 return 1;
   5676         }
   5677         if (isinstance) {
   5678                 expr_ty value;
   5679                 identifier attr;
   5680                 expr_context_ty ctx;
   5681 
   5682                 if (PyObject_HasAttrString(obj, "value")) {
   5683                         int res;
   5684                         tmp = PyObject_GetAttrString(obj, "value");
   5685                         if (tmp == NULL) goto failed;
   5686                         res = obj2ast_expr(tmp, &value, arena);
   5687                         if (res != 0) goto failed;
   5688                         Py_XDECREF(tmp);
   5689                         tmp = NULL;
   5690                 } else {
   5691                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
   5692                         return 1;
   5693                 }
   5694                 if (PyObject_HasAttrString(obj, "attr")) {
   5695                         int res;
   5696                         tmp = PyObject_GetAttrString(obj, "attr");
   5697                         if (tmp == NULL) goto failed;
   5698                         res = obj2ast_identifier(tmp, &attr, arena);
   5699                         if (res != 0) goto failed;
   5700                         Py_XDECREF(tmp);
   5701                         tmp = NULL;
   5702                 } else {
   5703                         PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
   5704                         return 1;
   5705                 }
   5706                 if (PyObject_HasAttrString(obj, "ctx")) {
   5707                         int res;
   5708                         tmp = PyObject_GetAttrString(obj, "ctx");
   5709                         if (tmp == NULL) goto failed;
   5710                         res = obj2ast_expr_context(tmp, &ctx, arena);
   5711                         if (res != 0) goto failed;
   5712                         Py_XDECREF(tmp);
   5713                         tmp = NULL;
   5714                 } else {
   5715                         PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
   5716                         return 1;
   5717                 }
   5718                 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
   5719                 if (*out == NULL) goto failed;
   5720                 return 0;
   5721         }
   5722         isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
   5723         if (isinstance == -1) {
   5724                 return 1;
   5725         }
   5726         if (isinstance) {
   5727                 expr_ty value;
   5728                 slice_ty slice;
   5729                 expr_context_ty ctx;
   5730 
   5731                 if (PyObject_HasAttrString(obj, "value")) {
   5732                         int res;
   5733                         tmp = PyObject_GetAttrString(obj, "value");
   5734                         if (tmp == NULL) goto failed;
   5735                         res = obj2ast_expr(tmp, &value, arena);
   5736                         if (res != 0) goto failed;
   5737                         Py_XDECREF(tmp);
   5738                         tmp = NULL;
   5739                 } else {
   5740                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
   5741                         return 1;
   5742                 }
   5743                 if (PyObject_HasAttrString(obj, "slice")) {
   5744                         int res;
   5745                         tmp = PyObject_GetAttrString(obj, "slice");
   5746                         if (tmp == NULL) goto failed;
   5747                         res = obj2ast_slice(tmp, &slice, arena);
   5748                         if (res != 0) goto failed;
   5749                         Py_XDECREF(tmp);
   5750                         tmp = NULL;
   5751                 } else {
   5752                         PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
   5753                         return 1;
   5754                 }
   5755                 if (PyObject_HasAttrString(obj, "ctx")) {
   5756                         int res;
   5757                         tmp = PyObject_GetAttrString(obj, "ctx");
   5758                         if (tmp == NULL) goto failed;
   5759                         res = obj2ast_expr_context(tmp, &ctx, arena);
   5760                         if (res != 0) goto failed;
   5761                         Py_XDECREF(tmp);
   5762                         tmp = NULL;
   5763                 } else {
   5764                         PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
   5765                         return 1;
   5766                 }
   5767                 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
   5768                 if (*out == NULL) goto failed;
   5769                 return 0;
   5770         }
   5771         isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
   5772         if (isinstance == -1) {
   5773                 return 1;
   5774         }
   5775         if (isinstance) {
   5776                 identifier id;
   5777                 expr_context_ty ctx;
   5778 
   5779                 if (PyObject_HasAttrString(obj, "id")) {
   5780                         int res;
   5781                         tmp = PyObject_GetAttrString(obj, "id");
   5782                         if (tmp == NULL) goto failed;
   5783                         res = obj2ast_identifier(tmp, &id, arena);
   5784                         if (res != 0) goto failed;
   5785                         Py_XDECREF(tmp);
   5786                         tmp = NULL;
   5787                 } else {
   5788                         PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
   5789                         return 1;
   5790                 }
   5791                 if (PyObject_HasAttrString(obj, "ctx")) {
   5792                         int res;
   5793                         tmp = PyObject_GetAttrString(obj, "ctx");
   5794                         if (tmp == NULL) goto failed;
   5795                         res = obj2ast_expr_context(tmp, &ctx, arena);
   5796                         if (res != 0) goto failed;
   5797                         Py_XDECREF(tmp);
   5798                         tmp = NULL;
   5799                 } else {
   5800                         PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
   5801                         return 1;
   5802                 }
   5803                 *out = Name(id, ctx, lineno, col_offset, arena);
   5804                 if (*out == NULL) goto failed;
   5805                 return 0;
   5806         }
   5807         isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
   5808         if (isinstance == -1) {
   5809                 return 1;
   5810         }
   5811         if (isinstance) {
   5812                 asdl_seq* elts;
   5813                 expr_context_ty ctx;
   5814 
   5815                 if (PyObject_HasAttrString(obj, "elts")) {
   5816                         int res;
   5817                         Py_ssize_t len;
   5818                         Py_ssize_t i;
   5819                         tmp = PyObject_GetAttrString(obj, "elts");
   5820                         if (tmp == NULL) goto failed;
   5821                         if (!PyList_Check(tmp)) {
   5822                                 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5823                                 goto failed;
   5824                         }
   5825                         len = PyList_GET_SIZE(tmp);
   5826                         elts = asdl_seq_new(len, arena);
   5827                         if (elts == NULL) goto failed;
   5828                         for (i = 0; i < len; i++) {
   5829                                 expr_ty val;
   5830                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5831                                 if (res != 0) goto failed;
   5832                                 if (len != PyList_GET_SIZE(tmp)) {
   5833                                         PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
   5834                                         goto failed;
   5835                                 }
   5836                                 asdl_seq_SET(elts, i, val);
   5837                         }
   5838                         Py_XDECREF(tmp);
   5839                         tmp = NULL;
   5840                 } else {
   5841                         PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
   5842                         return 1;
   5843                 }
   5844                 if (PyObject_HasAttrString(obj, "ctx")) {
   5845                         int res;
   5846                         tmp = PyObject_GetAttrString(obj, "ctx");
   5847                         if (tmp == NULL) goto failed;
   5848                         res = obj2ast_expr_context(tmp, &ctx, arena);
   5849                         if (res != 0) goto failed;
   5850                         Py_XDECREF(tmp);
   5851                         tmp = NULL;
   5852                 } else {
   5853                         PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
   5854                         return 1;
   5855                 }
   5856                 *out = List(elts, ctx, lineno, col_offset, arena);
   5857                 if (*out == NULL) goto failed;
   5858                 return 0;
   5859         }
   5860         isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
   5861         if (isinstance == -1) {
   5862                 return 1;
   5863         }
   5864         if (isinstance) {
   5865                 asdl_seq* elts;
   5866                 expr_context_ty ctx;
   5867 
   5868                 if (PyObject_HasAttrString(obj, "elts")) {
   5869                         int res;
   5870                         Py_ssize_t len;
   5871                         Py_ssize_t i;
   5872                         tmp = PyObject_GetAttrString(obj, "elts");
   5873                         if (tmp == NULL) goto failed;
   5874                         if (!PyList_Check(tmp)) {
   5875                                 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   5876                                 goto failed;
   5877                         }
   5878                         len = PyList_GET_SIZE(tmp);
   5879                         elts = asdl_seq_new(len, arena);
   5880                         if (elts == NULL) goto failed;
   5881                         for (i = 0; i < len; i++) {
   5882                                 expr_ty val;
   5883                                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   5884                                 if (res != 0) goto failed;
   5885                                 if (len != PyList_GET_SIZE(tmp)) {
   5886                                         PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
   5887                                         goto failed;
   5888                                 }
   5889                                 asdl_seq_SET(elts, i, val);
   5890                         }
   5891                         Py_XDECREF(tmp);
   5892                         tmp = NULL;
   5893                 } else {
   5894                         PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
   5895                         return 1;
   5896                 }
   5897                 if (PyObject_HasAttrString(obj, "ctx")) {
   5898                         int res;
   5899                         tmp = PyObject_GetAttrString(obj, "ctx");
   5900                         if (tmp == NULL) goto failed;
   5901                         res = obj2ast_expr_context(tmp, &ctx, arena);
   5902                         if (res != 0) goto failed;
   5903                         Py_XDECREF(tmp);
   5904                         tmp = NULL;
   5905                 } else {
   5906                         PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
   5907                         return 1;
   5908                 }
   5909                 *out = Tuple(elts, ctx, lineno, col_offset, arena);
   5910                 if (*out == NULL) goto failed;
   5911                 return 0;
   5912         }
   5913 
   5914         tmp = PyObject_Repr(obj);
   5915         if (tmp == NULL) goto failed;
   5916         PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
   5917 failed:
   5918         Py_XDECREF(tmp);
   5919         return 1;
   5920 }
   5921 
   5922 int
   5923 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
   5924 {
   5925         PyObject* tmp = NULL;
   5926         int isinstance;
   5927 
   5928         isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
   5929         if (isinstance == -1) {
   5930                 return 1;
   5931         }
   5932         if (isinstance) {
   5933                 *out = Load;
   5934                 return 0;
   5935         }
   5936         isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
   5937         if (isinstance == -1) {
   5938                 return 1;
   5939         }
   5940         if (isinstance) {
   5941                 *out = Store;
   5942                 return 0;
   5943         }
   5944         isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
   5945         if (isinstance == -1) {
   5946                 return 1;
   5947         }
   5948         if (isinstance) {
   5949                 *out = Del;
   5950                 return 0;
   5951         }
   5952         isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
   5953         if (isinstance == -1) {
   5954                 return 1;
   5955         }
   5956         if (isinstance) {
   5957                 *out = AugLoad;
   5958                 return 0;
   5959         }
   5960         isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
   5961         if (isinstance == -1) {
   5962                 return 1;
   5963         }
   5964         if (isinstance) {
   5965                 *out = AugStore;
   5966                 return 0;
   5967         }
   5968         isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
   5969         if (isinstance == -1) {
   5970                 return 1;
   5971         }
   5972         if (isinstance) {
   5973                 *out = Param;
   5974                 return 0;
   5975         }
   5976 
   5977         tmp = PyObject_Repr(obj);
   5978         if (tmp == NULL) goto failed;
   5979         PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
   5980 failed:
   5981         Py_XDECREF(tmp);
   5982         return 1;
   5983 }
   5984 
   5985 int
   5986 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
   5987 {
   5988         PyObject* tmp = NULL;
   5989         int isinstance;
   5990 
   5991 
   5992         if (obj == Py_None) {
   5993                 *out = NULL;
   5994                 return 0;
   5995         }
   5996         isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
   5997         if (isinstance == -1) {
   5998                 return 1;
   5999         }
   6000         if (isinstance) {
   6001 
   6002                 *out = Ellipsis(arena);
   6003                 if (*out == NULL) goto failed;
   6004                 return 0;
   6005         }
   6006         isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
   6007         if (isinstance == -1) {
   6008                 return 1;
   6009         }
   6010         if (isinstance) {
   6011                 expr_ty lower;
   6012                 expr_ty upper;
   6013                 expr_ty step;
   6014 
   6015                 if (PyObject_HasAttrString(obj, "lower")) {
   6016                         int res;
   6017                         tmp = PyObject_GetAttrString(obj, "lower");
   6018                         if (tmp == NULL) goto failed;
   6019                         res = obj2ast_expr(tmp, &lower, arena);
   6020                         if (res != 0) goto failed;
   6021                         Py_XDECREF(tmp);
   6022                         tmp = NULL;
   6023                 } else {
   6024                         lower = NULL;
   6025                 }
   6026                 if (PyObject_HasAttrString(obj, "upper")) {
   6027                         int res;
   6028                         tmp = PyObject_GetAttrString(obj, "upper");
   6029                         if (tmp == NULL) goto failed;
   6030                         res = obj2ast_expr(tmp, &upper, arena);
   6031                         if (res != 0) goto failed;
   6032                         Py_XDECREF(tmp);
   6033                         tmp = NULL;
   6034                 } else {
   6035                         upper = NULL;
   6036                 }
   6037                 if (PyObject_HasAttrString(obj, "step")) {
   6038                         int res;
   6039                         tmp = PyObject_GetAttrString(obj, "step");
   6040                         if (tmp == NULL) goto failed;
   6041                         res = obj2ast_expr(tmp, &step, arena);
   6042                         if (res != 0) goto failed;
   6043                         Py_XDECREF(tmp);
   6044                         tmp = NULL;
   6045                 } else {
   6046                         step = NULL;
   6047                 }
   6048                 *out = Slice(lower, upper, step, arena);
   6049                 if (*out == NULL) goto failed;
   6050                 return 0;
   6051         }
   6052         isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
   6053         if (isinstance == -1) {
   6054                 return 1;
   6055         }
   6056         if (isinstance) {
   6057                 asdl_seq* dims;
   6058 
   6059                 if (PyObject_HasAttrString(obj, "dims")) {
   6060                         int res;
   6061                         Py_ssize_t len;
   6062                         Py_ssize_t i;
   6063                         tmp = PyObject_GetAttrString(obj, "dims");
   6064                         if (tmp == NULL) goto failed;
   6065                         if (!PyList_Check(tmp)) {
   6066                                 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   6067                                 goto failed;
   6068                         }
   6069                         len = PyList_GET_SIZE(tmp);
   6070                         dims = asdl_seq_new(len, arena);
   6071                         if (dims == NULL) goto failed;
   6072                         for (i = 0; i < len; i++) {
   6073                                 slice_ty val;
   6074                                 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena);
   6075                                 if (res != 0) goto failed;
   6076                                 if (len != PyList_GET_SIZE(tmp)) {
   6077                                         PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
   6078                                         goto failed;
   6079                                 }
   6080                                 asdl_seq_SET(dims, i, val);
   6081                         }
   6082                         Py_XDECREF(tmp);
   6083                         tmp = NULL;
   6084                 } else {
   6085                         PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
   6086                         return 1;
   6087                 }
   6088                 *out = ExtSlice(dims, arena);
   6089                 if (*out == NULL) goto failed;
   6090                 return 0;
   6091         }
   6092         isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
   6093         if (isinstance == -1) {
   6094                 return 1;
   6095         }
   6096         if (isinstance) {
   6097                 expr_ty value;
   6098 
   6099                 if (PyObject_HasAttrString(obj, "value")) {
   6100                         int res;
   6101                         tmp = PyObject_GetAttrString(obj, "value");
   6102                         if (tmp == NULL) goto failed;
   6103                         res = obj2ast_expr(tmp, &value, arena);
   6104                         if (res != 0) goto failed;
   6105                         Py_XDECREF(tmp);
   6106                         tmp = NULL;
   6107                 } else {
   6108                         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
   6109                         return 1;
   6110                 }
   6111                 *out = Index(value, arena);
   6112                 if (*out == NULL) goto failed;
   6113                 return 0;
   6114         }
   6115 
   6116         tmp = PyObject_Repr(obj);
   6117         if (tmp == NULL) goto failed;
   6118         PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
   6119 failed:
   6120         Py_XDECREF(tmp);
   6121         return 1;
   6122 }
   6123 
   6124 int
   6125 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
   6126 {
   6127         PyObject* tmp = NULL;
   6128         int isinstance;
   6129 
   6130         isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
   6131         if (isinstance == -1) {
   6132                 return 1;
   6133         }
   6134         if (isinstance) {
   6135                 *out = And;
   6136                 return 0;
   6137         }
   6138         isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
   6139         if (isinstance == -1) {
   6140                 return 1;
   6141         }
   6142         if (isinstance) {
   6143                 *out = Or;
   6144                 return 0;
   6145         }
   6146 
   6147         tmp = PyObject_Repr(obj);
   6148         if (tmp == NULL) goto failed;
   6149         PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
   6150 failed:
   6151         Py_XDECREF(tmp);
   6152         return 1;
   6153 }
   6154 
   6155 int
   6156 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
   6157 {
   6158         PyObject* tmp = NULL;
   6159         int isinstance;
   6160 
   6161         isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
   6162         if (isinstance == -1) {
   6163                 return 1;
   6164         }
   6165         if (isinstance) {
   6166                 *out = Add;
   6167                 return 0;
   6168         }
   6169         isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
   6170         if (isinstance == -1) {
   6171                 return 1;
   6172         }
   6173         if (isinstance) {
   6174                 *out = Sub;
   6175                 return 0;
   6176         }
   6177         isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
   6178         if (isinstance == -1) {
   6179                 return 1;
   6180         }
   6181         if (isinstance) {
   6182                 *out = Mult;
   6183                 return 0;
   6184         }
   6185         isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
   6186         if (isinstance == -1) {
   6187                 return 1;
   6188         }
   6189         if (isinstance) {
   6190                 *out = Div;
   6191                 return 0;
   6192         }
   6193         isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
   6194         if (isinstance == -1) {
   6195                 return 1;
   6196         }
   6197         if (isinstance) {
   6198                 *out = Mod;
   6199                 return 0;
   6200         }
   6201         isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
   6202         if (isinstance == -1) {
   6203                 return 1;
   6204         }
   6205         if (isinstance) {
   6206                 *out = Pow;
   6207                 return 0;
   6208         }
   6209         isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
   6210         if (isinstance == -1) {
   6211                 return 1;
   6212         }
   6213         if (isinstance) {
   6214                 *out = LShift;
   6215                 return 0;
   6216         }
   6217         isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
   6218         if (isinstance == -1) {
   6219                 return 1;
   6220         }
   6221         if (isinstance) {
   6222                 *out = RShift;
   6223                 return 0;
   6224         }
   6225         isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
   6226         if (isinstance == -1) {
   6227                 return 1;
   6228         }
   6229         if (isinstance) {
   6230                 *out = BitOr;
   6231                 return 0;
   6232         }
   6233         isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
   6234         if (isinstance == -1) {
   6235                 return 1;
   6236         }
   6237         if (isinstance) {
   6238                 *out = BitXor;
   6239                 return 0;
   6240         }
   6241         isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
   6242         if (isinstance == -1) {
   6243                 return 1;
   6244         }
   6245         if (isinstance) {
   6246                 *out = BitAnd;
   6247                 return 0;
   6248         }
   6249         isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
   6250         if (isinstance == -1) {
   6251                 return 1;
   6252         }
   6253         if (isinstance) {
   6254                 *out = FloorDiv;
   6255                 return 0;
   6256         }
   6257 
   6258         tmp = PyObject_Repr(obj);
   6259         if (tmp == NULL) goto failed;
   6260         PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
   6261 failed:
   6262         Py_XDECREF(tmp);
   6263         return 1;
   6264 }
   6265 
   6266 int
   6267 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
   6268 {
   6269         PyObject* tmp = NULL;
   6270         int isinstance;
   6271 
   6272         isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
   6273         if (isinstance == -1) {
   6274                 return 1;
   6275         }
   6276         if (isinstance) {
   6277                 *out = Invert;
   6278                 return 0;
   6279         }
   6280         isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
   6281         if (isinstance == -1) {
   6282                 return 1;
   6283         }
   6284         if (isinstance) {
   6285                 *out = Not;
   6286                 return 0;
   6287         }
   6288         isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
   6289         if (isinstance == -1) {
   6290                 return 1;
   6291         }
   6292         if (isinstance) {
   6293                 *out = UAdd;
   6294                 return 0;
   6295         }
   6296         isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
   6297         if (isinstance == -1) {
   6298                 return 1;
   6299         }
   6300         if (isinstance) {
   6301                 *out = USub;
   6302                 return 0;
   6303         }
   6304 
   6305         tmp = PyObject_Repr(obj);
   6306         if (tmp == NULL) goto failed;
   6307         PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
   6308 failed:
   6309         Py_XDECREF(tmp);
   6310         return 1;
   6311 }
   6312 
   6313 int
   6314 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
   6315 {
   6316         PyObject* tmp = NULL;
   6317         int isinstance;
   6318 
   6319         isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
   6320         if (isinstance == -1) {
   6321                 return 1;
   6322         }
   6323         if (isinstance) {
   6324                 *out = Eq;
   6325                 return 0;
   6326         }
   6327         isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
   6328         if (isinstance == -1) {
   6329                 return 1;
   6330         }
   6331         if (isinstance) {
   6332                 *out = NotEq;
   6333                 return 0;
   6334         }
   6335         isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
   6336         if (isinstance == -1) {
   6337                 return 1;
   6338         }
   6339         if (isinstance) {
   6340                 *out = Lt;
   6341                 return 0;
   6342         }
   6343         isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
   6344         if (isinstance == -1) {
   6345                 return 1;
   6346         }
   6347         if (isinstance) {
   6348                 *out = LtE;
   6349                 return 0;
   6350         }
   6351         isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
   6352         if (isinstance == -1) {
   6353                 return 1;
   6354         }
   6355         if (isinstance) {
   6356                 *out = Gt;
   6357                 return 0;
   6358         }
   6359         isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
   6360         if (isinstance == -1) {
   6361                 return 1;
   6362         }
   6363         if (isinstance) {
   6364                 *out = GtE;
   6365                 return 0;
   6366         }
   6367         isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
   6368         if (isinstance == -1) {
   6369                 return 1;
   6370         }
   6371         if (isinstance) {
   6372                 *out = Is;
   6373                 return 0;
   6374         }
   6375         isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
   6376         if (isinstance == -1) {
   6377                 return 1;
   6378         }
   6379         if (isinstance) {
   6380                 *out = IsNot;
   6381                 return 0;
   6382         }
   6383         isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
   6384         if (isinstance == -1) {
   6385                 return 1;
   6386         }
   6387         if (isinstance) {
   6388                 *out = In;
   6389                 return 0;
   6390         }
   6391         isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
   6392         if (isinstance == -1) {
   6393                 return 1;
   6394         }
   6395         if (isinstance) {
   6396                 *out = NotIn;
   6397                 return 0;
   6398         }
   6399 
   6400         tmp = PyObject_Repr(obj);
   6401         if (tmp == NULL) goto failed;
   6402         PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
   6403 failed:
   6404         Py_XDECREF(tmp);
   6405         return 1;
   6406 }
   6407 
   6408 int
   6409 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
   6410 {
   6411         PyObject* tmp = NULL;
   6412         expr_ty target;
   6413         expr_ty iter;
   6414         asdl_seq* ifs;
   6415 
   6416         if (PyObject_HasAttrString(obj, "target")) {
   6417                 int res;
   6418                 tmp = PyObject_GetAttrString(obj, "target");
   6419                 if (tmp == NULL) goto failed;
   6420                 res = obj2ast_expr(tmp, &target, arena);
   6421                 if (res != 0) goto failed;
   6422                 Py_XDECREF(tmp);
   6423                 tmp = NULL;
   6424         } else {
   6425                 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
   6426                 return 1;
   6427         }
   6428         if (PyObject_HasAttrString(obj, "iter")) {
   6429                 int res;
   6430                 tmp = PyObject_GetAttrString(obj, "iter");
   6431                 if (tmp == NULL) goto failed;
   6432                 res = obj2ast_expr(tmp, &iter, arena);
   6433                 if (res != 0) goto failed;
   6434                 Py_XDECREF(tmp);
   6435                 tmp = NULL;
   6436         } else {
   6437                 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
   6438                 return 1;
   6439         }
   6440         if (PyObject_HasAttrString(obj, "ifs")) {
   6441                 int res;
   6442                 Py_ssize_t len;
   6443                 Py_ssize_t i;
   6444                 tmp = PyObject_GetAttrString(obj, "ifs");
   6445                 if (tmp == NULL) goto failed;
   6446                 if (!PyList_Check(tmp)) {
   6447                         PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   6448                         goto failed;
   6449                 }
   6450                 len = PyList_GET_SIZE(tmp);
   6451                 ifs = asdl_seq_new(len, arena);
   6452                 if (ifs == NULL) goto failed;
   6453                 for (i = 0; i < len; i++) {
   6454                         expr_ty val;
   6455                         res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   6456                         if (res != 0) goto failed;
   6457                         if (len != PyList_GET_SIZE(tmp)) {
   6458                                 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
   6459                                 goto failed;
   6460                         }
   6461                         asdl_seq_SET(ifs, i, val);
   6462                 }
   6463                 Py_XDECREF(tmp);
   6464                 tmp = NULL;
   6465         } else {
   6466                 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
   6467                 return 1;
   6468         }
   6469         *out = comprehension(target, iter, ifs, arena);
   6470         return 0;
   6471 failed:
   6472         Py_XDECREF(tmp);
   6473         return 1;
   6474 }
   6475 
   6476 int
   6477 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
   6478 {
   6479         PyObject* tmp = NULL;
   6480         int isinstance;
   6481 
   6482         int lineno;
   6483         int col_offset;
   6484 
   6485         if (obj == Py_None) {
   6486                 *out = NULL;
   6487                 return 0;
   6488         }
   6489         if (PyObject_HasAttrString(obj, "lineno")) {
   6490                 int res;
   6491                 tmp = PyObject_GetAttrString(obj, "lineno");
   6492                 if (tmp == NULL) goto failed;
   6493                 res = obj2ast_int(tmp, &lineno, arena);
   6494                 if (res != 0) goto failed;
   6495                 Py_XDECREF(tmp);
   6496                 tmp = NULL;
   6497         } else {
   6498                 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
   6499                 return 1;
   6500         }
   6501         if (PyObject_HasAttrString(obj, "col_offset")) {
   6502                 int res;
   6503                 tmp = PyObject_GetAttrString(obj, "col_offset");
   6504                 if (tmp == NULL) goto failed;
   6505                 res = obj2ast_int(tmp, &col_offset, arena);
   6506                 if (res != 0) goto failed;
   6507                 Py_XDECREF(tmp);
   6508                 tmp = NULL;
   6509         } else {
   6510                 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
   6511                 return 1;
   6512         }
   6513         isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
   6514         if (isinstance == -1) {
   6515                 return 1;
   6516         }
   6517         if (isinstance) {
   6518                 expr_ty type;
   6519                 expr_ty name;
   6520                 asdl_seq* body;
   6521 
   6522                 if (PyObject_HasAttrString(obj, "type")) {
   6523                         int res;
   6524                         tmp = PyObject_GetAttrString(obj, "type");
   6525                         if (tmp == NULL) goto failed;
   6526                         res = obj2ast_expr(tmp, &type, arena);
   6527                         if (res != 0) goto failed;
   6528                         Py_XDECREF(tmp);
   6529                         tmp = NULL;
   6530                 } else {
   6531                         type = NULL;
   6532                 }
   6533                 if (PyObject_HasAttrString(obj, "name")) {
   6534                         int res;
   6535                         tmp = PyObject_GetAttrString(obj, "name");
   6536                         if (tmp == NULL) goto failed;
   6537                         res = obj2ast_expr(tmp, &name, arena);
   6538                         if (res != 0) goto failed;
   6539                         Py_XDECREF(tmp);
   6540                         tmp = NULL;
   6541                 } else {
   6542                         name = NULL;
   6543                 }
   6544                 if (PyObject_HasAttrString(obj, "body")) {
   6545                         int res;
   6546                         Py_ssize_t len;
   6547                         Py_ssize_t i;
   6548                         tmp = PyObject_GetAttrString(obj, "body");
   6549                         if (tmp == NULL) goto failed;
   6550                         if (!PyList_Check(tmp)) {
   6551                                 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   6552                                 goto failed;
   6553                         }
   6554                         len = PyList_GET_SIZE(tmp);
   6555                         body = asdl_seq_new(len, arena);
   6556                         if (body == NULL) goto failed;
   6557                         for (i = 0; i < len; i++) {
   6558                                 stmt_ty val;
   6559                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
   6560                                 if (res != 0) goto failed;
   6561                                 if (len != PyList_GET_SIZE(tmp)) {
   6562                                         PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
   6563                                         goto failed;
   6564                                 }
   6565                                 asdl_seq_SET(body, i, val);
   6566                         }
   6567                         Py_XDECREF(tmp);
   6568                         tmp = NULL;
   6569                 } else {
   6570                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
   6571                         return 1;
   6572                 }
   6573                 *out = ExceptHandler(type, name, body, lineno, col_offset,
   6574                                      arena);
   6575                 if (*out == NULL) goto failed;
   6576                 return 0;
   6577         }
   6578 
   6579         tmp = PyObject_Repr(obj);
   6580         if (tmp == NULL) goto failed;
   6581         PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
   6582 failed:
   6583         Py_XDECREF(tmp);
   6584         return 1;
   6585 }
   6586 
   6587 int
   6588 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
   6589 {
   6590         PyObject* tmp = NULL;
   6591         asdl_seq* args;
   6592         identifier vararg;
   6593         identifier kwarg;
   6594         asdl_seq* defaults;
   6595 
   6596         if (PyObject_HasAttrString(obj, "args")) {
   6597                 int res;
   6598                 Py_ssize_t len;
   6599                 Py_ssize_t i;
   6600                 tmp = PyObject_GetAttrString(obj, "args");
   6601                 if (tmp == NULL) goto failed;
   6602                 if (!PyList_Check(tmp)) {
   6603                         PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   6604                         goto failed;
   6605                 }
   6606                 len = PyList_GET_SIZE(tmp);
   6607                 args = asdl_seq_new(len, arena);
   6608                 if (args == NULL) goto failed;
   6609                 for (i = 0; i < len; i++) {
   6610                         expr_ty val;
   6611                         res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   6612                         if (res != 0) goto failed;
   6613                         if (len != PyList_GET_SIZE(tmp)) {
   6614                                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
   6615                                 goto failed;
   6616                         }
   6617                         asdl_seq_SET(args, i, val);
   6618                 }
   6619                 Py_XDECREF(tmp);
   6620                 tmp = NULL;
   6621         } else {
   6622                 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
   6623                 return 1;
   6624         }
   6625         if (PyObject_HasAttrString(obj, "vararg")) {
   6626                 int res;
   6627                 tmp = PyObject_GetAttrString(obj, "vararg");
   6628                 if (tmp == NULL) goto failed;
   6629                 res = obj2ast_identifier(tmp, &vararg, arena);
   6630                 if (res != 0) goto failed;
   6631                 Py_XDECREF(tmp);
   6632                 tmp = NULL;
   6633         } else {
   6634                 vararg = NULL;
   6635         }
   6636         if (PyObject_HasAttrString(obj, "kwarg")) {
   6637                 int res;
   6638                 tmp = PyObject_GetAttrString(obj, "kwarg");
   6639                 if (tmp == NULL) goto failed;
   6640                 res = obj2ast_identifier(tmp, &kwarg, arena);
   6641                 if (res != 0) goto failed;
   6642                 Py_XDECREF(tmp);
   6643                 tmp = NULL;
   6644         } else {
   6645                 kwarg = NULL;
   6646         }
   6647         if (PyObject_HasAttrString(obj, "defaults")) {
   6648                 int res;
   6649                 Py_ssize_t len;
   6650                 Py_ssize_t i;
   6651                 tmp = PyObject_GetAttrString(obj, "defaults");
   6652                 if (tmp == NULL) goto failed;
   6653                 if (!PyList_Check(tmp)) {
   6654                         PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
   6655                         goto failed;
   6656                 }
   6657                 len = PyList_GET_SIZE(tmp);
   6658                 defaults = asdl_seq_new(len, arena);
   6659                 if (defaults == NULL) goto failed;
   6660                 for (i = 0; i < len; i++) {
   6661                         expr_ty val;
   6662                         res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
   6663                         if (res != 0) goto failed;
   6664                         if (len != PyList_GET_SIZE(tmp)) {
   6665                                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
   6666                                 goto failed;
   6667                         }
   6668                         asdl_seq_SET(defaults, i, val);
   6669                 }
   6670                 Py_XDECREF(tmp);
   6671                 tmp = NULL;
   6672         } else {
   6673                 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
   6674                 return 1;
   6675         }
   6676         *out = arguments(args, vararg, kwarg, defaults, arena);
   6677         return 0;
   6678 failed:
   6679         Py_XDECREF(tmp);
   6680         return 1;
   6681 }
   6682 
   6683 int
   6684 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
   6685 {
   6686         PyObject* tmp = NULL;
   6687         identifier arg;
   6688         expr_ty value;
   6689 
   6690         if (PyObject_HasAttrString(obj, "arg")) {
   6691                 int res;
   6692                 tmp = PyObject_GetAttrString(obj, "arg");
   6693                 if (tmp == NULL) goto failed;
   6694                 res = obj2ast_identifier(tmp, &arg, arena);
   6695                 if (res != 0) goto failed;
   6696                 Py_XDECREF(tmp);
   6697                 tmp = NULL;
   6698         } else {
   6699                 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
   6700                 return 1;
   6701         }
   6702         if (PyObject_HasAttrString(obj, "value")) {
   6703                 int res;
   6704                 tmp = PyObject_GetAttrString(obj, "value");
   6705                 if (tmp == NULL) goto failed;
   6706                 res = obj2ast_expr(tmp, &value, arena);
   6707                 if (res != 0) goto failed;
   6708                 Py_XDECREF(tmp);
   6709                 tmp = NULL;
   6710         } else {
   6711                 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
   6712                 return 1;
   6713         }
   6714         *out = keyword(arg, value, arena);
   6715         return 0;
   6716 failed:
   6717         Py_XDECREF(tmp);
   6718         return 1;
   6719 }
   6720 
   6721 int
   6722 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
   6723 {
   6724         PyObject* tmp = NULL;
   6725         identifier name;
   6726         identifier asname;
   6727 
   6728         if (PyObject_HasAttrString(obj, "name")) {
   6729                 int res;
   6730                 tmp = PyObject_GetAttrString(obj, "name");
   6731                 if (tmp == NULL) goto failed;
   6732                 res = obj2ast_identifier(tmp, &name, arena);
   6733                 if (res != 0) goto failed;
   6734                 Py_XDECREF(tmp);
   6735                 tmp = NULL;
   6736         } else {
   6737                 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
   6738                 return 1;
   6739         }
   6740         if (PyObject_HasAttrString(obj, "asname")) {
   6741                 int res;
   6742                 tmp = PyObject_GetAttrString(obj, "asname");
   6743                 if (tmp == NULL) goto failed;
   6744                 res = obj2ast_identifier(tmp, &asname, arena);
   6745                 if (res != 0) goto failed;
   6746                 Py_XDECREF(tmp);
   6747                 tmp = NULL;
   6748         } else {
   6749                 asname = NULL;
   6750         }
   6751         *out = alias(name, asname, arena);
   6752         return 0;
   6753 failed:
   6754         Py_XDECREF(tmp);
   6755         return 1;
   6756 }
   6757 
   6758 
   6759 PyMODINIT_FUNC
   6760 init_ast(void)
   6761 {
   6762         PyObject *m, *d;
   6763         if (!init_types()) return;
   6764         m = Py_InitModule3("_ast", NULL, NULL);
   6765         if (!m) return;
   6766         d = PyModule_GetDict(m);
   6767         if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
   6768         if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
   6769                 return;
   6770         if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)
   6771                 return;
   6772         if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
   6773         if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
   6774             return;
   6775         if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
   6776             < 0) return;
   6777         if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
   6778             0) return;
   6779         if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
   6780         if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
   6781         if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
   6782             < 0) return;
   6783         if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
   6784             return;
   6785         if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
   6786             return;
   6787         if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
   6788             return;
   6789         if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
   6790             return;
   6791         if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
   6792             0) return;
   6793         if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
   6794         if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
   6795         if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
   6796         if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
   6797         if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
   6798         if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
   6799         if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
   6800             0) return;
   6801         if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
   6802             0) return;
   6803         if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
   6804             return;
   6805         if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
   6806             return;
   6807         if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
   6808             0) return;
   6809         if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
   6810         if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
   6811             return;
   6812         if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
   6813         if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
   6814         if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
   6815         if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
   6816             return;
   6817         if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
   6818         if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
   6819             return;
   6820         if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
   6821         if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
   6822             return;
   6823         if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
   6824             return;
   6825         if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
   6826         if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
   6827         if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
   6828         if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
   6829             return;
   6830         if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
   6831             return;
   6832         if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
   6833             return;
   6834         if (PyDict_SetItemString(d, "GeneratorExp",
   6835             (PyObject*)GeneratorExp_type) < 0) return;
   6836         if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
   6837         if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
   6838             return;
   6839         if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
   6840         if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
   6841         if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
   6842         if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
   6843         if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
   6844             0) return;
   6845         if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
   6846             0) return;
   6847         if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
   6848         if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
   6849         if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
   6850         if (PyDict_SetItemString(d, "expr_context",
   6851             (PyObject*)expr_context_type) < 0) return;
   6852         if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
   6853         if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
   6854         if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
   6855         if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
   6856             return;
   6857         if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
   6858             return;
   6859         if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
   6860         if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
   6861         if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
   6862             return;
   6863         if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
   6864         if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
   6865             return;
   6866         if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
   6867         if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
   6868             return;
   6869         if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
   6870         if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
   6871         if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
   6872             return;
   6873         if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
   6874         if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
   6875         if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
   6876         if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
   6877         if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
   6878         if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
   6879         if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
   6880             return;
   6881         if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
   6882             return;
   6883         if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
   6884         if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
   6885             return;
   6886         if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
   6887             return;
   6888         if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
   6889             return;
   6890         if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
   6891             return;
   6892         if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
   6893             return;
   6894         if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
   6895         if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
   6896         if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
   6897         if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
   6898         if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
   6899         if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
   6900         if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
   6901         if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
   6902         if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
   6903         if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
   6904         if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
   6905         if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
   6906         if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
   6907         if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
   6908         if (PyDict_SetItemString(d, "comprehension",
   6909             (PyObject*)comprehension_type) < 0) return;
   6910         if (PyDict_SetItemString(d, "excepthandler",
   6911             (PyObject*)excepthandler_type) < 0) return;
   6912         if (PyDict_SetItemString(d, "ExceptHandler",
   6913             (PyObject*)ExceptHandler_type) < 0) return;
   6914         if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
   6915             0) return;
   6916         if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
   6917             return;
   6918         if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
   6919 }
   6920 
   6921 
   6922 PyObject* PyAST_mod2obj(mod_ty t)
   6923 {
   6924     init_types();
   6925     return ast2obj_mod(t);
   6926 }
   6927 
   6928 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
   6929 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
   6930 {
   6931     mod_ty res;
   6932     PyObject *req_type[3];
   6933     char *req_name[3];
   6934     int isinstance;
   6935 
   6936     req_type[0] = (PyObject*)Module_type;
   6937     req_type[1] = (PyObject*)Expression_type;
   6938     req_type[2] = (PyObject*)Interactive_type;
   6939 
   6940     req_name[0] = "Module";
   6941     req_name[1] = "Expression";
   6942     req_name[2] = "Interactive";
   6943 
   6944     assert(0 <= mode && mode <= 2);
   6945 
   6946     init_types();
   6947 
   6948     isinstance = PyObject_IsInstance(ast, req_type[mode]);
   6949     if (isinstance == -1)
   6950         return NULL;
   6951     if (!isinstance) {
   6952         PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
   6953                      req_name[mode], Py_TYPE(ast)->tp_name);
   6954         return NULL;
   6955     }
   6956     if (obj2ast_mod(ast, &res, arena) != 0)
   6957         return NULL;
   6958     else
   6959         return res;
   6960 }
   6961 
   6962 int PyAST_Check(PyObject* obj)
   6963 {
   6964     init_types();
   6965     return PyObject_IsInstance(obj, (PyObject*)&AST_type);
   6966 }
   6967 
   6968 
   6969