PageRenderTime 1231ms CodeModel.GetById 363ms app.highlight 593ms RepoModel.GetById 151ms app.codeStats 3ms

/Python/Python-ast.c

http://unladen-swallow.googlecode.com/
C | 6134 lines | 5910 code | 206 blank | 18 comment | 1940 complexity | abfbffdcfe07f2a65d5898b87275d44b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* File automatically generated by Parser/asdl_c.py. */
   2
   3
   4/*
   5   __version__ 62047.
   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
  15static PyTypeObject AST_type;
  16static PyTypeObject *mod_type;
  17static PyObject* ast2obj_mod(void*);
  18static PyTypeObject *Module_type;
  19static char *Module_fields[]={
  20        "body",
  21};
  22static PyTypeObject *Interactive_type;
  23static char *Interactive_fields[]={
  24        "body",
  25};
  26static PyTypeObject *Expression_type;
  27static char *Expression_fields[]={
  28        "body",
  29};
  30static PyTypeObject *Suite_type;
  31static char *Suite_fields[]={
  32        "body",
  33};
  34static PyTypeObject *stmt_type;
  35static char *stmt_attributes[] = {
  36        "lineno",
  37        "col_offset",
  38};
  39static PyObject* ast2obj_stmt(void*);
  40static PyTypeObject *FunctionDef_type;
  41static char *FunctionDef_fields[]={
  42        "name",
  43        "args",
  44        "body",
  45        "decorator_list",
  46};
  47static PyTypeObject *ClassDef_type;
  48static char *ClassDef_fields[]={
  49        "name",
  50        "bases",
  51        "body",
  52        "decorator_list",
  53};
  54static PyTypeObject *Return_type;
  55static char *Return_fields[]={
  56        "value",
  57};
  58static PyTypeObject *Delete_type;
  59static char *Delete_fields[]={
  60        "targets",
  61};
  62static PyTypeObject *Assign_type;
  63static char *Assign_fields[]={
  64        "targets",
  65        "value",
  66};
  67static PyTypeObject *AugAssign_type;
  68static char *AugAssign_fields[]={
  69        "target",
  70        "op",
  71        "value",
  72};
  73static PyTypeObject *Print_type;
  74static char *Print_fields[]={
  75        "dest",
  76        "values",
  77        "nl",
  78};
  79static PyTypeObject *For_type;
  80static char *For_fields[]={
  81        "target",
  82        "iter",
  83        "body",
  84        "orelse",
  85};
  86static PyTypeObject *While_type;
  87static char *While_fields[]={
  88        "test",
  89        "body",
  90        "orelse",
  91};
  92static PyTypeObject *If_type;
  93static char *If_fields[]={
  94        "test",
  95        "body",
  96        "orelse",
  97};
  98static PyTypeObject *With_type;
  99static char *With_fields[]={
 100        "context_expr",
 101        "optional_vars",
 102        "body",
 103};
 104static PyTypeObject *Raise_type;
 105static char *Raise_fields[]={
 106        "type",
 107        "inst",
 108        "tback",
 109};
 110static PyTypeObject *TryExcept_type;
 111static char *TryExcept_fields[]={
 112        "body",
 113        "handlers",
 114        "orelse",
 115};
 116static PyTypeObject *TryFinally_type;
 117static char *TryFinally_fields[]={
 118        "body",
 119        "finalbody",
 120};
 121static PyTypeObject *Assert_type;
 122static char *Assert_fields[]={
 123        "test",
 124        "msg",
 125};
 126static PyTypeObject *Import_type;
 127static char *Import_fields[]={
 128        "names",
 129};
 130static PyTypeObject *ImportFrom_type;
 131static char *ImportFrom_fields[]={
 132        "module",
 133        "names",
 134        "level",
 135};
 136static PyTypeObject *Exec_type;
 137static char *Exec_fields[]={
 138        "body",
 139        "globals",
 140        "locals",
 141};
 142static PyTypeObject *Global_type;
 143static char *Global_fields[]={
 144        "names",
 145};
 146static PyTypeObject *Expr_type;
 147static char *Expr_fields[]={
 148        "value",
 149};
 150static PyTypeObject *Pass_type;
 151static PyTypeObject *Break_type;
 152static PyTypeObject *Continue_type;
 153static PyTypeObject *expr_type;
 154static char *expr_attributes[] = {
 155        "lineno",
 156        "col_offset",
 157};
 158static PyObject* ast2obj_expr(void*);
 159static PyTypeObject *BoolOp_type;
 160static char *BoolOp_fields[]={
 161        "op",
 162        "values",
 163};
 164static PyTypeObject *BinOp_type;
 165static char *BinOp_fields[]={
 166        "left",
 167        "op",
 168        "right",
 169};
 170static PyTypeObject *UnaryOp_type;
 171static char *UnaryOp_fields[]={
 172        "op",
 173        "operand",
 174};
 175static PyTypeObject *Lambda_type;
 176static char *Lambda_fields[]={
 177        "args",
 178        "body",
 179};
 180static PyTypeObject *IfExp_type;
 181static char *IfExp_fields[]={
 182        "test",
 183        "body",
 184        "orelse",
 185};
 186static PyTypeObject *Dict_type;
 187static char *Dict_fields[]={
 188        "keys",
 189        "values",
 190};
 191static PyTypeObject *ListComp_type;
 192static char *ListComp_fields[]={
 193        "elt",
 194        "generators",
 195};
 196static PyTypeObject *GeneratorExp_type;
 197static char *GeneratorExp_fields[]={
 198        "elt",
 199        "generators",
 200};
 201static PyTypeObject *Yield_type;
 202static char *Yield_fields[]={
 203        "value",
 204};
 205static PyTypeObject *Compare_type;
 206static char *Compare_fields[]={
 207        "left",
 208        "ops",
 209        "comparators",
 210};
 211static PyTypeObject *Call_type;
 212static char *Call_fields[]={
 213        "func",
 214        "args",
 215        "keywords",
 216        "starargs",
 217        "kwargs",
 218};
 219static PyTypeObject *Repr_type;
 220static char *Repr_fields[]={
 221        "value",
 222};
 223static PyTypeObject *Num_type;
 224static char *Num_fields[]={
 225        "n",
 226};
 227static PyTypeObject *Str_type;
 228static char *Str_fields[]={
 229        "s",
 230};
 231static PyTypeObject *Attribute_type;
 232static char *Attribute_fields[]={
 233        "value",
 234        "attr",
 235        "ctx",
 236};
 237static PyTypeObject *Subscript_type;
 238static char *Subscript_fields[]={
 239        "value",
 240        "slice",
 241        "ctx",
 242};
 243static PyTypeObject *Name_type;
 244static char *Name_fields[]={
 245        "id",
 246        "ctx",
 247};
 248static PyTypeObject *List_type;
 249static char *List_fields[]={
 250        "elts",
 251        "ctx",
 252};
 253static PyTypeObject *Tuple_type;
 254static char *Tuple_fields[]={
 255        "elts",
 256        "ctx",
 257};
 258static PyTypeObject *expr_context_type;
 259static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
 260*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
 261static PyObject* ast2obj_expr_context(expr_context_ty);
 262static PyTypeObject *Load_type;
 263static PyTypeObject *Store_type;
 264static PyTypeObject *Del_type;
 265static PyTypeObject *AugLoad_type;
 266static PyTypeObject *AugStore_type;
 267static PyTypeObject *Param_type;
 268static PyTypeObject *slice_type;
 269static PyObject* ast2obj_slice(void*);
 270static PyTypeObject *Ellipsis_type;
 271static PyTypeObject *Slice_type;
 272static char *Slice_fields[]={
 273        "lower",
 274        "upper",
 275        "step",
 276};
 277static PyTypeObject *ExtSlice_type;
 278static char *ExtSlice_fields[]={
 279        "dims",
 280};
 281static PyTypeObject *Index_type;
 282static char *Index_fields[]={
 283        "value",
 284};
 285static PyTypeObject *boolop_type;
 286static PyObject *And_singleton, *Or_singleton;
 287static PyObject* ast2obj_boolop(boolop_ty);
 288static PyTypeObject *And_type;
 289static PyTypeObject *Or_type;
 290static PyTypeObject *operator_type;
 291static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
 292*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
 293*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
 294*FloorDiv_singleton;
 295static PyObject* ast2obj_operator(operator_ty);
 296static PyTypeObject *Add_type;
 297static PyTypeObject *Sub_type;
 298static PyTypeObject *Mult_type;
 299static PyTypeObject *Div_type;
 300static PyTypeObject *Mod_type;
 301static PyTypeObject *Pow_type;
 302static PyTypeObject *LShift_type;
 303static PyTypeObject *RShift_type;
 304static PyTypeObject *BitOr_type;
 305static PyTypeObject *BitXor_type;
 306static PyTypeObject *BitAnd_type;
 307static PyTypeObject *FloorDiv_type;
 308static PyTypeObject *unaryop_type;
 309static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
 310*USub_singleton;
 311static PyObject* ast2obj_unaryop(unaryop_ty);
 312static PyTypeObject *Invert_type;
 313static PyTypeObject *Not_type;
 314static PyTypeObject *UAdd_type;
 315static PyTypeObject *USub_type;
 316static PyTypeObject *cmpop_type;
 317static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
 318*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
 319*NotIn_singleton;
 320static PyObject* ast2obj_cmpop(cmpop_ty);
 321static PyTypeObject *Eq_type;
 322static PyTypeObject *NotEq_type;
 323static PyTypeObject *Lt_type;
 324static PyTypeObject *LtE_type;
 325static PyTypeObject *Gt_type;
 326static PyTypeObject *GtE_type;
 327static PyTypeObject *Is_type;
 328static PyTypeObject *IsNot_type;
 329static PyTypeObject *In_type;
 330static PyTypeObject *NotIn_type;
 331static PyTypeObject *comprehension_type;
 332static PyObject* ast2obj_comprehension(void*);
 333static char *comprehension_fields[]={
 334        "target",
 335        "iter",
 336        "ifs",
 337};
 338static PyTypeObject *excepthandler_type;
 339static char *excepthandler_attributes[] = {
 340        "lineno",
 341        "col_offset",
 342};
 343static PyObject* ast2obj_excepthandler(void*);
 344static PyTypeObject *ExceptHandler_type;
 345static char *ExceptHandler_fields[]={
 346        "type",
 347        "name",
 348        "body",
 349};
 350static PyTypeObject *arguments_type;
 351static PyObject* ast2obj_arguments(void*);
 352static char *arguments_fields[]={
 353        "args",
 354        "vararg",
 355        "kwarg",
 356        "defaults",
 357};
 358static PyTypeObject *keyword_type;
 359static PyObject* ast2obj_keyword(void*);
 360static char *keyword_fields[]={
 361        "arg",
 362        "value",
 363};
 364static PyTypeObject *alias_type;
 365static PyObject* ast2obj_alias(void*);
 366static char *alias_fields[]={
 367        "name",
 368        "asname",
 369};
 370
 371
 372static int
 373ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
 374{
 375    Py_ssize_t i, numfields = 0;
 376    int res = -1;
 377    PyObject *key, *value, *fields;
 378    fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
 379    if (!fields)
 380        PyErr_Clear();
 381    if (fields) {
 382        numfields = PySequence_Size(fields);
 383        if (numfields == -1)
 384            goto cleanup;
 385    }
 386    res = 0; /* if no error occurs, this stays 0 to the end */
 387    if (PyTuple_GET_SIZE(args) > 0) {
 388        if (numfields != PyTuple_GET_SIZE(args)) {
 389            PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
 390                         "%zd positional argument%s",
 391                         Py_TYPE(self)->tp_name,
 392                         numfields == 0 ? "" : "either 0 or ",
 393                         numfields, numfields == 1 ? "" : "s");
 394            res = -1;
 395            goto cleanup;
 396        }
 397        for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
 398            /* cannot be reached when fields is NULL */
 399            PyObject *name = PySequence_GetItem(fields, i);
 400            if (!name) {
 401                res = -1;
 402                goto cleanup;
 403            }
 404            res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
 405            Py_DECREF(name);
 406            if (res < 0)
 407                goto cleanup;
 408        }
 409    }
 410    if (kw) {
 411        i = 0;  /* needed by PyDict_Next */
 412        while (PyDict_Next(kw, &i, &key, &value)) {
 413            res = PyObject_SetAttr(self, key, value);
 414            if (res < 0)
 415                goto cleanup;
 416        }
 417    }
 418  cleanup:
 419    Py_XDECREF(fields);
 420    return res;
 421}
 422
 423/* Pickling support */
 424static PyObject *
 425ast_type_reduce(PyObject *self, PyObject *unused)
 426{
 427    PyObject *res;
 428    PyObject *dict = PyObject_GetAttrString(self, "__dict__");
 429    if (dict == NULL) {
 430        if (PyErr_ExceptionMatches(PyExc_AttributeError))
 431            PyErr_Clear();
 432        else
 433            return NULL;
 434    }
 435    if (dict) {
 436        res = Py_BuildValue("O()O", Py_TYPE(self), dict);
 437        Py_DECREF(dict);
 438        return res;
 439    }
 440    return Py_BuildValue("O()", Py_TYPE(self));
 441}
 442
 443static PyMethodDef ast_type_methods[] = {
 444    {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
 445    {NULL}
 446};
 447
 448static PyTypeObject AST_type = {
 449    PyVarObject_HEAD_INIT(&PyType_Type, 0)
 450    "_ast.AST",
 451    sizeof(PyObject),
 452    0,
 453    0,                       /* tp_dealloc */
 454    0,                       /* tp_print */
 455    0,                       /* tp_getattr */
 456    0,                       /* tp_setattr */
 457    0,                       /* tp_compare */
 458    0,                       /* tp_repr */
 459    0,                       /* tp_as_number */
 460    0,                       /* tp_as_sequence */
 461    0,                       /* tp_as_mapping */
 462    0,                       /* tp_hash */
 463    0,                       /* tp_call */
 464    0,                       /* tp_str */
 465    PyObject_GenericGetAttr, /* tp_getattro */
 466    PyObject_GenericSetAttr, /* tp_setattro */
 467    0,                       /* tp_as_buffer */
 468    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
 469    0,                       /* tp_doc */
 470    0,                       /* tp_traverse */
 471    0,                       /* tp_clear */
 472    0,                       /* tp_richcompare */
 473    0,                       /* tp_weaklistoffset */
 474    0,                       /* tp_iter */
 475    0,                       /* tp_iternext */
 476    ast_type_methods,        /* tp_methods */
 477    0,                       /* tp_members */
 478    0,                       /* tp_getset */
 479    0,                       /* tp_base */
 480    0,                       /* tp_dict */
 481    0,                       /* tp_descr_get */
 482    0,                       /* tp_descr_set */
 483    0,                       /* tp_dictoffset */
 484    (initproc)ast_type_init, /* tp_init */
 485    PyType_GenericAlloc,     /* tp_alloc */
 486    PyType_GenericNew,       /* tp_new */
 487    PyObject_Del,            /* tp_free */
 488};
 489
 490
 491static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
 492{
 493    PyObject *fnames, *result;
 494    int i;
 495    fnames = PyTuple_New(num_fields);
 496    if (!fnames) return NULL;
 497    for (i = 0; i < num_fields; i++) {
 498        PyObject *field = PyString_FromString(fields[i]);
 499        if (!field) {
 500            Py_DECREF(fnames);
 501            return NULL;
 502        }
 503        PyTuple_SET_ITEM(fnames, i, field);
 504    }
 505    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
 506                    type, base, "_fields", fnames, "__module__", "_ast");
 507    Py_DECREF(fnames);
 508    return (PyTypeObject*)result;
 509}
 510
 511static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
 512{
 513    int i, result;
 514    PyObject *s, *l = PyTuple_New(num_fields);
 515    if (!l) return 0;
 516    for(i = 0; i < num_fields; i++) {
 517        s = PyString_FromString(attrs[i]);
 518        if (!s) {
 519            Py_DECREF(l);
 520            return 0;
 521        }
 522        PyTuple_SET_ITEM(l, i, s);
 523    }
 524    result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
 525    Py_DECREF(l);
 526    return result;
 527}
 528
 529/* Conversion AST -> Python */
 530
 531static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
 532{
 533    int i, n = asdl_seq_LEN(seq);
 534    PyObject *result = PyList_New(n);
 535    PyObject *value;
 536    if (!result)
 537        return NULL;
 538    for (i = 0; i < n; i++) {
 539        value = func(asdl_seq_GET(seq, i));
 540        if (!value) {
 541            Py_DECREF(result);
 542            return NULL;
 543        }
 544        PyList_SET_ITEM(result, i, value);
 545    }
 546    return result;
 547}
 548
 549static PyObject* ast2obj_object(void *o)
 550{
 551    if (!o)
 552        o = Py_None;
 553    Py_INCREF((PyObject*)o);
 554    return (PyObject*)o;
 555}
 556#define ast2obj_identifier ast2obj_object
 557#define ast2obj_string ast2obj_object
 558static PyObject* ast2obj_bool(bool b)
 559{
 560    return PyBool_FromLong(b);
 561}
 562
 563static PyObject* ast2obj_int(long b)
 564{
 565    return PyInt_FromLong(b);
 566}
 567
 568/* Conversion Python -> AST */
 569
 570static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
 571{
 572    if (obj == Py_None)
 573        obj = NULL;
 574    if (obj)
 575        PyArena_AddPyObject(arena, obj);
 576    Py_XINCREF(obj);
 577    *out = obj;
 578    return 0;
 579}
 580
 581#define obj2ast_identifier obj2ast_object
 582#define obj2ast_string obj2ast_object
 583
 584static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
 585{
 586    int i;
 587    if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
 588        PyObject *s = PyObject_Repr(obj);
 589        if (s == NULL) return 1;
 590        PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
 591                     PyString_AS_STRING(s));
 592        Py_DECREF(s);
 593        return 1;
 594    }
 595
 596    i = (int)PyLong_AsLong(obj);
 597    if (i == -1 && PyErr_Occurred())
 598        return 1;
 599    *out = i;
 600    return 0;
 601}
 602
 603static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
 604{
 605    if (!PyBool_Check(obj)) {
 606        PyObject *s = PyObject_Repr(obj);
 607        if (s == NULL) return 1;
 608        PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
 609                     PyString_AS_STRING(s));
 610        Py_DECREF(s);
 611        return 1;
 612    }
 613
 614    *out = (obj == Py_True);
 615    return 0;
 616}
 617
 618static int add_ast_fields(void)
 619{
 620    PyObject *empty_tuple, *d;
 621    if (PyType_Ready(&AST_type) < 0)
 622        return -1;
 623    d = AST_type.tp_dict;
 624    empty_tuple = PyTuple_New(0);
 625    if (!empty_tuple ||
 626        PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
 627        PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
 628        Py_XDECREF(empty_tuple);
 629        return -1;
 630    }
 631    Py_DECREF(empty_tuple);
 632    return 0;
 633}
 634
 635
 636static int init_types(void)
 637{
 638        static int initialized;
 639        if (initialized) return 1;
 640        if (add_ast_fields() < 0) return 0;
 641        mod_type = make_type("mod", &AST_type, NULL, 0);
 642        if (!mod_type) return 0;
 643        if (!add_attributes(mod_type, NULL, 0)) return 0;
 644        Module_type = make_type("Module", mod_type, Module_fields, 1);
 645        if (!Module_type) return 0;
 646        Interactive_type = make_type("Interactive", mod_type,
 647                                     Interactive_fields, 1);
 648        if (!Interactive_type) return 0;
 649        Expression_type = make_type("Expression", mod_type, Expression_fields,
 650                                    1);
 651        if (!Expression_type) return 0;
 652        Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
 653        if (!Suite_type) return 0;
 654        stmt_type = make_type("stmt", &AST_type, NULL, 0);
 655        if (!stmt_type) return 0;
 656        if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
 657        FunctionDef_type = make_type("FunctionDef", stmt_type,
 658                                     FunctionDef_fields, 4);
 659        if (!FunctionDef_type) return 0;
 660        ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
 661        if (!ClassDef_type) return 0;
 662        Return_type = make_type("Return", stmt_type, Return_fields, 1);
 663        if (!Return_type) return 0;
 664        Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
 665        if (!Delete_type) return 0;
 666        Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
 667        if (!Assign_type) return 0;
 668        AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
 669        if (!AugAssign_type) return 0;
 670        Print_type = make_type("Print", stmt_type, Print_fields, 3);
 671        if (!Print_type) return 0;
 672        For_type = make_type("For", stmt_type, For_fields, 4);
 673        if (!For_type) return 0;
 674        While_type = make_type("While", stmt_type, While_fields, 3);
 675        if (!While_type) return 0;
 676        If_type = make_type("If", stmt_type, If_fields, 3);
 677        if (!If_type) return 0;
 678        With_type = make_type("With", stmt_type, With_fields, 3);
 679        if (!With_type) return 0;
 680        Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
 681        if (!Raise_type) return 0;
 682        TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
 683        if (!TryExcept_type) return 0;
 684        TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
 685                                    2);
 686        if (!TryFinally_type) return 0;
 687        Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
 688        if (!Assert_type) return 0;
 689        Import_type = make_type("Import", stmt_type, Import_fields, 1);
 690        if (!Import_type) return 0;
 691        ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
 692                                    3);
 693        if (!ImportFrom_type) return 0;
 694        Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
 695        if (!Exec_type) return 0;
 696        Global_type = make_type("Global", stmt_type, Global_fields, 1);
 697        if (!Global_type) return 0;
 698        Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
 699        if (!Expr_type) return 0;
 700        Pass_type = make_type("Pass", stmt_type, NULL, 0);
 701        if (!Pass_type) return 0;
 702        Break_type = make_type("Break", stmt_type, NULL, 0);
 703        if (!Break_type) return 0;
 704        Continue_type = make_type("Continue", stmt_type, NULL, 0);
 705        if (!Continue_type) return 0;
 706        expr_type = make_type("expr", &AST_type, NULL, 0);
 707        if (!expr_type) return 0;
 708        if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
 709        BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
 710        if (!BoolOp_type) return 0;
 711        BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
 712        if (!BinOp_type) return 0;
 713        UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
 714        if (!UnaryOp_type) return 0;
 715        Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
 716        if (!Lambda_type) return 0;
 717        IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
 718        if (!IfExp_type) return 0;
 719        Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
 720        if (!Dict_type) return 0;
 721        ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
 722        if (!ListComp_type) return 0;
 723        GeneratorExp_type = make_type("GeneratorExp", expr_type,
 724                                      GeneratorExp_fields, 2);
 725        if (!GeneratorExp_type) return 0;
 726        Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
 727        if (!Yield_type) return 0;
 728        Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
 729        if (!Compare_type) return 0;
 730        Call_type = make_type("Call", expr_type, Call_fields, 5);
 731        if (!Call_type) return 0;
 732        Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
 733        if (!Repr_type) return 0;
 734        Num_type = make_type("Num", expr_type, Num_fields, 1);
 735        if (!Num_type) return 0;
 736        Str_type = make_type("Str", expr_type, Str_fields, 1);
 737        if (!Str_type) return 0;
 738        Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
 739        if (!Attribute_type) return 0;
 740        Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
 741        if (!Subscript_type) return 0;
 742        Name_type = make_type("Name", expr_type, Name_fields, 2);
 743        if (!Name_type) return 0;
 744        List_type = make_type("List", expr_type, List_fields, 2);
 745        if (!List_type) return 0;
 746        Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
 747        if (!Tuple_type) return 0;
 748        expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
 749        if (!expr_context_type) return 0;
 750        if (!add_attributes(expr_context_type, NULL, 0)) return 0;
 751        Load_type = make_type("Load", expr_context_type, NULL, 0);
 752        if (!Load_type) return 0;
 753        Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
 754        if (!Load_singleton) return 0;
 755        Store_type = make_type("Store", expr_context_type, NULL, 0);
 756        if (!Store_type) return 0;
 757        Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
 758        if (!Store_singleton) return 0;
 759        Del_type = make_type("Del", expr_context_type, NULL, 0);
 760        if (!Del_type) return 0;
 761        Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
 762        if (!Del_singleton) return 0;
 763        AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
 764        if (!AugLoad_type) return 0;
 765        AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
 766        if (!AugLoad_singleton) return 0;
 767        AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
 768        if (!AugStore_type) return 0;
 769        AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
 770        if (!AugStore_singleton) return 0;
 771        Param_type = make_type("Param", expr_context_type, NULL, 0);
 772        if (!Param_type) return 0;
 773        Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
 774        if (!Param_singleton) return 0;
 775        slice_type = make_type("slice", &AST_type, NULL, 0);
 776        if (!slice_type) return 0;
 777        if (!add_attributes(slice_type, NULL, 0)) return 0;
 778        Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
 779        if (!Ellipsis_type) return 0;
 780        Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
 781        if (!Slice_type) return 0;
 782        ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
 783        if (!ExtSlice_type) return 0;
 784        Index_type = make_type("Index", slice_type, Index_fields, 1);
 785        if (!Index_type) return 0;
 786        boolop_type = make_type("boolop", &AST_type, NULL, 0);
 787        if (!boolop_type) return 0;
 788        if (!add_attributes(boolop_type, NULL, 0)) return 0;
 789        And_type = make_type("And", boolop_type, NULL, 0);
 790        if (!And_type) return 0;
 791        And_singleton = PyType_GenericNew(And_type, NULL, NULL);
 792        if (!And_singleton) return 0;
 793        Or_type = make_type("Or", boolop_type, NULL, 0);
 794        if (!Or_type) return 0;
 795        Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
 796        if (!Or_singleton) return 0;
 797        operator_type = make_type("operator", &AST_type, NULL, 0);
 798        if (!operator_type) return 0;
 799        if (!add_attributes(operator_type, NULL, 0)) return 0;
 800        Add_type = make_type("Add", operator_type, NULL, 0);
 801        if (!Add_type) return 0;
 802        Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
 803        if (!Add_singleton) return 0;
 804        Sub_type = make_type("Sub", operator_type, NULL, 0);
 805        if (!Sub_type) return 0;
 806        Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
 807        if (!Sub_singleton) return 0;
 808        Mult_type = make_type("Mult", operator_type, NULL, 0);
 809        if (!Mult_type) return 0;
 810        Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
 811        if (!Mult_singleton) return 0;
 812        Div_type = make_type("Div", operator_type, NULL, 0);
 813        if (!Div_type) return 0;
 814        Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
 815        if (!Div_singleton) return 0;
 816        Mod_type = make_type("Mod", operator_type, NULL, 0);
 817        if (!Mod_type) return 0;
 818        Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
 819        if (!Mod_singleton) return 0;
 820        Pow_type = make_type("Pow", operator_type, NULL, 0);
 821        if (!Pow_type) return 0;
 822        Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
 823        if (!Pow_singleton) return 0;
 824        LShift_type = make_type("LShift", operator_type, NULL, 0);
 825        if (!LShift_type) return 0;
 826        LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
 827        if (!LShift_singleton) return 0;
 828        RShift_type = make_type("RShift", operator_type, NULL, 0);
 829        if (!RShift_type) return 0;
 830        RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
 831        if (!RShift_singleton) return 0;
 832        BitOr_type = make_type("BitOr", operator_type, NULL, 0);
 833        if (!BitOr_type) return 0;
 834        BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
 835        if (!BitOr_singleton) return 0;
 836        BitXor_type = make_type("BitXor", operator_type, NULL, 0);
 837        if (!BitXor_type) return 0;
 838        BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
 839        if (!BitXor_singleton) return 0;
 840        BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
 841        if (!BitAnd_type) return 0;
 842        BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
 843        if (!BitAnd_singleton) return 0;
 844        FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
 845        if (!FloorDiv_type) return 0;
 846        FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
 847        if (!FloorDiv_singleton) return 0;
 848        unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
 849        if (!unaryop_type) return 0;
 850        if (!add_attributes(unaryop_type, NULL, 0)) return 0;
 851        Invert_type = make_type("Invert", unaryop_type, NULL, 0);
 852        if (!Invert_type) return 0;
 853        Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
 854        if (!Invert_singleton) return 0;
 855        Not_type = make_type("Not", unaryop_type, NULL, 0);
 856        if (!Not_type) return 0;
 857        Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
 858        if (!Not_singleton) return 0;
 859        UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
 860        if (!UAdd_type) return 0;
 861        UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
 862        if (!UAdd_singleton) return 0;
 863        USub_type = make_type("USub", unaryop_type, NULL, 0);
 864        if (!USub_type) return 0;
 865        USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
 866        if (!USub_singleton) return 0;
 867        cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
 868        if (!cmpop_type) return 0;
 869        if (!add_attributes(cmpop_type, NULL, 0)) return 0;
 870        Eq_type = make_type("Eq", cmpop_type, NULL, 0);
 871        if (!Eq_type) return 0;
 872        Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
 873        if (!Eq_singleton) return 0;
 874        NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
 875        if (!NotEq_type) return 0;
 876        NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
 877        if (!NotEq_singleton) return 0;
 878        Lt_type = make_type("Lt", cmpop_type, NULL, 0);
 879        if (!Lt_type) return 0;
 880        Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
 881        if (!Lt_singleton) return 0;
 882        LtE_type = make_type("LtE", cmpop_type, NULL, 0);
 883        if (!LtE_type) return 0;
 884        LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
 885        if (!LtE_singleton) return 0;
 886        Gt_type = make_type("Gt", cmpop_type, NULL, 0);
 887        if (!Gt_type) return 0;
 888        Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
 889        if (!Gt_singleton) return 0;
 890        GtE_type = make_type("GtE", cmpop_type, NULL, 0);
 891        if (!GtE_type) return 0;
 892        GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
 893        if (!GtE_singleton) return 0;
 894        Is_type = make_type("Is", cmpop_type, NULL, 0);
 895        if (!Is_type) return 0;
 896        Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
 897        if (!Is_singleton) return 0;
 898        IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
 899        if (!IsNot_type) return 0;
 900        IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
 901        if (!IsNot_singleton) return 0;
 902        In_type = make_type("In", cmpop_type, NULL, 0);
 903        if (!In_type) return 0;
 904        In_singleton = PyType_GenericNew(In_type, NULL, NULL);
 905        if (!In_singleton) return 0;
 906        NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
 907        if (!NotIn_type) return 0;
 908        NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
 909        if (!NotIn_singleton) return 0;
 910        comprehension_type = make_type("comprehension", &AST_type,
 911                                       comprehension_fields, 3);
 912        if (!comprehension_type) return 0;
 913        excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
 914        if (!excepthandler_type) return 0;
 915        if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
 916            return 0;
 917        ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
 918                                       ExceptHandler_fields, 3);
 919        if (!ExceptHandler_type) return 0;
 920        arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
 921        if (!arguments_type) return 0;
 922        keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
 923        if (!keyword_type) return 0;
 924        alias_type = make_type("alias", &AST_type, alias_fields, 2);
 925        if (!alias_type) return 0;
 926        initialized = 1;
 927        return 1;
 928}
 929
 930static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
 931static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
 932static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
 933static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
 934                                arena);
 935static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
 936static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
 937static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
 938static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
 939static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
 940static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
 941                                 arena);
 942static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
 943                                 arena);
 944static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
 945static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
 946static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
 947
 948mod_ty
 949Module(asdl_seq * body, PyArena *arena)
 950{
 951        mod_ty p;
 952        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
 953        if (!p)
 954                return NULL;
 955        p->kind = Module_kind;
 956        p->v.Module.body = body;
 957        return p;
 958}
 959
 960mod_ty
 961Interactive(asdl_seq * body, PyArena *arena)
 962{
 963        mod_ty p;
 964        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
 965        if (!p)
 966                return NULL;
 967        p->kind = Interactive_kind;
 968        p->v.Interactive.body = body;
 969        return p;
 970}
 971
 972mod_ty
 973Expression(expr_ty body, PyArena *arena)
 974{
 975        mod_ty p;
 976        if (!body) {
 977                PyErr_SetString(PyExc_ValueError,
 978                                "field body is required for Expression");
 979                return NULL;
 980        }
 981        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
 982        if (!p)
 983                return NULL;
 984        p->kind = Expression_kind;
 985        p->v.Expression.body = body;
 986        return p;
 987}
 988
 989mod_ty
 990Suite(asdl_seq * body, PyArena *arena)
 991{
 992        mod_ty p;
 993        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
 994        if (!p)
 995                return NULL;
 996        p->kind = Suite_kind;
 997        p->v.Suite.body = body;
 998        return p;
 999}
