Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 36660:3c0b26113df6 legacy-trunk
Generate code to recursively copy an AST into
a tree of Python objects. Expose this through compile().
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sun, 26 Feb 2006 19:42:26 +0000 |
| parents | 85b2d804ac0a |
| children | 710cbdd478a8 |
comparison
equal
deleted
inserted
replaced
| 36659:bb48115e6dab | 36660:3c0b26113df6 |
|---|---|
| 1 /* File automatically generated by Parser/asdl_c.py */ | 1 /* File automatically generated by Parser/asdl_c.py */ |
| 2 | 2 |
| 3 #include "Python.h" | 3 #include "Python.h" |
| 4 #include "Python-ast.h" | 4 #include "Python-ast.h" |
| 5 | 5 |
| 6 static int marshal_write_mod(PyObject **, int *, mod_ty); | 6 PyTypeObject *mod_type; |
| 7 static int marshal_write_stmt(PyObject **, int *, stmt_ty); | 7 static PyObject* ast2obj_mod(void*); |
| 8 static int marshal_write_expr(PyObject **, int *, expr_ty); | 8 PyTypeObject *Module_type; |
| 9 static int marshal_write_expr_context(PyObject **, int *, expr_context_ty); | 9 char *Module_fields[]={ |
| 10 static int marshal_write_slice(PyObject **, int *, slice_ty); | 10 "body", |
| 11 static int marshal_write_boolop(PyObject **, int *, boolop_ty); | 11 }; |
| 12 static int marshal_write_operator(PyObject **, int *, operator_ty); | 12 PyTypeObject *Interactive_type; |
| 13 static int marshal_write_unaryop(PyObject **, int *, unaryop_ty); | 13 char *Interactive_fields[]={ |
| 14 static int marshal_write_cmpop(PyObject **, int *, cmpop_ty); | 14 "body", |
| 15 static int marshal_write_comprehension(PyObject **, int *, comprehension_ty); | 15 }; |
| 16 static int marshal_write_excepthandler(PyObject **, int *, excepthandler_ty); | 16 PyTypeObject *Expression_type; |
| 17 static int marshal_write_arguments(PyObject **, int *, arguments_ty); | 17 char *Expression_fields[]={ |
| 18 static int marshal_write_keyword(PyObject **, int *, keyword_ty); | 18 "body", |
| 19 static int marshal_write_alias(PyObject **, int *, alias_ty); | 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 } | |
| 20 | 617 |
| 21 mod_ty | 618 mod_ty |
| 22 Module(asdl_seq * body, PyArena *arena) | 619 Module(asdl_seq * body, PyArena *arena) |
| 23 { | 620 { |
| 24 mod_ty p; | 621 mod_ty p; |
| 1094 p->asname = asname; | 1691 p->asname = asname; |
| 1095 return p; | 1692 return p; |
| 1096 } | 1693 } |
| 1097 | 1694 |
| 1098 | 1695 |
| 1099 | 1696 PyObject* |
| 1100 #define CHECKSIZE(BUF, OFF, MIN) { \ | 1697 ast2obj_mod(void* _o) |
| 1101 int need = *(OFF) + MIN; \ | 1698 { |
| 1102 if (need >= PyString_GET_SIZE(*(BUF))) { \ | 1699 mod_ty o = (mod_ty)_o; |
| 1103 int newsize = PyString_GET_SIZE(*(BUF)) * 2; \ | 1700 PyObject *result = NULL, *value = NULL; |
| 1104 if (newsize < need) \ | 1701 if (!o) { |
| 1105 newsize = need; \ | 1702 Py_INCREF(Py_None); |
| 1106 if (_PyString_Resize((BUF), newsize) < 0) \ | 1703 return Py_None; |
| 1107 return 0; \ | 1704 } |
| 1108 } \ | 1705 |
| 1109 } | |
| 1110 | |
| 1111 static int | |
| 1112 marshal_write_int(PyObject **buf, int *offset, int x) | |
| 1113 { | |
| 1114 char *s; | |
| 1115 | |
| 1116 CHECKSIZE(buf, offset, 4) | |
| 1117 s = PyString_AS_STRING(*buf) + (*offset); | |
| 1118 s[0] = (x & 0xff); | |
| 1119 s[1] = (x >> 8) & 0xff; | |
| 1120 s[2] = (x >> 16) & 0xff; | |
| 1121 s[3] = (x >> 24) & 0xff; | |
| 1122 *offset += 4; | |
| 1123 return 1; | |
| 1124 } | |
| 1125 | |
| 1126 static int | |
| 1127 marshal_write_bool(PyObject **buf, int *offset, bool b) | |
| 1128 { | |
| 1129 if (b) | |
| 1130 marshal_write_int(buf, offset, 1); | |
| 1131 else | |
| 1132 marshal_write_int(buf, offset, 0); | |
| 1133 return 1; | |
| 1134 } | |
| 1135 | |
| 1136 static int | |
| 1137 marshal_write_identifier(PyObject **buf, int *offset, identifier id) | |
| 1138 { | |
| 1139 int l = PyString_GET_SIZE(id); | |
| 1140 marshal_write_int(buf, offset, l); | |
| 1141 CHECKSIZE(buf, offset, l); | |
| 1142 memcpy(PyString_AS_STRING(*buf) + *offset, | |
| 1143 PyString_AS_STRING(id), l); | |
| 1144 *offset += l; | |
| 1145 return 1; | |
| 1146 } | |
| 1147 | |
| 1148 static int | |
| 1149 marshal_write_string(PyObject **buf, int *offset, string s) | |
| 1150 { | |
| 1151 int len = PyString_GET_SIZE(s); | |
| 1152 marshal_write_int(buf, offset, len); | |
| 1153 CHECKSIZE(buf, offset, len); | |
| 1154 memcpy(PyString_AS_STRING(*buf) + *offset, | |
| 1155 PyString_AS_STRING(s), len); | |
| 1156 *offset += len; | |
| 1157 return 1; | |
| 1158 } | |
| 1159 | |
| 1160 static int | |
| 1161 marshal_write_object(PyObject **buf, int *offset, object s) | |
| 1162 { | |
| 1163 /* XXX */ | |
| 1164 return 0; | |
| 1165 } | |
| 1166 | |
| 1167 | |
| 1168 static int | |
| 1169 marshal_write_mod(PyObject **buf, int *off, mod_ty o) | |
| 1170 { | |
| 1171 int i; | |
| 1172 switch (o->kind) { | 1706 switch (o->kind) { |
| 1173 case Module_kind: | 1707 case Module_kind: |
| 1174 marshal_write_int(buf, off, 1); | 1708 result = PyType_GenericNew(Module_type, NULL, NULL); |
| 1175 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Module.body)); | 1709 if (!result) goto failed; |
| 1176 for (i = 0; i < asdl_seq_LEN(o->v.Module.body); i++) { | 1710 value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 1177 void *elt = asdl_seq_GET(o->v.Module.body, i); | 1711 if (!value) goto failed; |
| 1178 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1712 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1179 } | 1713 goto failed; |
| 1714 Py_DECREF(value); | |
| 1180 break; | 1715 break; |
| 1181 case Interactive_kind: | 1716 case Interactive_kind: |
| 1182 marshal_write_int(buf, off, 2); | 1717 result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 1183 marshal_write_int(buf, off, | 1718 if (!result) goto failed; |
| 1184 asdl_seq_LEN(o->v.Interactive.body)); | 1719 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 1185 for (i = 0; i < asdl_seq_LEN(o->v.Interactive.body); i++) { | 1720 if (!value) goto failed; |
| 1186 void *elt = asdl_seq_GET(o->v.Interactive.body, i); | 1721 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1187 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1722 goto failed; |
| 1188 } | 1723 Py_DECREF(value); |
| 1189 break; | 1724 break; |
| 1190 case Expression_kind: | 1725 case Expression_kind: |
| 1191 marshal_write_int(buf, off, 3); | 1726 result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 1192 marshal_write_expr(buf, off, o->v.Expression.body); | 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); | |
| 1193 break; | 1733 break; |
| 1194 case Suite_kind: | 1734 case Suite_kind: |
| 1195 marshal_write_int(buf, off, 4); | 1735 result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 1196 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Suite.body)); | 1736 if (!result) goto failed; |
| 1197 for (i = 0; i < asdl_seq_LEN(o->v.Suite.body); i++) { | 1737 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 1198 void *elt = asdl_seq_GET(o->v.Suite.body, i); | 1738 if (!value) goto failed; |
| 1199 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1739 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1200 } | 1740 goto failed; |
| 1201 break; | 1741 Py_DECREF(value); |
| 1202 } | 1742 break; |
| 1203 return 1; | 1743 } |
| 1204 } | 1744 |
| 1205 | 1745 return result; |
| 1206 static int | 1746 failed: |
| 1207 marshal_write_stmt(PyObject **buf, int *off, stmt_ty o) | 1747 Py_XDECREF(value); |
| 1208 { | 1748 Py_XDECREF(result); |
| 1209 int i; | 1749 return NULL; |
| 1750 } | |
| 1751 | |
| 1752 PyObject* | |
| 1753 ast2obj_stmt(void* _o) | |
| 1754 { | |
| 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 | |
| 1210 switch (o->kind) { | 1762 switch (o->kind) { |
| 1211 case FunctionDef_kind: | 1763 case FunctionDef_kind: |
| 1212 marshal_write_int(buf, off, 1); | 1764 result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 1213 marshal_write_identifier(buf, off, o->v.FunctionDef.name); | 1765 if (!result) goto failed; |
| 1214 marshal_write_arguments(buf, off, o->v.FunctionDef.args); | 1766 value = ast2obj_identifier(o->v.FunctionDef.name); |
| 1215 marshal_write_int(buf, off, | 1767 if (!value) goto failed; |
| 1216 asdl_seq_LEN(o->v.FunctionDef.body)); | 1768 if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1217 for (i = 0; i < asdl_seq_LEN(o->v.FunctionDef.body); i++) { | 1769 goto failed; |
| 1218 void *elt = asdl_seq_GET(o->v.FunctionDef.body, i); | 1770 Py_DECREF(value); |
| 1219 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1771 value = ast2obj_arguments(o->v.FunctionDef.args); |
| 1220 } | 1772 if (!value) goto failed; |
| 1221 marshal_write_int(buf, off, | 1773 if (PyObject_SetAttrString(result, "args", value) == -1) |
| 1222 asdl_seq_LEN(o->v.FunctionDef.decorators)); | 1774 goto failed; |
| 1223 for (i = 0; i < asdl_seq_LEN(o->v.FunctionDef.decorators); i++) | 1775 Py_DECREF(value); |
| 1224 { | 1776 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 1225 void *elt = asdl_seq_GET(o->v.FunctionDef.decorators, | 1777 if (!value) goto failed; |
| 1226 i); | 1778 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1227 marshal_write_expr(buf, off, (expr_ty)elt); | 1779 goto failed; |
| 1228 } | 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); | |
| 1229 break; | 1786 break; |
| 1230 case ClassDef_kind: | 1787 case ClassDef_kind: |
| 1231 marshal_write_int(buf, off, 2); | 1788 result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 1232 marshal_write_identifier(buf, off, o->v.ClassDef.name); | 1789 if (!result) goto failed; |
| 1233 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ClassDef.bases)); | 1790 value = ast2obj_identifier(o->v.ClassDef.name); |
| 1234 for (i = 0; i < asdl_seq_LEN(o->v.ClassDef.bases); i++) { | 1791 if (!value) goto failed; |
| 1235 void *elt = asdl_seq_GET(o->v.ClassDef.bases, i); | 1792 if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1236 marshal_write_expr(buf, off, (expr_ty)elt); | 1793 goto failed; |
| 1237 } | 1794 Py_DECREF(value); |
| 1238 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ClassDef.body)); | 1795 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 1239 for (i = 0; i < asdl_seq_LEN(o->v.ClassDef.body); i++) { | 1796 if (!value) goto failed; |
| 1240 void *elt = asdl_seq_GET(o->v.ClassDef.body, i); | 1797 if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 1241 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1798 goto failed; |
| 1242 } | 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); | |
| 1243 break; | 1805 break; |
| 1244 case Return_kind: | 1806 case Return_kind: |
| 1245 marshal_write_int(buf, off, 3); | 1807 result = PyType_GenericNew(Return_type, NULL, NULL); |
| 1246 if (o->v.Return.value) { | 1808 if (!result) goto failed; |
| 1247 marshal_write_int(buf, off, 1); | 1809 value = ast2obj_expr(o->v.Return.value); |
| 1248 marshal_write_expr(buf, off, o->v.Return.value); | 1810 if (!value) goto failed; |
| 1249 } | 1811 if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1250 else { | 1812 goto failed; |
| 1251 marshal_write_int(buf, off, 0); | 1813 Py_DECREF(value); |
| 1252 } | |
| 1253 break; | 1814 break; |
| 1254 case Delete_kind: | 1815 case Delete_kind: |
| 1255 marshal_write_int(buf, off, 4); | 1816 result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 1256 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Delete.targets)); | 1817 if (!result) goto failed; |
| 1257 for (i = 0; i < asdl_seq_LEN(o->v.Delete.targets); i++) { | 1818 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 1258 void *elt = asdl_seq_GET(o->v.Delete.targets, i); | 1819 if (!value) goto failed; |
| 1259 marshal_write_expr(buf, off, (expr_ty)elt); | 1820 if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 1260 } | 1821 goto failed; |
| 1822 Py_DECREF(value); | |
| 1261 break; | 1823 break; |
| 1262 case Assign_kind: | 1824 case Assign_kind: |
| 1263 marshal_write_int(buf, off, 5); | 1825 result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 1264 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Assign.targets)); | 1826 if (!result) goto failed; |
| 1265 for (i = 0; i < asdl_seq_LEN(o->v.Assign.targets); i++) { | 1827 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 1266 void *elt = asdl_seq_GET(o->v.Assign.targets, i); | 1828 if (!value) goto failed; |
| 1267 marshal_write_expr(buf, off, (expr_ty)elt); | 1829 if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 1268 } | 1830 goto failed; |
| 1269 marshal_write_expr(buf, off, o->v.Assign.value); | 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); | |
| 1270 break; | 1837 break; |
| 1271 case AugAssign_kind: | 1838 case AugAssign_kind: |
| 1272 marshal_write_int(buf, off, 6); | 1839 result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 1273 marshal_write_expr(buf, off, o->v.AugAssign.target); | 1840 if (!result) goto failed; |
| 1274 marshal_write_operator(buf, off, o->v.AugAssign.op); | 1841 value = ast2obj_expr(o->v.AugAssign.target); |
| 1275 marshal_write_expr(buf, off, o->v.AugAssign.value); | 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); | |
| 1276 break; | 1856 break; |
| 1277 case Print_kind: | 1857 case Print_kind: |
| 1278 marshal_write_int(buf, off, 7); | 1858 result = PyType_GenericNew(Print_type, NULL, NULL); |
| 1279 if (o->v.Print.dest) { | 1859 if (!result) goto failed; |
| 1280 marshal_write_int(buf, off, 1); | 1860 value = ast2obj_expr(o->v.Print.dest); |
| 1281 marshal_write_expr(buf, off, o->v.Print.dest); | 1861 if (!value) goto failed; |
| 1282 } | 1862 if (PyObject_SetAttrString(result, "dest", value) == -1) |
| 1283 else { | 1863 goto failed; |
| 1284 marshal_write_int(buf, off, 0); | 1864 Py_DECREF(value); |
| 1285 } | 1865 value = ast2obj_list(o->v.Print.values, ast2obj_expr); |
| 1286 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Print.values)); | 1866 if (!value) goto failed; |
| 1287 for (i = 0; i < asdl_seq_LEN(o->v.Print.values); i++) { | 1867 if (PyObject_SetAttrString(result, "values", value) == -1) |
| 1288 void *elt = asdl_seq_GET(o->v.Print.values, i); | 1868 goto failed; |
| 1289 marshal_write_expr(buf, off, (expr_ty)elt); | 1869 Py_DECREF(value); |
| 1290 } | 1870 value = ast2obj_bool(o->v.Print.nl); |
| 1291 marshal_write_bool(buf, off, o->v.Print.nl); | 1871 if (!value) goto failed; |
| 1872 if (PyObject_SetAttrString(result, "nl", value) == -1) | |
| 1873 goto failed; | |
| 1874 Py_DECREF(value); | |
| 1292 break; | 1875 break; |
| 1293 case For_kind: | 1876 case For_kind: |
| 1294 marshal_write_int(buf, off, 8); | 1877 result = PyType_GenericNew(For_type, NULL, NULL); |
| 1295 marshal_write_expr(buf, off, o->v.For.target); | 1878 if (!result) goto failed; |
| 1296 marshal_write_expr(buf, off, o->v.For.iter); | 1879 value = ast2obj_expr(o->v.For.target); |
| 1297 marshal_write_int(buf, off, asdl_seq_LEN(o->v.For.body)); | 1880 if (!value) goto failed; |
| 1298 for (i = 0; i < asdl_seq_LEN(o->v.For.body); i++) { | 1881 if (PyObject_SetAttrString(result, "target", value) == -1) |
| 1299 void *elt = asdl_seq_GET(o->v.For.body, i); | 1882 goto failed; |
| 1300 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1883 Py_DECREF(value); |
| 1301 } | 1884 value = ast2obj_expr(o->v.For.iter); |
| 1302 marshal_write_int(buf, off, asdl_seq_LEN(o->v.For.orelse)); | 1885 if (!value) goto failed; |
| 1303 for (i = 0; i < asdl_seq_LEN(o->v.For.orelse); i++) { | 1886 if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 1304 void *elt = asdl_seq_GET(o->v.For.orelse, i); | 1887 goto failed; |
| 1305 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1888 Py_DECREF(value); |
| 1306 } | 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); | |
| 1307 break; | 1899 break; |
| 1308 case While_kind: | 1900 case While_kind: |
| 1309 marshal_write_int(buf, off, 9); | 1901 result = PyType_GenericNew(While_type, NULL, NULL); |
| 1310 marshal_write_expr(buf, off, o->v.While.test); | 1902 if (!result) goto failed; |
| 1311 marshal_write_int(buf, off, asdl_seq_LEN(o->v.While.body)); | 1903 value = ast2obj_expr(o->v.While.test); |
| 1312 for (i = 0; i < asdl_seq_LEN(o->v.While.body); i++) { | 1904 if (!value) goto failed; |
| 1313 void *elt = asdl_seq_GET(o->v.While.body, i); | 1905 if (PyObject_SetAttrString(result, "test", value) == -1) |
| 1314 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1906 goto failed; |
| 1315 } | 1907 Py_DECREF(value); |
| 1316 marshal_write_int(buf, off, asdl_seq_LEN(o->v.While.orelse)); | 1908 value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 1317 for (i = 0; i < asdl_seq_LEN(o->v.While.orelse); i++) { | 1909 if (!value) goto failed; |
| 1318 void *elt = asdl_seq_GET(o->v.While.orelse, i); | 1910 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1319 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1911 goto failed; |
| 1320 } | 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); | |
| 1321 break; | 1918 break; |
| 1322 case If_kind: | 1919 case If_kind: |
| 1323 marshal_write_int(buf, off, 10); | 1920 result = PyType_GenericNew(If_type, NULL, NULL); |
| 1324 marshal_write_expr(buf, off, o->v.If.test); | 1921 if (!result) goto failed; |
| 1325 marshal_write_int(buf, off, asdl_seq_LEN(o->v.If.body)); | 1922 value = ast2obj_expr(o->v.If.test); |
| 1326 for (i = 0; i < asdl_seq_LEN(o->v.If.body); i++) { | 1923 if (!value) goto failed; |
| 1327 void *elt = asdl_seq_GET(o->v.If.body, i); | 1924 if (PyObject_SetAttrString(result, "test", value) == -1) |
| 1328 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1925 goto failed; |
| 1329 } | 1926 Py_DECREF(value); |
| 1330 marshal_write_int(buf, off, asdl_seq_LEN(o->v.If.orelse)); | 1927 value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 1331 for (i = 0; i < asdl_seq_LEN(o->v.If.orelse); i++) { | 1928 if (!value) goto failed; |
| 1332 void *elt = asdl_seq_GET(o->v.If.orelse, i); | 1929 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1333 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1930 goto failed; |
| 1334 } | 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); | |
| 1335 break; | 1937 break; |
| 1336 case Raise_kind: | 1938 case Raise_kind: |
| 1337 marshal_write_int(buf, off, 11); | 1939 result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 1338 if (o->v.Raise.type) { | 1940 if (!result) goto failed; |
| 1339 marshal_write_int(buf, off, 1); | 1941 value = ast2obj_expr(o->v.Raise.type); |
| 1340 marshal_write_expr(buf, off, o->v.Raise.type); | 1942 if (!value) goto failed; |
| 1341 } | 1943 if (PyObject_SetAttrString(result, "type", value) == -1) |
| 1342 else { | 1944 goto failed; |
| 1343 marshal_write_int(buf, off, 0); | 1945 Py_DECREF(value); |
| 1344 } | 1946 value = ast2obj_expr(o->v.Raise.inst); |
| 1345 if (o->v.Raise.inst) { | 1947 if (!value) goto failed; |
| 1346 marshal_write_int(buf, off, 1); | 1948 if (PyObject_SetAttrString(result, "inst", value) == -1) |
| 1347 marshal_write_expr(buf, off, o->v.Raise.inst); | 1949 goto failed; |
| 1348 } | 1950 Py_DECREF(value); |
| 1349 else { | 1951 value = ast2obj_expr(o->v.Raise.tback); |
| 1350 marshal_write_int(buf, off, 0); | 1952 if (!value) goto failed; |
| 1351 } | 1953 if (PyObject_SetAttrString(result, "tback", value) == -1) |
| 1352 if (o->v.Raise.tback) { | 1954 goto failed; |
| 1353 marshal_write_int(buf, off, 1); | 1955 Py_DECREF(value); |
| 1354 marshal_write_expr(buf, off, o->v.Raise.tback); | |
| 1355 } | |
| 1356 else { | |
| 1357 marshal_write_int(buf, off, 0); | |
| 1358 } | |
| 1359 break; | 1956 break; |
| 1360 case TryExcept_kind: | 1957 case TryExcept_kind: |
| 1361 marshal_write_int(buf, off, 12); | 1958 result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 1362 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryExcept.body)); | 1959 if (!result) goto failed; |
| 1363 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.body); i++) { | 1960 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 1364 void *elt = asdl_seq_GET(o->v.TryExcept.body, i); | 1961 if (!value) goto failed; |
| 1365 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1962 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1366 } | 1963 goto failed; |
| 1367 marshal_write_int(buf, off, | 1964 Py_DECREF(value); |
| 1368 asdl_seq_LEN(o->v.TryExcept.handlers)); | 1965 value = ast2obj_list(o->v.TryExcept.handlers, |
| 1369 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.handlers); i++) { | 1966 ast2obj_excepthandler); |
| 1370 void *elt = asdl_seq_GET(o->v.TryExcept.handlers, i); | 1967 if (!value) goto failed; |
| 1371 marshal_write_excepthandler(buf, off, | 1968 if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 1372 (excepthandler_ty)elt); | 1969 goto failed; |
| 1373 } | 1970 Py_DECREF(value); |
| 1374 marshal_write_int(buf, off, | 1971 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 1375 asdl_seq_LEN(o->v.TryExcept.orelse)); | 1972 if (!value) goto failed; |
| 1376 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.orelse); i++) { | 1973 if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 1377 void *elt = asdl_seq_GET(o->v.TryExcept.orelse, i); | 1974 goto failed; |
| 1378 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1975 Py_DECREF(value); |
| 1379 } | |
| 1380 break; | 1976 break; |
| 1381 case TryFinally_kind: | 1977 case TryFinally_kind: |
| 1382 marshal_write_int(buf, off, 13); | 1978 result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 1383 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryFinally.body)); | 1979 if (!result) goto failed; |
| 1384 for (i = 0; i < asdl_seq_LEN(o->v.TryFinally.body); i++) { | 1980 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 1385 void *elt = asdl_seq_GET(o->v.TryFinally.body, i); | 1981 if (!value) goto failed; |
| 1386 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1982 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1387 } | 1983 goto failed; |
| 1388 marshal_write_int(buf, off, | 1984 Py_DECREF(value); |
| 1389 asdl_seq_LEN(o->v.TryFinally.finalbody)); | 1985 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 1390 for (i = 0; i < asdl_seq_LEN(o->v.TryFinally.finalbody); i++) { | 1986 if (!value) goto failed; |
| 1391 void *elt = asdl_seq_GET(o->v.TryFinally.finalbody, i); | 1987 if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 1392 marshal_write_stmt(buf, off, (stmt_ty)elt); | 1988 goto failed; |
| 1393 } | 1989 Py_DECREF(value); |
| 1394 break; | 1990 break; |
| 1395 case Assert_kind: | 1991 case Assert_kind: |
| 1396 marshal_write_int(buf, off, 14); | 1992 result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 1397 marshal_write_expr(buf, off, o->v.Assert.test); | 1993 if (!result) goto failed; |
| 1398 if (o->v.Assert.msg) { | 1994 value = ast2obj_expr(o->v.Assert.test); |
| 1399 marshal_write_int(buf, off, 1); | 1995 if (!value) goto failed; |
| 1400 marshal_write_expr(buf, off, o->v.Assert.msg); | 1996 if (PyObject_SetAttrString(result, "test", value) == -1) |
| 1401 } | 1997 goto failed; |
| 1402 else { | 1998 Py_DECREF(value); |
| 1403 marshal_write_int(buf, off, 0); | 1999 value = ast2obj_expr(o->v.Assert.msg); |
| 1404 } | 2000 if (!value) goto failed; |
| 2001 if (PyObject_SetAttrString(result, "msg", value) == -1) | |
| 2002 goto failed; | |
| 2003 Py_DECREF(value); | |
| 1405 break; | 2004 break; |
| 1406 case Import_kind: | 2005 case Import_kind: |
| 1407 marshal_write_int(buf, off, 15); | 2006 result = PyType_GenericNew(Import_type, NULL, NULL); |
| 1408 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Import.names)); | 2007 if (!result) goto failed; |
| 1409 for (i = 0; i < asdl_seq_LEN(o->v.Import.names); i++) { | 2008 value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 1410 void *elt = asdl_seq_GET(o->v.Import.names, i); | 2009 if (!value) goto failed; |
| 1411 marshal_write_alias(buf, off, (alias_ty)elt); | 2010 if (PyObject_SetAttrString(result, "names", value) == -1) |
| 1412 } | 2011 goto failed; |
| 2012 Py_DECREF(value); | |
| 1413 break; | 2013 break; |
| 1414 case ImportFrom_kind: | 2014 case ImportFrom_kind: |
| 1415 marshal_write_int(buf, off, 16); | 2015 result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 1416 marshal_write_identifier(buf, off, o->v.ImportFrom.module); | 2016 if (!result) goto failed; |
| 1417 marshal_write_int(buf, off, | 2017 value = ast2obj_identifier(o->v.ImportFrom.module); |
| 1418 asdl_seq_LEN(o->v.ImportFrom.names)); | 2018 if (!value) goto failed; |
| 1419 for (i = 0; i < asdl_seq_LEN(o->v.ImportFrom.names); i++) { | 2019 if (PyObject_SetAttrString(result, "module", value) == -1) |
| 1420 void *elt = asdl_seq_GET(o->v.ImportFrom.names, i); | 2020 goto failed; |
| 1421 marshal_write_alias(buf, off, (alias_ty)elt); | 2021 Py_DECREF(value); |
| 1422 } | 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); | |
| 1423 break; | 2027 break; |
| 1424 case Exec_kind: | 2028 case Exec_kind: |
| 1425 marshal_write_int(buf, off, 17); | 2029 result = PyType_GenericNew(Exec_type, NULL, NULL); |
| 1426 marshal_write_expr(buf, off, o->v.Exec.body); | 2030 if (!result) goto failed; |
| 1427 if (o->v.Exec.globals) { | 2031 value = ast2obj_expr(o->v.Exec.body); |
| 1428 marshal_write_int(buf, off, 1); | 2032 if (!value) goto failed; |
| 1429 marshal_write_expr(buf, off, o->v.Exec.globals); | 2033 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1430 } | 2034 goto failed; |
| 1431 else { | 2035 Py_DECREF(value); |
| 1432 marshal_write_int(buf, off, 0); | 2036 value = ast2obj_expr(o->v.Exec.globals); |
| 1433 } | 2037 if (!value) goto failed; |
| 1434 if (o->v.Exec.locals) { | 2038 if (PyObject_SetAttrString(result, "globals", value) == -1) |
| 1435 marshal_write_int(buf, off, 1); | 2039 goto failed; |
| 1436 marshal_write_expr(buf, off, o->v.Exec.locals); | 2040 Py_DECREF(value); |
| 1437 } | 2041 value = ast2obj_expr(o->v.Exec.locals); |
| 1438 else { | 2042 if (!value) goto failed; |
| 1439 marshal_write_int(buf, off, 0); | 2043 if (PyObject_SetAttrString(result, "locals", value) == -1) |
| 1440 } | 2044 goto failed; |
| 2045 Py_DECREF(value); | |
| 1441 break; | 2046 break; |
| 1442 case Global_kind: | 2047 case Global_kind: |
| 1443 marshal_write_int(buf, off, 18); | 2048 result = PyType_GenericNew(Global_type, NULL, NULL); |
| 1444 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Global.names)); | 2049 if (!result) goto failed; |
| 1445 for (i = 0; i < asdl_seq_LEN(o->v.Global.names); i++) { | 2050 value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 1446 void *elt = asdl_seq_GET(o->v.Global.names, i); | 2051 if (!value) goto failed; |
| 1447 marshal_write_identifier(buf, off, (identifier)elt); | 2052 if (PyObject_SetAttrString(result, "names", value) == -1) |
| 1448 } | 2053 goto failed; |
| 2054 Py_DECREF(value); | |
| 1449 break; | 2055 break; |
| 1450 case Expr_kind: | 2056 case Expr_kind: |
| 1451 marshal_write_int(buf, off, 19); | 2057 result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 1452 marshal_write_expr(buf, off, o->v.Expr.value); | 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); | |
| 1453 break; | 2064 break; |
| 1454 case Pass_kind: | 2065 case Pass_kind: |
| 1455 marshal_write_int(buf, off, 20); | 2066 result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2067 if (!result) goto failed; | |
| 1456 break; | 2068 break; |
| 1457 case Break_kind: | 2069 case Break_kind: |
| 1458 marshal_write_int(buf, off, 21); | 2070 result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2071 if (!result) goto failed; | |
| 1459 break; | 2072 break; |
| 1460 case Continue_kind: | 2073 case Continue_kind: |
| 1461 marshal_write_int(buf, off, 22); | 2074 result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 1462 break; | 2075 if (!result) goto failed; |
| 1463 } | 2076 break; |
| 1464 return 1; | 2077 } |
| 1465 } | 2078 |
| 1466 | 2079 return result; |
| 1467 static int | 2080 failed: |
| 1468 marshal_write_expr(PyObject **buf, int *off, expr_ty o) | 2081 Py_XDECREF(value); |
| 1469 { | 2082 Py_XDECREF(result); |
| 1470 int i; | 2083 return NULL; |
| 2084 } | |
| 2085 | |
| 2086 PyObject* | |
| 2087 ast2obj_expr(void* _o) | |
| 2088 { | |
| 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 | |
| 1471 switch (o->kind) { | 2096 switch (o->kind) { |
| 1472 case BoolOp_kind: | 2097 case BoolOp_kind: |
| 1473 marshal_write_int(buf, off, 1); | 2098 result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 1474 marshal_write_boolop(buf, off, o->v.BoolOp.op); | 2099 if (!result) goto failed; |
| 1475 marshal_write_int(buf, off, asdl_seq_LEN(o->v.BoolOp.values)); | 2100 value = ast2obj_boolop(o->v.BoolOp.op); |
| 1476 for (i = 0; i < asdl_seq_LEN(o->v.BoolOp.values); i++) { | 2101 if (!value) goto failed; |
| 1477 void *elt = asdl_seq_GET(o->v.BoolOp.values, i); | 2102 if (PyObject_SetAttrString(result, "op", value) == -1) |
| 1478 marshal_write_expr(buf, off, (expr_ty)elt); | 2103 goto failed; |
| 1479 } | 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); | |
| 1480 break; | 2110 break; |
| 1481 case BinOp_kind: | 2111 case BinOp_kind: |
| 1482 marshal_write_int(buf, off, 2); | 2112 result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 1483 marshal_write_expr(buf, off, o->v.BinOp.left); | 2113 if (!result) goto failed; |
| 1484 marshal_write_operator(buf, off, o->v.BinOp.op); | 2114 value = ast2obj_expr(o->v.BinOp.left); |
| 1485 marshal_write_expr(buf, off, o->v.BinOp.right); | 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); | |
| 1486 break; | 2129 break; |
| 1487 case UnaryOp_kind: | 2130 case UnaryOp_kind: |
| 1488 marshal_write_int(buf, off, 3); | 2131 result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 1489 marshal_write_unaryop(buf, off, o->v.UnaryOp.op); | 2132 if (!result) goto failed; |
| 1490 marshal_write_expr(buf, off, o->v.UnaryOp.operand); | 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); | |
| 1491 break; | 2143 break; |
| 1492 case Lambda_kind: | 2144 case Lambda_kind: |
| 1493 marshal_write_int(buf, off, 4); | 2145 result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 1494 marshal_write_arguments(buf, off, o->v.Lambda.args); | 2146 if (!result) goto failed; |
| 1495 marshal_write_expr(buf, off, o->v.Lambda.body); | 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); | |
| 1496 break; | 2157 break; |
| 1497 case Dict_kind: | 2158 case Dict_kind: |
| 1498 marshal_write_int(buf, off, 5); | 2159 result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 1499 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Dict.keys)); | 2160 if (!result) goto failed; |
| 1500 for (i = 0; i < asdl_seq_LEN(o->v.Dict.keys); i++) { | 2161 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 1501 void *elt = asdl_seq_GET(o->v.Dict.keys, i); | 2162 if (!value) goto failed; |
| 1502 marshal_write_expr(buf, off, (expr_ty)elt); | 2163 if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 1503 } | 2164 goto failed; |
| 1504 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Dict.values)); | 2165 Py_DECREF(value); |
| 1505 for (i = 0; i < asdl_seq_LEN(o->v.Dict.values); i++) { | 2166 value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 1506 void *elt = asdl_seq_GET(o->v.Dict.values, i); | 2167 if (!value) goto failed; |
| 1507 marshal_write_expr(buf, off, (expr_ty)elt); | 2168 if (PyObject_SetAttrString(result, "values", value) == -1) |
| 1508 } | 2169 goto failed; |
| 2170 Py_DECREF(value); | |
| 1509 break; | 2171 break; |
| 1510 case ListComp_kind: | 2172 case ListComp_kind: |
| 1511 marshal_write_int(buf, off, 6); | 2173 result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 1512 marshal_write_expr(buf, off, o->v.ListComp.elt); | 2174 if (!result) goto failed; |
| 1513 marshal_write_int(buf, off, | 2175 value = ast2obj_expr(o->v.ListComp.elt); |
| 1514 asdl_seq_LEN(o->v.ListComp.generators)); | 2176 if (!value) goto failed; |
| 1515 for (i = 0; i < asdl_seq_LEN(o->v.ListComp.generators); i++) { | 2177 if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 1516 void *elt = asdl_seq_GET(o->v.ListComp.generators, i); | 2178 goto failed; |
| 1517 marshal_write_comprehension(buf, off, | 2179 Py_DECREF(value); |
| 1518 (comprehension_ty)elt); | 2180 value = ast2obj_list(o->v.ListComp.generators, |
| 1519 } | 2181 ast2obj_comprehension); |
| 2182 if (!value) goto failed; | |
| 2183 if (PyObject_SetAttrString(result, "generators", value) == -1) | |
| 2184 goto failed; | |
| 2185 Py_DECREF(value); | |
| 1520 break; | 2186 break; |
| 1521 case GeneratorExp_kind: | 2187 case GeneratorExp_kind: |
| 1522 marshal_write_int(buf, off, 7); | 2188 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 1523 marshal_write_expr(buf, off, o->v.GeneratorExp.elt); | 2189 if (!result) goto failed; |
| 1524 marshal_write_int(buf, off, | 2190 value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 1525 asdl_seq_LEN(o->v.GeneratorExp.generators)); | 2191 if (!value) goto failed; |
| 1526 for (i = 0; i < asdl_seq_LEN(o->v.GeneratorExp.generators); | 2192 if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 1527 i++) { | 2193 goto failed; |
| 1528 void *elt = asdl_seq_GET(o->v.GeneratorExp.generators, | 2194 Py_DECREF(value); |
| 1529 i); | 2195 value = ast2obj_list(o->v.GeneratorExp.generators, |
| 1530 marshal_write_comprehension(buf, off, | 2196 ast2obj_comprehension); |
| 1531 (comprehension_ty)elt); | 2197 if (!value) goto failed; |
| 1532 } | 2198 if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2199 goto failed; | |
| 2200 Py_DECREF(value); | |
| 1533 break; | 2201 break; |
| 1534 case Yield_kind: | 2202 case Yield_kind: |
| 1535 marshal_write_int(buf, off, 8); | 2203 result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 1536 if (o->v.Yield.value) { | 2204 if (!result) goto failed; |
| 1537 marshal_write_int(buf, off, 1); | 2205 value = ast2obj_expr(o->v.Yield.value); |
| 1538 marshal_write_expr(buf, off, o->v.Yield.value); | 2206 if (!value) goto failed; |
| 1539 } | 2207 if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1540 else { | 2208 goto failed; |
| 1541 marshal_write_int(buf, off, 0); | 2209 Py_DECREF(value); |
| 1542 } | |
| 1543 break; | 2210 break; |
| 1544 case Compare_kind: | 2211 case Compare_kind: |
| 1545 marshal_write_int(buf, off, 9); | 2212 result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 1546 marshal_write_expr(buf, off, o->v.Compare.left); | 2213 if (!result) goto failed; |
| 1547 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Compare.ops)); | 2214 value = ast2obj_expr(o->v.Compare.left); |
| 1548 for (i = 0; i < asdl_seq_LEN(o->v.Compare.ops); i++) { | 2215 if (!value) goto failed; |
| 1549 void *elt = asdl_seq_GET(o->v.Compare.ops, i); | 2216 if (PyObject_SetAttrString(result, "left", value) == -1) |
| 1550 marshal_write_cmpop(buf, off, (cmpop_ty)elt); | 2217 goto failed; |
| 1551 } | 2218 Py_DECREF(value); |
| 1552 marshal_write_int(buf, off, | 2219 value = ast2obj_list(o->v.Compare.ops, |
| 1553 asdl_seq_LEN(o->v.Compare.comparators)); | 2220 (PyObject*(*)(void*))ast2obj_cmpop); |
| 1554 for (i = 0; i < asdl_seq_LEN(o->v.Compare.comparators); i++) { | 2221 if (!value) goto failed; |
| 1555 void *elt = asdl_seq_GET(o->v.Compare.comparators, i); | 2222 if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 1556 marshal_write_expr(buf, off, (expr_ty)elt); | 2223 goto failed; |
| 1557 } | 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); | |
| 1558 break; | 2230 break; |
| 1559 case Call_kind: | 2231 case Call_kind: |
| 1560 marshal_write_int(buf, off, 10); | 2232 result = PyType_GenericNew(Call_type, NULL, NULL); |
| 1561 marshal_write_expr(buf, off, o->v.Call.func); | 2233 if (!result) goto failed; |
| 1562 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.args)); | 2234 value = ast2obj_expr(o->v.Call.func); |
| 1563 for (i = 0; i < asdl_seq_LEN(o->v.Call.args); i++) { | 2235 if (!value) goto failed; |
| 1564 void *elt = asdl_seq_GET(o->v.Call.args, i); | 2236 if (PyObject_SetAttrString(result, "func", value) == -1) |
| 1565 marshal_write_expr(buf, off, (expr_ty)elt); | 2237 goto failed; |
| 1566 } | 2238 Py_DECREF(value); |
| 1567 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.keywords)); | 2239 value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 1568 for (i = 0; i < asdl_seq_LEN(o->v.Call.keywords); i++) { | 2240 if (!value) goto failed; |
| 1569 void *elt = asdl_seq_GET(o->v.Call.keywords, i); | 2241 if (PyObject_SetAttrString(result, "args", value) == -1) |
| 1570 marshal_write_keyword(buf, off, (keyword_ty)elt); | 2242 goto failed; |
| 1571 } | 2243 Py_DECREF(value); |
| 1572 if (o->v.Call.starargs) { | 2244 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 1573 marshal_write_int(buf, off, 1); | 2245 if (!value) goto failed; |
| 1574 marshal_write_expr(buf, off, o->v.Call.starargs); | 2246 if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 1575 } | 2247 goto failed; |
| 1576 else { | 2248 Py_DECREF(value); |
| 1577 marshal_write_int(buf, off, 0); | 2249 value = ast2obj_expr(o->v.Call.starargs); |
| 1578 } | 2250 if (!value) goto failed; |
| 1579 if (o->v.Call.kwargs) { | 2251 if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 1580 marshal_write_int(buf, off, 1); | 2252 goto failed; |
| 1581 marshal_write_expr(buf, off, o->v.Call.kwargs); | 2253 Py_DECREF(value); |
| 1582 } | 2254 value = ast2obj_expr(o->v.Call.kwargs); |
| 1583 else { | 2255 if (!value) goto failed; |
| 1584 marshal_write_int(buf, off, 0); | 2256 if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 1585 } | 2257 goto failed; |
| 2258 Py_DECREF(value); | |
| 1586 break; | 2259 break; |
| 1587 case Repr_kind: | 2260 case Repr_kind: |
| 1588 marshal_write_int(buf, off, 11); | 2261 result = PyType_GenericNew(Repr_type, NULL, NULL); |
| 1589 marshal_write_expr(buf, off, o->v.Repr.value); | 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); | |
| 1590 break; | 2268 break; |
| 1591 case Num_kind: | 2269 case Num_kind: |
| 1592 marshal_write_int(buf, off, 12); | 2270 result = PyType_GenericNew(Num_type, NULL, NULL); |
| 1593 marshal_write_object(buf, off, o->v.Num.n); | 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); | |
| 1594 break; | 2277 break; |
| 1595 case Str_kind: | 2278 case Str_kind: |
| 1596 marshal_write_int(buf, off, 13); | 2279 result = PyType_GenericNew(Str_type, NULL, NULL); |
| 1597 marshal_write_string(buf, off, o->v.Str.s); | 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); | |
| 1598 break; | 2286 break; |
| 1599 case Attribute_kind: | 2287 case Attribute_kind: |
| 1600 marshal_write_int(buf, off, 14); | 2288 result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 1601 marshal_write_expr(buf, off, o->v.Attribute.value); | 2289 if (!result) goto failed; |
| 1602 marshal_write_identifier(buf, off, o->v.Attribute.attr); | 2290 value = ast2obj_expr(o->v.Attribute.value); |
| 1603 marshal_write_expr_context(buf, off, o->v.Attribute.ctx); | 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); | |
| 1604 break; | 2305 break; |
| 1605 case Subscript_kind: | 2306 case Subscript_kind: |
| 1606 marshal_write_int(buf, off, 15); | 2307 result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 1607 marshal_write_expr(buf, off, o->v.Subscript.value); | 2308 if (!result) goto failed; |
| 1608 marshal_write_slice(buf, off, o->v.Subscript.slice); | 2309 value = ast2obj_expr(o->v.Subscript.value); |
| 1609 marshal_write_expr_context(buf, off, o->v.Subscript.ctx); | 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); | |
| 1610 break; | 2324 break; |
| 1611 case Name_kind: | 2325 case Name_kind: |
| 1612 marshal_write_int(buf, off, 16); | 2326 result = PyType_GenericNew(Name_type, NULL, NULL); |
| 1613 marshal_write_identifier(buf, off, o->v.Name.id); | 2327 if (!result) goto failed; |
| 1614 marshal_write_expr_context(buf, off, o->v.Name.ctx); | 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); | |
| 1615 break; | 2338 break; |
| 1616 case List_kind: | 2339 case List_kind: |
| 1617 marshal_write_int(buf, off, 17); | 2340 result = PyType_GenericNew(List_type, NULL, NULL); |
| 1618 marshal_write_int(buf, off, asdl_seq_LEN(o->v.List.elts)); | 2341 if (!result) goto failed; |
| 1619 for (i = 0; i < asdl_seq_LEN(o->v.List.elts); i++) { | 2342 value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 1620 void *elt = asdl_seq_GET(o->v.List.elts, i); | 2343 if (!value) goto failed; |
| 1621 marshal_write_expr(buf, off, (expr_ty)elt); | 2344 if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 1622 } | 2345 goto failed; |
| 1623 marshal_write_expr_context(buf, off, o->v.List.ctx); | 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); | |
| 1624 break; | 2352 break; |
| 1625 case Tuple_kind: | 2353 case Tuple_kind: |
| 1626 marshal_write_int(buf, off, 18); | 2354 result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 1627 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Tuple.elts)); | 2355 if (!result) goto failed; |
| 1628 for (i = 0; i < asdl_seq_LEN(o->v.Tuple.elts); i++) { | 2356 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 1629 void *elt = asdl_seq_GET(o->v.Tuple.elts, i); | 2357 if (!value) goto failed; |
| 1630 marshal_write_expr(buf, off, (expr_ty)elt); | 2358 if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 1631 } | 2359 goto failed; |
| 1632 marshal_write_expr_context(buf, off, o->v.Tuple.ctx); | 2360 Py_DECREF(value); |
| 1633 break; | 2361 value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 1634 } | 2362 if (!value) goto failed; |
| 1635 return 1; | 2363 if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 1636 } | 2364 goto failed; |
| 1637 | 2365 Py_DECREF(value); |
| 1638 static int | 2366 break; |
| 1639 marshal_write_expr_context(PyObject **buf, int *off, expr_context_ty o) | 2367 } |
| 1640 { | 2368 |
| 1641 switch (o) { | 2369 return result; |
| 1642 case Load: | 2370 failed: |
| 1643 marshal_write_int(buf, off, 1); | 2371 Py_XDECREF(value); |
| 1644 break; | 2372 Py_XDECREF(result); |
| 1645 case Store: | 2373 return NULL; |
| 1646 marshal_write_int(buf, off, 2); | 2374 } |
| 1647 break; | 2375 |
| 1648 case Del: | 2376 PyObject* ast2obj_expr_context(expr_context_ty o) |
| 1649 marshal_write_int(buf, off, 3); | 2377 { |
| 1650 break; | 2378 switch(o) { |
| 1651 case AugLoad: | 2379 case Load: |
| 1652 marshal_write_int(buf, off, 4); | 2380 Py_INCREF(Load_singleton); |
| 1653 break; | 2381 return Load_singleton; |
| 1654 case AugStore: | 2382 case Store: |
| 1655 marshal_write_int(buf, off, 5); | 2383 Py_INCREF(Store_singleton); |
| 1656 break; | 2384 return Store_singleton; |
| 1657 case Param: | 2385 case Del: |
| 1658 marshal_write_int(buf, off, 6); | 2386 Py_INCREF(Del_singleton); |
| 1659 break; | 2387 return Del_singleton; |
| 1660 } | 2388 case AugLoad: |
| 1661 return 1; | 2389 Py_INCREF(AugLoad_singleton); |
| 1662 } | 2390 return AugLoad_singleton; |
| 1663 | 2391 case AugStore: |
| 1664 static int | 2392 Py_INCREF(AugStore_singleton); |
| 1665 marshal_write_slice(PyObject **buf, int *off, slice_ty o) | 2393 return AugStore_singleton; |
| 1666 { | 2394 case Param: |
| 1667 int i; | 2395 Py_INCREF(Param_singleton); |
| 2396 return Param_singleton; | |
| 2397 } | |
| 2398 return NULL; /* cannot happen */ | |
| 2399 } | |
| 2400 PyObject* | |
| 2401 ast2obj_slice(void* _o) | |
| 2402 { | |
| 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 | |
| 1668 switch (o->kind) { | 2410 switch (o->kind) { |
| 1669 case Ellipsis_kind: | 2411 case Ellipsis_kind: |
| 1670 marshal_write_int(buf, off, 1); | 2412 result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2413 if (!result) goto failed; | |
| 1671 break; | 2414 break; |
| 1672 case Slice_kind: | 2415 case Slice_kind: |
| 1673 marshal_write_int(buf, off, 2); | 2416 result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 1674 if (o->v.Slice.lower) { | 2417 if (!result) goto failed; |
| 1675 marshal_write_int(buf, off, 1); | 2418 value = ast2obj_expr(o->v.Slice.lower); |
| 1676 marshal_write_expr(buf, off, o->v.Slice.lower); | 2419 if (!value) goto failed; |
| 1677 } | 2420 if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 1678 else { | 2421 goto failed; |
| 1679 marshal_write_int(buf, off, 0); | 2422 Py_DECREF(value); |
| 1680 } | 2423 value = ast2obj_expr(o->v.Slice.upper); |
| 1681 if (o->v.Slice.upper) { | 2424 if (!value) goto failed; |
| 1682 marshal_write_int(buf, off, 1); | 2425 if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 1683 marshal_write_expr(buf, off, o->v.Slice.upper); | 2426 goto failed; |
| 1684 } | 2427 Py_DECREF(value); |
| 1685 else { | 2428 value = ast2obj_expr(o->v.Slice.step); |
| 1686 marshal_write_int(buf, off, 0); | 2429 if (!value) goto failed; |
| 1687 } | 2430 if (PyObject_SetAttrString(result, "step", value) == -1) |
| 1688 if (o->v.Slice.step) { | 2431 goto failed; |
| 1689 marshal_write_int(buf, off, 1); | 2432 Py_DECREF(value); |
| 1690 marshal_write_expr(buf, off, o->v.Slice.step); | |
| 1691 } | |
| 1692 else { | |
| 1693 marshal_write_int(buf, off, 0); | |
| 1694 } | |
| 1695 break; | 2433 break; |
| 1696 case ExtSlice_kind: | 2434 case ExtSlice_kind: |
| 1697 marshal_write_int(buf, off, 3); | 2435 result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 1698 marshal_write_int(buf, off, asdl_seq_LEN(o->v.ExtSlice.dims)); | 2436 if (!result) goto failed; |
| 1699 for (i = 0; i < asdl_seq_LEN(o->v.ExtSlice.dims); i++) { | 2437 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 1700 void *elt = asdl_seq_GET(o->v.ExtSlice.dims, i); | 2438 if (!value) goto failed; |
| 1701 marshal_write_slice(buf, off, (slice_ty)elt); | 2439 if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 1702 } | 2440 goto failed; |
| 2441 Py_DECREF(value); | |
| 1703 break; | 2442 break; |
| 1704 case Index_kind: | 2443 case Index_kind: |
| 1705 marshal_write_int(buf, off, 4); | 2444 result = PyType_GenericNew(Index_type, NULL, NULL); |
| 1706 marshal_write_expr(buf, off, o->v.Index.value); | 2445 if (!result) goto failed; |
| 1707 break; | 2446 value = ast2obj_expr(o->v.Index.value); |
| 1708 } | 2447 if (!value) goto failed; |
| 1709 return 1; | 2448 if (PyObject_SetAttrString(result, "value", value) == -1) |
| 1710 } | 2449 goto failed; |
| 1711 | 2450 Py_DECREF(value); |
| 1712 static int | 2451 break; |
| 1713 marshal_write_boolop(PyObject **buf, int *off, boolop_ty o) | 2452 } |
| 1714 { | 2453 |
| 1715 switch (o) { | 2454 return result; |
| 1716 case And: | 2455 failed: |
| 1717 marshal_write_int(buf, off, 1); | 2456 Py_XDECREF(value); |
| 1718 break; | 2457 Py_XDECREF(result); |
| 1719 case Or: | 2458 return NULL; |
| 1720 marshal_write_int(buf, off, 2); | 2459 } |
| 1721 break; | 2460 |
| 1722 } | 2461 PyObject* ast2obj_boolop(boolop_ty o) |
| 1723 return 1; | 2462 { |
| 1724 } | 2463 switch(o) { |
| 1725 | 2464 case And: |
| 1726 static int | 2465 Py_INCREF(And_singleton); |
| 1727 marshal_write_operator(PyObject **buf, int *off, operator_ty o) | 2466 return And_singleton; |
| 1728 { | 2467 case Or: |
| 1729 switch (o) { | 2468 Py_INCREF(Or_singleton); |
| 1730 case Add: | 2469 return Or_singleton; |
| 1731 marshal_write_int(buf, off, 1); | 2470 } |
| 1732 break; | 2471 return NULL; /* cannot happen */ |
| 1733 case Sub: | 2472 } |
| 1734 marshal_write_int(buf, off, 2); | 2473 PyObject* ast2obj_operator(operator_ty o) |
| 1735 break; | 2474 { |
| 1736 case Mult: | 2475 switch(o) { |
| 1737 marshal_write_int(buf, off, 3); | 2476 case Add: |
| 1738 break; | 2477 Py_INCREF(Add_singleton); |
| 1739 case Div: | 2478 return Add_singleton; |
| 1740 marshal_write_int(buf, off, 4); | 2479 case Sub: |
| 1741 break; | 2480 Py_INCREF(Sub_singleton); |
| 1742 case Mod: | 2481 return Sub_singleton; |
| 1743 marshal_write_int(buf, off, 5); | 2482 case Mult: |
| 1744 break; | 2483 Py_INCREF(Mult_singleton); |
| 1745 case Pow: | 2484 return Mult_singleton; |
| 1746 marshal_write_int(buf, off, 6); | 2485 case Div: |
| 1747 break; | 2486 Py_INCREF(Div_singleton); |
| 1748 case LShift: | 2487 return Div_singleton; |
| 1749 marshal_write_int(buf, off, 7); | 2488 case Mod: |
| 1750 break; | 2489 Py_INCREF(Mod_singleton); |
| 1751 case RShift: | 2490 return Mod_singleton; |
| 1752 marshal_write_int(buf, off, 8); | 2491 case Pow: |
| 1753 break; | 2492 Py_INCREF(Pow_singleton); |
| 1754 case BitOr: | 2493 return Pow_singleton; |
| 1755 marshal_write_int(buf, off, 9); | 2494 case LShift: |
| 1756 break; | 2495 Py_INCREF(LShift_singleton); |
| 1757 case BitXor: | 2496 return LShift_singleton; |
| 1758 marshal_write_int(buf, off, 10); | 2497 case RShift: |
| 1759 break; | 2498 Py_INCREF(RShift_singleton); |
| 1760 case BitAnd: | 2499 return RShift_singleton; |
| 1761 marshal_write_int(buf, off, 11); | 2500 case BitOr: |
| 1762 break; | 2501 Py_INCREF(BitOr_singleton); |
| 1763 case FloorDiv: | 2502 return BitOr_singleton; |
| 1764 marshal_write_int(buf, off, 12); | 2503 case BitXor: |
| 1765 break; | 2504 Py_INCREF(BitXor_singleton); |
| 1766 } | 2505 return BitXor_singleton; |
| 1767 return 1; | 2506 case BitAnd: |
| 1768 } | 2507 Py_INCREF(BitAnd_singleton); |
| 1769 | 2508 return BitAnd_singleton; |
| 1770 static int | 2509 case FloorDiv: |
| 1771 marshal_write_unaryop(PyObject **buf, int *off, unaryop_ty o) | 2510 Py_INCREF(FloorDiv_singleton); |
| 1772 { | 2511 return FloorDiv_singleton; |
| 1773 switch (o) { | 2512 } |
| 1774 case Invert: | 2513 return NULL; /* cannot happen */ |
| 1775 marshal_write_int(buf, off, 1); | 2514 } |
| 1776 break; | 2515 PyObject* ast2obj_unaryop(unaryop_ty o) |
| 1777 case Not: | 2516 { |
| 1778 marshal_write_int(buf, off, 2); | 2517 switch(o) { |
| 1779 break; | 2518 case Invert: |
| 1780 case UAdd: | 2519 Py_INCREF(Invert_singleton); |
| 1781 marshal_write_int(buf, off, 3); | 2520 return Invert_singleton; |
| 1782 break; | 2521 case Not: |
| 1783 case USub: | 2522 Py_INCREF(Not_singleton); |
| 1784 marshal_write_int(buf, off, 4); | 2523 return Not_singleton; |
| 1785 break; | 2524 case UAdd: |
| 1786 } | 2525 Py_INCREF(UAdd_singleton); |
| 1787 return 1; | 2526 return UAdd_singleton; |
| 1788 } | 2527 case USub: |
| 1789 | 2528 Py_INCREF(USub_singleton); |
| 1790 static int | 2529 return USub_singleton; |
| 1791 marshal_write_cmpop(PyObject **buf, int *off, cmpop_ty o) | 2530 } |
| 1792 { | 2531 return NULL; /* cannot happen */ |
| 1793 switch (o) { | 2532 } |
| 1794 case Eq: | 2533 PyObject* ast2obj_cmpop(cmpop_ty o) |
| 1795 marshal_write_int(buf, off, 1); | 2534 { |
| 1796 break; | 2535 switch(o) { |
| 1797 case NotEq: | 2536 case Eq: |
| 1798 marshal_write_int(buf, off, 2); | 2537 Py_INCREF(Eq_singleton); |
| 1799 break; | 2538 return Eq_singleton; |
| 1800 case Lt: | 2539 case NotEq: |
| 1801 marshal_write_int(buf, off, 3); | 2540 Py_INCREF(NotEq_singleton); |
| 1802 break; | 2541 return NotEq_singleton; |
| 1803 case LtE: | 2542 case Lt: |
| 1804 marshal_write_int(buf, off, 4); | 2543 Py_INCREF(Lt_singleton); |
| 1805 break; | 2544 return Lt_singleton; |
| 1806 case Gt: | 2545 case LtE: |
| 1807 marshal_write_int(buf, off, 5); | 2546 Py_INCREF(LtE_singleton); |
| 1808 break; | 2547 return LtE_singleton; |
| 1809 case GtE: | 2548 case Gt: |
| 1810 marshal_write_int(buf, off, 6); | 2549 Py_INCREF(Gt_singleton); |
| 1811 break; | 2550 return Gt_singleton; |
| 1812 case Is: | 2551 case GtE: |
| 1813 marshal_write_int(buf, off, 7); | 2552 Py_INCREF(GtE_singleton); |
| 1814 break; | 2553 return GtE_singleton; |
| 1815 case IsNot: | 2554 case Is: |
| 1816 marshal_write_int(buf, off, 8); | 2555 Py_INCREF(Is_singleton); |
| 1817 break; | 2556 return Is_singleton; |
| 1818 case In: | 2557 case IsNot: |
| 1819 marshal_write_int(buf, off, 9); | 2558 Py_INCREF(IsNot_singleton); |
| 1820 break; | 2559 return IsNot_singleton; |
| 1821 case NotIn: | 2560 case In: |
| 1822 marshal_write_int(buf, off, 10); | 2561 Py_INCREF(In_singleton); |
| 1823 break; | 2562 return In_singleton; |
| 1824 } | 2563 case NotIn: |
| 1825 return 1; | 2564 Py_INCREF(NotIn_singleton); |
| 1826 } | 2565 return NotIn_singleton; |
| 1827 | 2566 } |
| 1828 static int | 2567 return NULL; /* cannot happen */ |
| 1829 marshal_write_comprehension(PyObject **buf, int *off, comprehension_ty o) | 2568 } |
| 1830 { | 2569 PyObject* |
| 1831 int i; | 2570 ast2obj_comprehension(void* _o) |
| 1832 marshal_write_expr(buf, off, o->target); | 2571 { |
| 1833 marshal_write_expr(buf, off, o->iter); | 2572 comprehension_ty o = (comprehension_ty)_o; |
| 1834 marshal_write_int(buf, off, asdl_seq_LEN(o->ifs)); | 2573 PyObject *result = NULL, *value = NULL; |
| 1835 for (i = 0; i < asdl_seq_LEN(o->ifs); i++) { | 2574 if (!o) { |
| 1836 void *elt = asdl_seq_GET(o->ifs, i); | 2575 Py_INCREF(Py_None); |
| 1837 marshal_write_expr(buf, off, (expr_ty)elt); | 2576 return Py_None; |
| 1838 } | 2577 } |
| 1839 return 1; | 2578 |
| 1840 } | 2579 result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 1841 | 2580 if (!result) return NULL; |
| 1842 static int | 2581 value = ast2obj_expr(o->target); |
| 1843 marshal_write_excepthandler(PyObject **buf, int *off, excepthandler_ty o) | 2582 if (!value) goto failed; |
| 1844 { | 2583 if (PyObject_SetAttrString(result, "target", value) == -1) |
| 1845 int i; | 2584 goto failed; |
| 1846 if (o->type) { | 2585 Py_DECREF(value); |
| 1847 marshal_write_int(buf, off, 1); | 2586 value = ast2obj_expr(o->iter); |
| 1848 marshal_write_expr(buf, off, o->type); | 2587 if (!value) goto failed; |
| 1849 } | 2588 if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 1850 else { | 2589 goto failed; |
| 1851 marshal_write_int(buf, off, 0); | 2590 Py_DECREF(value); |
| 1852 } | 2591 value = ast2obj_list(o->ifs, ast2obj_expr); |
| 1853 if (o->name) { | 2592 if (!value) goto failed; |
| 1854 marshal_write_int(buf, off, 1); | 2593 if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 1855 marshal_write_expr(buf, off, o->name); | 2594 goto failed; |
| 1856 } | 2595 Py_DECREF(value); |
| 1857 else { | 2596 |
| 1858 marshal_write_int(buf, off, 0); | 2597 return result; |
| 1859 } | 2598 failed: |
| 1860 marshal_write_int(buf, off, asdl_seq_LEN(o->body)); | 2599 Py_XDECREF(value); |
| 1861 for (i = 0; i < asdl_seq_LEN(o->body); i++) { | 2600 Py_XDECREF(result); |
| 1862 void *elt = asdl_seq_GET(o->body, i); | 2601 return NULL; |
| 1863 marshal_write_stmt(buf, off, (stmt_ty)elt); | 2602 } |
| 1864 } | 2603 |
| 1865 return 1; | 2604 PyObject* |
| 1866 } | 2605 ast2obj_excepthandler(void* _o) |
| 1867 | 2606 { |
| 1868 static int | 2607 excepthandler_ty o = (excepthandler_ty)_o; |
| 1869 marshal_write_arguments(PyObject **buf, int *off, arguments_ty o) | 2608 PyObject *result = NULL, *value = NULL; |
| 1870 { | 2609 if (!o) { |
| 1871 int i; | 2610 Py_INCREF(Py_None); |
| 1872 marshal_write_int(buf, off, asdl_seq_LEN(o->args)); | 2611 return Py_None; |
| 1873 for (i = 0; i < asdl_seq_LEN(o->args); i++) { | 2612 } |
| 1874 void *elt = asdl_seq_GET(o->args, i); | 2613 |
| 1875 marshal_write_expr(buf, off, (expr_ty)elt); | 2614 result = PyType_GenericNew(excepthandler_type, NULL, NULL); |
| 1876 } | 2615 if (!result) return NULL; |
| 1877 if (o->vararg) { | 2616 value = ast2obj_expr(o->type); |
| 1878 marshal_write_int(buf, off, 1); | 2617 if (!value) goto failed; |
| 1879 marshal_write_identifier(buf, off, o->vararg); | 2618 if (PyObject_SetAttrString(result, "type", value) == -1) |
| 1880 } | 2619 goto failed; |
| 1881 else { | 2620 Py_DECREF(value); |
| 1882 marshal_write_int(buf, off, 0); | 2621 value = ast2obj_expr(o->name); |
| 1883 } | 2622 if (!value) goto failed; |
| 1884 if (o->kwarg) { | 2623 if (PyObject_SetAttrString(result, "name", value) == -1) |
| 1885 marshal_write_int(buf, off, 1); | 2624 goto failed; |
| 1886 marshal_write_identifier(buf, off, o->kwarg); | 2625 Py_DECREF(value); |
| 1887 } | 2626 value = ast2obj_list(o->body, ast2obj_stmt); |
| 1888 else { | 2627 if (!value) goto failed; |
| 1889 marshal_write_int(buf, off, 0); | 2628 if (PyObject_SetAttrString(result, "body", value) == -1) |
| 1890 } | 2629 goto failed; |
| 1891 marshal_write_int(buf, off, asdl_seq_LEN(o->defaults)); | 2630 Py_DECREF(value); |
| 1892 for (i = 0; i < asdl_seq_LEN(o->defaults); i++) { | 2631 |
| 1893 void *elt = asdl_seq_GET(o->defaults, i); | 2632 return result; |
| 1894 marshal_write_expr(buf, off, (expr_ty)elt); | 2633 failed: |
| 1895 } | 2634 Py_XDECREF(value); |
| 1896 return 1; | 2635 Py_XDECREF(result); |
| 1897 } | 2636 return NULL; |
| 1898 | 2637 } |
| 1899 static int | 2638 |
| 1900 marshal_write_keyword(PyObject **buf, int *off, keyword_ty o) | 2639 PyObject* |
| 1901 { | 2640 ast2obj_arguments(void* _o) |
| 1902 marshal_write_identifier(buf, off, o->arg); | 2641 { |
| 1903 marshal_write_expr(buf, off, o->value); | 2642 arguments_ty o = (arguments_ty)_o; |
| 1904 return 1; | 2643 PyObject *result = NULL, *value = NULL; |
| 1905 } | 2644 if (!o) { |
| 1906 | 2645 Py_INCREF(Py_None); |
| 1907 static int | 2646 return Py_None; |
| 1908 marshal_write_alias(PyObject **buf, int *off, alias_ty o) | 2647 } |
| 1909 { | 2648 |
| 1910 marshal_write_identifier(buf, off, o->name); | 2649 result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 1911 if (o->asname) { | 2650 if (!result) return NULL; |
| 1912 marshal_write_int(buf, off, 1); | 2651 value = ast2obj_list(o->args, ast2obj_expr); |
| 1913 marshal_write_identifier(buf, off, o->asname); | 2652 if (!value) goto failed; |
| 1914 } | 2653 if (PyObject_SetAttrString(result, "args", value) == -1) |
| 1915 else { | 2654 goto failed; |
| 1916 marshal_write_int(buf, off, 0); | 2655 Py_DECREF(value); |
| 1917 } | 2656 value = ast2obj_identifier(o->vararg); |
| 1918 return 1; | 2657 if (!value) goto failed; |
| 1919 } | 2658 if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 1920 | 2659 goto failed; |
| 1921 | 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; | |
| 2677 } | |
| 2678 | |
| 2679 PyObject* | |
| 2680 ast2obj_keyword(void* _o) | |
| 2681 { | |
| 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; | |
| 2687 } | |
| 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; | |
| 2707 } | |
| 2708 | |
| 2709 PyObject* | |
| 2710 ast2obj_alias(void* _o) | |
| 2711 { | |
| 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; | |
| 2717 } | |
| 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; | |
| 2737 } | |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 PyObject* PyAST_mod2obj(mod_ty t) | |
| 2742 { | |
| 2743 init_types(); | |
| 2744 return ast2obj_mod(t); | |
| 2745 } | |
| 2746 | |
| 2747 |
