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