1000
1001stmt_ty
1002FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
1003            decorator_list, int lineno, int col_offset, PyArena *arena)
1004{
1005        stmt_ty p;
1006        if (!name) {
1007                PyErr_SetString(PyExc_ValueError,
1008                                "field name is required for FunctionDef");
1009                return NULL;
1010        }
1011        if (!args) {
1012                PyErr_SetString(PyExc_ValueError,
1013                                "field args is required for FunctionDef");
1014                return NULL;
1015        }
1016        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1017        if (!p)
1018                return NULL;
1019        p->kind = FunctionDef_kind;
1020        p->v.FunctionDef.name = name;
1021        p->v.FunctionDef.args = args;
1022        p->v.FunctionDef.body = body;
1023        p->v.FunctionDef.decorator_list = decorator_list;
1024        p->lineno = lineno;
1025        p->col_offset = col_offset;
1026        return p;
1027}
1028
1029stmt_ty
1030ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
1031         decorator_list, int lineno, int col_offset, PyArena *arena)
1032{
1033        stmt_ty p;
1034        if (!name) {
1035                PyErr_SetString(PyExc_ValueError,
1036                                "field name is required for ClassDef");
1037                return NULL;
1038        }
1039        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1040        if (!p)
1041                return NULL;
1042        p->kind = ClassDef_kind;
1043        p->v.ClassDef.name = name;
1044        p->v.ClassDef.bases = bases;
1045        p->v.ClassDef.body = body;
1046        p->v.ClassDef.decorator_list = decorator_list;
1047        p->lineno = lineno;
1048        p->col_offset = col_offset;
1049        return p;
1050}
1051
1052stmt_ty
1053Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
1054{
1055        stmt_ty p;
1056        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1057        if (!p)
1058                return NULL;
1059        p->kind = Return_kind;
1060        p->v.Return.value = value;
1061        p->lineno = lineno;
1062        p->col_offset = col_offset;
1063        return p;
1064}
1065
1066stmt_ty
1067Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
1068{
1069        stmt_ty p;
1070        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1071        if (!p)
1072                return NULL;
1073        p->kind = Delete_kind;
1074        p->v.Delete.targets = targets;
1075        p->lineno = lineno;
1076        p->col_offset = col_offset;
1077        return p;
1078}
1079
1080stmt_ty
1081Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1082       *arena)
1083{
1084        stmt_ty p;
1085        if (!value) {
1086                PyErr_SetString(PyExc_ValueError,
1087                                "field value is required for Assign");
1088                return NULL;
1089        }
1090        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1091        if (!p)
1092                return NULL;
1093        p->kind = Assign_kind;
1094        p->v.Assign.targets = targets;
1095        p->v.Assign.value = value;
1096        p->lineno = lineno;
1097        p->col_offset = col_offset;
1098        return p;
1099}
1100
1101stmt_ty
1102AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1103          col_offset, PyArena *arena)
1104{
1105        stmt_ty p;
1106        if (!target) {
1107                PyErr_SetString(PyExc_ValueError,
1108                                "field target is required for AugAssign");
1109                return NULL;
1110        }
1111        if (!op) {
1112                PyErr_SetString(PyExc_ValueError,
1113                                "field op is required for AugAssign");
1114                return NULL;
1115        }
1116        if (!value) {
1117                PyErr_SetString(PyExc_ValueError,
1118                                "field value is required for AugAssign");
1119                return NULL;
1120        }
1121        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1122        if (!p)
1123                return NULL;
1124        p->kind = AugAssign_kind;
1125        p->v.AugAssign.target = target;
1126        p->v.AugAssign.op = op;
1127        p->v.AugAssign.value = value;
1128        p->lineno = lineno;
1129        p->col_offset = col_offset;
1130        return p;
1131}
1132
1133stmt_ty
1134Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
1135      PyArena *arena)
1136{
1137        stmt_ty p;
1138        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1139        if (!p)
1140                return NULL;
1141        p->kind = Print_kind;
1142        p->v.Print.dest = dest;
1143        p->v.Print.values = values;
1144        p->v.Print.nl = nl;
1145        p->lineno = lineno;
1146        p->col_offset = col_offset;
1147        return p;
1148}
1149
1150stmt_ty
1151For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1152    lineno, int col_offset, PyArena *arena)
1153{
1154        stmt_ty p;
1155        if (!target) {
1156                PyErr_SetString(PyExc_ValueError,
1157                                "field target is required for For");
1158                return NULL;
1159        }
1160        if (!iter) {
1161                PyErr_SetString(PyExc_ValueError,
1162                                "field iter is required for For");
1163                return NULL;
1164        }
1165        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1166        if (!p)
1167                return NULL;
1168        p->kind = For_kind;
1169        p->v.For.target = target;
1170        p->v.For.iter = iter;
1171        p->v.For.body = body;
1172        p->v.For.orelse = orelse;
1173        p->lineno = lineno;
1174        p->col_offset = col_offset;
1175        return p;
1176}
1177
1178stmt_ty
1179While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1180      col_offset, PyArena *arena)
1181{
1182        stmt_ty p;
1183        if (!test) {
1184                PyErr_SetString(PyExc_ValueError,
1185                                "field test is required for While");
1186                return NULL;
1187        }
1188        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1189        if (!p)
1190                return NULL;
1191        p->kind = While_kind;
1192        p->v.While.test = test;
1193        p->v.While.body = body;
1194        p->v.While.orelse = orelse;
1195        p->lineno = lineno;
1196        p->col_offset = col_offset;
1197        return p;
1198}
1199
1200stmt_ty
1201If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1202   col_offset, PyArena *arena)
1203{
1204        stmt_ty p;
1205        if (!test) {
1206                PyErr_SetString(PyExc_ValueError,
1207                                "field test is required for If");
1208                return NULL;
1209        }
1210        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1211        if (!p)
1212                return NULL;
1213        p->kind = If_kind;
1214        p->v.If.test = test;
1215        p->v.If.body = body;
1216        p->v.If.orelse = orelse;
1217        p->lineno = lineno;
1218        p->col_offset = col_offset;
1219        return p;
1220}
1221
1222stmt_ty
1223With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1224     int col_offset, PyArena *arena)
1225{
1226        stmt_ty p;
1227        if (!context_expr) {
1228                PyErr_SetString(PyExc_ValueError,
1229                                "field context_expr is required for With");
1230                return NULL;
1231        }
1232        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1233        if (!p)
1234                return NULL;
1235        p->kind = With_kind;
1236        p->v.With.context_expr = context_expr;
1237        p->v.With.optional_vars = optional_vars;
1238        p->v.With.body = body;
1239        p->lineno = lineno;
1240        p->col_offset = col_offset;
1241        return p;
1242}
1243
1244stmt_ty
1245Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1246      PyArena *arena)
1247{
1248        stmt_ty p;
1249        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1250        if (!p)
1251                return NULL;
1252        p->kind = Raise_kind;
1253        p->v.Raise.type = type;
1254        p->v.Raise.inst = inst;
1255        p->v.Raise.tback = tback;
1256        p->lineno = lineno;
1257        p->col_offset = col_offset;
1258        return p;
1259}
1260
1261stmt_ty
1262TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1263          int col_offset, PyArena *arena)
1264{
1265        stmt_ty p;
1266        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1267        if (!p)
1268                return NULL;
1269        p->kind = TryExcept_kind;
1270        p->v.TryExcept.body = body;
1271        p->v.TryExcept.handlers = handlers;
1272        p->v.TryExcept.orelse = orelse;
1273        p->lineno = lineno;
1274        p->col_offset = col_offset;
1275        return p;
1276}
1277
1278stmt_ty
1279TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1280           PyArena *arena)
1281{
1282        stmt_ty p;
1283        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1284        if (!p)
1285                return NULL;
1286        p->kind = TryFinally_kind;
1287        p->v.TryFinally.body = body;
1288        p->v.TryFinally.finalbody = finalbody;
1289        p->lineno = lineno;
1290        p->col_offset = col_offset;
1291        return p;
1292}
1293
1294stmt_ty
1295Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1296{
1297        stmt_ty p;
1298        if (!test) {
1299                PyErr_SetString(PyExc_ValueError,
1300                                "field test is required for Assert");
1301                return NULL;
1302        }
1303        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1304        if (!p)
1305                return NULL;
1306        p->kind = Assert_kind;
1307        p->v.Assert.test = test;
1308        p->v.Assert.msg = msg;
1309        p->lineno = lineno;
1310        p->col_offset = col_offset;
1311        return p;
1312}
1313
1314stmt_ty
1315Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1316{
1317        stmt_ty p;
1318        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1319        if (!p)
1320                return NULL;
1321        p->kind = Import_kind;
1322        p->v.Import.names = names;
1323        p->lineno = lineno;
1324        p->col_offset = col_offset;
1325        return p;
1326}
1327
1328stmt_ty
1329ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1330           col_offset, PyArena *arena)
1331{
1332        stmt_ty p;
1333        if (!module) {
1334                PyErr_SetString(PyExc_ValueError,
1335                                "field module is required for ImportFrom");
1336                return NULL;
1337        }
1338        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1339        if (!p)
1340                return NULL;
1341        p->kind = ImportFrom_kind;
1342        p->v.ImportFrom.module = module;
1343        p->v.ImportFrom.names = names;
1344        p->v.ImportFrom.level = level;
1345        p->lineno = lineno;
1346        p->col_offset = col_offset;
1347        return p;
1348}
1349
1350stmt_ty
1351Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1352     PyArena *arena)
1353{
1354        stmt_ty p;
1355        if (!body) {
1356                PyErr_SetString(PyExc_ValueError,
1357                                "field body is required for Exec");
1358                return NULL;
1359        }
1360        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1361        if (!p)
1362                return NULL;
1363        p->kind = Exec_kind;
1364        p->v.Exec.body = body;
1365        p->v.Exec.globals = globals;
1366        p->v.Exec.locals = locals;
1367        p->lineno = lineno;
1368        p->col_offset = col_offset;
1369        return p;
1370}
1371
1372stmt_ty
1373Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1374{
1375        stmt_ty p;
1376        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1377        if (!p)
1378                return NULL;
1379        p->kind = Global_kind;
1380        p->v.Global.names = names;
1381        p->lineno = lineno;
1382        p->col_offset = col_offset;
1383        return p;
1384}
1385
1386stmt_ty
1387Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1388{
1389        stmt_ty p;
1390        if (!value) {
1391                PyErr_SetString(PyExc_ValueError,
1392                                "field value is required for Expr");
1393                return NULL;
1394        }
1395        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1396        if (!p)
1397                return NULL;
1398        p->kind = Expr_kind;
1399        p->v.Expr.value = value;
1400        p->lineno = lineno;
1401        p->col_offset = col_offset;
1402        return p;
1403}
1404
1405stmt_ty
1406Pass(int lineno, int col_offset, PyArena *arena)
1407{
1408        stmt_ty p;
1409        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1410        if (!p)
1411                return NULL;
1412        p->kind = Pass_kind;
1413        p->lineno = lineno;
1414        p->col_offset = col_offset;
1415        return p;
1416}
1417
1418stmt_ty
1419Break(int lineno, int col_offset, PyArena *arena)
1420{
1421        stmt_ty p;
1422        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1423        if (!p)
1424                return NULL;
1425        p->kind = Break_kind;
1426        p->lineno = lineno;
1427        p->col_offset = col_offset;
1428        return p;
1429}
1430
1431stmt_ty
1432Continue(int lineno, int col_offset, PyArena *arena)
1433{
1434        stmt_ty p;
1435        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1436        if (!p)
1437                return NULL;
1438        p->kind = Continue_kind;
1439        p->lineno = lineno;
1440        p->col_offset = col_offset;
1441        return p;
1442}
1443
1444expr_ty
1445BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1446       *arena)
1447{
1448        expr_ty p;
1449        if (!op) {
1450                PyErr_SetString(PyExc_ValueError,
1451                                "field op is required for BoolOp");
1452                return NULL;
1453        }
1454        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1455        if (!p)
1456                return NULL;
1457        p->kind = BoolOp_kind;
1458        p->v.BoolOp.op = op;
1459        p->v.BoolOp.values = values;
1460        p->lineno = lineno;
1461        p->col_offset = col_offset;
1462        return p;
1463}
1464
1465expr_ty
1466BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1467      PyArena *arena)
1468{
1469        expr_ty p;
1470        if (!left) {
1471                PyErr_SetString(PyExc_ValueError,
1472                                "field left is required for BinOp");
1473                return NULL;
1474        }
1475        if (!op) {
1476                PyErr_SetString(PyExc_ValueError,
1477                                "field op is required for BinOp");
1478                return NULL;
1479        }
1480        if (!right) {
1481                PyErr_SetString(PyExc_ValueError,
1482                                "field right is required for BinOp");
1483                return NULL;
1484        }
1485        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1486        if (!p)
1487                return NULL;
1488        p->kind = BinOp_kind;
1489        p->v.BinOp.left = left;
1490        p->v.BinOp.op = op;
1491        p->v.BinOp.right = right;
1492        p->lineno = lineno;
1493        p->col_offset = col_offset;
1494        return p;
1495}
1496
1497expr_ty
1498UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1499        *arena)
1500{
1501        expr_ty p;
1502        if (!op) {
1503                PyErr_SetString(PyExc_ValueError,
1504                                "field op is required for UnaryOp");
1505                return NULL;
1506        }
1507        if (!operand) {
1508                PyErr_SetString(PyExc_ValueError,
1509                                "field operand is required for UnaryOp");
1510                return NULL;
1511        }
1512        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1513        if (!p)
1514                return NULL;
1515        p->kind = UnaryOp_kind;
1516        p->v.UnaryOp.op = op;
1517        p->v.UnaryOp.operand = operand;
1518        p->lineno = lineno;
1519        p->col_offset = col_offset;
1520        return p;
1521}
1522
1523expr_ty
1524Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1525       *arena)
1526{
1527        expr_ty p;
1528        if (!args) {
1529                PyErr_SetString(PyExc_ValueError,
1530                                "field args is required for Lambda");
1531                return NULL;
1532        }
1533        if (!body) {
1534                PyErr_SetString(PyExc_ValueError,
1535                                "field body is required for Lambda");
1536                return NULL;
1537        }
1538        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1539        if (!p)
1540                return NULL;
1541        p->kind = Lambda_kind;
1542        p->v.Lambda.args = args;
1543        p->v.Lambda.body = body;
1544        p->lineno = lineno;
1545        p->col_offset = col_offset;
1546        return p;
1547}
1548
1549expr_ty
1550IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1551      PyArena *arena)
1552{
1553        expr_ty p;
1554        if (!test) {
1555                PyErr_SetString(PyExc_ValueError,
1556                                "field test is required for IfExp");
1557                return NULL;
1558        }
1559        if (!body) {
1560                PyErr_SetString(PyExc_Value

Large files files are truncated, but you can click here to view the full file