Python-2.7.3/Python/Python-ast.c

No issues found

   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 (!PyInt_Check(obj) && !PyLong_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 value;
3352                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3353                                 if (res != 0) goto failed;
3354                                 asdl_seq_SET(body, i, value);
3355                         }
3356                         Py_XDECREF(tmp);
3357                         tmp = NULL;
3358                 } else {
3359                         PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
3360                         return 1;
3361                 }
3362                 *out = Module(body, arena);
3363                 if (*out == NULL) goto failed;
3364                 return 0;
3365         }
3366         isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
3367         if (isinstance == -1) {
3368                 return 1;
3369         }
3370         if (isinstance) {
3371                 asdl_seq* body;
3372 
3373                 if (PyObject_HasAttrString(obj, "body")) {
3374                         int res;
3375                         Py_ssize_t len;
3376                         Py_ssize_t i;
3377                         tmp = PyObject_GetAttrString(obj, "body");
3378                         if (tmp == NULL) goto failed;
3379                         if (!PyList_Check(tmp)) {
3380                                 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3381                                 goto failed;
3382                         }
3383                         len = PyList_GET_SIZE(tmp);
3384                         body = asdl_seq_new(len, arena);
3385                         if (body == NULL) goto failed;
3386                         for (i = 0; i < len; i++) {
3387                                 stmt_ty value;
3388                                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3389                                 if (res != 0) goto failed;
3390                                 asdl_seq_SET(body, i, value);
3391                         }
3392                         Py_XDECREF(tmp);
3393                         tmp = NULL;
3394                 } else {
3395                         PyErr_SetString(