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