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