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