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