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