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