Showing the changes to sys/src/cmd/python/Python/Python-ast.c (1 of 3706 files). Show all
Unified · Split
| @@ -0,0 +1,3202 @@ | ||
| 1 | +/* File automatically generated by Parser/asdl_c.py */ | |
| 2 | + | |
| 3 | +#include "Python.h" | |
| 4 | +#include "Python-ast.h" | |
| 5 | + | |
| 6 | +static PyTypeObject* AST_type; | |
| 7 | +static PyTypeObject *mod_type; | |
| 8 | +static PyObject* ast2obj_mod(void*); | |
| 9 | +static PyTypeObject *Module_type; | |
| 10 | +static char *Module_fields[]={ | |
| 11 | + "body", | |
| 12 | +}; | |
| 13 | +static PyTypeObject *Interactive_type; | |
| 14 | +static char *Interactive_fields[]={ | |
| 15 | + "body", | |
| 16 | +}; | |
| 17 | +static PyTypeObject *Expression_type; | |
| 18 | +static char *Expression_fields[]={ | |
| 19 | + "body", | |
| 20 | +}; | |
| 21 | +static PyTypeObject *Suite_type; | |
| 22 | +static char *Suite_fields[]={ | |
| 23 | + "body", | |
| 24 | +}; | |
| 25 | +static PyTypeObject *stmt_type; | |
| 26 | +static char *stmt_attributes[] = { | |
| 27 | + "lineno", | |
| 28 | + "col_offset", | |
| 29 | +}; | |
| 30 | +static PyObject* ast2obj_stmt(void*); | |
| 31 | +static PyTypeObject *FunctionDef_type; | |
| 32 | +static char *FunctionDef_fields[]={ | |
| 33 | + "name", | |
| 34 | + "args", | |
| 35 | + "body", | |
| 36 | + "decorators", | |
| 37 | +}; | |
| 38 | +static PyTypeObject *ClassDef_type; | |
| 39 | +static char *ClassDef_fields[]={ | |
| 40 | + "name", | |
| 41 | + "bases", | |
| 42 | + "body", | |
| 43 | +}; | |
| 44 | +static PyTypeObject *Return_type; | |
| 45 | +static char *Return_fields[]={ | |
| 46 | + "value", | |
| 47 | +}; | |
| 48 | +static PyTypeObject *Delete_type; | |
| 49 | +static char *Delete_fields[]={ | |
| 50 | + "targets", | |
| 51 | +}; | |
| 52 | +static PyTypeObject *Assign_type; | |
| 53 | +static char *Assign_fields[]={ | |
| 54 | + "targets", | |
| 55 | + "value", | |
| 56 | +}; | |
| 57 | +static PyTypeObject *AugAssign_type; | |
| 58 | +static char *AugAssign_fields[]={ | |
| 59 | + "target", | |
| 60 | + "op", | |
| 61 | + "value", | |
| 62 | +}; | |
| 63 | +static PyTypeObject *Print_type; | |
| 64 | +static char *Print_fields[]={ | |
| 65 | + "dest", | |
| 66 | + "values", | |
| 67 | + "nl", | |
| 68 | +}; | |
| 69 | +static PyTypeObject *For_type; | |
| 70 | +static char *For_fields[]={ | |
| 71 | + "target", | |
| 72 | + "iter", | |
| 73 | + "body", | |
| 74 | + "orelse", | |
| 75 | +}; | |
| 76 | +static PyTypeObject *While_type; | |
| 77 | +static char *While_fields[]={ | |
| 78 | + "test", | |
| 79 | + "body", | |
| 80 | + "orelse", | |
| 81 | +}; | |
| 82 | +static PyTypeObject *If_type; | |
| 83 | +static char *If_fields[]={ | |
| 84 | + "test", | |
| 85 | + "body", | |
| 86 | + "orelse", | |
| 87 | +}; | |
| 88 | +static PyTypeObject *With_type; | |
| 89 | +static char *With_fields[]={ | |
| 90 | + "context_expr", | |
| 91 | + "optional_vars", | |
| 92 | + "body", | |
| 93 | +}; | |
| 94 | +static PyTypeObject *Raise_type; | |
| 95 | +static char *Raise_fields[]={ | |
| 96 | + "type", | |
| 97 | + "inst", | |
| 98 | + "tback", | |
| 99 | +}; | |
| 100 | +static PyTypeObject *TryExcept_type; | |
| 101 | +static char *TryExcept_fields[]={ | |
| 102 | + "body", | |
| 103 | + "handlers", | |
| 104 | + "orelse", | |
| 105 | +}; | |
| 106 | +static PyTypeObject *TryFinally_type; | |
| 107 | +static char *TryFinally_fields[]={ | |
| 108 | + "body", | |
| 109 | + "finalbody", | |
| 110 | +}; | |
| 111 | +static PyTypeObject *Assert_type; | |
| 112 | +static char *Assert_fields[]={ | |
| 113 | + "test", | |
| 114 | + "msg", | |
| 115 | +}; | |
| 116 | +static PyTypeObject *Import_type; | |
| 117 | +static char *Import_fields[]={ | |
| 118 | + "names", | |
| 119 | +}; | |
| 120 | +static PyTypeObject *ImportFrom_type; | |
| 121 | +static char *ImportFrom_fields[]={ | |
| 122 | + "module", | |
| 123 | + "names", | |
| 124 | + "level", | |
| 125 | +}; | |
| 126 | +static PyTypeObject *Exec_type; | |
| 127 | +static char *Exec_fields[]={ | |
| 128 | + "body", | |
| 129 | + "globals", | |
| 130 | + "locals", | |
| 131 | +}; | |
| 132 | +static PyTypeObject *Global_type; | |
| 133 | +static char *Global_fields[]={ | |
| 134 | + "names", | |
| 135 | +}; | |
| 136 | +static PyTypeObject *Expr_type; | |
| 137 | +static char *Expr_fields[]={ | |
| 138 | + "value", | |
| 139 | +}; | |
| 140 | +static PyTypeObject *Pass_type; | |
| 141 | +static PyTypeObject *Break_type; | |
| 142 | +static PyTypeObject *Continue_type; | |
| 143 | +static PyTypeObject *expr_type; | |
| 144 | +static char *expr_attributes[] = { | |
| 145 | + "lineno", | |
| 146 | + "col_offset", | |
| 147 | +}; | |
| 148 | +static PyObject* ast2obj_expr(void*); | |
| 149 | +static PyTypeObject *BoolOp_type; | |
| 150 | +static char *BoolOp_fields[]={ | |
| 151 | + "op", | |
| 152 | + "values", | |
| 153 | +}; | |
| 154 | +static PyTypeObject *BinOp_type; | |
| 155 | +static char *BinOp_fields[]={ | |
| 156 | + "left", | |
| 157 | + "op", | |
| 158 | + "right", | |
| 159 | +}; | |
| 160 | +static PyTypeObject *UnaryOp_type; | |
| 161 | +static char *UnaryOp_fields[]={ | |
| 162 | + "op", | |
| 163 | + "operand", | |
| 164 | +}; | |
| 165 | +static PyTypeObject *Lambda_type; | |
| 166 | +static char *Lambda_fields[]={ | |
| 167 | + "args", | |
| 168 | + "body", | |
| 169 | +}; | |
| 170 | +static PyTypeObject *IfExp_type; | |
| 171 | +static char *IfExp_fields[]={ | |
| 172 | + "test", | |
| 173 | + "body", | |
| 174 | + "orelse", | |
| 175 | +}; | |
| 176 | +static PyTypeObject *Dict_type; | |
| 177 | +static char *Dict_fields[]={ | |
| 178 | + "keys", | |
| 179 | + "values", | |
| 180 | +}; | |
| 181 | +static PyTypeObject *ListComp_type; | |
| 182 | +static char *ListComp_fields[]={ | |
| 183 | + "elt", | |
| 184 | + "generators", | |
| 185 | +}; | |
| 186 | +static PyTypeObject *GeneratorExp_type; | |
| 187 | +static char *GeneratorExp_fields[]={ | |
| 188 | + "elt", | |
| 189 | + "generators", | |
| 190 | +}; | |
| 191 | +static PyTypeObject *Yield_type; | |
| 192 | +static char *Yield_fields[]={ | |
| 193 | + "value", | |
| 194 | +}; | |
| 195 | +static PyTypeObject *Compare_type; | |
| 196 | +static char *Compare_fields[]={ | |
| 197 | + "left", | |
| 198 | + "ops", | |
| 199 | + "comparators", | |
| 200 | +}; | |
| 201 | +static PyTypeObject *Call_type; | |
| 202 | +static char *Call_fields[]={ | |
| 203 | + "func", | |
| 204 | + "args", | |
| 205 | + "keywords", | |
| 206 | + "starargs", | |
| 207 | + "kwargs", | |
| 208 | +}; | |
| 209 | +static PyTypeObject *Repr_type; | |
| 210 | +static char *Repr_fields[]={ | |
| 211 | + "value", | |
| 212 | +}; | |
| 213 | +static PyTypeObject *Num_type; | |
| 214 | +static char *Num_fields[]={ | |
| 215 | + "n", | |
| 216 | +}; | |
| 217 | +static PyTypeObject *Str_type; | |
| 218 | +static char *Str_fields[]={ | |
| 219 | + "s", | |
| 220 | +}; | |
| 221 | +static PyTypeObject *Attribute_type; | |
| 222 | +static char *Attribute_fields[]={ | |
| 223 | + "value", | |
| 224 | + "attr", | |
| 225 | + "ctx", | |
| 226 | +}; | |
| 227 | +static PyTypeObject *Subscript_type; | |
| 228 | +static char *Subscript_fields[]={ | |
| 229 | + "value", | |
| 230 | + "slice", | |
| 231 | + "ctx", | |
| 232 | +}; | |
| 233 | +static PyTypeObject *Name_type; | |
| 234 | +static char *Name_fields[]={ | |
| 235 | + "id", | |
| 236 | + "ctx", | |
| 237 | +}; | |
| 238 | +static PyTypeObject *List_type; | |
| 239 | +static char *List_fields[]={ | |
| 240 | + "elts", | |
| 241 | + "ctx", | |
| 242 | +}; | |
| 243 | +static PyTypeObject *Tuple_type; | |
| 244 | +static char *Tuple_fields[]={ | |
| 245 | + "elts", | |
| 246 | + "ctx", | |
| 247 | +}; | |
| 248 | +static PyTypeObject *expr_context_type; | |
| 249 | +static PyObject *Load_singleton, *Store_singleton, *Del_singleton, | |
| 250 | +*AugLoad_singleton, *AugStore_singleton, *Param_singleton; | |
| 251 | +static PyObject* ast2obj_expr_context(expr_context_ty); | |
| 252 | +static PyTypeObject *Load_type; | |
| 253 | +static PyTypeObject *Store_type; | |
| 254 | +static PyTypeObject *Del_type; | |
| 255 | +static PyTypeObject *AugLoad_type; | |
| 256 | +static PyTypeObject *AugStore_type; | |
| 257 | +static PyTypeObject *Param_type; | |
| 258 | +static PyTypeObject *slice_type; | |
| 259 | +static PyObject* ast2obj_slice(void*); | |
| 260 | +static PyTypeObject *Ellipsis_type; | |
| 261 | +static PyTypeObject *Slice_type; | |
| 262 | +static char *Slice_fields[]={ | |
| 263 | + "lower", | |
| 264 | + "upper", | |
| 265 | + "step", | |
| 266 | +}; | |
| 267 | +static PyTypeObject *ExtSlice_type; | |
| 268 | +static char *ExtSlice_fields[]={ | |
| 269 | + "dims", | |
| 270 | +}; | |
| 271 | +static PyTypeObject *Index_type; | |
| 272 | +static char *Index_fields[]={ | |
| 273 | + "value", | |
| 274 | +}; | |
| 275 | +static PyTypeObject *boolop_type; | |
| 276 | +static PyObject *And_singleton, *Or_singleton; | |
| 277 | +static PyObject* ast2obj_boolop(boolop_ty); | |
| 278 | +static PyTypeObject *And_type; | |
| 279 | +static PyTypeObject *Or_type; | |
| 280 | +static PyTypeObject *operator_type; | |
| 281 | +static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, | |
| 282 | +*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, | |
| 283 | +*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, | |
| 284 | +*FloorDiv_singleton; | |
| 285 | +static PyObject* ast2obj_operator(operator_ty); | |
| 286 | +static PyTypeObject *Add_type; | |
| 287 | +static PyTypeObject *Sub_type; | |
| 288 | +static PyTypeObject *Mult_type; | |
| 289 | +static PyTypeObject *Div_type; | |
| 290 | +static PyTypeObject *Mod_type; | |
| 291 | +static PyTypeObject *Pow_type; | |
| 292 | +static PyTypeObject *LShift_type; | |
| 293 | +static PyTypeObject *RShift_type; | |
| 294 | +static PyTypeObject *BitOr_type; | |
| 295 | +static PyTypeObject *BitXor_type; | |
| 296 | +static PyTypeObject *BitAnd_type; | |
| 297 | +static PyTypeObject *FloorDiv_type; | |
| 298 | +static PyTypeObject *unaryop_type; | |
| 299 | +static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, | |
| 300 | +*USub_singleton; | |
| 301 | +static PyObject* ast2obj_unaryop(unaryop_ty); | |
| 302 | +static PyTypeObject *Invert_type; | |
| 303 | +static PyTypeObject *Not_type; | |
| 304 | +static PyTypeObject *UAdd_type; | |
| 305 | +static PyTypeObject *USub_type; | |
| 306 | +static PyTypeObject *cmpop_type; | |
| 307 | +static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, | |
| 308 | +*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, | |
| 309 | +*NotIn_singleton; | |
| 310 | +static PyObject* ast2obj_cmpop(cmpop_ty); | |
| 311 | +static PyTypeObject *Eq_type; | |
| 312 | +static PyTypeObject *NotEq_type; | |
| 313 | +static PyTypeObject *Lt_type; | |
| 314 | +static PyTypeObject *LtE_type; | |
| 315 | +static PyTypeObject *Gt_type; | |
| 316 | +static PyTypeObject *GtE_type; | |
| 317 | +static PyTypeObject *Is_type; | |
| 318 | +static PyTypeObject *IsNot_type; | |
| 319 | +static PyTypeObject *In_type; | |
| 320 | +static PyTypeObject *NotIn_type; | |
| 321 | +static PyTypeObject *comprehension_type; | |
| 322 | +static PyObject* ast2obj_comprehension(void*); | |
| 323 | +static char *comprehension_fields[]={ | |
| 324 | + "target", | |
| 325 | + "iter", | |
| 326 | + "ifs", | |
| 327 | +}; | |
| 328 | +static PyTypeObject *excepthandler_type; | |
| 329 | +static PyObject* ast2obj_excepthandler(void*); | |
| 330 | +static char *excepthandler_fields[]={ | |
| 331 | + "type", | |
| 332 | + "name", | |
| 333 | + "body", | |
| 334 | + "lineno", | |
| 335 | + "col_offset", | |
| 336 | +}; | |
| 337 | +static PyTypeObject *arguments_type; | |
| 338 | +static PyObject* ast2obj_arguments(void*); | |
| 339 | +static char *arguments_fields[]={ | |
| 340 | + "args", | |
| 341 | + "vararg", | |
| 342 | + "kwarg", | |
| 343 | + "defaults", | |
| 344 | +}; | |
| 345 | +static PyTypeObject *keyword_type; | |
| 346 | +static PyObject* ast2obj_keyword(void*); | |
| 347 | +static char *keyword_fields[]={ | |
| 348 | + "arg", | |
| 349 | + "value", | |
| 350 | +}; | |
| 351 | +static PyTypeObject *alias_type; | |
| 352 | +static PyObject* ast2obj_alias(void*); | |
| 353 | +static char *alias_fields[]={ | |
| 354 | + "name", | |
| 355 | + "asname", | |
| 356 | +}; | |
| 357 | + | |
| 358 | + | |
| 359 | +static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) | |
| 360 | +{ | |
| 361 | + PyObject *fnames, *result; | |
| 362 | + int i; | |
| 363 | + if (num_fields) { | |
| 364 | + fnames = PyTuple_New(num_fields); | |
| 365 | + if (!fnames) return NULL; | |
| 366 | + } else { | |
| 367 | + fnames = Py_None; | |
| 368 | + Py_INCREF(Py_None); | |
| 369 | + } | |
| 370 | + for(i=0; i < num_fields; i++) { | |
| 371 | + PyObject *field = PyString_FromString(fields[i]); | |
| 372 | + if (!field) { | |
| 373 | + Py_DECREF(fnames); | |
| 374 | + return NULL; | |
| 375 | + } | |
| 376 | + PyTuple_SET_ITEM(fnames, i, field); | |
| 377 | + } | |
| 378 | + result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", | |
| 379 | + type, base, "_fields", fnames, "__module__", "_ast"); | |
| 380 | + Py_DECREF(fnames); | |
| 381 | + return (PyTypeObject*)result; | |
| 382 | +} | |
| 383 | + | |
| 384 | +static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) | |
| 385 | +{ | |
| 386 | + int i, result; | |
| 387 | + PyObject *s, *l = PyList_New(num_fields); | |
| 388 | + if (!l) return 0; | |
| 389 | + for(i = 0; i < num_fields; i++) { | |
| 390 | + s = PyString_FromString(attrs[i]); | |
| 391 | + if (!s) { | |
| 392 | + Py_DECREF(l); | |
| 393 | + return 0; | |
| 394 | + } | |
| 395 | + PyList_SET_ITEM(l, i, s); | |
| 396 | + } | |
| 397 | + result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; | |
| 398 | + Py_DECREF(l); | |
| 399 | + return result; | |
| 400 | +} | |
| 401 | + | |
| 402 | +static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) | |
| 403 | +{ | |
| 404 | + int i, n = asdl_seq_LEN(seq); | |
| 405 | + PyObject *result = PyList_New(n); | |
| 406 | + PyObject *value; | |
| 407 | + if (!result) | |
| 408 | + return NULL; | |
| 409 | + for (i = 0; i < n; i++) { | |
| 410 | + value = func(asdl_seq_GET(seq, i)); | |
| 411 | + if (!value) { | |
| 412 | + Py_DECREF(result); | |
| 413 | + return NULL; | |
| 414 | + } | |
| 415 | + PyList_SET_ITEM(result, i, value); | |
| 416 | + } | |
| 417 | + return result; | |
| 418 | +} | |
| 419 | + | |
| 420 | +static PyObject* ast2obj_object(void *o) | |
| 421 | +{ | |
| 422 | + if (!o) | |
| 423 | + o = Py_None; | |
| 424 | + Py_INCREF((PyObject*)o); | |
| 425 | + return (PyObject*)o; | |
| 426 | +} | |
| 427 | +#define ast2obj_identifier ast2obj_object | |
| 428 | +#define ast2obj_string ast2obj_object | |
| 429 | +static PyObject* ast2obj_bool(bool b) | |
| 430 | +{ | |
| 431 | + return PyBool_FromLong(b); | |
| 432 | +} | |
| 433 | + | |
| 434 | +static PyObject* ast2obj_int(bool b) | |
| 435 | +{ | |
| 436 | + return PyInt_FromLong(b); | |
| 437 | +} | |
| 438 | + | |
| 439 | +static int init_types(void) | |
| 440 | +{ | |
| 441 | + static int initialized; | |
| 442 | + if (initialized) return 1; | |
| 443 | + AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0); | |
| 444 | + mod_type = make_type("mod", AST_type, NULL, 0); | |
| 445 | + if (!mod_type) return 0; | |
| 446 | + if (!add_attributes(mod_type, NULL, 0)) return 0; | |
| 447 | + Module_type = make_type("Module", mod_type, Module_fields, 1); | |
| 448 | + if (!Module_type) return 0; | |
| 449 | + Interactive_type = make_type("Interactive", mod_type, | |
| 450 | + Interactive_fields, 1); | |
| 451 | + if (!Interactive_type) return 0; | |
| 452 | + Expression_type = make_type("Expression", mod_type, Expression_fields, | |
| 453 | + 1); | |
| 454 | + if (!Expression_type) return 0; | |
| 455 | + Suite_type = make_type("Suite", mod_type, Suite_fields, 1); | |
| 456 | + if (!Suite_type) return 0; | |
| 457 | + stmt_type = make_type("stmt", AST_type, NULL, 0); | |
| 458 | + if (!stmt_type) return 0; | |
| 459 | + if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; | |
| 460 | + FunctionDef_type = make_type("FunctionDef", stmt_type, | |
| 461 | + FunctionDef_fields, 4); | |
| 462 | + if (!FunctionDef_type) return 0; | |
| 463 | + ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3); | |
| 464 | + if (!ClassDef_type) return 0; | |
| 465 | + Return_type = make_type("Return", stmt_type, Return_fields, 1); | |
| 466 | + if (!Return_type) return 0; | |
| 467 | + Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); | |
| 468 | + if (!Delete_type) return 0; | |
| 469 | + Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); | |
| 470 | + if (!Assign_type) return 0; | |
| 471 | + AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); | |
| 472 | + if (!AugAssign_type) return 0; | |
| 473 | + Print_type = make_type("Print", stmt_type, Print_fields, 3); | |
| 474 | + if (!Print_type) return 0; | |
| 475 | + For_type = make_type("For", stmt_type, For_fields, 4); | |
| 476 | + if (!For_type) return 0; | |
| 477 | + While_type = make_type("While", stmt_type, While_fields, 3); | |
| 478 | + if (!While_type) return 0; | |
| 479 | + If_type = make_type("If", stmt_type, If_fields, 3); | |
| 480 | + if (!If_type) return 0; | |
| 481 | + With_type = make_type("With", stmt_type, With_fields, 3); | |
| 482 | + if (!With_type) return 0; | |
| 483 | + Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); | |
| 484 | + if (!Raise_type) return 0; | |
| 485 | + TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); | |
| 486 | + if (!TryExcept_type) return 0; | |
| 487 | + TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, | |
| 488 | + 2); | |
| 489 | + if (!TryFinally_type) return 0; | |
| 490 | + Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); | |
| 491 | + if (!Assert_type) return 0; | |
| 492 | + Import_type = make_type("Import", stmt_type, Import_fields, 1); | |
| 493 | + if (!Import_type) return 0; | |
| 494 | + ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, | |
| 495 | + 3); | |
| 496 | + if (!ImportFrom_type) return 0; | |
| 497 | + Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); | |
| 498 | + if (!Exec_type) return 0; | |
| 499 | + Global_type = make_type("Global", stmt_type, Global_fields, 1); | |
| 500 | + if (!Global_type) return 0; | |
| 501 | + Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); | |
| 502 | + if (!Expr_type) return 0; | |
| 503 | + Pass_type = make_type("Pass", stmt_type, NULL, 0); | |
| 504 | + if (!Pass_type) return 0; | |
| 505 | + Break_type = make_type("Break", stmt_type, NULL, 0); | |
| 506 | + if (!Break_type) return 0; | |
| 507 | + Continue_type = make_type("Continue", stmt_type, NULL, 0); | |
| 508 | + if (!Continue_type) return 0; | |
| 509 | + expr_type = make_type("expr", AST_type, NULL, 0); | |
| 510 | + if (!expr_type) return 0; | |
| 511 | + if (!add_attributes(expr_type, expr_attributes, 2)) return 0; | |
| 512 | + BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); | |
| 513 | + if (!BoolOp_type) return 0; | |
| 514 | + BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); | |
| 515 | + if (!BinOp_type) return 0; | |
| 516 | + UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); | |
| 517 | + if (!UnaryOp_type) return 0; | |
| 518 | + Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); | |
| 519 | + if (!Lambda_type) return 0; | |
| 520 | + IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); | |
| 521 | + if (!IfExp_type) return 0; | |
| 522 | + Dict_type = make_type("Dict", expr_type, Dict_fields, 2); | |
| 523 | + if (!Dict_type) return 0; | |
| 524 | + ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); | |
| 525 | + if (!ListComp_type) return 0; | |
| 526 | + GeneratorExp_type = make_type("GeneratorExp", expr_type, | |
| 527 | + GeneratorExp_fields, 2); | |
| 528 | + if (!GeneratorExp_type) return 0; | |
| 529 | + Yield_type = make_type("Yield", expr_type, Yield_fields, 1); | |
| 530 | + if (!Yield_type) return 0; | |
| 531 | + Compare_type = make_type("Compare", expr_type, Compare_fields, 3); | |
| 532 | + if (!Compare_type) return 0; | |
| 533 | + Call_type = make_type("Call", expr_type, Call_fields, 5); | |
| 534 | + if (!Call_type) return 0; | |
| 535 | + Repr_type = make_type("Repr", expr_type, Repr_fields, 1); | |
| 536 | + if (!Repr_type) return 0; | |
| 537 | + Num_type = make_type("Num", expr_type, Num_fields, 1); | |
| 538 | + if (!Num_type) return 0; | |
| 539 | + Str_type = make_type("Str", expr_type, Str_fields, 1); | |
| 540 | + if (!Str_type) return 0; | |
| 541 | + Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); | |
| 542 | + if (!Attribute_type) return 0; | |
| 543 | + Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); | |
| 544 | + if (!Subscript_type) return 0; | |
| 545 | + Name_type = make_type("Name", expr_type, Name_fields, 2); | |
| 546 | + if (!Name_type) return 0; | |
| 547 | + List_type = make_type("List", expr_type, List_fields, 2); | |
| 548 | + if (!List_type) return 0; | |
| 549 | + Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); | |
| 550 | + if (!Tuple_type) return 0; | |
| 551 | + expr_context_type = make_type("expr_context", AST_type, NULL, 0); | |
| 552 | + if (!expr_context_type) return 0; | |
| 553 | + if (!add_attributes(expr_context_type, NULL, 0)) return 0; | |
| 554 | + Load_type = make_type("Load", expr_context_type, NULL, 0); | |
| 555 | + if (!Load_type) return 0; | |
| 556 | + Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); | |
| 557 | + if (!Load_singleton) return 0; | |
| 558 | + Store_type = make_type("Store", expr_context_type, NULL, 0); | |
| 559 | + if (!Store_type) return 0; | |
| 560 | + Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); | |
| 561 | + if (!Store_singleton) return 0; | |
| 562 | + Del_type = make_type("Del", expr_context_type, NULL, 0); | |
| 563 | + if (!Del_type) return 0; | |
| 564 | + Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); | |
| 565 | + if (!Del_singleton) return 0; | |
| 566 | + AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); | |
| 567 | + if (!AugLoad_type) return 0; | |
| 568 | + AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); | |
| 569 | + if (!AugLoad_singleton) return 0; | |
| 570 | + AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); | |
| 571 | + if (!AugStore_type) return 0; | |
| 572 | + AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); | |
| 573 | + if (!AugStore_singleton) return 0; | |
| 574 | + Param_type = make_type("Param", expr_context_type, NULL, 0); | |
| 575 | + if (!Param_type) return 0; | |
| 576 | + Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); | |
| 577 | + if (!Param_singleton) return 0; | |
| 578 | + slice_type = make_type("slice", AST_type, NULL, 0); | |
| 579 | + if (!slice_type) return 0; | |
| 580 | + if (!add_attributes(slice_type, NULL, 0)) return 0; | |
| 581 | + Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); | |
| 582 | + if (!Ellipsis_type) return 0; | |
| 583 | + Slice_type = make_type("Slice", slice_type, Slice_fields, 3); | |
| 584 | + if (!Slice_type) return 0; | |
| 585 | + ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); | |
| 586 | + if (!ExtSlice_type) return 0; | |
| 587 | + Index_type = make_type("Index", slice_type, Index_fields, 1); | |
| 588 | + if (!Index_type) return 0; | |
| 589 | + boolop_type = make_type("boolop", AST_type, NULL, 0); | |
| 590 | + if (!boolop_type) return 0; | |
| 591 | + if (!add_attributes(boolop_type, NULL, 0)) return 0; | |
| 592 | + And_type = make_type("And", boolop_type, NULL, 0); | |
| 593 | + if (!And_type) return 0; | |
| 594 | + And_singleton = PyType_GenericNew(And_type, NULL, NULL); | |
| 595 | + if (!And_singleton) return 0; | |
| 596 | + Or_type = make_type("Or", boolop_type, NULL, 0); | |
| 597 | + if (!Or_type) return 0; | |
| 598 | + Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); | |
| 599 | + if (!Or_singleton) return 0; | |
| 600 | + operator_type = make_type("operator", AST_type, NULL, 0); | |
| 601 | + if (!operator_type) return 0; | |
| 602 | + if (!add_attributes(operator_type, NULL, 0)) return 0; | |
| 603 | + Add_type = make_type("Add", operator_type, NULL, 0); | |
| 604 | + if (!Add_type) return 0; | |
| 605 | + Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); | |
| 606 | + if (!Add_singleton) return 0; | |
| 607 | + Sub_type = make_type("Sub", operator_type, NULL, 0); | |
| 608 | + if (!Sub_type) return 0; | |
| 609 | + Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); | |
| 610 | + if (!Sub_singleton) return 0; | |
| 611 | + Mult_type = make_type("Mult", operator_type, NULL, 0); | |
| 612 | + if (!Mult_type) return 0; | |
| 613 | + Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); | |
| 614 | + if (!Mult_singleton) return 0; | |
| 615 | + Div_type = make_type("Div", operator_type, NULL, 0); | |
| 616 | + if (!Div_type) return 0; | |
| 617 | + Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); | |
| 618 | + if (!Div_singleton) return 0; | |
| 619 | + Mod_type = make_type("Mod", operator_type, NULL, 0); | |
| 620 | + if (!Mod_type) return 0; | |
| 621 | + Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); | |
| 622 | + if (!Mod_singleton) return 0; | |
| 623 | + Pow_type = make_type("Pow", operator_type, NULL, 0); | |
| 624 | + if (!Pow_type) return 0; | |
| 625 | + Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); | |
| 626 | + if (!Pow_singleton) return 0; | |
| 627 | + LShift_type = make_type("LShift", operator_type, NULL, 0); | |
| 628 | + if (!LShift_type) return 0; | |
| 629 | + LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); | |
| 630 | + if (!LShift_singleton) return 0; | |
| 631 | + RShift_type = make_type("RShift", operator_type, NULL, 0); | |
| 632 | + if (!RShift_type) return 0; | |
| 633 | + RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); | |
| 634 | + if (!RShift_singleton) return 0; | |
| 635 | + BitOr_type = make_type("BitOr", operator_type, NULL, 0); | |
| 636 | + if (!BitOr_type) return 0; | |
| 637 | + BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); | |
| 638 | + if (!BitOr_singleton) return 0; | |
| 639 | + BitXor_type = make_type("BitXor", operator_type, NULL, 0); | |
| 640 | + if (!BitXor_type) return 0; | |
| 641 | + BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); | |
| 642 | + if (!BitXor_singleton) return 0; | |
| 643 | + BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); | |
| 644 | + if (!BitAnd_type) return 0; | |
| 645 | + BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); | |
| 646 | + if (!BitAnd_singleton) return 0; | |
| 647 | + FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); | |
| 648 | + if (!FloorDiv_type) return 0; | |
| 649 | + FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); | |
| 650 | + if (!FloorDiv_singleton) return 0; | |
| 651 | + unaryop_type = make_type("unaryop", AST_type, NULL, 0); | |
| 652 | + if (!unaryop_type) return 0; | |
| 653 | + if (!add_attributes(unaryop_type, NULL, 0)) return 0; | |
| 654 | + Invert_type = make_type("Invert", unaryop_type, NULL, 0); | |
| 655 | + if (!Invert_type) return 0; | |
| 656 | + Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); | |
| 657 | + if (!Invert_singleton) return 0; | |
| 658 | + Not_type = make_type("Not", unaryop_type, NULL, 0); | |
| 659 | + if (!Not_type) return 0; | |
| 660 | + Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); | |
| 661 | + if (!Not_singleton) return 0; | |
| 662 | + UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); | |
| 663 | + if (!UAdd_type) return 0; | |
| 664 | + UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); | |
| 665 | + if (!UAdd_singleton) return 0; | |
| 666 | + USub_type = make_type("USub", unaryop_type, NULL, 0); | |
| 667 | + if (!USub_type) return 0; | |
| 668 | + USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); | |
| 669 | + if (!USub_singleton) return 0; | |
| 670 | + cmpop_type = make_type("cmpop", AST_type, NULL, 0); | |
| 671 | + if (!cmpop_type) return 0; | |
| 672 | + if (!add_attributes(cmpop_type, NULL, 0)) return 0; | |
| 673 | + Eq_type = make_type("Eq", cmpop_type, NULL, 0); | |
| 674 | + if (!Eq_type) return 0; | |
| 675 | + Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); | |
| 676 | + if (!Eq_singleton) return 0; | |
| 677 | + NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); | |
| 678 | + if (!NotEq_type) return 0; | |
| 679 | + NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); | |
| 680 | + if (!NotEq_singleton) return 0; | |
| 681 | + Lt_type = make_type("Lt", cmpop_type, NULL, 0); | |
| 682 | + if (!Lt_type) return 0; | |
| 683 | + Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); | |
| 684 | + if (!Lt_singleton) return 0; | |
| 685 | + LtE_type = make_type("LtE", cmpop_type, NULL, 0); | |
| 686 | + if (!LtE_type) return 0; | |
| 687 | + LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); | |
| 688 | + if (!LtE_singleton) return 0; | |
| 689 | + Gt_type = make_type("Gt", cmpop_type, NULL, 0); | |
| 690 | + if (!Gt_type) return 0; | |
| 691 | + Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); | |
| 692 | + if (!Gt_singleton) return 0; | |
| 693 | + GtE_type = make_type("GtE", cmpop_type, NULL, 0); | |
| 694 | + if (!GtE_type) return 0; | |
| 695 | + GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); | |
| 696 | + if (!GtE_singleton) return 0; | |
| 697 | + Is_type = make_type("Is", cmpop_type, NULL, 0); | |
| 698 | + if (!Is_type) return 0; | |
| 699 | + Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); | |
| 700 | + if (!Is_singleton) return 0; | |
| 701 | + IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); | |
| 702 | + if (!IsNot_type) return 0; | |
| 703 | + IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); | |
| 704 | + if (!IsNot_singleton) return 0; | |
| 705 | + In_type = make_type("In", cmpop_type, NULL, 0); | |
| 706 | + if (!In_type) return 0; | |
| 707 | + In_singleton = PyType_GenericNew(In_type, NULL, NULL); | |
| 708 | + if (!In_singleton) return 0; | |
| 709 | + NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); | |
| 710 | + if (!NotIn_type) return 0; | |
| 711 | + NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); | |
| 712 | + if (!NotIn_singleton) return 0; | |
| 713 | + comprehension_type = make_type("comprehension", AST_type, | |
| 714 | + comprehension_fields, 3); | |
| 715 | + if (!comprehension_type) return 0; | |
| 716 | + excepthandler_type = make_type("excepthandler", AST_type, | |
| 717 | + excepthandler_fields, 5); | |
| 718 | + if (!excepthandler_type) return 0; | |
| 719 | + arguments_type = make_type("arguments", AST_type, arguments_fields, 4); | |
| 720 | + if (!arguments_type) return 0; | |
| 721 | + keyword_type = make_type("keyword", AST_type, keyword_fields, 2); | |
| 722 | + if (!keyword_type) return 0; | |
| 723 | + alias_type = make_type("alias", AST_type, alias_fields, 2); | |
| 724 | + if (!alias_type) return 0; | |
| 725 | + initialized = 1; | |
| 726 | + return 1; | |
| 727 | +} | |
| 728 | + | |
| 729 | +mod_ty | |
| 730 | +Module(asdl_seq * body, PyArena *arena) | |
| 731 | +{ | |
| 732 | + mod_ty p; | |
| 733 | + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 734 | + if (!p) { | |
| 735 | + PyErr_NoMemory(); | |
| 736 | + return NULL; | |
| 737 | + } | |
| 738 | + p->kind = Module_kind; | |
| 739 | + p->v.Module.body = body; | |
| 740 | + return p; | |
| 741 | +} | |
| 742 | + | |
| 743 | +mod_ty | |
| 744 | +Interactive(asdl_seq * body, PyArena *arena) | |
| 745 | +{ | |
| 746 | + mod_ty p; | |
| 747 | + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 748 | + if (!p) { | |
| 749 | + PyErr_NoMemory(); | |
| 750 | + return NULL; | |
| 751 | + } | |
| 752 | + p->kind = Interactive_kind; | |
| 753 | + p->v.Interactive.body = body; | |
| 754 | + return p; | |
| 755 | +} | |
| 756 | + | |
| 757 | +mod_ty | |
| 758 | +Expression(expr_ty body, PyArena *arena) | |
| 759 | +{ | |
| 760 | + mod_ty p; | |
| 761 | + if (!body) { | |
| 762 | + PyErr_SetString(PyExc_ValueError, | |
| 763 | + "field body is required for Expression"); | |
| 764 | + return NULL; | |
| 765 | + } | |
| 766 | + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 767 | + if (!p) { | |
| 768 | + PyErr_NoMemory(); | |
| 769 | + return NULL; | |
| 770 | + } | |
| 771 | + p->kind = Expression_kind; | |
| 772 | + p->v.Expression.body = body; | |
| 773 | + return p; | |
| 774 | +} | |
| 775 | + | |
| 776 | +mod_ty | |
| 777 | +Suite(asdl_seq * body, PyArena *arena) | |
| 778 | +{ | |
| 779 | + mod_ty p; | |
| 780 | + p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 781 | + if (!p) { | |
| 782 | + PyErr_NoMemory(); | |
| 783 | + return NULL; | |
| 784 | + } | |
| 785 | + p->kind = Suite_kind; | |
| 786 | + p->v.Suite.body = body; | |
| 787 | + return p; | |
| 788 | +} | |
| 789 | + | |
| 790 | +stmt_ty | |
| 791 | +FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * | |
| 792 | + decorators, int lineno, int col_offset, PyArena *arena) | |
| 793 | +{ | |
| 794 | + stmt_ty p; | |
| 795 | + if (!name) { | |
| 796 | + PyErr_SetString(PyExc_ValueError, | |
| 797 | + "field name is required for FunctionDef"); | |
| 798 | + return NULL; | |
| 799 | + } | |
| 800 | + if (!args) { | |
| 801 | + PyErr_SetString(PyExc_ValueError, | |
| 802 | + "field args is required for FunctionDef"); | |
| 803 | + return NULL; | |
| 804 | + } | |
| 805 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 806 | + if (!p) { | |
| 807 | + PyErr_NoMemory(); | |
| 808 | + return NULL; | |
| 809 | + } | |
| 810 | + p->kind = FunctionDef_kind; | |
| 811 | + p->v.FunctionDef.name = name; | |
| 812 | + p->v.FunctionDef.args = args; | |
| 813 | + p->v.FunctionDef.body = body; | |
| 814 | + p->v.FunctionDef.decorators = decorators; | |
| 815 | + p->lineno = lineno; | |
| 816 | + p->col_offset = col_offset; | |
| 817 | + return p; | |
| 818 | +} | |
| 819 | + | |
| 820 | +stmt_ty | |
| 821 | +ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int | |
| 822 | + col_offset, PyArena *arena) | |
| 823 | +{ | |
| 824 | + stmt_ty p; | |
| 825 | + if (!name) { | |
| 826 | + PyErr_SetString(PyExc_ValueError, | |
| 827 | + "field name is required for ClassDef"); | |
| 828 | + return NULL; | |
| 829 | + } | |
| 830 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 831 | + if (!p) { | |
| 832 | + PyErr_NoMemory(); | |
| 833 | + return NULL; | |
| 834 | + } | |
| 835 | + p->kind = ClassDef_kind; | |
| 836 | + p->v.ClassDef.name = name; | |
| 837 | + p->v.ClassDef.bases = bases; | |
| 838 | + p->v.ClassDef.body = body; | |
| 839 | + p->lineno = lineno; | |
| 840 | + p->col_offset = col_offset; | |
| 841 | + return p; | |
| 842 | +} | |
| 843 | + | |
| 844 | +stmt_ty | |
| 845 | +Return(expr_ty value, int lineno, int col_offset, PyArena *arena) | |
| 846 | +{ | |
| 847 | + stmt_ty p; | |
| 848 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 849 | + if (!p) { | |
| 850 | + PyErr_NoMemory(); | |
| 851 | + return NULL; | |
| 852 | + } | |
| 853 | + p->kind = Return_kind; | |
| 854 | + p->v.Return.value = value; | |
| 855 | + p->lineno = lineno; | |
| 856 | + p->col_offset = col_offset; | |
| 857 | + return p; | |
| 858 | +} | |
| 859 | + | |
| 860 | +stmt_ty | |
| 861 | +Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) | |
| 862 | +{ | |
| 863 | + stmt_ty p; | |
| 864 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 865 | + if (!p) { | |
| 866 | + PyErr_NoMemory(); | |
| 867 | + return NULL; | |
| 868 | + } | |
| 869 | + p->kind = Delete_kind; | |
| 870 | + p->v.Delete.targets = targets; | |
| 871 | + p->lineno = lineno; | |
| 872 | + p->col_offset = col_offset; | |
| 873 | + return p; | |
| 874 | +} | |
| 875 | + | |
| 876 | +stmt_ty | |
| 877 | +Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena | |
| 878 | + *arena) | |
| 879 | +{ | |
| 880 | + stmt_ty p; | |
| 881 | + if (!value) { | |
| 882 | + PyErr_SetString(PyExc_ValueError, | |
| 883 | + "field value is required for Assign"); | |
| 884 | + return NULL; | |
| 885 | + } | |
| 886 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 887 | + if (!p) { | |
| 888 | + PyErr_NoMemory(); | |
| 889 | + return NULL; | |
| 890 | + } | |
| 891 | + p->kind = Assign_kind; | |
| 892 | + p->v.Assign.targets = targets; | |
| 893 | + p->v.Assign.value = value; | |
| 894 | + p->lineno = lineno; | |
| 895 | + p->col_offset = col_offset; | |
| 896 | + return p; | |
| 897 | +} | |
| 898 | + | |
| 899 | +stmt_ty | |
| 900 | +AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int | |
| 901 | + col_offset, PyArena *arena) | |
| 902 | +{ | |
| 903 | + stmt_ty p; | |
| 904 | + if (!target) { | |
| 905 | + PyErr_SetString(PyExc_ValueError, | |
| 906 | + "field target is required for AugAssign"); | |
| 907 | + return NULL; | |
| 908 | + } | |
| 909 | + if (!op) { | |
| 910 | + PyErr_SetString(PyExc_ValueError, | |
| 911 | + "field op is required for AugAssign"); | |
| 912 | + return NULL; | |
| 913 | + } | |
| 914 | + if (!value) { | |
| 915 | + PyErr_SetString(PyExc_ValueError, | |
| 916 | + "field value is required for AugAssign"); | |
| 917 | + return NULL; | |
| 918 | + } | |
| 919 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 920 | + if (!p) { | |
| 921 | + PyErr_NoMemory(); | |
| 922 | + return NULL; | |
| 923 | + } | |
| 924 | + p->kind = AugAssign_kind; | |
| 925 | + p->v.AugAssign.target = target; | |
| 926 | + p->v.AugAssign.op = op; | |
| 927 | + p->v.AugAssign.value = value; | |
| 928 | + p->lineno = lineno; | |
| 929 | + p->col_offset = col_offset; | |
| 930 | + return p; | |
| 931 | +} | |
| 932 | + | |
| 933 | +stmt_ty | |
| 934 | +Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, | |
| 935 | + PyArena *arena) | |
| 936 | +{ | |
| 937 | + stmt_ty p; | |
| 938 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 939 | + if (!p) { | |
| 940 | + PyErr_NoMemory(); | |
| 941 | + return NULL; | |
| 942 | + } | |
| 943 | + p->kind = Print_kind; | |
| 944 | + p->v.Print.dest = dest; | |
| 945 | + p->v.Print.values = values; | |
| 946 | + p->v.Print.nl = nl; | |
| 947 | + p->lineno = lineno; | |
| 948 | + p->col_offset = col_offset; | |
| 949 | + return p; | |
| 950 | +} | |
| 951 | + | |
| 952 | +stmt_ty | |
| 953 | +For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int | |
| 954 | + lineno, int col_offset, PyArena *arena) | |
| 955 | +{ | |
| 956 | + stmt_ty p; | |
| 957 | + if (!target) { | |
| 958 | + PyErr_SetString(PyExc_ValueError, | |
| 959 | + "field target is required for For"); | |
| 960 | + return NULL; | |
| 961 | + } | |
| 962 | + if (!iter) { | |
| 963 | + PyErr_SetString(PyExc_ValueError, | |
| 964 | + "field iter is required for For"); | |
| 965 | + return NULL; | |
| 966 | + } | |
| 967 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 968 | + if (!p) { | |
| 969 | + PyErr_NoMemory(); | |
| 970 | + return NULL; | |
| 971 | + } | |
| 972 | + p->kind = For_kind; | |
| 973 | + p->v.For.target = target; | |
| 974 | + p->v.For.iter = iter; | |
| 975 | + p->v.For.body = body; | |
| 976 | + p->v.For.orelse = orelse; | |
| 977 | + p->lineno = lineno; | |
| 978 | + p->col_offset = col_offset; | |
| 979 | + return p; | |
| 980 | +} | |
| 981 | + | |
| 982 | +stmt_ty | |
| 983 | +While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int | |
| 984 | + col_offset, PyArena *arena) | |
| 985 | +{ | |
| 986 | + stmt_ty p; | |
| 987 | + if (!test) { | |
| 988 | + PyErr_SetString(PyExc_ValueError, | |
| 989 | + "field test is required for While"); | |
| 990 | + return NULL; | |
| 991 | + } | |
| 992 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 993 | + if (!p) { | |
| 994 | + PyErr_NoMemory(); | |
| 995 | + return NULL; | |
| 996 | + } | |
| 997 | + p->kind = While_kind; | |
| 998 | + p->v.While.test = test; | |
| 999 | + p->v.While.body = body; | |
| 1000 | + p->v.While.orelse = orelse; | |
| 1001 | + p->lineno = lineno; | |
| 1002 | + p->col_offset = col_offset; | |
| 1003 | + return p; | |
| 1004 | +} | |
| 1005 | + | |
| 1006 | +stmt_ty | |
| 1007 | +If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int | |
| 1008 | + col_offset, PyArena *arena) | |
| 1009 | +{ | |
| 1010 | + stmt_ty p; | |
| 1011 | + if (!test) { | |
| 1012 | + PyErr_SetString(PyExc_ValueError, | |
| 1013 | + "field test is required for If"); | |
| 1014 | + return NULL; | |
| 1015 | + } | |
| 1016 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1017 | + if (!p) { | |
| 1018 | + PyErr_NoMemory(); | |
| 1019 | + return NULL; | |
| 1020 | + } | |
| 1021 | + p->kind = If_kind; | |
| 1022 | + p->v.If.test = test; | |
| 1023 | + p->v.If.body = body; | |
| 1024 | + p->v.If.orelse = orelse; | |
| 1025 | + p->lineno = lineno; | |
| 1026 | + p->col_offset = col_offset; | |
| 1027 | + return p; | |
| 1028 | +} | |
| 1029 | + | |
| 1030 | +stmt_ty | |
| 1031 | +With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno, | |
| 1032 | + int col_offset, PyArena *arena) | |
| 1033 | +{ | |
| 1034 | + stmt_ty p; | |
| 1035 | + if (!context_expr) { | |
| 1036 | + PyErr_SetString(PyExc_ValueError, | |
| 1037 | + "field context_expr is required for With"); | |
| 1038 | + return NULL; | |
| 1039 | + } | |
| 1040 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1041 | + if (!p) { | |
| 1042 | + PyErr_NoMemory(); | |
| 1043 | + return NULL; | |
| 1044 | + } | |
| 1045 | + p->kind = With_kind; | |
| 1046 | + p->v.With.context_expr = context_expr; | |
| 1047 | + p->v.With.optional_vars = optional_vars; | |
| 1048 | + p->v.With.body = body; | |
| 1049 | + p->lineno = lineno; | |
| 1050 | + p->col_offset = col_offset; | |
| 1051 | + return p; | |
| 1052 | +} | |
| 1053 | + | |
| 1054 | +stmt_ty | |
| 1055 | +Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, | |
| 1056 | + PyArena *arena) | |
| 1057 | +{ | |
| 1058 | + stmt_ty p; | |
| 1059 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1060 | + if (!p) { | |
| 1061 | + PyErr_NoMemory(); | |
| 1062 | + return NULL; | |
| 1063 | + } | |
| 1064 | + p->kind = Raise_kind; | |
| 1065 | + p->v.Raise.type = type; | |
| 1066 | + p->v.Raise.inst = inst; | |
| 1067 | + p->v.Raise.tback = tback; | |
| 1068 | + p->lineno = lineno; | |
| 1069 | + p->col_offset = col_offset; | |
| 1070 | + return p; | |
| 1071 | +} | |
| 1072 | + | |
| 1073 | +stmt_ty | |
| 1074 | +TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno, | |
| 1075 | + int col_offset, PyArena *arena) | |
| 1076 | +{ | |
| 1077 | + stmt_ty p; | |
| 1078 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1079 | + if (!p) { | |
| 1080 | + PyErr_NoMemory(); | |
| 1081 | + return NULL; | |
| 1082 | + } | |
| 1083 | + p->kind = TryExcept_kind; | |
| 1084 | + p->v.TryExcept.body = body; | |
| 1085 | + p->v.TryExcept.handlers = handlers; | |
| 1086 | + p->v.TryExcept.orelse = orelse; | |
| 1087 | + p->lineno = lineno; | |
| 1088 | + p->col_offset = col_offset; | |
| 1089 | + return p; | |
| 1090 | +} | |
| 1091 | + | |
| 1092 | +stmt_ty | |
| 1093 | +TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, | |
| 1094 | + PyArena *arena) | |
| 1095 | +{ | |
| 1096 | + stmt_ty p; | |
| 1097 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1098 | + if (!p) { | |
| 1099 | + PyErr_NoMemory(); | |
| 1100 | + return NULL; | |
| 1101 | + } | |
| 1102 | + p->kind = TryFinally_kind; | |
| 1103 | + p->v.TryFinally.body = body; | |
| 1104 | + p->v.TryFinally.finalbody = finalbody; | |
| 1105 | + p->lineno = lineno; | |
| 1106 | + p->col_offset = col_offset; | |
| 1107 | + return p; | |
| 1108 | +} | |
| 1109 | + | |
| 1110 | +stmt_ty | |
| 1111 | +Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) | |
| 1112 | +{ | |
| 1113 | + stmt_ty p; | |
| 1114 | + if (!test) { | |
| 1115 | + PyErr_SetString(PyExc_ValueError, | |
| 1116 | + "field test is required for Assert"); | |
| 1117 | + return NULL; | |
| 1118 | + } | |
| 1119 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1120 | + if (!p) { | |
| 1121 | + PyErr_NoMemory(); | |
| 1122 | + return NULL; | |
| 1123 | + } | |
| 1124 | + p->kind = Assert_kind; | |
| 1125 | + p->v.Assert.test = test; | |
| 1126 | + p->v.Assert.msg = msg; | |
| 1127 | + p->lineno = lineno; | |
| 1128 | + p->col_offset = col_offset; | |
| 1129 | + return p; | |
| 1130 | +} | |
| 1131 | + | |
| 1132 | +stmt_ty | |
| 1133 | +Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) | |
| 1134 | +{ | |
| 1135 | + stmt_ty p; | |
| 1136 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1137 | + if (!p) { | |
| 1138 | + PyErr_NoMemory(); | |
| 1139 | + return NULL; | |
| 1140 | + } | |
| 1141 | + p->kind = Import_kind; | |
| 1142 | + p->v.Import.names = names; | |
| 1143 | + p->lineno = lineno; | |
| 1144 | + p->col_offset = col_offset; | |
| 1145 | + return p; | |
| 1146 | +} | |
| 1147 | + | |
| 1148 | +stmt_ty | |
| 1149 | +ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int | |
| 1150 | + col_offset, PyArena *arena) | |
| 1151 | +{ | |
| 1152 | + stmt_ty p; | |
| 1153 | + if (!module) { | |
| 1154 | + PyErr_SetString(PyExc_ValueError, | |
| 1155 | + "field module is required for ImportFrom"); | |
| 1156 | + return NULL; | |
| 1157 | + } | |
| 1158 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1159 | + if (!p) { | |
| 1160 | + PyErr_NoMemory(); | |
| 1161 | + return NULL; | |
| 1162 | + } | |
| 1163 | + p->kind = ImportFrom_kind; | |
| 1164 | + p->v.ImportFrom.module = module; | |
| 1165 | + p->v.ImportFrom.names = names; | |
| 1166 | + p->v.ImportFrom.level = level; | |
| 1167 | + p->lineno = lineno; | |
| 1168 | + p->col_offset = col_offset; | |
| 1169 | + return p; | |
| 1170 | +} | |
| 1171 | + | |
| 1172 | +stmt_ty | |
| 1173 | +Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, | |
| 1174 | + PyArena *arena) | |
| 1175 | +{ | |
| 1176 | + stmt_ty p; | |
| 1177 | + if (!body) { | |
| 1178 | + PyErr_SetString(PyExc_ValueError, | |
| 1179 | + "field body is required for Exec"); | |
| 1180 | + return NULL; | |
| 1181 | + } | |
| 1182 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1183 | + if (!p) { | |
| 1184 | + PyErr_NoMemory(); | |
| 1185 | + return NULL; | |
| 1186 | + } | |
| 1187 | + p->kind = Exec_kind; | |
| 1188 | + p->v.Exec.body = body; | |
| 1189 | + p->v.Exec.globals = globals; | |
| 1190 | + p->v.Exec.locals = locals; | |
| 1191 | + p->lineno = lineno; | |
| 1192 | + p->col_offset = col_offset; | |
| 1193 | + return p; | |
| 1194 | +} | |
| 1195 | + | |
| 1196 | +stmt_ty | |
| 1197 | +Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) | |
| 1198 | +{ | |
| 1199 | + stmt_ty p; | |
| 1200 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1201 | + if (!p) { | |
| 1202 | + PyErr_NoMemory(); | |
| 1203 | + return NULL; | |
| 1204 | + } | |
| 1205 | + p->kind = Global_kind; | |
| 1206 | + p->v.Global.names = names; | |
| 1207 | + p->lineno = lineno; | |
| 1208 | + p->col_offset = col_offset; | |
| 1209 | + return p; | |
| 1210 | +} | |
| 1211 | + | |
| 1212 | +stmt_ty | |
| 1213 | +Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) | |
| 1214 | +{ | |
| 1215 | + stmt_ty p; | |
| 1216 | + if (!value) { | |
| 1217 | + PyErr_SetString(PyExc_ValueError, | |
| 1218 | + "field value is required for Expr"); | |
| 1219 | + return NULL; | |
| 1220 | + } | |
| 1221 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1222 | + if (!p) { | |
| 1223 | + PyErr_NoMemory(); | |
| 1224 | + return NULL; | |
| 1225 | + } | |
| 1226 | + p->kind = Expr_kind; | |
| 1227 | + p->v.Expr.value = value; | |
| 1228 | + p->lineno = lineno; | |
| 1229 | + p->col_offset = col_offset; | |
| 1230 | + return p; | |
| 1231 | +} | |
| 1232 | + | |
| 1233 | +stmt_ty | |
| 1234 | +Pass(int lineno, int col_offset, PyArena *arena) | |
| 1235 | +{ | |
| 1236 | + stmt_ty p; | |
| 1237 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1238 | + if (!p) { | |
| 1239 | + PyErr_NoMemory(); | |
| 1240 | + return NULL; | |
| 1241 | + } | |
| 1242 | + p->kind = Pass_kind; | |
| 1243 | + p->lineno = lineno; | |
| 1244 | + p->col_offset = col_offset; | |
| 1245 | + return p; | |
| 1246 | +} | |
| 1247 | + | |
| 1248 | +stmt_ty | |
| 1249 | +Break(int lineno, int col_offset, PyArena *arena) | |
| 1250 | +{ | |
| 1251 | + stmt_ty p; | |
| 1252 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1253 | + if (!p) { | |
| 1254 | + PyErr_NoMemory(); | |
| 1255 | + return NULL; | |
| 1256 | + } | |
| 1257 | + p->kind = Break_kind; | |
| 1258 | + p->lineno = lineno; | |
| 1259 | + p->col_offset = col_offset; | |
| 1260 | + return p; | |
| 1261 | +} | |
| 1262 | + | |
| 1263 | +stmt_ty | |
| 1264 | +Continue(int lineno, int col_offset, PyArena *arena) | |
| 1265 | +{ | |
| 1266 | + stmt_ty p; | |
| 1267 | + p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1268 | + if (!p) { | |
| 1269 | + PyErr_NoMemory(); | |
| 1270 | + return NULL; | |
| 1271 | + } | |
| 1272 | + p->kind = Continue_kind; | |
| 1273 | + p->lineno = lineno; | |
| 1274 | + p->col_offset = col_offset; | |
| 1275 | + return p; | |
| 1276 | +} | |
| 1277 | + | |
| 1278 | +expr_ty | |
| 1279 | +BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena | |
| 1280 | + *arena) | |
| 1281 | +{ | |
| 1282 | + expr_ty p; | |
| 1283 | + if (!op) { | |
| 1284 | + PyErr_SetString(PyExc_ValueError, | |
| 1285 | + "field op is required for BoolOp"); | |
| 1286 | + return NULL; | |
| 1287 | + } | |
| 1288 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1289 | + if (!p) { | |
| 1290 | + PyErr_NoMemory(); | |
| 1291 | + return NULL; | |
| 1292 | + } | |
| 1293 | + p->kind = BoolOp_kind; | |
| 1294 | + p->v.BoolOp.op = op; | |
| 1295 | + p->v.BoolOp.values = values; | |
| 1296 | + p->lineno = lineno; | |
| 1297 | + p->col_offset = col_offset; | |
| 1298 | + return p; | |
| 1299 | +} | |
| 1300 | + | |
| 1301 | +expr_ty | |
| 1302 | +BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, | |
| 1303 | + PyArena *arena) | |
| 1304 | +{ | |
| 1305 | + expr_ty p; | |
| 1306 | + if (!left) { | |
| 1307 | + PyErr_SetString(PyExc_ValueError, | |
| 1308 | + "field left is required for BinOp"); | |
| 1309 | + return NULL; | |
| 1310 | + } | |
| 1311 | + if (!op) { | |
| 1312 | + PyErr_SetString(PyExc_ValueError, | |
| 1313 | + "field op is required for BinOp"); | |
| 1314 | + return NULL; | |
| 1315 | + } | |
| 1316 | + if (!right) { | |
| 1317 | + PyErr_SetString(PyExc_ValueError, | |
| 1318 | + "field right is required for BinOp"); | |
| 1319 | + return NULL; | |
| 1320 | + } | |
| 1321 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1322 | + if (!p) { | |
| 1323 | + PyErr_NoMemory(); | |
| 1324 | + return NULL; | |
| 1325 | + } | |
| 1326 | + p->kind = BinOp_kind; | |
| 1327 | + p->v.BinOp.left = left; | |
| 1328 | + p->v.BinOp.op = op; | |
| 1329 | + p->v.BinOp.right = right; | |
| 1330 | + p->lineno = lineno; | |
| 1331 | + p->col_offset = col_offset; | |
| 1332 | + return p; | |
| 1333 | +} | |
| 1334 | + | |
| 1335 | +expr_ty | |
| 1336 | +UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena | |
| 1337 | + *arena) | |
| 1338 | +{ | |
| 1339 | + expr_ty p; | |
| 1340 | + if (!op) { | |
| 1341 | + PyErr_SetString(PyExc_ValueError, | |
| 1342 | + "field op is required for UnaryOp"); | |
| 1343 | + return NULL; | |
| 1344 | + } | |
| 1345 | + if (!operand) { | |
| 1346 | + PyErr_SetString(PyExc_ValueError, | |
| 1347 | + "field operand is required for UnaryOp"); | |
| 1348 | + return NULL; | |
| 1349 | + } | |
| 1350 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1351 | + if (!p) { | |
| 1352 | + PyErr_NoMemory(); | |
| 1353 | + return NULL; | |
| 1354 | + } | |
| 1355 | + p->kind = UnaryOp_kind; | |
| 1356 | + p->v.UnaryOp.op = op; | |
| 1357 | + p->v.UnaryOp.operand = operand; | |
| 1358 | + p->lineno = lineno; | |
| 1359 | + p->col_offset = col_offset; | |
| 1360 | + return p; | |
| 1361 | +} | |
| 1362 | + | |
| 1363 | +expr_ty | |
| 1364 | +Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena | |
| 1365 | + *arena) | |
| 1366 | +{ | |
| 1367 | + expr_ty p; | |
| 1368 | + if (!args) { | |
| 1369 | + PyErr_SetString(PyExc_ValueError, | |
| 1370 | + "field args is required for Lambda"); | |
| 1371 | + return NULL; | |
| 1372 | + } | |
| 1373 | + if (!body) { | |
| 1374 | + PyErr_SetString(PyExc_ValueError, | |
| 1375 | + "field body is required for Lambda"); | |
| 1376 | + return NULL; | |
| 1377 | + } | |
| 1378 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1379 | + if (!p) { | |
| 1380 | + PyErr_NoMemory(); | |
| 1381 | + return NULL; | |
| 1382 | + } | |
| 1383 | + p->kind = Lambda_kind; | |
| 1384 | + p->v.Lambda.args = args; | |
| 1385 | + p->v.Lambda.body = body; | |
| 1386 | + p->lineno = lineno; | |
| 1387 | + p->col_offset = col_offset; | |
| 1388 | + return p; | |
| 1389 | +} | |
| 1390 | + | |
| 1391 | +expr_ty | |
| 1392 | +IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, | |
| 1393 | + PyArena *arena) | |
| 1394 | +{ | |
| 1395 | + expr_ty p; | |
| 1396 | + if (!test) { | |
| 1397 | + PyErr_SetString(PyExc_ValueError, | |
| 1398 | + "field test is required for IfExp"); | |
| 1399 | + return NULL; | |
| 1400 | + } | |
| 1401 | + if (!body) { | |
| 1402 | + PyErr_SetString(PyExc_ValueError, | |
| 1403 | + "field body is required for IfExp"); | |
| 1404 | + return NULL; | |
| 1405 | + } | |
| 1406 | + if (!orelse) { | |
| 1407 | + PyErr_SetString(PyExc_ValueError, | |
| 1408 | + "field orelse is required for IfExp"); | |
| 1409 | + return NULL; | |
| 1410 | + } | |
| 1411 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1412 | + if (!p) { | |
| 1413 | + PyErr_NoMemory(); | |
| 1414 | + return NULL; | |
| 1415 | + } | |
| 1416 | + p->kind = IfExp_kind; | |
| 1417 | + p->v.IfExp.test = test; | |
| 1418 | + p->v.IfExp.body = body; | |
| 1419 | + p->v.IfExp.orelse = orelse; | |
| 1420 | + p->lineno = lineno; | |
| 1421 | + p->col_offset = col_offset; | |
| 1422 | + return p; | |
| 1423 | +} | |
| 1424 | + | |
| 1425 | +expr_ty | |
| 1426 | +Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena | |
| 1427 | + *arena) | |
| 1428 | +{ | |
| 1429 | + expr_ty p; | |
| 1430 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1431 | + if (!p) { | |
| 1432 | + PyErr_NoMemory(); | |
| 1433 | + return NULL; | |
| 1434 | + } | |
| 1435 | + p->kind = Dict_kind; | |
| 1436 | + p->v.Dict.keys = keys; | |
| 1437 | + p->v.Dict.values = values; | |
| 1438 | + p->lineno = lineno; | |
| 1439 | + p->col_offset = col_offset; | |
| 1440 | + return p; | |
| 1441 | +} | |
| 1442 | + | |
| 1443 | +expr_ty | |
| 1444 | +ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, | |
| 1445 | + PyArena *arena) | |
| 1446 | +{ | |
| 1447 | + expr_ty p; | |
| 1448 | + if (!elt) { | |
| 1449 | + PyErr_SetString(PyExc_ValueError, | |
| 1450 | + "field elt is required for ListComp"); | |
| 1451 | + return NULL; | |
| 1452 | + } | |
| 1453 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1454 | + if (!p) { | |
| 1455 | + PyErr_NoMemory(); | |
| 1456 | + return NULL; | |
| 1457 | + } | |
| 1458 | + p->kind = ListComp_kind; | |
| 1459 | + p->v.ListComp.elt = elt; | |
| 1460 | + p->v.ListComp.generators = generators; | |
| 1461 | + p->lineno = lineno; | |
| 1462 | + p->col_offset = col_offset; | |
| 1463 | + return p; | |
| 1464 | +} | |
| 1465 | + | |
| 1466 | +expr_ty | |
| 1467 | +GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, | |
| 1468 | + PyArena *arena) | |
| 1469 | +{ | |
| 1470 | + expr_ty p; | |
| 1471 | + if (!elt) { | |
| 1472 | + PyErr_SetString(PyExc_ValueError, | |
| 1473 | + "field elt is required for GeneratorExp"); | |
| 1474 | + return NULL; | |
| 1475 | + } | |
| 1476 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1477 | + if (!p) { | |
| 1478 | + PyErr_NoMemory(); | |
| 1479 | + return NULL; | |
| 1480 | + } | |
| 1481 | + p->kind = GeneratorExp_kind; | |
| 1482 | + p->v.GeneratorExp.elt = elt; | |
| 1483 | + p->v.GeneratorExp.generators = generators; | |
| 1484 | + p->lineno = lineno; | |
| 1485 | + p->col_offset = col_offset; | |
| 1486 | + return p; | |
| 1487 | +} | |
| 1488 | + | |
| 1489 | +expr_ty | |
| 1490 | +Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) | |
| 1491 | +{ | |
| 1492 | + expr_ty p; | |
| 1493 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1494 | + if (!p) { | |
| 1495 | + PyErr_NoMemory(); | |
| 1496 | + return NULL; | |
| 1497 | + } | |
| 1498 | + p->kind = Yield_kind; | |
| 1499 | + p->v.Yield.value = value; | |
| 1500 | + p->lineno = lineno; | |
| 1501 | + p->col_offset = col_offset; | |
| 1502 | + return p; | |
| 1503 | +} | |
| 1504 | + | |
| 1505 | +expr_ty | |
| 1506 | +Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, | |
| 1507 | + int col_offset, PyArena *arena) | |
| 1508 | +{ | |
| 1509 | + expr_ty p; | |
| 1510 | + if (!left) { | |
| 1511 | + PyErr_SetString(PyExc_ValueError, | |
| 1512 | + "field left is required for Compare"); | |
| 1513 | + return NULL; | |
| 1514 | + } | |
| 1515 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1516 | + if (!p) { | |
| 1517 | + PyErr_NoMemory(); | |
| 1518 | + return NULL; | |
| 1519 | + } | |
| 1520 | + p->kind = Compare_kind; | |
| 1521 | + p->v.Compare.left = left; | |
| 1522 | + p->v.Compare.ops = ops; | |
| 1523 | + p->v.Compare.comparators = comparators; | |
| 1524 | + p->lineno = lineno; | |
| 1525 | + p->col_offset = col_offset; | |
| 1526 | + return p; | |
| 1527 | +} | |
| 1528 | + | |
| 1529 | +expr_ty | |
| 1530 | +Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs, | |
| 1531 | + expr_ty kwargs, int lineno, int col_offset, PyArena *arena) | |
| 1532 | +{ | |
| 1533 | + expr_ty p; | |
| 1534 | + if (!func) { | |
| 1535 | + PyErr_SetString(PyExc_ValueError, | |
| 1536 | + "field func is required for Call"); | |
| 1537 | + return NULL; | |
| 1538 | + } | |
| 1539 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1540 | + if (!p) { | |
| 1541 | + PyErr_NoMemory(); | |
| 1542 | + return NULL; | |
| 1543 | + } | |
| 1544 | + p->kind = Call_kind; | |
| 1545 | + p->v.Call.func = func; | |
| 1546 | + p->v.Call.args = args; | |
| 1547 | + p->v.Call.keywords = keywords; | |
| 1548 | + p->v.Call.starargs = starargs; | |
| 1549 | + p->v.Call.kwargs = kwargs; | |
| 1550 | + p->lineno = lineno; | |
| 1551 | + p->col_offset = col_offset; | |
| 1552 | + return p; | |
| 1553 | +} | |
| 1554 | + | |
| 1555 | +expr_ty | |
| 1556 | +Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) | |
| 1557 | +{ | |
| 1558 | + expr_ty p; | |
| 1559 | + if (!value) { | |
| 1560 | + PyErr_SetString(PyExc_ValueError, | |
| 1561 | + "field value is required for Repr"); | |
| 1562 | + return NULL; | |
| 1563 | + } | |
| 1564 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1565 | + if (!p) { | |
| 1566 | + PyErr_NoMemory(); | |
| 1567 | + return NULL; | |
| 1568 | + } | |
| 1569 | + p->kind = Repr_kind; | |
| 1570 | + p->v.Repr.value = value; | |
| 1571 | + p->lineno = lineno; | |
| 1572 | + p->col_offset = col_offset; | |
| 1573 | + return p; | |
| 1574 | +} | |
| 1575 | + | |
| 1576 | +expr_ty | |
| 1577 | +Num(object n, int lineno, int col_offset, PyArena *arena) | |
| 1578 | +{ | |
| 1579 | + expr_ty p; | |
| 1580 | + if (!n) { | |
| 1581 | + PyErr_SetString(PyExc_ValueError, | |
| 1582 | + "field n is required for Num"); | |
| 1583 | + return NULL; | |
| 1584 | + } | |
| 1585 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1586 | + if (!p) { | |
| 1587 | + PyErr_NoMemory(); | |
| 1588 | + return NULL; | |
| 1589 | + } | |
| 1590 | + p->kind = Num_kind; | |
| 1591 | + p->v.Num.n = n; | |
| 1592 | + p->lineno = lineno; | |
| 1593 | + p->col_offset = col_offset; | |
| 1594 | + return p; | |
| 1595 | +} | |
| 1596 | + | |
| 1597 | +expr_ty | |
| 1598 | +Str(string s, int lineno, int col_offset, PyArena *arena) | |
| 1599 | +{ | |
| 1600 | + expr_ty p; | |
| 1601 | + if (!s) { | |
| 1602 | + PyErr_SetString(PyExc_ValueError, | |
| 1603 | + "field s is required for Str"); | |
| 1604 | + return NULL; | |
| 1605 | + } | |
| 1606 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1607 | + if (!p) { | |
| 1608 | + PyErr_NoMemory(); | |
| 1609 | + return NULL; | |
| 1610 | + } | |
| 1611 | + p->kind = Str_kind; | |
| 1612 | + p->v.Str.s = s; | |
| 1613 | + p->lineno = lineno; | |
| 1614 | + p->col_offset = col_offset; | |
| 1615 | + return p; | |
| 1616 | +} | |
| 1617 | + | |
| 1618 | +expr_ty | |
| 1619 | +Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int | |
| 1620 | + col_offset, PyArena *arena) | |
| 1621 | +{ | |
| 1622 | + expr_ty p; | |
| 1623 | + if (!value) { | |
| 1624 | + PyErr_SetString(PyExc_ValueError, | |
| 1625 | + "field value is required for Attribute"); | |
| 1626 | + return NULL; | |
| 1627 | + } | |
| 1628 | + if (!attr) { | |
| 1629 | + PyErr_SetString(PyExc_ValueError, | |
| 1630 | + "field attr is required for Attribute"); | |
| 1631 | + return NULL; | |
| 1632 | + } | |
| 1633 | + if (!ctx) { | |
| 1634 | + PyErr_SetString(PyExc_ValueError, | |
| 1635 | + "field ctx is required for Attribute"); | |
| 1636 | + return NULL; | |
| 1637 | + } | |
| 1638 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1639 | + if (!p) { | |
| 1640 | + PyErr_NoMemory(); | |
| 1641 | + return NULL; | |
| 1642 | + } | |
| 1643 | + p->kind = Attribute_kind; | |
| 1644 | + p->v.Attribute.value = value; | |
| 1645 | + p->v.Attribute.attr = attr; | |
| 1646 | + p->v.Attribute.ctx = ctx; | |
| 1647 | + p->lineno = lineno; | |
| 1648 | + p->col_offset = col_offset; | |
| 1649 | + return p; | |
| 1650 | +} | |
| 1651 | + | |
| 1652 | +expr_ty | |
| 1653 | +Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int | |
| 1654 | + col_offset, PyArena *arena) | |
| 1655 | +{ | |
| 1656 | + expr_ty p; | |
| 1657 | + if (!value) { | |
| 1658 | + PyErr_SetString(PyExc_ValueError, | |
| 1659 | + "field value is required for Subscript"); | |
| 1660 | + return NULL; | |
| 1661 | + } | |
| 1662 | + if (!slice) { | |
| 1663 | + PyErr_SetString(PyExc_ValueError, | |
| 1664 | + "field slice is required for Subscript"); | |
| 1665 | + return NULL; | |
| 1666 | + } | |
| 1667 | + if (!ctx) { | |
| 1668 | + PyErr_SetString(PyExc_ValueError, | |
| 1669 | + "field ctx is required for Subscript"); | |
| 1670 | + return NULL; | |
| 1671 | + } | |
| 1672 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1673 | + if (!p) { | |
| 1674 | + PyErr_NoMemory(); | |
| 1675 | + return NULL; | |
| 1676 | + } | |
| 1677 | + p->kind = Subscript_kind; | |
| 1678 | + p->v.Subscript.value = value; | |
| 1679 | + p->v.Subscript.slice = slice; | |
| 1680 | + p->v.Subscript.ctx = ctx; | |
| 1681 | + p->lineno = lineno; | |
| 1682 | + p->col_offset = col_offset; | |
| 1683 | + return p; | |
| 1684 | +} | |
| 1685 | + | |
| 1686 | +expr_ty | |
| 1687 | +Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena | |
| 1688 | + *arena) | |
| 1689 | +{ | |
| 1690 | + expr_ty p; | |
| 1691 | + if (!id) { | |
| 1692 | + PyErr_SetString(PyExc_ValueError, | |
| 1693 | + "field id is required for Name"); | |
| 1694 | + return NULL; | |
| 1695 | + } | |
| 1696 | + if (!ctx) { | |
| 1697 | + PyErr_SetString(PyExc_ValueError, | |
| 1698 | + "field ctx is required for Name"); | |
| 1699 | + return NULL; | |
| 1700 | + } | |
| 1701 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1702 | + if (!p) { | |
| 1703 | + PyErr_NoMemory(); | |
| 1704 | + return NULL; | |
| 1705 | + } | |
| 1706 | + p->kind = Name_kind; | |
| 1707 | + p->v.Name.id = id; | |
| 1708 | + p->v.Name.ctx = ctx; | |
| 1709 | + p->lineno = lineno; | |
| 1710 | + p->col_offset = col_offset; | |
| 1711 | + return p; | |
| 1712 | +} | |
| 1713 | + | |
| 1714 | +expr_ty | |
| 1715 | +List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena | |
| 1716 | + *arena) | |
| 1717 | +{ | |
| 1718 | + expr_ty p; | |
| 1719 | + if (!ctx) { | |
| 1720 | + PyErr_SetString(PyExc_ValueError, | |
| 1721 | + "field ctx is required for List"); | |
| 1722 | + return NULL; | |
| 1723 | + } | |
| 1724 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1725 | + if (!p) { | |
| 1726 | + PyErr_NoMemory(); | |
| 1727 | + return NULL; | |
| 1728 | + } | |
| 1729 | + p->kind = List_kind; | |
| 1730 | + p->v.List.elts = elts; | |
| 1731 | + p->v.List.ctx = ctx; | |
| 1732 | + p->lineno = lineno; | |
| 1733 | + p->col_offset = col_offset; | |
| 1734 | + return p; | |
| 1735 | +} | |
| 1736 | + | |
| 1737 | +expr_ty | |
| 1738 | +Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena | |
| 1739 | + *arena) | |
| 1740 | +{ | |
| 1741 | + expr_ty p; | |
| 1742 | + if (!ctx) { | |
| 1743 | + PyErr_SetString(PyExc_ValueError, | |
| 1744 | + "field ctx is required for Tuple"); | |
| 1745 | + return NULL; | |
| 1746 | + } | |
| 1747 | + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1748 | + if (!p) { | |
| 1749 | + PyErr_NoMemory(); | |
| 1750 | + return NULL; | |
| 1751 | + } | |
| 1752 | + p->kind = Tuple_kind; | |
| 1753 | + p->v.Tuple.elts = elts; | |
| 1754 | + p->v.Tuple.ctx = ctx; | |
| 1755 | + p->lineno = lineno; | |
| 1756 | + p->col_offset = col_offset; | |
| 1757 | + return p; | |
| 1758 | +} | |
| 1759 | + | |
| 1760 | +slice_ty | |
| 1761 | +Ellipsis(PyArena *arena) | |
| 1762 | +{ | |
| 1763 | + slice_ty p; | |
| 1764 | + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1765 | + if (!p) { | |
| 1766 | + PyErr_NoMemory(); | |
| 1767 | + return NULL; | |
| 1768 | + } | |
| 1769 | + p->kind = Ellipsis_kind; | |
| 1770 | + return p; | |
| 1771 | +} | |
| 1772 | + | |
| 1773 | +slice_ty | |
| 1774 | +Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) | |
| 1775 | +{ | |
| 1776 | + slice_ty p; | |
| 1777 | + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1778 | + if (!p) { | |
| 1779 | + PyErr_NoMemory(); | |
| 1780 | + return NULL; | |
| 1781 | + } | |
| 1782 | + p->kind = Slice_kind; | |
| 1783 | + p->v.Slice.lower = lower; | |
| 1784 | + p->v.Slice.upper = upper; | |
| 1785 | + p->v.Slice.step = step; | |
| 1786 | + return p; | |
| 1787 | +} | |
| 1788 | + | |
| 1789 | +slice_ty | |
| 1790 | +ExtSlice(asdl_seq * dims, PyArena *arena) | |
| 1791 | +{ | |
| 1792 | + slice_ty p; | |
| 1793 | + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1794 | + if (!p) { | |
| 1795 | + PyErr_NoMemory(); | |
| 1796 | + return NULL; | |
| 1797 | + } | |
| 1798 | + p->kind = ExtSlice_kind; | |
| 1799 | + p->v.ExtSlice.dims = dims; | |
| 1800 | + return p; | |
| 1801 | +} | |
| 1802 | + | |
| 1803 | +slice_ty | |
| 1804 | +Index(expr_ty value, PyArena *arena) | |
| 1805 | +{ | |
| 1806 | + slice_ty p; | |
| 1807 | + if (!value) { | |
| 1808 | + PyErr_SetString(PyExc_ValueError, | |
| 1809 | + "field value is required for Index"); | |
| 1810 | + return NULL; | |
| 1811 | + } | |
| 1812 | + p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1813 | + if (!p) { | |
| 1814 | + PyErr_NoMemory(); | |
| 1815 | + return NULL; | |
| 1816 | + } | |
| 1817 | + p->kind = Index_kind; | |
| 1818 | + p->v.Index.value = value; | |
| 1819 | + return p; | |
| 1820 | +} | |
| 1821 | + | |
| 1822 | +comprehension_ty | |
| 1823 | +comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) | |
| 1824 | +{ | |
| 1825 | + comprehension_ty p; | |
| 1826 | + if (!target) { | |
| 1827 | + PyErr_SetString(PyExc_ValueError, | |
| 1828 | + "field target is required for comprehension"); | |
| 1829 | + return NULL; | |
| 1830 | + } | |
| 1831 | + if (!iter) { | |
| 1832 | + PyErr_SetString(PyExc_ValueError, | |
| 1833 | + "field iter is required for comprehension"); | |
| 1834 | + return NULL; | |
| 1835 | + } | |
| 1836 | + p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1837 | + if (!p) { | |
| 1838 | + PyErr_NoMemory(); | |
| 1839 | + return NULL; | |
| 1840 | + } | |
| 1841 | + p->target = target; | |
| 1842 | + p->iter = iter; | |
| 1843 | + p->ifs = ifs; | |
| 1844 | + return p; | |
| 1845 | +} | |
| 1846 | + | |
| 1847 | +excepthandler_ty | |
| 1848 | +excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int | |
| 1849 | + col_offset, PyArena *arena) | |
| 1850 | +{ | |
| 1851 | + excepthandler_ty p; | |
| 1852 | + p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1853 | + if (!p) { | |
| 1854 | + PyErr_NoMemory(); | |
| 1855 | + return NULL; | |
| 1856 | + } | |
| 1857 | + p->type = type; | |
| 1858 | + p->name = name; | |
| 1859 | + p->body = body; | |
| 1860 | + p->lineno = lineno; | |
| 1861 | + p->col_offset = col_offset; | |
| 1862 | + return p; | |
| 1863 | +} | |
| 1864 | + | |
| 1865 | +arguments_ty | |
| 1866 | +arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * | |
| 1867 | + defaults, PyArena *arena) | |
| 1868 | +{ | |
| 1869 | + arguments_ty p; | |
| 1870 | + p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1871 | + if (!p) { | |
| 1872 | + PyErr_NoMemory(); | |
| 1873 | + return NULL; | |
| 1874 | + } | |
| 1875 | + p->args = args; | |
| 1876 | + p->vararg = vararg; | |
| 1877 | + p->kwarg = kwarg; | |
| 1878 | + p->defaults = defaults; | |
| 1879 | + return p; | |
| 1880 | +} | |
| 1881 | + | |
| 1882 | +keyword_ty | |
| 1883 | +keyword(identifier arg, expr_ty value, PyArena *arena) | |
| 1884 | +{ | |
| 1885 | + keyword_ty p; | |
| 1886 | + if (!arg) { | |
| 1887 | + PyErr_SetString(PyExc_ValueError, | |
| 1888 | + "field arg is required for keyword"); | |
| 1889 | + return NULL; | |
| 1890 | + } | |
| 1891 | + if (!value) { | |
| 1892 | + PyErr_SetString(PyExc_ValueError, | |
| 1893 | + "field value is required for keyword"); | |
| 1894 | + return NULL; | |
| 1895 | + } | |
| 1896 | + p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1897 | + if (!p) { | |
| 1898 | + PyErr_NoMemory(); | |
| 1899 | + return NULL; | |
| 1900 | + } | |
| 1901 | + p->arg = arg; | |
| 1902 | + p->value = value; | |
| 1903 | + return p; | |
| 1904 | +} | |
| 1905 | + | |
| 1906 | +alias_ty | |
| 1907 | +alias(identifier name, identifier asname, PyArena *arena) | |
| 1908 | +{ | |
| 1909 | + alias_ty p; | |
| 1910 | + if (!name) { | |
| 1911 | + PyErr_SetString(PyExc_ValueError, | |
| 1912 | + "field name is required for alias"); | |
| 1913 | + return NULL; | |
| 1914 | + } | |
| 1915 | + p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1916 | + if (!p) { | |
| 1917 | + PyErr_NoMemory(); | |
| 1918 | + return NULL; | |
| 1919 | + } | |
| 1920 | + p->name = name; | |
| 1921 | + p->asname = asname; | |
| 1922 | + return p; | |
| 1923 | +} | |
| 1924 | + | |
| 1925 | + | |
| 1926 | +PyObject* | |
| 1927 | +ast2obj_mod(void* _o) | |
| 1928 | +{ | |
| 1929 | + mod_ty o = (mod_ty)_o; | |
| 1930 | + PyObject *result = NULL, *value = NULL; | |
| 1931 | + if (!o) { | |
| 1932 | + Py_INCREF(Py_None); | |
| 1933 | + return Py_None; | |
| 1934 | + } | |
| 1935 | + | |
| 1936 | + switch (o->kind) { | |
| 1937 | + case Module_kind: | |
| 1938 | + result = PyType_GenericNew(Module_type, NULL, NULL); | |
| 1939 | + if (!result) goto failed; | |
| 1940 | + value = ast2obj_list(o->v.Module.body, ast2obj_stmt); | |
| 1941 | + if (!value) goto failed; | |
| 1942 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 1943 | + goto failed; | |
| 1944 | + Py_DECREF(value); | |
| 1945 | + break; | |
| 1946 | + case Interactive_kind: | |
| 1947 | + result = PyType_GenericNew(Interactive_type, NULL, NULL); | |
| 1948 | + if (!result) goto failed; | |
| 1949 | + value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); | |
| 1950 | + if (!value) goto failed; | |
| 1951 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 1952 | + goto failed; | |
| 1953 | + Py_DECREF(value); | |
| 1954 | + break; | |
| 1955 | + case Expression_kind: | |
| 1956 | + result = PyType_GenericNew(Expression_type, NULL, NULL); | |
| 1957 | + if (!result) goto failed; | |
| 1958 | + value = ast2obj_expr(o->v.Expression.body); | |
| 1959 | + if (!value) goto failed; | |
| 1960 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 1961 | + goto failed; | |
| 1962 | + Py_DECREF(value); | |
| 1963 | + break; | |
| 1964 | + case Suite_kind: | |
| 1965 | + result = PyType_GenericNew(Suite_type, NULL, NULL); | |
| 1966 | + if (!result) goto failed; | |
| 1967 | + value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); | |
| 1968 | + if (!value) goto failed; | |
| 1969 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 1970 | + goto failed; | |
| 1971 | + Py_DECREF(value); | |
| 1972 | + break; | |
| 1973 | + } | |
| 1974 | + return result; | |
| 1975 | +failed: | |
| 1976 | + Py_XDECREF(value); | |
| 1977 | + Py_XDECREF(result); | |
| 1978 | + return NULL; | |
| 1979 | +} | |
| 1980 | + | |
| 1981 | +PyObject* | |
| 1982 | +ast2obj_stmt(void* _o) | |
| 1983 | +{ | |
| 1984 | + stmt_ty o = (stmt_ty)_o; | |
| 1985 | + PyObject *result = NULL, *value = NULL; | |
| 1986 | + if (!o) { | |
| 1987 | + Py_INCREF(Py_None); | |
| 1988 | + return Py_None; | |
| 1989 | + } | |
| 1990 | + | |
| 1991 | + switch (o->kind) { | |
| 1992 | + case FunctionDef_kind: | |
| 1993 | + result = PyType_GenericNew(FunctionDef_type, NULL, NULL); | |
| 1994 | + if (!result) goto failed; | |
| 1995 | + value = ast2obj_identifier(o->v.FunctionDef.name); | |
| 1996 | + if (!value) goto failed; | |
| 1997 | + if (PyObject_SetAttrString(result, "name", value) == -1) | |
| 1998 | + goto failed; | |
| 1999 | + Py_DECREF(value); | |
| 2000 | + value = ast2obj_arguments(o->v.FunctionDef.args); | |
| 2001 | + if (!value) goto failed; | |
| 2002 | + if (PyObject_SetAttrString(result, "args", value) == -1) | |
| 2003 | + goto failed; | |
| 2004 | + Py_DECREF(value); | |
| 2005 | + value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); | |
| 2006 | + if (!value) goto failed; | |
| 2007 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2008 | + goto failed; | |
| 2009 | + Py_DECREF(value); | |
| 2010 | + value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr); | |
| 2011 | + if (!value) goto failed; | |
| 2012 | + if (PyObject_SetAttrString(result, "decorators", value) == -1) | |
| 2013 | + goto failed; | |
| 2014 | + Py_DECREF(value); | |
| 2015 | + break; | |
| 2016 | + case ClassDef_kind: | |
| 2017 | + result = PyType_GenericNew(ClassDef_type, NULL, NULL); | |
| 2018 | + if (!result) goto failed; | |
| 2019 | + value = ast2obj_identifier(o->v.ClassDef.name); | |
| 2020 | + if (!value) goto failed; | |
| 2021 | + if (PyObject_SetAttrString(result, "name", value) == -1) | |
| 2022 | + goto failed; | |
| 2023 | + Py_DECREF(value); | |
| 2024 | + value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); | |
| 2025 | + if (!value) goto failed; | |
| 2026 | + if (PyObject_SetAttrString(result, "bases", value) == -1) | |
| 2027 | + goto failed; | |
| 2028 | + Py_DECREF(value); | |
| 2029 | + value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); | |
| 2030 | + if (!value) goto failed; | |
| 2031 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2032 | + goto failed; | |
| 2033 | + Py_DECREF(value); | |
| 2034 | + break; | |
| 2035 | + case Return_kind: | |
| 2036 | + result = PyType_GenericNew(Return_type, NULL, NULL); | |
| 2037 | + if (!result) goto failed; | |
| 2038 | + value = ast2obj_expr(o->v.Return.value); | |
| 2039 | + if (!value) goto failed; | |
| 2040 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2041 | + goto failed; | |
| 2042 | + Py_DECREF(value); | |
| 2043 | + break; | |
| 2044 | + case Delete_kind: | |
| 2045 | + result = PyType_GenericNew(Delete_type, NULL, NULL); | |
| 2046 | + if (!result) goto failed; | |
| 2047 | + value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); | |
| 2048 | + if (!value) goto failed; | |
| 2049 | + if (PyObject_SetAttrString(result, "targets", value) == -1) | |
| 2050 | + goto failed; | |
| 2051 | + Py_DECREF(value); | |
| 2052 | + break; | |
| 2053 | + case Assign_kind: | |
| 2054 | + result = PyType_GenericNew(Assign_type, NULL, NULL); | |
| 2055 | + if (!result) goto failed; | |
| 2056 | + value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); | |
| 2057 | + if (!value) goto failed; | |
| 2058 | + if (PyObject_SetAttrString(result, "targets", value) == -1) | |
| 2059 | + goto failed; | |
| 2060 | + Py_DECREF(value); | |
| 2061 | + value = ast2obj_expr(o->v.Assign.value); | |
| 2062 | + if (!value) goto failed; | |
| 2063 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2064 | + goto failed; | |
| 2065 | + Py_DECREF(value); | |
| 2066 | + break; | |
| 2067 | + case AugAssign_kind: | |
| 2068 | + result = PyType_GenericNew(AugAssign_type, NULL, NULL); | |
| 2069 | + if (!result) goto failed; | |
| 2070 | + value = ast2obj_expr(o->v.AugAssign.target); | |
| 2071 | + if (!value) goto failed; | |
| 2072 | + if (PyObject_SetAttrString(result, "target", value) == -1) | |
| 2073 | + goto failed; | |
| 2074 | + Py_DECREF(value); | |
| 2075 | + value = ast2obj_operator(o->v.AugAssign.op); | |
| 2076 | + if (!value) goto failed; | |
| 2077 | + if (PyObject_SetAttrString(result, "op", value) == -1) | |
| 2078 | + goto failed; | |
| 2079 | + Py_DECREF(value); | |
| 2080 | + value = ast2obj_expr(o->v.AugAssign.value); | |
| 2081 | + if (!value) goto failed; | |
| 2082 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2083 | + goto failed; | |
| 2084 | + Py_DECREF(value); | |
| 2085 | + break; | |
| 2086 | + case Print_kind: | |
| 2087 | + result = PyType_GenericNew(Print_type, NULL, NULL); | |
| 2088 | + if (!result) goto failed; | |
| 2089 | + value = ast2obj_expr(o->v.Print.dest); | |
| 2090 | + if (!value) goto failed; | |
| 2091 | + if (PyObject_SetAttrString(result, "dest", value) == -1) | |
| 2092 | + goto failed; | |
| 2093 | + Py_DECREF(value); | |
| 2094 | + value = ast2obj_list(o->v.Print.values, ast2obj_expr); | |
| 2095 | + if (!value) goto failed; | |
| 2096 | + if (PyObject_SetAttrString(result, "values", value) == -1) | |
| 2097 | + goto failed; | |
| 2098 | + Py_DECREF(value); | |
| 2099 | + value = ast2obj_bool(o->v.Print.nl); | |
| 2100 | + if (!value) goto failed; | |
| 2101 | + if (PyObject_SetAttrString(result, "nl", value) == -1) | |
| 2102 | + goto failed; | |
| 2103 | + Py_DECREF(value); | |
| 2104 | + break; | |
| 2105 | + case For_kind: | |
| 2106 | + result = PyType_GenericNew(For_type, NULL, NULL); | |
| 2107 | + if (!result) goto failed; | |
| 2108 | + value = ast2obj_expr(o->v.For.target); | |
| 2109 | + if (!value) goto failed; | |
| 2110 | + if (PyObject_SetAttrString(result, "target", value) == -1) | |
| 2111 | + goto failed; | |
| 2112 | + Py_DECREF(value); | |
| 2113 | + value = ast2obj_expr(o->v.For.iter); | |
| 2114 | + if (!value) goto failed; | |
| 2115 | + if (PyObject_SetAttrString(result, "iter", value) == -1) | |
| 2116 | + goto failed; | |
| 2117 | + Py_DECREF(value); | |
| 2118 | + value = ast2obj_list(o->v.For.body, ast2obj_stmt); | |
| 2119 | + if (!value) goto failed; | |
| 2120 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2121 | + goto failed; | |
| 2122 | + Py_DECREF(value); | |
| 2123 | + value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); | |
| 2124 | + if (!value) goto failed; | |
| 2125 | + if (PyObject_SetAttrString(result, "orelse", value) == -1) | |
| 2126 | + goto failed; | |
| 2127 | + Py_DECREF(value); | |
| 2128 | + break; | |
| 2129 | + case While_kind: | |
| 2130 | + result = PyType_GenericNew(While_type, NULL, NULL); | |
| 2131 | + if (!result) goto failed; | |
| 2132 | + value = ast2obj_expr(o->v.While.test); | |
| 2133 | + if (!value) goto failed; | |
| 2134 | + if (PyObject_SetAttrString(result, "test", value) == -1) | |
| 2135 | + goto failed; | |
| 2136 | + Py_DECREF(value); | |
| 2137 | + value = ast2obj_list(o->v.While.body, ast2obj_stmt); | |
| 2138 | + if (!value) goto failed; | |
| 2139 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2140 | + goto failed; | |
| 2141 | + Py_DECREF(value); | |
| 2142 | + value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); | |
| 2143 | + if (!value) goto failed; | |
| 2144 | + if (PyObject_SetAttrString(result, "orelse", value) == -1) | |
| 2145 | + goto failed; | |
| 2146 | + Py_DECREF(value); | |
| 2147 | + break; | |
| 2148 | + case If_kind: | |
| 2149 | + result = PyType_GenericNew(If_type, NULL, NULL); | |
| 2150 | + if (!result) goto failed; | |
| 2151 | + value = ast2obj_expr(o->v.If.test); | |
| 2152 | + if (!value) goto failed; | |
| 2153 | + if (PyObject_SetAttrString(result, "test", value) == -1) | |
| 2154 | + goto failed; | |
| 2155 | + Py_DECREF(value); | |
| 2156 | + value = ast2obj_list(o->v.If.body, ast2obj_stmt); | |
| 2157 | + if (!value) goto failed; | |
| 2158 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2159 | + goto failed; | |
| 2160 | + Py_DECREF(value); | |
| 2161 | + value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); | |
| 2162 | + if (!value) goto failed; | |
| 2163 | + if (PyObject_SetAttrString(result, "orelse", value) == -1) | |
| 2164 | + goto failed; | |
| 2165 | + Py_DECREF(value); | |
| 2166 | + break; | |
| 2167 | + case With_kind: | |
| 2168 | + result = PyType_GenericNew(With_type, NULL, NULL); | |
| 2169 | + if (!result) goto failed; | |
| 2170 | + value = ast2obj_expr(o->v.With.context_expr); | |
| 2171 | + if (!value) goto failed; | |
| 2172 | + if (PyObject_SetAttrString(result, "context_expr", value) == -1) | |
| 2173 | + goto failed; | |
| 2174 | + Py_DECREF(value); | |
| 2175 | + value = ast2obj_expr(o->v.With.optional_vars); | |
| 2176 | + if (!value) goto failed; | |
| 2177 | + if (PyObject_SetAttrString(result, "optional_vars", value) == | |
| 2178 | + -1) | |
| 2179 | + goto failed; | |
| 2180 | + Py_DECREF(value); | |
| 2181 | + value = ast2obj_list(o->v.With.body, ast2obj_stmt); | |
| 2182 | + if (!value) goto failed; | |
| 2183 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2184 | + goto failed; | |
| 2185 | + Py_DECREF(value); | |
| 2186 | + break; | |
| 2187 | + case Raise_kind: | |
| 2188 | + result = PyType_GenericNew(Raise_type, NULL, NULL); | |
| 2189 | + if (!result) goto failed; | |
| 2190 | + value = ast2obj_expr(o->v.Raise.type); | |
| 2191 | + if (!value) goto failed; | |
| 2192 | + if (PyObject_SetAttrString(result, "type", value) == -1) | |
| 2193 | + goto failed; | |
| 2194 | + Py_DECREF(value); | |
| 2195 | + value = ast2obj_expr(o->v.Raise.inst); | |
| 2196 | + if (!value) goto failed; | |
| 2197 | + if (PyObject_SetAttrString(result, "inst", value) == -1) | |
| 2198 | + goto failed; | |
| 2199 | + Py_DECREF(value); | |
| 2200 | + value = ast2obj_expr(o->v.Raise.tback); | |
| 2201 | + if (!value) goto failed; | |
| 2202 | + if (PyObject_SetAttrString(result, "tback", value) == -1) | |
| 2203 | + goto failed; | |
| 2204 | + Py_DECREF(value); | |
| 2205 | + break; | |
| 2206 | + case TryExcept_kind: | |
| 2207 | + result = PyType_GenericNew(TryExcept_type, NULL, NULL); | |
| 2208 | + if (!result) goto failed; | |
| 2209 | + value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); | |
| 2210 | + if (!value) goto failed; | |
| 2211 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2212 | + goto failed; | |
| 2213 | + Py_DECREF(value); | |
| 2214 | + value = ast2obj_list(o->v.TryExcept.handlers, | |
| 2215 | + ast2obj_excepthandler); | |
| 2216 | + if (!value) goto failed; | |
| 2217 | + if (PyObject_SetAttrString(result, "handlers", value) == -1) | |
| 2218 | + goto failed; | |
| 2219 | + Py_DECREF(value); | |
| 2220 | + value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); | |
| 2221 | + if (!value) goto failed; | |
| 2222 | + if (PyObject_SetAttrString(result, "orelse", value) == -1) | |
| 2223 | + goto failed; | |
| 2224 | + Py_DECREF(value); | |
| 2225 | + break; | |
| 2226 | + case TryFinally_kind: | |
| 2227 | + result = PyType_GenericNew(TryFinally_type, NULL, NULL); | |
| 2228 | + if (!result) goto failed; | |
| 2229 | + value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); | |
| 2230 | + if (!value) goto failed; | |
| 2231 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2232 | + goto failed; | |
| 2233 | + Py_DECREF(value); | |
| 2234 | + value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); | |
| 2235 | + if (!value) goto failed; | |
| 2236 | + if (PyObject_SetAttrString(result, "finalbody", value) == -1) | |
| 2237 | + goto failed; | |
| 2238 | + Py_DECREF(value); | |
| 2239 | + break; | |
| 2240 | + case Assert_kind: | |
| 2241 | + result = PyType_GenericNew(Assert_type, NULL, NULL); | |
| 2242 | + if (!result) goto failed; | |
| 2243 | + value = ast2obj_expr(o->v.Assert.test); | |
| 2244 | + if (!value) goto failed; | |
| 2245 | + if (PyObject_SetAttrString(result, "test", value) == -1) | |
| 2246 | + goto failed; | |
| 2247 | + Py_DECREF(value); | |
| 2248 | + value = ast2obj_expr(o->v.Assert.msg); | |
| 2249 | + if (!value) goto failed; | |
| 2250 | + if (PyObject_SetAttrString(result, "msg", value) == -1) | |
| 2251 | + goto failed; | |
| 2252 | + Py_DECREF(value); | |
| 2253 | + break; | |
| 2254 | + case Import_kind: | |
| 2255 | + result = PyType_GenericNew(Import_type, NULL, NULL); | |
| 2256 | + if (!result) goto failed; | |
| 2257 | + value = ast2obj_list(o->v.Import.names, ast2obj_alias); | |
| 2258 | + if (!value) goto failed; | |
| 2259 | + if (PyObject_SetAttrString(result, "names", value) == -1) | |
| 2260 | + goto failed; | |
| 2261 | + Py_DECREF(value); | |
| 2262 | + break; | |
| 2263 | + case ImportFrom_kind: | |
| 2264 | + result = PyType_GenericNew(ImportFrom_type, NULL, NULL); | |
| 2265 | + if (!result) goto failed; | |
| 2266 | + value = ast2obj_identifier(o->v.ImportFrom.module); | |
| 2267 | + if (!value) goto failed; | |
| 2268 | + if (PyObject_SetAttrString(result, "module", value) == -1) | |
| 2269 | + goto failed; | |
| 2270 | + Py_DECREF(value); | |
| 2271 | + value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); | |
| 2272 | + if (!value) goto failed; | |
| 2273 | + if (PyObject_SetAttrString(result, "names", value) == -1) | |
| 2274 | + goto failed; | |
| 2275 | + Py_DECREF(value); | |
| 2276 | + value = ast2obj_int(o->v.ImportFrom.level); | |
| 2277 | + if (!value) goto failed; | |
| 2278 | + if (PyObject_SetAttrString(result, "level", value) == -1) | |
| 2279 | + goto failed; | |
| 2280 | + Py_DECREF(value); | |
| 2281 | + break; | |
| 2282 | + case Exec_kind: | |
| 2283 | + result = PyType_GenericNew(Exec_type, NULL, NULL); | |
| 2284 | + if (!result) goto failed; | |
| 2285 | + value = ast2obj_expr(o->v.Exec.body); | |
| 2286 | + if (!value) goto failed; | |
| 2287 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2288 | + goto failed; | |
| 2289 | + Py_DECREF(value); | |
| 2290 | + value = ast2obj_expr(o->v.Exec.globals); | |
| 2291 | + if (!value) goto failed; | |
| 2292 | + if (PyObject_SetAttrString(result, "globals", value) == -1) | |
| 2293 | + goto failed; | |
| 2294 | + Py_DECREF(value); | |
| 2295 | + value = ast2obj_expr(o->v.Exec.locals); | |
| 2296 | + if (!value) goto failed; | |
| 2297 | + if (PyObject_SetAttrString(result, "locals", value) == -1) | |
| 2298 | + goto failed; | |
| 2299 | + Py_DECREF(value); | |
| 2300 | + break; | |
| 2301 | + case Global_kind: | |
| 2302 | + result = PyType_GenericNew(Global_type, NULL, NULL); | |
| 2303 | + if (!result) goto failed; | |
| 2304 | + value = ast2obj_list(o->v.Global.names, ast2obj_identifier); | |
| 2305 | + if (!value) goto failed; | |
| 2306 | + if (PyObject_SetAttrString(result, "names", value) == -1) | |
| 2307 | + goto failed; | |
| 2308 | + Py_DECREF(value); | |
| 2309 | + break; | |
| 2310 | + case Expr_kind: | |
| 2311 | + result = PyType_GenericNew(Expr_type, NULL, NULL); | |
| 2312 | + if (!result) goto failed; | |
| 2313 | + value = ast2obj_expr(o->v.Expr.value); | |
| 2314 | + if (!value) goto failed; | |
| 2315 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2316 | + goto failed; | |
| 2317 | + Py_DECREF(value); | |
| 2318 | + break; | |
| 2319 | + case Pass_kind: | |
| 2320 | + result = PyType_GenericNew(Pass_type, NULL, NULL); | |
| 2321 | + if (!result) goto failed; | |
| 2322 | + break; | |
| 2323 | + case Break_kind: | |
| 2324 | + result = PyType_GenericNew(Break_type, NULL, NULL); | |
| 2325 | + if (!result) goto failed; | |
| 2326 | + break; | |
| 2327 | + case Continue_kind: | |
| 2328 | + result = PyType_GenericNew(Continue_type, NULL, NULL); | |
| 2329 | + if (!result) goto failed; | |
| 2330 | + break; | |
| 2331 | + } | |
| 2332 | + value = ast2obj_int(o->lineno); | |
| 2333 | + if (!value) goto failed; | |
| 2334 | + if (PyObject_SetAttrString(result, "lineno", value) < 0) | |
| 2335 | + goto failed; | |
| 2336 | + Py_DECREF(value); | |
| 2337 | + value = ast2obj_int(o->col_offset); | |
| 2338 | + if (!value) goto failed; | |
| 2339 | + if (PyObject_SetAttrString(result, "col_offset", value) < 0) | |
| 2340 | + goto failed; | |
| 2341 | + Py_DECREF(value); | |
| 2342 | + return result; | |
| 2343 | +failed: | |
| 2344 | + Py_XDECREF(value); | |
| 2345 | + Py_XDECREF(result); | |
| 2346 | + return NULL; | |
| 2347 | +} | |
| 2348 | + | |
| 2349 | +PyObject* | |
| 2350 | +ast2obj_expr(void* _o) | |
| 2351 | +{ | |
| 2352 | + expr_ty o = (expr_ty)_o; | |
| 2353 | + PyObject *result = NULL, *value = NULL; | |
| 2354 | + if (!o) { | |
| 2355 | + Py_INCREF(Py_None); | |
| 2356 | + return Py_None; | |
| 2357 | + } | |
| 2358 | + | |
| 2359 | + switch (o->kind) { | |
| 2360 | + case BoolOp_kind: | |
| 2361 | + result = PyType_GenericNew(BoolOp_type, NULL, NULL); | |
| 2362 | + if (!result) goto failed; | |
| 2363 | + value = ast2obj_boolop(o->v.BoolOp.op); | |
| 2364 | + if (!value) goto failed; | |
| 2365 | + if (PyObject_SetAttrString(result, "op", value) == -1) | |
| 2366 | + goto failed; | |
| 2367 | + Py_DECREF(value); | |
| 2368 | + value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); | |
| 2369 | + if (!value) goto failed; | |
| 2370 | + if (PyObject_SetAttrString(result, "values", value) == -1) | |
| 2371 | + goto failed; | |
| 2372 | + Py_DECREF(value); | |
| 2373 | + break; | |
| 2374 | + case BinOp_kind: | |
| 2375 | + result = PyType_GenericNew(BinOp_type, NULL, NULL); | |
| 2376 | + if (!result) goto failed; | |
| 2377 | + value = ast2obj_expr(o->v.BinOp.left); | |
| 2378 | + if (!value) goto failed; | |
| 2379 | + if (PyObject_SetAttrString(result, "left", value) == -1) | |
| 2380 | + goto failed; | |
| 2381 | + Py_DECREF(value); | |
| 2382 | + value = ast2obj_operator(o->v.BinOp.op); | |
| 2383 | + if (!value) goto failed; | |
| 2384 | + if (PyObject_SetAttrString(result, "op", value) == -1) | |
| 2385 | + goto failed; | |
| 2386 | + Py_DECREF(value); | |
| 2387 | + value = ast2obj_expr(o->v.BinOp.right); | |
| 2388 | + if (!value) goto failed; | |
| 2389 | + if (PyObject_SetAttrString(result, "right", value) == -1) | |
| 2390 | + goto failed; | |
| 2391 | + Py_DECREF(value); | |
| 2392 | + break; | |
| 2393 | + case UnaryOp_kind: | |
| 2394 | + result = PyType_GenericNew(UnaryOp_type, NULL, NULL); | |
| 2395 | + if (!result) goto failed; | |
| 2396 | + value = ast2obj_unaryop(o->v.UnaryOp.op); | |
| 2397 | + if (!value) goto failed; | |
| 2398 | + if (PyObject_SetAttrString(result, "op", value) == -1) | |
| 2399 | + goto failed; | |
| 2400 | + Py_DECREF(value); | |
| 2401 | + value = ast2obj_expr(o->v.UnaryOp.operand); | |
| 2402 | + if (!value) goto failed; | |
| 2403 | + if (PyObject_SetAttrString(result, "operand", value) == -1) | |
| 2404 | + goto failed; | |
| 2405 | + Py_DECREF(value); | |
| 2406 | + break; | |
| 2407 | + case Lambda_kind: | |
| 2408 | + result = PyType_GenericNew(Lambda_type, NULL, NULL); | |
| 2409 | + if (!result) goto failed; | |
| 2410 | + value = ast2obj_arguments(o->v.Lambda.args); | |
| 2411 | + if (!value) goto failed; | |
| 2412 | + if (PyObject_SetAttrString(result, "args", value) == -1) | |
| 2413 | + goto failed; | |
| 2414 | + Py_DECREF(value); | |
| 2415 | + value = ast2obj_expr(o->v.Lambda.body); | |
| 2416 | + if (!value) goto failed; | |
| 2417 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2418 | + goto failed; | |
| 2419 | + Py_DECREF(value); | |
| 2420 | + break; | |
| 2421 | + case IfExp_kind: | |
| 2422 | + result = PyType_GenericNew(IfExp_type, NULL, NULL); | |
| 2423 | + if (!result) goto failed; | |
| 2424 | + value = ast2obj_expr(o->v.IfExp.test); | |
| 2425 | + if (!value) goto failed; | |
| 2426 | + if (PyObject_SetAttrString(result, "test", value) == -1) | |
| 2427 | + goto failed; | |
| 2428 | + Py_DECREF(value); | |
| 2429 | + value = ast2obj_expr(o->v.IfExp.body); | |
| 2430 | + if (!value) goto failed; | |
| 2431 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2432 | + goto failed; | |
| 2433 | + Py_DECREF(value); | |
| 2434 | + value = ast2obj_expr(o->v.IfExp.orelse); | |
| 2435 | + if (!value) goto failed; | |
| 2436 | + if (PyObject_SetAttrString(result, "orelse", value) == -1) | |
| 2437 | + goto failed; | |
| 2438 | + Py_DECREF(value); | |
| 2439 | + break; | |
| 2440 | + case Dict_kind: | |
| 2441 | + result = PyType_GenericNew(Dict_type, NULL, NULL); | |
| 2442 | + if (!result) goto failed; | |
| 2443 | + value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); | |
| 2444 | + if (!value) goto failed; | |
| 2445 | + if (PyObject_SetAttrString(result, "keys", value) == -1) | |
| 2446 | + goto failed; | |
| 2447 | + Py_DECREF(value); | |
| 2448 | + value = ast2obj_list(o->v.Dict.values, ast2obj_expr); | |
| 2449 | + if (!value) goto failed; | |
| 2450 | + if (PyObject_SetAttrString(result, "values", value) == -1) | |
| 2451 | + goto failed; | |
| 2452 | + Py_DECREF(value); | |
| 2453 | + break; | |
| 2454 | + case ListComp_kind: | |
| 2455 | + result = PyType_GenericNew(ListComp_type, NULL, NULL); | |
| 2456 | + if (!result) goto failed; | |
| 2457 | + value = ast2obj_expr(o->v.ListComp.elt); | |
| 2458 | + if (!value) goto failed; | |
| 2459 | + if (PyObject_SetAttrString(result, "elt", value) == -1) | |
| 2460 | + goto failed; | |
| 2461 | + Py_DECREF(value); | |
| 2462 | + value = ast2obj_list(o->v.ListComp.generators, | |
| 2463 | + ast2obj_comprehension); | |
| 2464 | + if (!value) goto failed; | |
| 2465 | + if (PyObject_SetAttrString(result, "generators", value) == -1) | |
| 2466 | + goto failed; | |
| 2467 | + Py_DECREF(value); | |
| 2468 | + break; | |
| 2469 | + case GeneratorExp_kind: | |
| 2470 | + result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); | |
| 2471 | + if (!result) goto failed; | |
| 2472 | + value = ast2obj_expr(o->v.GeneratorExp.elt); | |
| 2473 | + if (!value) goto failed; | |
| 2474 | + if (PyObject_SetAttrString(result, "elt", value) == -1) | |
| 2475 | + goto failed; | |
| 2476 | + Py_DECREF(value); | |
| 2477 | + value = ast2obj_list(o->v.GeneratorExp.generators, | |
| 2478 | + ast2obj_comprehension); | |
| 2479 | + if (!value) goto failed; | |
| 2480 | + if (PyObject_SetAttrString(result, "generators", value) == -1) | |
| 2481 | + goto failed; | |
| 2482 | + Py_DECREF(value); | |
| 2483 | + break; | |
| 2484 | + case Yield_kind: | |
| 2485 | + result = PyType_GenericNew(Yield_type, NULL, NULL); | |
| 2486 | + if (!result) goto failed; | |
| 2487 | + value = ast2obj_expr(o->v.Yield.value); | |
| 2488 | + if (!value) goto failed; | |
| 2489 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2490 | + goto failed; | |
| 2491 | + Py_DECREF(value); | |
| 2492 | + break; | |
| 2493 | + case Compare_kind: | |
| 2494 | + result = PyType_GenericNew(Compare_type, NULL, NULL); | |
| 2495 | + if (!result) goto failed; | |
| 2496 | + value = ast2obj_expr(o->v.Compare.left); | |
| 2497 | + if (!value) goto failed; | |
| 2498 | + if (PyObject_SetAttrString(result, "left", value) == -1) | |
| 2499 | + goto failed; | |
| 2500 | + Py_DECREF(value); | |
| 2501 | + { | |
| 2502 | + int i, n = asdl_seq_LEN(o->v.Compare.ops); | |
| 2503 | + value = PyList_New(n); | |
| 2504 | + if (!value) goto failed; | |
| 2505 | + for(i = 0; i < n; i++) | |
| 2506 | + PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); | |
| 2507 | + } | |
| 2508 | + if (!value) goto failed; | |
| 2509 | + if (PyObject_SetAttrString(result, "ops", value) == -1) | |
| 2510 | + goto failed; | |
| 2511 | + Py_DECREF(value); | |
| 2512 | + value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); | |
| 2513 | + if (!value) goto failed; | |
| 2514 | + if (PyObject_SetAttrString(result, "comparators", value) == -1) | |
| 2515 | + goto failed; | |
| 2516 | + Py_DECREF(value); | |
| 2517 | + break; | |
| 2518 | + case Call_kind: | |
| 2519 | + result = PyType_GenericNew(Call_type, NULL, NULL); | |
| 2520 | + if (!result) goto failed; | |
| 2521 | + value = ast2obj_expr(o->v.Call.func); | |
| 2522 | + if (!value) goto failed; | |
| 2523 | + if (PyObject_SetAttrString(result, "func", value) == -1) | |
| 2524 | + goto failed; | |
| 2525 | + Py_DECREF(value); | |
| 2526 | + value = ast2obj_list(o->v.Call.args, ast2obj_expr); | |
| 2527 | + if (!value) goto failed; | |
| 2528 | + if (PyObject_SetAttrString(result, "args", value) == -1) | |
| 2529 | + goto failed; | |
| 2530 | + Py_DECREF(value); | |
| 2531 | + value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); | |
| 2532 | + if (!value) goto failed; | |
| 2533 | + if (PyObject_SetAttrString(result, "keywords", value) == -1) | |
| 2534 | + goto failed; | |
| 2535 | + Py_DECREF(value); | |
| 2536 | + value = ast2obj_expr(o->v.Call.starargs); | |
| 2537 | + if (!value) goto failed; | |
| 2538 | + if (PyObject_SetAttrString(result, "starargs", value) == -1) | |
| 2539 | + goto failed; | |
| 2540 | + Py_DECREF(value); | |
| 2541 | + value = ast2obj_expr(o->v.Call.kwargs); | |
| 2542 | + if (!value) goto failed; | |
| 2543 | + if (PyObject_SetAttrString(result, "kwargs", value) == -1) | |
| 2544 | + goto failed; | |
| 2545 | + Py_DECREF(value); | |
| 2546 | + break; | |
| 2547 | + case Repr_kind: | |
| 2548 | + result = PyType_GenericNew(Repr_type, NULL, NULL); | |
| 2549 | + if (!result) goto failed; | |
| 2550 | + value = ast2obj_expr(o->v.Repr.value); | |
| 2551 | + if (!value) goto failed; | |
| 2552 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2553 | + goto failed; | |
| 2554 | + Py_DECREF(value); | |
| 2555 | + break; | |
| 2556 | + case Num_kind: | |
| 2557 | + result = PyType_GenericNew(Num_type, NULL, NULL); | |
| 2558 | + if (!result) goto failed; | |
| 2559 | + value = ast2obj_object(o->v.Num.n); | |
| 2560 | + if (!value) goto failed; | |
| 2561 | + if (PyObject_SetAttrString(result, "n", value) == -1) | |
| 2562 | + goto failed; | |
| 2563 | + Py_DECREF(value); | |
| 2564 | + break; | |
| 2565 | + case Str_kind: | |
| 2566 | + result = PyType_GenericNew(Str_type, NULL, NULL); | |
| 2567 | + if (!result) goto failed; | |
| 2568 | + value = ast2obj_string(o->v.Str.s); | |
| 2569 | + if (!value) goto failed; | |
| 2570 | + if (PyObject_SetAttrString(result, "s", value) == -1) | |
| 2571 | + goto failed; | |
| 2572 | + Py_DECREF(value); | |
| 2573 | + break; | |
| 2574 | + case Attribute_kind: | |
| 2575 | + result = PyType_GenericNew(Attribute_type, NULL, NULL); | |
| 2576 | + if (!result) goto failed; | |
| 2577 | + value = ast2obj_expr(o->v.Attribute.value); | |
| 2578 | + if (!value) goto failed; | |
| 2579 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2580 | + goto failed; | |
| 2581 | + Py_DECREF(value); | |
| 2582 | + value = ast2obj_identifier(o->v.Attribute.attr); | |
| 2583 | + if (!value) goto failed; | |
| 2584 | + if (PyObject_SetAttrString(result, "attr", value) == -1) | |
| 2585 | + goto failed; | |
| 2586 | + Py_DECREF(value); | |
| 2587 | + value = ast2obj_expr_context(o->v.Attribute.ctx); | |
| 2588 | + if (!value) goto failed; | |
| 2589 | + if (PyObject_SetAttrString(result, "ctx", value) == -1) | |
| 2590 | + goto failed; | |
| 2591 | + Py_DECREF(value); | |
| 2592 | + break; | |
| 2593 | + case Subscript_kind: | |
| 2594 | + result = PyType_GenericNew(Subscript_type, NULL, NULL); | |
| 2595 | + if (!result) goto failed; | |
| 2596 | + value = ast2obj_expr(o->v.Subscript.value); | |
| 2597 | + if (!value) goto failed; | |
| 2598 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2599 | + goto failed; | |
| 2600 | + Py_DECREF(value); | |
| 2601 | + value = ast2obj_slice(o->v.Subscript.slice); | |
| 2602 | + if (!value) goto failed; | |
| 2603 | + if (PyObject_SetAttrString(result, "slice", value) == -1) | |
| 2604 | + goto failed; | |
| 2605 | + Py_DECREF(value); | |
| 2606 | + value = ast2obj_expr_context(o->v.Subscript.ctx); | |
| 2607 | + if (!value) goto failed; | |
| 2608 | + if (PyObject_SetAttrString(result, "ctx", value) == -1) | |
| 2609 | + goto failed; | |
| 2610 | + Py_DECREF(value); | |
| 2611 | + break; | |
| 2612 | + case Name_kind: | |
| 2613 | + result = PyType_GenericNew(Name_type, NULL, NULL); | |
| 2614 | + if (!result) goto failed; | |
| 2615 | + value = ast2obj_identifier(o->v.Name.id); | |
| 2616 | + if (!value) goto failed; | |
| 2617 | + if (PyObject_SetAttrString(result, "id", value) == -1) | |
| 2618 | + goto failed; | |
| 2619 | + Py_DECREF(value); | |
| 2620 | + value = ast2obj_expr_context(o->v.Name.ctx); | |
| 2621 | + if (!value) goto failed; | |
| 2622 | + if (PyObject_SetAttrString(result, "ctx", value) == -1) | |
| 2623 | + goto failed; | |
| 2624 | + Py_DECREF(value); | |
| 2625 | + break; | |
| 2626 | + case List_kind: | |
| 2627 | + result = PyType_GenericNew(List_type, NULL, NULL); | |
| 2628 | + if (!result) goto failed; | |
| 2629 | + value = ast2obj_list(o->v.List.elts, ast2obj_expr); | |
| 2630 | + if (!value) goto failed; | |
| 2631 | + if (PyObject_SetAttrString(result, "elts", value) == -1) | |
| 2632 | + goto failed; | |
| 2633 | + Py_DECREF(value); | |
| 2634 | + value = ast2obj_expr_context(o->v.List.ctx); | |
| 2635 | + if (!value) goto failed; | |
| 2636 | + if (PyObject_SetAttrString(result, "ctx", value) == -1) | |
| 2637 | + goto failed; | |
| 2638 | + Py_DECREF(value); | |
| 2639 | + break; | |
| 2640 | + case Tuple_kind: | |
| 2641 | + result = PyType_GenericNew(Tuple_type, NULL, NULL); | |
| 2642 | + if (!result) goto failed; | |
| 2643 | + value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); | |
| 2644 | + if (!value) goto failed; | |
| 2645 | + if (PyObject_SetAttrString(result, "elts", value) == -1) | |
| 2646 | + goto failed; | |
| 2647 | + Py_DECREF(value); | |
| 2648 | + value = ast2obj_expr_context(o->v.Tuple.ctx); | |
| 2649 | + if (!value) goto failed; | |
| 2650 | + if (PyObject_SetAttrString(result, "ctx", value) == -1) | |
| 2651 | + goto failed; | |
| 2652 | + Py_DECREF(value); | |
| 2653 | + break; | |
| 2654 | + } | |
| 2655 | + value = ast2obj_int(o->lineno); | |
| 2656 | + if (!value) goto failed; | |
| 2657 | + if (PyObject_SetAttrString(result, "lineno", value) < 0) | |
| 2658 | + goto failed; | |
| 2659 | + Py_DECREF(value); | |
| 2660 | + value = ast2obj_int(o->col_offset); | |
| 2661 | + if (!value) goto failed; | |
| 2662 | + if (PyObject_SetAttrString(result, "col_offset", value) < 0) | |
| 2663 | + goto failed; | |
| 2664 | + Py_DECREF(value); | |
| 2665 | + return result; | |
| 2666 | +failed: | |
| 2667 | + Py_XDECREF(value); | |
| 2668 | + Py_XDECREF(result); | |
| 2669 | + return NULL; | |
| 2670 | +} | |
| 2671 | + | |
| 2672 | +PyObject* ast2obj_expr_context(expr_context_ty o) | |
| 2673 | +{ | |
| 2674 | + switch(o) { | |
| 2675 | + case Load: | |
| 2676 | + Py_INCREF(Load_singleton); | |
| 2677 | + return Load_singleton; | |
| 2678 | + case Store: | |
| 2679 | + Py_INCREF(Store_singleton); | |
| 2680 | + return Store_singleton; | |
| 2681 | + case Del: | |
| 2682 | + Py_INCREF(Del_singleton); | |
| 2683 | + return Del_singleton; | |
| 2684 | + case AugLoad: | |
| 2685 | + Py_INCREF(AugLoad_singleton); | |
| 2686 | + return AugLoad_singleton; | |
| 2687 | + case AugStore: | |
| 2688 | + Py_INCREF(AugStore_singleton); | |
| 2689 | + return AugStore_singleton; | |
| 2690 | + case Param: | |
| 2691 | + Py_INCREF(Param_singleton); | |
| 2692 | + return Param_singleton; | |
| 2693 | + } | |
| 2694 | + return NULL; /* cannot happen */ | |
| 2695 | +} | |
| 2696 | +PyObject* | |
| 2697 | +ast2obj_slice(void* _o) | |
| 2698 | +{ | |
| 2699 | + slice_ty o = (slice_ty)_o; | |
| 2700 | + PyObject *result = NULL, *value = NULL; | |
| 2701 | + if (!o) { | |
| 2702 | + Py_INCREF(Py_None); | |
| 2703 | + return Py_None; | |
| 2704 | + } | |
| 2705 | + | |
| 2706 | + switch (o->kind) { | |
| 2707 | + case Ellipsis_kind: | |
| 2708 | + result = PyType_GenericNew(Ellipsis_type, NULL, NULL); | |
| 2709 | + if (!result) goto failed; | |
| 2710 | + break; | |
| 2711 | + case Slice_kind: | |
| 2712 | + result = PyType_GenericNew(Slice_type, NULL, NULL); | |
| 2713 | + if (!result) goto failed; | |
| 2714 | + value = ast2obj_expr(o->v.Slice.lower); | |
| 2715 | + if (!value) goto failed; | |
| 2716 | + if (PyObject_SetAttrString(result, "lower", value) == -1) | |
| 2717 | + goto failed; | |
| 2718 | + Py_DECREF(value); | |
| 2719 | + value = ast2obj_expr(o->v.Slice.upper); | |
| 2720 | + if (!value) goto failed; | |
| 2721 | + if (PyObject_SetAttrString(result, "upper", value) == -1) | |
| 2722 | + goto failed; | |
| 2723 | + Py_DECREF(value); | |
| 2724 | + value = ast2obj_expr(o->v.Slice.step); | |
| 2725 | + if (!value) goto failed; | |
| 2726 | + if (PyObject_SetAttrString(result, "step", value) == -1) | |
| 2727 | + goto failed; | |
| 2728 | + Py_DECREF(value); | |
| 2729 | + break; | |
| 2730 | + case ExtSlice_kind: | |
| 2731 | + result = PyType_GenericNew(ExtSlice_type, NULL, NULL); | |
| 2732 | + if (!result) goto failed; | |
| 2733 | + value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); | |
| 2734 | + if (!value) goto failed; | |
| 2735 | + if (PyObject_SetAttrString(result, "dims", value) == -1) | |
| 2736 | + goto failed; | |
| 2737 | + Py_DECREF(value); | |
| 2738 | + break; | |
| 2739 | + case Index_kind: | |
| 2740 | + result = PyType_GenericNew(Index_type, NULL, NULL); | |
| 2741 | + if (!result) goto failed; | |
| 2742 | + value = ast2obj_expr(o->v.Index.value); | |
| 2743 | + if (!value) goto failed; | |
| 2744 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 2745 | + goto failed; | |
| 2746 | + Py_DECREF(value); | |
| 2747 | + break; | |
| 2748 | + } | |
| 2749 | + return result; | |
| 2750 | +failed: | |
| 2751 | + Py_XDECREF(value); | |
| 2752 | + Py_XDECREF(result); | |
| 2753 | + return NULL; | |
| 2754 | +} | |
| 2755 | + | |
| 2756 | +PyObject* ast2obj_boolop(boolop_ty o) | |
| 2757 | +{ | |
| 2758 | + switch(o) { | |
| 2759 | + case And: | |
| 2760 | + Py_INCREF(And_singleton); | |
| 2761 | + return And_singleton; | |
| 2762 | + case Or: | |
| 2763 | + Py_INCREF(Or_singleton); | |
| 2764 | + return Or_singleton; | |
| 2765 | + } | |
| 2766 | + return NULL; /* cannot happen */ | |
| 2767 | +} | |
| 2768 | +PyObject* ast2obj_operator(operator_ty o) | |
| 2769 | +{ | |
| 2770 | + switch(o) { | |
| 2771 | + case Add: | |
| 2772 | + Py_INCREF(Add_singleton); | |
| 2773 | + return Add_singleton; | |
| 2774 | + case Sub: | |
| 2775 | + Py_INCREF(Sub_singleton); | |
| 2776 | + return Sub_singleton; | |
| 2777 | + case Mult: | |
| 2778 | + Py_INCREF(Mult_singleton); | |
| 2779 | + return Mult_singleton; | |
| 2780 | + case Div: | |
| 2781 | + Py_INCREF(Div_singleton); | |
| 2782 | + return Div_singleton; | |
| 2783 | + case Mod: | |
| 2784 | + Py_INCREF(Mod_singleton); | |
| 2785 | + return Mod_singleton; | |
| 2786 | + case Pow: | |
| 2787 | + Py_INCREF(Pow_singleton); | |
| 2788 | + return Pow_singleton; | |
| 2789 | + case LShift: | |
| 2790 | + Py_INCREF(LShift_singleton); | |
| 2791 | + return LShift_singleton; | |
| 2792 | + case RShift: | |
| 2793 | + Py_INCREF(RShift_singleton); | |
| 2794 | + return RShift_singleton; | |
| 2795 | + case BitOr: | |
| 2796 | + Py_INCREF(BitOr_singleton); | |
| 2797 | + return BitOr_singleton; | |
| 2798 | + case BitXor: | |
| 2799 | + Py_INCREF(BitXor_singleton); | |
| 2800 | + return BitXor_singleton; | |
| 2801 | + case BitAnd: | |
| 2802 | + Py_INCREF(BitAnd_singleton); | |
| 2803 | + return BitAnd_singleton; | |
| 2804 | + case FloorDiv: | |
| 2805 | + Py_INCREF(FloorDiv_singleton); | |
| 2806 | + return FloorDiv_singleton; | |
| 2807 | + } | |
| 2808 | + return NULL; /* cannot happen */ | |
| 2809 | +} | |
| 2810 | +PyObject* ast2obj_unaryop(unaryop_ty o) | |
| 2811 | +{ | |
| 2812 | + switch(o) { | |
| 2813 | + case Invert: | |
| 2814 | + Py_INCREF(Invert_singleton); | |
| 2815 | + return Invert_singleton; | |
| 2816 | + case Not: | |
| 2817 | + Py_INCREF(Not_singleton); | |
| 2818 | + return Not_singleton; | |
| 2819 | + case UAdd: | |
| 2820 | + Py_INCREF(UAdd_singleton); | |
| 2821 | + return UAdd_singleton; | |
| 2822 | + case USub: | |
| 2823 | + Py_INCREF(USub_singleton); | |
| 2824 | + return USub_singleton; | |
| 2825 | + } | |
| 2826 | + return NULL; /* cannot happen */ | |
| 2827 | +} | |
| 2828 | +PyObject* ast2obj_cmpop(cmpop_ty o) | |
| 2829 | +{ | |
| 2830 | + switch(o) { | |
| 2831 | + case Eq: | |
| 2832 | + Py_INCREF(Eq_singleton); | |
| 2833 | + return Eq_singleton; | |
| 2834 | + case NotEq: | |
| 2835 | + Py_INCREF(NotEq_singleton); | |
| 2836 | + return NotEq_singleton; | |
| 2837 | + case Lt: | |
| 2838 | + Py_INCREF(Lt_singleton); | |
| 2839 | + return Lt_singleton; | |
| 2840 | + case LtE: | |
| 2841 | + Py_INCREF(LtE_singleton); | |
| 2842 | + return LtE_singleton; | |
| 2843 | + case Gt: | |
| 2844 | + Py_INCREF(Gt_singleton); | |
| 2845 | + return Gt_singleton; | |
| 2846 | + case GtE: | |
| 2847 | + Py_INCREF(GtE_singleton); | |
| 2848 | + return GtE_singleton; | |
| 2849 | + case Is: | |
| 2850 | + Py_INCREF(Is_singleton); | |
| 2851 | + return Is_singleton; | |
| 2852 | + case IsNot: | |
| 2853 | + Py_INCREF(IsNot_singleton); | |
| 2854 | + return IsNot_singleton; | |
| 2855 | + case In: | |
| 2856 | + Py_INCREF(In_singleton); | |
| 2857 | + return In_singleton; | |
| 2858 | + case NotIn: | |
| 2859 | + Py_INCREF(NotIn_singleton); | |
| 2860 | + return NotIn_singleton; | |
| 2861 | + } | |
| 2862 | + return NULL; /* cannot happen */ | |
| 2863 | +} | |
| 2864 | +PyObject* | |
| 2865 | +ast2obj_comprehension(void* _o) | |
| 2866 | +{ | |
| 2867 | + comprehension_ty o = (comprehension_ty)_o; | |
| 2868 | + PyObject *result = NULL, *value = NULL; | |
| 2869 | + if (!o) { | |
| 2870 | + Py_INCREF(Py_None); | |
| 2871 | + return Py_None; | |
| 2872 | + } | |
| 2873 | + | |
| 2874 | + result = PyType_GenericNew(comprehension_type, NULL, NULL); | |
| 2875 | + if (!result) return NULL; | |
| 2876 | + value = ast2obj_expr(o->target); | |
| 2877 | + if (!value) goto failed; | |
| 2878 | + if (PyObject_SetAttrString(result, "target", value) == -1) | |
| 2879 | + goto failed; | |
| 2880 | + Py_DECREF(value); | |
| 2881 | + value = ast2obj_expr(o->iter); | |
| 2882 | + if (!value) goto failed; | |
| 2883 | + if (PyObject_SetAttrString(result, "iter", value) == -1) | |
| 2884 | + goto failed; | |
| 2885 | + Py_DECREF(value); | |
| 2886 | + value = ast2obj_list(o->ifs, ast2obj_expr); | |
| 2887 | + if (!value) goto failed; | |
| 2888 | + if (PyObject_SetAttrString(result, "ifs", value) == -1) | |
| 2889 | + goto failed; | |
| 2890 | + Py_DECREF(value); | |
| 2891 | + return result; | |
| 2892 | +failed: | |
| 2893 | + Py_XDECREF(value); | |
| 2894 | + Py_XDECREF(result); | |
| 2895 | + return NULL; | |
| 2896 | +} | |
| 2897 | + | |
| 2898 | +PyObject* | |
| 2899 | +ast2obj_excepthandler(void* _o) | |
| 2900 | +{ | |
| 2901 | + excepthandler_ty o = (excepthandler_ty)_o; | |
| 2902 | + PyObject *result = NULL, *value = NULL; | |
| 2903 | + if (!o) { | |
| 2904 | + Py_INCREF(Py_None); | |
| 2905 | + return Py_None; | |
| 2906 | + } | |
| 2907 | + | |
| 2908 | + result = PyType_GenericNew(excepthandler_type, NULL, NULL); | |
| 2909 | + if (!result) return NULL; | |
| 2910 | + value = ast2obj_expr(o->type); | |
| 2911 | + if (!value) goto failed; | |
| 2912 | + if (PyObject_SetAttrString(result, "type", value) == -1) | |
| 2913 | + goto failed; | |
| 2914 | + Py_DECREF(value); | |
| 2915 | + value = ast2obj_expr(o->name); | |
| 2916 | + if (!value) goto failed; | |
| 2917 | + if (PyObject_SetAttrString(result, "name", value) == -1) | |
| 2918 | + goto failed; | |
| 2919 | + Py_DECREF(value); | |
| 2920 | + value = ast2obj_list(o->body, ast2obj_stmt); | |
| 2921 | + if (!value) goto failed; | |
| 2922 | + if (PyObject_SetAttrString(result, "body", value) == -1) | |
| 2923 | + goto failed; | |
| 2924 | + Py_DECREF(value); | |
| 2925 | + value = ast2obj_int(o->lineno); | |
| 2926 | + if (!value) goto failed; | |
| 2927 | + if (PyObject_SetAttrString(result, "lineno", value) == -1) | |
| 2928 | + goto failed; | |
| 2929 | + Py_DECREF(value); | |
| 2930 | + value = ast2obj_int(o->col_offset); | |
| 2931 | + if (!value) goto failed; | |
| 2932 | + if (PyObject_SetAttrString(result, "col_offset", value) == -1) | |
| 2933 | + goto failed; | |
| 2934 | + Py_DECREF(value); | |
| 2935 | + return result; | |
| 2936 | +failed: | |
| 2937 | + Py_XDECREF(value); | |
| 2938 | + Py_XDECREF(result); | |
| 2939 | + return NULL; | |
| 2940 | +} | |
| 2941 | + | |
| 2942 | +PyObject* | |
| 2943 | +ast2obj_arguments(void* _o) | |
| 2944 | +{ | |
| 2945 | + arguments_ty o = (arguments_ty)_o; | |
| 2946 | + PyObject *result = NULL, *value = NULL; | |
| 2947 | + if (!o) { | |
| 2948 | + Py_INCREF(Py_None); | |
| 2949 | + return Py_None; | |
| 2950 | + } | |
| 2951 | + | |
| 2952 | + result = PyType_GenericNew(arguments_type, NULL, NULL); | |
| 2953 | + if (!result) return NULL; | |
| 2954 | + value = ast2obj_list(o->args, ast2obj_expr); | |
| 2955 | + if (!value) goto failed; | |
| 2956 | + if (PyObject_SetAttrString(result, "args", value) == -1) | |
| 2957 | + goto failed; | |
| 2958 | + Py_DECREF(value); | |
| 2959 | + value = ast2obj_identifier(o->vararg); | |
| 2960 | + if (!value) goto failed; | |
| 2961 | + if (PyObject_SetAttrString(result, "vararg", value) == -1) | |
| 2962 | + goto failed; | |
| 2963 | + Py_DECREF(value); | |
| 2964 | + value = ast2obj_identifier(o->kwarg); | |
| 2965 | + if (!value) goto failed; | |
| 2966 | + if (PyObject_SetAttrString(result, "kwarg", value) == -1) | |
| 2967 | + goto failed; | |
| 2968 | + Py_DECREF(value); | |
| 2969 | + value = ast2obj_list(o->defaults, ast2obj_expr); | |
| 2970 | + if (!value) goto failed; | |
| 2971 | + if (PyObject_SetAttrString(result, "defaults", value) == -1) | |
| 2972 | + goto failed; | |
| 2973 | + Py_DECREF(value); | |
| 2974 | + return result; | |
| 2975 | +failed: | |
| 2976 | + Py_XDECREF(value); | |
| 2977 | + Py_XDECREF(result); | |
| 2978 | + return NULL; | |
| 2979 | +} | |
| 2980 | + | |
| 2981 | +PyObject* | |
| 2982 | +ast2obj_keyword(void* _o) | |
| 2983 | +{ | |
| 2984 | + keyword_ty o = (keyword_ty)_o; | |
| 2985 | + PyObject *result = NULL, *value = NULL; | |
| 2986 | + if (!o) { | |
| 2987 | + Py_INCREF(Py_None); | |
| 2988 | + return Py_None; | |
| 2989 | + } | |
| 2990 | + | |
| 2991 | + result = PyType_GenericNew(keyword_type, NULL, NULL); | |
| 2992 | + if (!result) return NULL; | |
| 2993 | + value = ast2obj_identifier(o->arg); | |
| 2994 | + if (!value) goto failed; | |
| 2995 | + if (PyObject_SetAttrString(result, "arg", value) == -1) | |
| 2996 | + goto failed; | |
| 2997 | + Py_DECREF(value); | |
| 2998 | + value = ast2obj_expr(o->value); | |
| 2999 | + if (!value) goto failed; | |
| 3000 | + if (PyObject_SetAttrString(result, "value", value) == -1) | |
| 3001 | + goto failed; | |
| 3002 | + Py_DECREF(value); | |
| 3003 | + return result; | |
| 3004 | +failed: | |
| 3005 | + Py_XDECREF(value); | |
| 3006 | + Py_XDECREF(result); | |
| 3007 | + return NULL; | |
| 3008 | +} | |
| 3009 | + | |
| 3010 | +PyObject* | |
| 3011 | +ast2obj_alias(void* _o) | |
| 3012 | +{ | |
| 3013 | + alias_ty o = (alias_ty)_o; | |
| 3014 | + PyObject *result = NULL, *value = NULL; | |
| 3015 | + if (!o) { | |
| 3016 | + Py_INCREF(Py_None); | |
| 3017 | + return Py_None; | |
| 3018 | + } | |
| 3019 | + | |
| 3020 | + result = PyType_GenericNew(alias_type, NULL, NULL); | |
| 3021 | + if (!result) return NULL; | |
| 3022 | + value = ast2obj_identifier(o->name); | |
| 3023 | + if (!value) goto failed; | |
| 3024 | + if (PyObject_SetAttrString(result, "name", value) == -1) | |
| 3025 | + goto failed; | |
| 3026 | + Py_DECREF(value); | |
| 3027 | + value = ast2obj_identifier(o->asname); | |
| 3028 | + if (!value) goto failed; | |
| 3029 | + if (PyObject_SetAttrString(result, "asname", value) == -1) | |
| 3030 | + goto failed; | |
| 3031 | + Py_DECREF(value); | |
| 3032 | + return result; | |
| 3033 | +failed: | |
| 3034 | + Py_XDECREF(value); | |
| 3035 | + Py_XDECREF(result); | |
| 3036 | + return NULL; | |
| 3037 | +} | |
| 3038 | + | |
| 3039 | + | |
| 3040 | +PyMODINIT_FUNC | |
| 3041 | +init_ast(void) | |
| 3042 | +{ | |
| 3043 | + PyObject *m, *d; | |
| 3044 | + if (!init_types()) return; | |
| 3045 | + m = Py_InitModule3("_ast", NULL, NULL); | |
| 3046 | + if (!m) return; | |
| 3047 | + d = PyModule_GetDict(m); | |
| 3048 | + if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; | |
| 3049 | + if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) | |
| 3050 | + return; | |
| 3051 | + if (PyModule_AddStringConstant(m, "__version__", "43614") < 0) | |
| 3052 | + return; | |
| 3053 | + if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; | |
| 3054 | + if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) | |
| 3055 | + return; | |
| 3056 | + if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) | |
| 3057 | + < 0) return; | |
| 3058 | + if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < | |
| 3059 | + 0) return; | |
| 3060 | + if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; | |
| 3061 | + if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; | |
| 3062 | + if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) | |
| 3063 | + < 0) return; | |
| 3064 | + if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) | |
| 3065 | + return; | |
| 3066 | + if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) | |
| 3067 | + return; | |
| 3068 | + if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) | |
| 3069 | + return; | |
| 3070 | + if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) | |
| 3071 | + return; | |
| 3072 | + if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < | |
| 3073 | + 0) return; | |
| 3074 | + if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return; | |
| 3075 | + if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; | |
| 3076 | + if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; | |
| 3077 | + if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; | |
| 3078 | + if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; | |
| 3079 | + if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; | |
| 3080 | + if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < | |
| 3081 | + 0) return; | |
| 3082 | + if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < | |
| 3083 | + 0) return; | |
| 3084 | + if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) | |
| 3085 | + return; | |
| 3086 | + if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) | |
| 3087 | + return; | |
| 3088 | + if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < | |
| 3089 | + 0) return; | |
| 3090 | + if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return; | |
| 3091 | + if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) | |
| 3092 | + return; | |
| 3093 | + if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; | |
| 3094 | + if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; | |
| 3095 | + if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; | |
| 3096 | + if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) | |
| 3097 | + return; | |
| 3098 | + if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; | |
| 3099 | + if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) | |
| 3100 | + return; | |
| 3101 | + if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; | |
| 3102 | + if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) | |
| 3103 | + return; | |
| 3104 | + if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) | |
| 3105 | + return; | |
| 3106 | + if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; | |
| 3107 | + if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; | |
| 3108 | + if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) | |
| 3109 | + return; | |
| 3110 | + if (PyDict_SetItemString(d, "GeneratorExp", | |
| 3111 | + (PyObject*)GeneratorExp_type) < 0) return; | |
| 3112 | + if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; | |
| 3113 | + if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) | |
| 3114 | + return; | |
| 3115 | + if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; | |
| 3116 | + if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return; | |
| 3117 | + if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; | |
| 3118 | + if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; | |
| 3119 | + if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < | |
| 3120 | + 0) return; | |
| 3121 | + if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < | |
| 3122 | + 0) return; | |
| 3123 | + if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; | |
| 3124 | + if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; | |
| 3125 | + if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; | |
| 3126 | + if (PyDict_SetItemString(d, "expr_context", | |
| 3127 | + (PyObject*)expr_context_type) < 0) return; | |
| 3128 | + if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; | |
| 3129 | + if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; | |
| 3130 | + if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; | |
| 3131 | + if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) | |
| 3132 | + return; | |
| 3133 | + if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) | |
| 3134 | + return; | |
| 3135 | + if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; | |
| 3136 | + if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; | |
| 3137 | + if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) | |
| 3138 | + return; | |
| 3139 | + if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; | |
| 3140 | + if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) | |
| 3141 | + return; | |
| 3142 | + if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; | |
| 3143 | + if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) | |
| 3144 | + return; | |
| 3145 | + if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; | |
| 3146 | + if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; | |
| 3147 | + if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) | |
| 3148 | + return; | |
| 3149 | + if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; | |
| 3150 | + if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; | |
| 3151 | + if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; | |
| 3152 | + if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; | |
| 3153 | + if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; | |
| 3154 | + if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; | |
| 3155 | + if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) | |
| 3156 | + return; | |
| 3157 | + if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) | |
| 3158 | + return; | |
| 3159 | + if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; | |
| 3160 | + if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) | |
| 3161 | + return; | |
| 3162 | + if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) | |
| 3163 | + return; | |
| 3164 | + if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) | |
| 3165 | + return; | |
| 3166 | + if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) | |
| 3167 | + return; | |
| 3168 | + if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) | |
| 3169 | + return; | |
| 3170 | + if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; | |
| 3171 | + if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; | |
| 3172 | + if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; | |
| 3173 | + if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; | |
| 3174 | + if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; | |
| 3175 | + if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; | |
| 3176 | + if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; | |
| 3177 | + if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; | |
| 3178 | + if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; | |
| 3179 | + if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; | |
| 3180 | + if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; | |
| 3181 | + if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; | |
| 3182 | + if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; | |
| 3183 | + if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; | |
| 3184 | + if (PyDict_SetItemString(d, "comprehension", | |
| 3185 | + (PyObject*)comprehension_type) < 0) return; | |
| 3186 | + if (PyDict_SetItemString(d, "excepthandler", | |
| 3187 | + (PyObject*)excepthandler_type) < 0) return; | |
| 3188 | + if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < | |
| 3189 | + 0) return; | |
| 3190 | + if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) | |
| 3191 | + return; | |
| 3192 | + if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; | |
| 3193 | +} | |
| 3194 | + | |
| 3195 | + | |
| 3196 | +PyObject* PyAST_mod2obj(mod_ty t) | |
| 3197 | +{ | |
| 3198 | + init_types(); | |
| 3199 | + return ast2obj_mod(t); | |
| 3200 | +} | |
| 3201 | + | |
| 3202 | + | |