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