Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
| 3 | |
| 4 | /* |
Christian Heimes | d3eb5a15 | 2008-02-24 00:38:49 +0000 | [diff] [blame] | 5 | __version__ 57783. |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 6 | |
| 7 | This module must be committed separately after each AST grammar change; |
| 8 | The __version__ number is set to the revision number of the commit |
| 9 | containing the grammar change. |
| 10 | */ |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | |
| 12 | #include "Python.h" |
| 13 | #include "Python-ast.h" |
| 14 | |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 15 | static PyTypeObject* AST_type; |
| 16 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Module_type; |
| 19 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 20 | "body", |
| 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Interactive_type; |
| 23 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 24 | "body", |
| 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *Expression_type; |
| 27 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 28 | "body", |
| 29 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 30 | static PyTypeObject *Suite_type; |
| 31 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 32 | "body", |
| 33 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 34 | static PyTypeObject *stmt_type; |
| 35 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 36 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 37 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 38 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 39 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 40 | static PyTypeObject *FunctionDef_type; |
| 41 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 45 | "decorator_list", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 46 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 47 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 48 | static PyTypeObject *ClassDef_type; |
| 49 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 50 | "name", |
| 51 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 52 | "keywords", |
| 53 | "starargs", |
| 54 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 55 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 56 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 57 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 58 | static PyTypeObject *Return_type; |
| 59 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 60 | "value", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *Delete_type; |
| 63 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "targets", |
| 65 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 66 | static PyTypeObject *Assign_type; |
| 67 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 68 | "targets", |
| 69 | "value", |
| 70 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 71 | static PyTypeObject *AugAssign_type; |
| 72 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 73 | "target", |
| 74 | "op", |
| 75 | "value", |
| 76 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 77 | static PyTypeObject *For_type; |
| 78 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 79 | "target", |
| 80 | "iter", |
| 81 | "body", |
| 82 | "orelse", |
| 83 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 84 | static PyTypeObject *While_type; |
| 85 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 86 | "test", |
| 87 | "body", |
| 88 | "orelse", |
| 89 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 90 | static PyTypeObject *If_type; |
| 91 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 92 | "test", |
| 93 | "body", |
| 94 | "orelse", |
| 95 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 96 | static PyTypeObject *With_type; |
| 97 | static char *With_fields[]={ |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 98 | "context_expr", |
| 99 | "optional_vars", |
| 100 | "body", |
| 101 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 102 | static PyTypeObject *Raise_type; |
| 103 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 104 | "exc", |
| 105 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static PyTypeObject *TryExcept_type; |
| 108 | static char *TryExcept_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 109 | "body", |
| 110 | "handlers", |
| 111 | "orelse", |
| 112 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 113 | static PyTypeObject *TryFinally_type; |
| 114 | static char *TryFinally_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 115 | "body", |
| 116 | "finalbody", |
| 117 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 118 | static PyTypeObject *Assert_type; |
| 119 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 120 | "test", |
| 121 | "msg", |
| 122 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 123 | static PyTypeObject *Import_type; |
| 124 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 125 | "names", |
| 126 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 127 | static PyTypeObject *ImportFrom_type; |
| 128 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 129 | "module", |
| 130 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 131 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 132 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 133 | static PyTypeObject *Global_type; |
| 134 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | "names", |
| 136 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 137 | static PyTypeObject *Nonlocal_type; |
| 138 | static char *Nonlocal_fields[]={ |
| 139 | "names", |
| 140 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 141 | static PyTypeObject *Expr_type; |
| 142 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 143 | "value", |
| 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *Pass_type; |
| 146 | static PyTypeObject *Break_type; |
| 147 | static PyTypeObject *Continue_type; |
| 148 | static PyTypeObject *expr_type; |
| 149 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 150 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 151 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 152 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 153 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 154 | static PyTypeObject *BoolOp_type; |
| 155 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 156 | "op", |
| 157 | "values", |
| 158 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *BinOp_type; |
| 160 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 161 | "left", |
| 162 | "op", |
| 163 | "right", |
| 164 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 165 | static PyTypeObject *UnaryOp_type; |
| 166 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 167 | "op", |
| 168 | "operand", |
| 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *Lambda_type; |
| 171 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 172 | "args", |
| 173 | "body", |
| 174 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 175 | static PyTypeObject *IfExp_type; |
| 176 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 177 | "test", |
| 178 | "body", |
| 179 | "orelse", |
| 180 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 181 | static PyTypeObject *Dict_type; |
| 182 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 183 | "keys", |
| 184 | "values", |
| 185 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 186 | static PyTypeObject *Set_type; |
| 187 | static char *Set_fields[]={ |
| 188 | "elts", |
| 189 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 190 | static PyTypeObject *ListComp_type; |
| 191 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 192 | "elt", |
| 193 | "generators", |
| 194 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 195 | static PyTypeObject *SetComp_type; |
| 196 | static char *SetComp_fields[]={ |
| 197 | "elt", |
| 198 | "generators", |
| 199 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 200 | static PyTypeObject *DictComp_type; |
| 201 | static char *DictComp_fields[]={ |
| 202 | "key", |
| 203 | "value", |
| 204 | "generators", |
| 205 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 206 | static PyTypeObject *GeneratorExp_type; |
| 207 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 208 | "elt", |
| 209 | "generators", |
| 210 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 211 | static PyTypeObject *Yield_type; |
| 212 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 213 | "value", |
| 214 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 215 | static PyTypeObject *Compare_type; |
| 216 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 217 | "left", |
| 218 | "ops", |
| 219 | "comparators", |
| 220 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 221 | static PyTypeObject *Call_type; |
| 222 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 223 | "func", |
| 224 | "args", |
| 225 | "keywords", |
| 226 | "starargs", |
| 227 | "kwargs", |
| 228 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 229 | static PyTypeObject *Num_type; |
| 230 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 231 | "n", |
| 232 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 233 | static PyTypeObject *Str_type; |
| 234 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 235 | "s", |
| 236 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 237 | static PyTypeObject *Bytes_type; |
| 238 | static char *Bytes_fields[]={ |
| 239 | "s", |
| 240 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 241 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 242 | static PyTypeObject *Attribute_type; |
| 243 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 244 | "value", |
| 245 | "attr", |
| 246 | "ctx", |
| 247 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 248 | static PyTypeObject *Subscript_type; |
| 249 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | "value", |
| 251 | "slice", |
| 252 | "ctx", |
| 253 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 254 | static PyTypeObject *Starred_type; |
| 255 | static char *Starred_fields[]={ |
| 256 | "value", |
| 257 | "ctx", |
| 258 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 259 | static PyTypeObject *Name_type; |
| 260 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 261 | "id", |
| 262 | "ctx", |
| 263 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 264 | static PyTypeObject *List_type; |
| 265 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 266 | "elts", |
| 267 | "ctx", |
| 268 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 269 | static PyTypeObject *Tuple_type; |
| 270 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 271 | "elts", |
| 272 | "ctx", |
| 273 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 274 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 275 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 276 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 277 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *Load_type; |
| 279 | static PyTypeObject *Store_type; |
| 280 | static PyTypeObject *Del_type; |
| 281 | static PyTypeObject *AugLoad_type; |
| 282 | static PyTypeObject *AugStore_type; |
| 283 | static PyTypeObject *Param_type; |
| 284 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 285 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 286 | static PyTypeObject *Slice_type; |
| 287 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 288 | "lower", |
| 289 | "upper", |
| 290 | "step", |
| 291 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 292 | static PyTypeObject *ExtSlice_type; |
| 293 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 294 | "dims", |
| 295 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 296 | static PyTypeObject *Index_type; |
| 297 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 298 | "value", |
| 299 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 300 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 301 | static PyObject *And_singleton, *Or_singleton; |
| 302 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 303 | static PyTypeObject *And_type; |
| 304 | static PyTypeObject *Or_type; |
| 305 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 306 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 307 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 308 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 309 | *FloorDiv_singleton; |
| 310 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 311 | static PyTypeObject *Add_type; |
| 312 | static PyTypeObject *Sub_type; |
| 313 | static PyTypeObject *Mult_type; |
| 314 | static PyTypeObject *Div_type; |
| 315 | static PyTypeObject *Mod_type; |
| 316 | static PyTypeObject *Pow_type; |
| 317 | static PyTypeObject *LShift_type; |
| 318 | static PyTypeObject *RShift_type; |
| 319 | static PyTypeObject *BitOr_type; |
| 320 | static PyTypeObject *BitXor_type; |
| 321 | static PyTypeObject *BitAnd_type; |
| 322 | static PyTypeObject *FloorDiv_type; |
| 323 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 324 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 325 | *USub_singleton; |
| 326 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 327 | static PyTypeObject *Invert_type; |
| 328 | static PyTypeObject *Not_type; |
| 329 | static PyTypeObject *UAdd_type; |
| 330 | static PyTypeObject *USub_type; |
| 331 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 332 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 333 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 334 | *NotIn_singleton; |
| 335 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 336 | static PyTypeObject *Eq_type; |
| 337 | static PyTypeObject *NotEq_type; |
| 338 | static PyTypeObject *Lt_type; |
| 339 | static PyTypeObject *LtE_type; |
| 340 | static PyTypeObject *Gt_type; |
| 341 | static PyTypeObject *GtE_type; |
| 342 | static PyTypeObject *Is_type; |
| 343 | static PyTypeObject *IsNot_type; |
| 344 | static PyTypeObject *In_type; |
| 345 | static PyTypeObject *NotIn_type; |
| 346 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 347 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 348 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 349 | "target", |
| 350 | "iter", |
| 351 | "ifs", |
| 352 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 353 | static PyTypeObject *excepthandler_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 354 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 355 | static char *excepthandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 356 | "type", |
| 357 | "name", |
| 358 | "body", |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 359 | "lineno", |
| 360 | "col_offset", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 361 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 362 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 363 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 364 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | "args", |
| 366 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 367 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 368 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 370 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 371 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 372 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 373 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 374 | static PyTypeObject *arg_type; |
| 375 | static PyObject* ast2obj_arg(void*); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 376 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 377 | "arg", |
| 378 | "annotation", |
| 379 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 380 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 381 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 383 | "arg", |
| 384 | "value", |
| 385 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 387 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 388 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 389 | "name", |
| 390 | "asname", |
| 391 | }; |
| 392 | |
| 393 | |
| 394 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 395 | { |
| 396 | PyObject *fnames, *result; |
| 397 | int i; |
| 398 | if (num_fields) { |
| 399 | fnames = PyTuple_New(num_fields); |
| 400 | if (!fnames) return NULL; |
| 401 | } else { |
| 402 | fnames = Py_None; |
| 403 | Py_INCREF(Py_None); |
| 404 | } |
| 405 | for(i=0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 406 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 407 | if (!field) { |
| 408 | Py_DECREF(fnames); |
| 409 | return NULL; |
| 410 | } |
| 411 | PyTuple_SET_ITEM(fnames, i, field); |
| 412 | } |
Guido van Rossum | e845c0f | 2007-11-02 23:07:07 +0000 | [diff] [blame] | 413 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 414 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 415 | Py_DECREF(fnames); |
| 416 | return (PyTypeObject*)result; |
| 417 | } |
| 418 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 419 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 420 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 421 | int i, result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 422 | PyObject *s, *l = PyList_New(num_fields); |
| 423 | if (!l) return 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 424 | for(i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 425 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 426 | if (!s) { |
| 427 | Py_DECREF(l); |
| 428 | return 0; |
| 429 | } |
| 430 | PyList_SET_ITEM(l, i, s); |
| 431 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 432 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 433 | Py_DECREF(l); |
| 434 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 437 | /* Conversion AST -> Python */ |
| 438 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 439 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 440 | { |
| 441 | int i, n = asdl_seq_LEN(seq); |
| 442 | PyObject *result = PyList_New(n); |
| 443 | PyObject *value; |
| 444 | if (!result) |
| 445 | return NULL; |
| 446 | for (i = 0; i < n; i++) { |
| 447 | value = func(asdl_seq_GET(seq, i)); |
| 448 | if (!value) { |
| 449 | Py_DECREF(result); |
| 450 | return NULL; |
| 451 | } |
| 452 | PyList_SET_ITEM(result, i, value); |
| 453 | } |
| 454 | return result; |
| 455 | } |
| 456 | |
| 457 | static PyObject* ast2obj_object(void *o) |
| 458 | { |
| 459 | if (!o) |
| 460 | o = Py_None; |
| 461 | Py_INCREF((PyObject*)o); |
| 462 | return (PyObject*)o; |
| 463 | } |
| 464 | #define ast2obj_identifier ast2obj_object |
| 465 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 466 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 467 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 468 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 469 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 472 | /* Conversion Python -> AST */ |
| 473 | |
| 474 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 475 | { |
| 476 | if (obj == Py_None) |
| 477 | obj = NULL; |
| 478 | if (obj) |
| 479 | PyArena_AddPyObject(arena, obj); |
| 480 | Py_XINCREF(obj); |
| 481 | *out = obj; |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | #define obj2ast_identifier obj2ast_object |
| 486 | #define obj2ast_string obj2ast_object |
| 487 | |
| 488 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 489 | { |
| 490 | int i; |
| 491 | if (!PyLong_Check(obj)) { |
| 492 | PyObject *s = PyObject_Repr(obj); |
| 493 | if (s == NULL) return 1; |
| 494 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
| 495 | PyString_AS_STRING(s)); |
| 496 | Py_DECREF(s); |
| 497 | return 1; |
| 498 | } |
| 499 | |
| 500 | i = (int)PyLong_AsLong(obj); |
| 501 | if (i == -1 && PyErr_Occurred()) |
| 502 | return 1; |
| 503 | *out = i; |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 508 | static int init_types(void) |
| 509 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 510 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 511 | if (initialized) return 1; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 512 | AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0); |
| 513 | mod_type = make_type("mod", AST_type, NULL, 0); |
| 514 | if (!mod_type) return 0; |
| 515 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 516 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 517 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 518 | Interactive_type = make_type("Interactive", mod_type, |
| 519 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 520 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 521 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 522 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 523 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 524 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 525 | if (!Suite_type) return 0; |
| 526 | stmt_type = make_type("stmt", AST_type, NULL, 0); |
| 527 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 528 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 529 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 530 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 531 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 532 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 533 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 534 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 535 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 536 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 537 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 538 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 539 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 540 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 541 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 542 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 543 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 544 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 545 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 546 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 547 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 548 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 549 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 550 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 551 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 552 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 553 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 554 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 555 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 556 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 557 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 558 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 559 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 560 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 561 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 562 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 563 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 564 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 565 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 566 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 567 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 568 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 569 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 570 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 571 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 572 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 573 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 574 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 575 | if (!Continue_type) return 0; |
| 576 | expr_type = make_type("expr", AST_type, NULL, 0); |
| 577 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 578 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 579 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 580 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 581 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 582 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 583 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 584 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 585 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 586 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 587 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 588 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 589 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 590 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 591 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 592 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 593 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 594 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 595 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 596 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 597 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 598 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 599 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 600 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 601 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 602 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 603 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 604 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 605 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 606 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 607 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 608 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 609 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 610 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 611 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 612 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 613 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 614 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 615 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 616 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 617 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 618 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 619 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 620 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 621 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 622 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 623 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 624 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 625 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 626 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 627 | if (!Tuple_type) return 0; |
| 628 | expr_context_type = make_type("expr_context", AST_type, NULL, 0); |
| 629 | if (!expr_context_type) return 0; |
| 630 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 631 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 632 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 633 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 634 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 635 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 636 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 637 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 638 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 639 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 640 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 641 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 642 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 643 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 644 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 645 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 646 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 647 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 648 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 649 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 650 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 651 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 654 | if (!Param_singleton) return 0; |
| 655 | slice_type = make_type("slice", AST_type, NULL, 0); |
| 656 | if (!slice_type) return 0; |
| 657 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 658 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 662 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 663 | if (!Index_type) return 0; |
| 664 | boolop_type = make_type("boolop", AST_type, NULL, 0); |
| 665 | if (!boolop_type) return 0; |
| 666 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 667 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 668 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 669 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 670 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 671 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 672 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 673 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 674 | if (!Or_singleton) return 0; |
| 675 | operator_type = make_type("operator", AST_type, NULL, 0); |
| 676 | if (!operator_type) return 0; |
| 677 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 678 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 681 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 682 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 683 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 685 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 686 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 688 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 689 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 690 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 691 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 692 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 693 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 694 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 695 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 696 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 698 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 700 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 701 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 702 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 704 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 705 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 706 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 708 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 709 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 710 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 711 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 712 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 713 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 714 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 715 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 716 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 717 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 718 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 719 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 720 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 721 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 722 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 723 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 724 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!FloorDiv_singleton) return 0; |
| 726 | unaryop_type = make_type("unaryop", AST_type, NULL, 0); |
| 727 | if (!unaryop_type) return 0; |
| 728 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 729 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 730 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 731 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 732 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 733 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 734 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 735 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 736 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 737 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 738 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 739 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 740 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 741 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 742 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 743 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 744 | if (!USub_singleton) return 0; |
| 745 | cmpop_type = make_type("cmpop", AST_type, NULL, 0); |
| 746 | if (!cmpop_type) return 0; |
| 747 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 748 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 749 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 751 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 752 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 753 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 754 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 756 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 759 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 760 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 762 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 763 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 764 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 765 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 766 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 767 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 768 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 769 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 770 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 771 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 772 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 773 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 774 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 775 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 776 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 777 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 778 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 779 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 780 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 782 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 784 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!NotIn_singleton) return 0; |
| 788 | comprehension_type = make_type("comprehension", AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 789 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 790 | if (!comprehension_type) return 0; |
| 791 | excepthandler_type = make_type("excepthandler", AST_type, |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 792 | excepthandler_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!excepthandler_type) return 0; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 794 | arguments_type = make_type("arguments", AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!arguments_type) return 0; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 796 | arg_type = make_type("arg", AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 797 | if (!arg_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 798 | keyword_type = make_type("keyword", AST_type, keyword_fields, 2); |
| 799 | if (!keyword_type) return 0; |
| 800 | alias_type = make_type("alias", AST_type, alias_fields, 2); |
| 801 | if (!alias_type) return 0; |
| 802 | initialized = 1; |
| 803 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 804 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 805 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 806 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 807 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 808 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 809 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 810 | arena); |
| 811 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 812 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 813 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 814 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 815 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 816 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 817 | arena); |
| 818 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 819 | arena); |
| 820 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 821 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 822 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 823 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 824 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 825 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 826 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 827 | { |
| 828 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 829 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 830 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 831 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 832 | p->kind = Module_kind; |
| 833 | p->v.Module.body = body; |
| 834 | return p; |
| 835 | } |
| 836 | |
| 837 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 838 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 839 | { |
| 840 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 841 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 842 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 843 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 844 | p->kind = Interactive_kind; |
| 845 | p->v.Interactive.body = body; |
| 846 | return p; |
| 847 | } |
| 848 | |
| 849 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 850 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 851 | { |
| 852 | mod_ty p; |
| 853 | if (!body) { |
| 854 | PyErr_SetString(PyExc_ValueError, |
| 855 | "field body is required for Expression"); |
| 856 | return NULL; |
| 857 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 858 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 859 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 860 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 861 | p->kind = Expression_kind; |
| 862 | p->v.Expression.body = body; |
| 863 | return p; |
| 864 | } |
| 865 | |
| 866 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 867 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 868 | { |
| 869 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 870 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 871 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 872 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 873 | p->kind = Suite_kind; |
| 874 | p->v.Suite.body = body; |
| 875 | return p; |
| 876 | } |
| 877 | |
| 878 | stmt_ty |
| 879 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 880 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 881 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 882 | { |
| 883 | stmt_ty p; |
| 884 | if (!name) { |
| 885 | PyErr_SetString(PyExc_ValueError, |
| 886 | "field name is required for FunctionDef"); |
| 887 | return NULL; |
| 888 | } |
| 889 | if (!args) { |
| 890 | PyErr_SetString(PyExc_ValueError, |
| 891 | "field args is required for FunctionDef"); |
| 892 | return NULL; |
| 893 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 894 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 895 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 896 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 897 | p->kind = FunctionDef_kind; |
| 898 | p->v.FunctionDef.name = name; |
| 899 | p->v.FunctionDef.args = args; |
| 900 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 901 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 902 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 903 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 904 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 905 | return p; |
| 906 | } |
| 907 | |
| 908 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 909 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 910 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 911 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 912 | { |
| 913 | stmt_ty p; |
| 914 | if (!name) { |
| 915 | PyErr_SetString(PyExc_ValueError, |
| 916 | "field name is required for ClassDef"); |
| 917 | return NULL; |
| 918 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 919 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 920 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 921 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 922 | p->kind = ClassDef_kind; |
| 923 | p->v.ClassDef.name = name; |
| 924 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 925 | p->v.ClassDef.keywords = keywords; |
| 926 | p->v.ClassDef.starargs = starargs; |
| 927 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 928 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 929 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 930 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 931 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 932 | return p; |
| 933 | } |
| 934 | |
| 935 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 936 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 937 | { |
| 938 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 939 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 940 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 941 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 942 | p->kind = Return_kind; |
| 943 | p->v.Return.value = value; |
| 944 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 945 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 946 | return p; |
| 947 | } |
| 948 | |
| 949 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 950 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 951 | { |
| 952 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 953 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 954 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 955 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 956 | p->kind = Delete_kind; |
| 957 | p->v.Delete.targets = targets; |
| 958 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 959 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 960 | return p; |
| 961 | } |
| 962 | |
| 963 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 964 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 965 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 966 | { |
| 967 | stmt_ty p; |
| 968 | if (!value) { |
| 969 | PyErr_SetString(PyExc_ValueError, |
| 970 | "field value is required for Assign"); |
| 971 | return NULL; |
| 972 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 973 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 974 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 975 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 976 | p->kind = Assign_kind; |
| 977 | p->v.Assign.targets = targets; |
| 978 | p->v.Assign.value = value; |
| 979 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 980 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 981 | return p; |
| 982 | } |
| 983 | |
| 984 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 985 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 986 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 987 | { |
| 988 | stmt_ty p; |
| 989 | if (!target) { |
| 990 | PyErr_SetString(PyExc_ValueError, |
| 991 | "field target is required for AugAssign"); |
| 992 | return NULL; |
| 993 | } |
| 994 | if (!op) { |
| 995 | PyErr_SetString(PyExc_ValueError, |
| 996 | "field op is required for AugAssign"); |
| 997 | return NULL; |
| 998 | } |
| 999 | if (!value) { |
| 1000 | PyErr_SetString(PyExc_ValueError, |
| 1001 | "field value is required for AugAssign"); |
| 1002 | return NULL; |
| 1003 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1004 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1005 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1006 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1007 | p->kind = AugAssign_kind; |
| 1008 | p->v.AugAssign.target = target; |
| 1009 | p->v.AugAssign.op = op; |
| 1010 | p->v.AugAssign.value = value; |
| 1011 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1012 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1013 | return p; |
| 1014 | } |
| 1015 | |
| 1016 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1017 | 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] | 1018 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1019 | { |
| 1020 | stmt_ty p; |
| 1021 | if (!target) { |
| 1022 | PyErr_SetString(PyExc_ValueError, |
| 1023 | "field target is required for For"); |
| 1024 | return NULL; |
| 1025 | } |
| 1026 | if (!iter) { |
| 1027 | PyErr_SetString(PyExc_ValueError, |
| 1028 | "field iter is required for For"); |
| 1029 | return NULL; |
| 1030 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1031 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1032 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1033 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1034 | p->kind = For_kind; |
| 1035 | p->v.For.target = target; |
| 1036 | p->v.For.iter = iter; |
| 1037 | p->v.For.body = body; |
| 1038 | p->v.For.orelse = orelse; |
| 1039 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1040 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1041 | return p; |
| 1042 | } |
| 1043 | |
| 1044 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1045 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1046 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1047 | { |
| 1048 | stmt_ty p; |
| 1049 | if (!test) { |
| 1050 | PyErr_SetString(PyExc_ValueError, |
| 1051 | "field test is required for While"); |
| 1052 | return NULL; |
| 1053 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1054 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1055 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1056 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1057 | p->kind = While_kind; |
| 1058 | p->v.While.test = test; |
| 1059 | p->v.While.body = body; |
| 1060 | p->v.While.orelse = orelse; |
| 1061 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1062 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1063 | return p; |
| 1064 | } |
| 1065 | |
| 1066 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1067 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1068 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1069 | { |
| 1070 | stmt_ty p; |
| 1071 | if (!test) { |
| 1072 | PyErr_SetString(PyExc_ValueError, |
| 1073 | "field test is required for If"); |
| 1074 | return NULL; |
| 1075 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1076 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1077 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1078 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1079 | p->kind = If_kind; |
| 1080 | p->v.If.test = test; |
| 1081 | p->v.If.body = body; |
| 1082 | p->v.If.orelse = orelse; |
| 1083 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1084 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1085 | return p; |
| 1086 | } |
| 1087 | |
| 1088 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1089 | 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] | 1090 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1091 | { |
| 1092 | stmt_ty p; |
| 1093 | if (!context_expr) { |
| 1094 | PyErr_SetString(PyExc_ValueError, |
| 1095 | "field context_expr is required for With"); |
| 1096 | return NULL; |
| 1097 | } |
| 1098 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1099 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1100 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1101 | p->kind = With_kind; |
| 1102 | p->v.With.context_expr = context_expr; |
| 1103 | p->v.With.optional_vars = optional_vars; |
| 1104 | p->v.With.body = body; |
| 1105 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1106 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1107 | return p; |
| 1108 | } |
| 1109 | |
| 1110 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1111 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1112 | { |
| 1113 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1114 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1115 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1116 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1117 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1118 | p->v.Raise.exc = exc; |
| 1119 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1120 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1121 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1122 | return p; |
| 1123 | } |
| 1124 | |
| 1125 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1126 | 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] | 1127 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1128 | { |
| 1129 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1130 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1131 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1132 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | p->kind = TryExcept_kind; |
| 1134 | p->v.TryExcept.body = body; |
| 1135 | p->v.TryExcept.handlers = handlers; |
| 1136 | p->v.TryExcept.orelse = orelse; |
| 1137 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1138 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1139 | return p; |
| 1140 | } |
| 1141 | |
| 1142 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1143 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1144 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1145 | { |
| 1146 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1147 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1148 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1149 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1150 | p->kind = TryFinally_kind; |
| 1151 | p->v.TryFinally.body = body; |
| 1152 | p->v.TryFinally.finalbody = finalbody; |
| 1153 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1154 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1155 | return p; |
| 1156 | } |
| 1157 | |
| 1158 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1159 | 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] | 1160 | { |
| 1161 | stmt_ty p; |
| 1162 | if (!test) { |
| 1163 | PyErr_SetString(PyExc_ValueError, |
| 1164 | "field test is required for Assert"); |
| 1165 | return NULL; |
| 1166 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1167 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1168 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1170 | p->kind = Assert_kind; |
| 1171 | p->v.Assert.test = test; |
| 1172 | p->v.Assert.msg = msg; |
| 1173 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1174 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1175 | return p; |
| 1176 | } |
| 1177 | |
| 1178 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1179 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1180 | { |
| 1181 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1182 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1183 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1184 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1185 | p->kind = Import_kind; |
| 1186 | p->v.Import.names = names; |
| 1187 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1188 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1189 | return p; |
| 1190 | } |
| 1191 | |
| 1192 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1193 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1194 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1195 | { |
| 1196 | stmt_ty p; |
| 1197 | if (!module) { |
| 1198 | PyErr_SetString(PyExc_ValueError, |
| 1199 | "field module is required for ImportFrom"); |
| 1200 | return NULL; |
| 1201 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1202 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1203 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1204 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1205 | p->kind = ImportFrom_kind; |
| 1206 | p->v.ImportFrom.module = module; |
| 1207 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1208 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1210 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1211 | return p; |
| 1212 | } |
| 1213 | |
| 1214 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1215 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | { |
| 1217 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1218 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1219 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1220 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1221 | p->kind = Global_kind; |
| 1222 | p->v.Global.names = names; |
| 1223 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1224 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1225 | return p; |
| 1226 | } |
| 1227 | |
| 1228 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1229 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1230 | { |
| 1231 | stmt_ty p; |
| 1232 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1233 | if (!p) |
| 1234 | return NULL; |
| 1235 | p->kind = Nonlocal_kind; |
| 1236 | p->v.Nonlocal.names = names; |
| 1237 | p->lineno = lineno; |
| 1238 | p->col_offset = col_offset; |
| 1239 | return p; |
| 1240 | } |
| 1241 | |
| 1242 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1243 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1244 | { |
| 1245 | stmt_ty p; |
| 1246 | if (!value) { |
| 1247 | PyErr_SetString(PyExc_ValueError, |
| 1248 | "field value is required for Expr"); |
| 1249 | return NULL; |
| 1250 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1251 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1252 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1253 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1254 | p->kind = Expr_kind; |
| 1255 | p->v.Expr.value = value; |
| 1256 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1257 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1258 | return p; |
| 1259 | } |
| 1260 | |
| 1261 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1262 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1263 | { |
| 1264 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1265 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1266 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1268 | p->kind = Pass_kind; |
| 1269 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1270 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1271 | return p; |
| 1272 | } |
| 1273 | |
| 1274 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1275 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1276 | { |
| 1277 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1278 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1279 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1280 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1281 | p->kind = Break_kind; |
| 1282 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1283 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1284 | return p; |
| 1285 | } |
| 1286 | |
| 1287 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1288 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1289 | { |
| 1290 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1291 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1292 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1293 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1294 | p->kind = Continue_kind; |
| 1295 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1296 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1297 | return p; |
| 1298 | } |
| 1299 | |
| 1300 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1301 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1302 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1303 | { |
| 1304 | expr_ty p; |
| 1305 | if (!op) { |
| 1306 | PyErr_SetString(PyExc_ValueError, |
| 1307 | "field op is required for BoolOp"); |
| 1308 | return NULL; |
| 1309 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1310 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1311 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1312 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1313 | p->kind = BoolOp_kind; |
| 1314 | p->v.BoolOp.op = op; |
| 1315 | p->v.BoolOp.values = values; |
| 1316 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1317 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1318 | return p; |
| 1319 | } |
| 1320 | |
| 1321 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1322 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1323 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1324 | { |
| 1325 | expr_ty p; |
| 1326 | if (!left) { |
| 1327 | PyErr_SetString(PyExc_ValueError, |
| 1328 | "field left is required for BinOp"); |
| 1329 | return NULL; |
| 1330 | } |
| 1331 | if (!op) { |
| 1332 | PyErr_SetString(PyExc_ValueError, |
| 1333 | "field op is required for BinOp"); |
| 1334 | return NULL; |
| 1335 | } |
| 1336 | if (!right) { |
| 1337 | PyErr_SetString(PyExc_ValueError, |
| 1338 | "field right is required for BinOp"); |
| 1339 | return NULL; |
| 1340 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1341 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1342 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1343 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | p->kind = BinOp_kind; |
| 1345 | p->v.BinOp.left = left; |
| 1346 | p->v.BinOp.op = op; |
| 1347 | p->v.BinOp.right = right; |
| 1348 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1349 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1350 | return p; |
| 1351 | } |
| 1352 | |
| 1353 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1354 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1355 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1356 | { |
| 1357 | expr_ty p; |
| 1358 | if (!op) { |
| 1359 | PyErr_SetString(PyExc_ValueError, |
| 1360 | "field op is required for UnaryOp"); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | if (!operand) { |
| 1364 | PyErr_SetString(PyExc_ValueError, |
| 1365 | "field operand is required for UnaryOp"); |
| 1366 | return NULL; |
| 1367 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1368 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1369 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1370 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1371 | p->kind = UnaryOp_kind; |
| 1372 | p->v.UnaryOp.op = op; |
| 1373 | p->v.UnaryOp.operand = operand; |
| 1374 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1375 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1376 | return p; |
| 1377 | } |
| 1378 | |
| 1379 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1380 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1381 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1382 | { |
| 1383 | expr_ty p; |
| 1384 | if (!args) { |
| 1385 | PyErr_SetString(PyExc_ValueError, |
| 1386 | "field args is required for Lambda"); |
| 1387 | return NULL; |
| 1388 | } |
| 1389 | if (!body) { |
| 1390 | PyErr_SetString(PyExc_ValueError, |
| 1391 | "field body is required for Lambda"); |
| 1392 | return NULL; |
| 1393 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1394 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1395 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1396 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | p->kind = Lambda_kind; |
| 1398 | p->v.Lambda.args = args; |
| 1399 | p->v.Lambda.body = body; |
| 1400 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1401 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1402 | return p; |
| 1403 | } |
| 1404 | |
| 1405 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1406 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1407 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1408 | { |
| 1409 | expr_ty p; |
| 1410 | if (!test) { |
| 1411 | PyErr_SetString(PyExc_ValueError, |
| 1412 | "field test is required for IfExp"); |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | if (!body) { |
| 1416 | PyErr_SetString(PyExc_ValueError, |
| 1417 | "field body is required for IfExp"); |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | if (!orelse) { |
| 1421 | PyErr_SetString(PyExc_ValueError, |
| 1422 | "field orelse is required for IfExp"); |
| 1423 | return NULL; |
| 1424 | } |
| 1425 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1426 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1427 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1428 | p->kind = IfExp_kind; |
| 1429 | p->v.IfExp.test = test; |
| 1430 | p->v.IfExp.body = body; |
| 1431 | p->v.IfExp.orelse = orelse; |
| 1432 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1433 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1434 | return p; |
| 1435 | } |
| 1436 | |
| 1437 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1438 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1439 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1440 | { |
| 1441 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1442 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1443 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1444 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1445 | p->kind = Dict_kind; |
| 1446 | p->v.Dict.keys = keys; |
| 1447 | p->v.Dict.values = values; |
| 1448 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1449 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1450 | return p; |
| 1451 | } |
| 1452 | |
| 1453 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1454 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1455 | { |
| 1456 | expr_ty p; |
| 1457 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1458 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1459 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1460 | p->kind = Set_kind; |
| 1461 | p->v.Set.elts = elts; |
| 1462 | p->lineno = lineno; |
| 1463 | p->col_offset = col_offset; |
| 1464 | return p; |
| 1465 | } |
| 1466 | |
| 1467 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1468 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1469 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | { |
| 1471 | expr_ty p; |
| 1472 | if (!elt) { |
| 1473 | PyErr_SetString(PyExc_ValueError, |
| 1474 | "field elt is required for ListComp"); |
| 1475 | return NULL; |
| 1476 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1477 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1478 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1479 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1480 | p->kind = ListComp_kind; |
| 1481 | p->v.ListComp.elt = elt; |
| 1482 | p->v.ListComp.generators = generators; |
| 1483 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1484 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1485 | return p; |
| 1486 | } |
| 1487 | |
| 1488 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1489 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1490 | *arena) |
| 1491 | { |
| 1492 | expr_ty p; |
| 1493 | if (!elt) { |
| 1494 | PyErr_SetString(PyExc_ValueError, |
| 1495 | "field elt is required for SetComp"); |
| 1496 | return NULL; |
| 1497 | } |
| 1498 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1499 | if (!p) |
| 1500 | return NULL; |
| 1501 | p->kind = SetComp_kind; |
| 1502 | p->v.SetComp.elt = elt; |
| 1503 | p->v.SetComp.generators = generators; |
| 1504 | p->lineno = lineno; |
| 1505 | p->col_offset = col_offset; |
| 1506 | return p; |
| 1507 | } |
| 1508 | |
| 1509 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1510 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1511 | col_offset, PyArena *arena) |
| 1512 | { |
| 1513 | expr_ty p; |
| 1514 | if (!key) { |
| 1515 | PyErr_SetString(PyExc_ValueError, |
| 1516 | "field key is required for DictComp"); |
| 1517 | return NULL; |
| 1518 | } |
| 1519 | if (!value) { |
| 1520 | PyErr_SetString(PyExc_ValueError, |
| 1521 | "field value is required for DictComp"); |
| 1522 | return NULL; |
| 1523 | } |
| 1524 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1525 | if (!p) |
| 1526 | return NULL; |
| 1527 | p->kind = DictComp_kind; |
| 1528 | p->v.DictComp.key = key; |
| 1529 | p->v.DictComp.value = value; |
| 1530 | p->v.DictComp.generators = generators; |
| 1531 | p->lineno = lineno; |
| 1532 | p->col_offset = col_offset; |
| 1533 | return p; |
| 1534 | } |
| 1535 | |
| 1536 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1537 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1538 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1539 | { |
| 1540 | expr_ty p; |
| 1541 | if (!elt) { |
| 1542 | PyErr_SetString(PyExc_ValueError, |
| 1543 | "field elt is required for GeneratorExp"); |
| 1544 | return NULL; |
| 1545 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1546 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1547 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1548 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1549 | p->kind = GeneratorExp_kind; |
| 1550 | p->v.GeneratorExp.elt = elt; |
| 1551 | p->v.GeneratorExp.generators = generators; |
| 1552 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1553 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1554 | return p; |
| 1555 | } |
| 1556 | |
| 1557 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1558 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1559 | { |
| 1560 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1561 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1562 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1563 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1564 | p->kind = Yield_kind; |
| 1565 | p->v.Yield.value = value; |
| 1566 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1567 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1568 | return p; |
| 1569 | } |
| 1570 | |
| 1571 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1572 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1573 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1574 | { |
| 1575 | expr_ty p; |
| 1576 | if (!left) { |
| 1577 | PyErr_SetString(PyExc_ValueError, |
| 1578 | "field left is required for Compare"); |
| 1579 | return NULL; |
| 1580 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1581 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1582 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1583 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1584 | p->kind = Compare_kind; |
| 1585 | p->v.Compare.left = left; |
| 1586 | p->v.Compare.ops = ops; |
| 1587 | p->v.Compare.comparators = comparators; |
| 1588 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1589 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1590 | return p; |
| 1591 | } |
| 1592 | |
| 1593 | expr_ty |
| 1594 | 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] | 1595 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1596 | { |
| 1597 | expr_ty p; |
| 1598 | if (!func) { |
| 1599 | PyErr_SetString(PyExc_ValueError, |
| 1600 | "field func is required for Call"); |
| 1601 | return NULL; |
| 1602 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1603 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1604 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1605 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1606 | p->kind = Call_kind; |
| 1607 | p->v.Call.func = func; |
| 1608 | p->v.Call.args = args; |
| 1609 | p->v.Call.keywords = keywords; |
| 1610 | p->v.Call.starargs = starargs; |
| 1611 | p->v.Call.kwargs = kwargs; |
| 1612 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1613 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1614 | return p; |
| 1615 | } |
| 1616 | |
| 1617 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1618 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1619 | { |
| 1620 | expr_ty p; |
| 1621 | if (!n) { |
| 1622 | PyErr_SetString(PyExc_ValueError, |
| 1623 | "field n is required for Num"); |
| 1624 | return NULL; |
| 1625 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1626 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1627 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1628 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1629 | p->kind = Num_kind; |
| 1630 | p->v.Num.n = n; |
| 1631 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1632 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1633 | return p; |
| 1634 | } |
| 1635 | |
| 1636 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1637 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1638 | { |
| 1639 | expr_ty p; |
| 1640 | if (!s) { |
| 1641 | PyErr_SetString(PyExc_ValueError, |
| 1642 | "field s is required for Str"); |
| 1643 | return NULL; |
| 1644 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1645 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1646 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1647 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1648 | p->kind = Str_kind; |
| 1649 | p->v.Str.s = s; |
| 1650 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1651 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1652 | return p; |
| 1653 | } |
| 1654 | |
| 1655 | expr_ty |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1656 | Bytes(string s, int lineno, int col_offset, PyArena *arena) |
| 1657 | { |
| 1658 | expr_ty p; |
| 1659 | if (!s) { |
| 1660 | PyErr_SetString(PyExc_ValueError, |
| 1661 | "field s is required for Bytes"); |
| 1662 | return NULL; |
| 1663 | } |
| 1664 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1665 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1666 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1667 | p->kind = Bytes_kind; |
| 1668 | p->v.Bytes.s = s; |
| 1669 | p->lineno = lineno; |
| 1670 | p->col_offset = col_offset; |
| 1671 | return p; |
| 1672 | } |
| 1673 | |
| 1674 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1675 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1676 | { |
| 1677 | expr_ty p; |
| 1678 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1679 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1680 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1681 | p->kind = Ellipsis_kind; |
| 1682 | p->lineno = lineno; |
| 1683 | p->col_offset = col_offset; |
| 1684 | return p; |
| 1685 | } |
| 1686 | |
| 1687 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1688 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1689 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1690 | { |
| 1691 | expr_ty p; |
| 1692 | if (!value) { |
| 1693 | PyErr_SetString(PyExc_ValueError, |
| 1694 | "field value is required for Attribute"); |
| 1695 | return NULL; |
| 1696 | } |
| 1697 | if (!attr) { |
| 1698 | PyErr_SetString(PyExc_ValueError, |
| 1699 | "field attr is required for Attribute"); |
| 1700 | return NULL; |
| 1701 | } |
| 1702 | if (!ctx) { |
| 1703 | PyErr_SetString(PyExc_ValueError, |
| 1704 | "field ctx is required for Attribute"); |
| 1705 | return NULL; |
| 1706 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1707 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1708 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1709 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | p->kind = Attribute_kind; |
| 1711 | p->v.Attribute.value = value; |
| 1712 | p->v.Attribute.attr = attr; |
| 1713 | p->v.Attribute.ctx = ctx; |
| 1714 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1715 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1716 | return p; |
| 1717 | } |
| 1718 | |
| 1719 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1720 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1721 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1722 | { |
| 1723 | expr_ty p; |
| 1724 | if (!value) { |
| 1725 | PyErr_SetString(PyExc_ValueError, |
| 1726 | "field value is required for Subscript"); |
| 1727 | return NULL; |
| 1728 | } |
| 1729 | if (!slice) { |
| 1730 | PyErr_SetString(PyExc_ValueError, |
| 1731 | "field slice is required for Subscript"); |
| 1732 | return NULL; |
| 1733 | } |
| 1734 | if (!ctx) { |
| 1735 | PyErr_SetString(PyExc_ValueError, |
| 1736 | "field ctx is required for Subscript"); |
| 1737 | return NULL; |
| 1738 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1739 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1740 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1741 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1742 | p->kind = Subscript_kind; |
| 1743 | p->v.Subscript.value = value; |
| 1744 | p->v.Subscript.slice = slice; |
| 1745 | p->v.Subscript.ctx = ctx; |
| 1746 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1747 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | return p; |
| 1749 | } |
| 1750 | |
| 1751 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1752 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1753 | *arena) |
| 1754 | { |
| 1755 | expr_ty p; |
| 1756 | if (!value) { |
| 1757 | PyErr_SetString(PyExc_ValueError, |
| 1758 | "field value is required for Starred"); |
| 1759 | return NULL; |
| 1760 | } |
| 1761 | if (!ctx) { |
| 1762 | PyErr_SetString(PyExc_ValueError, |
| 1763 | "field ctx is required for Starred"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1767 | if (!p) |
| 1768 | return NULL; |
| 1769 | p->kind = Starred_kind; |
| 1770 | p->v.Starred.value = value; |
| 1771 | p->v.Starred.ctx = ctx; |
| 1772 | p->lineno = lineno; |
| 1773 | p->col_offset = col_offset; |
| 1774 | return p; |
| 1775 | } |
| 1776 | |
| 1777 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1778 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1779 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1780 | { |
| 1781 | expr_ty p; |
| 1782 | if (!id) { |
| 1783 | PyErr_SetString(PyExc_ValueError, |
| 1784 | "field id is required for Name"); |
| 1785 | return NULL; |
| 1786 | } |
| 1787 | if (!ctx) { |
| 1788 | PyErr_SetString(PyExc_ValueError, |
| 1789 | "field ctx is required for Name"); |
| 1790 | return NULL; |
| 1791 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1792 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1793 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1794 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1795 | p->kind = Name_kind; |
| 1796 | p->v.Name.id = id; |
| 1797 | p->v.Name.ctx = ctx; |
| 1798 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1799 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1800 | return p; |
| 1801 | } |
| 1802 | |
| 1803 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1804 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1805 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1806 | { |
| 1807 | expr_ty p; |
| 1808 | if (!ctx) { |
| 1809 | PyErr_SetString(PyExc_ValueError, |
| 1810 | "field ctx is required for List"); |
| 1811 | return NULL; |
| 1812 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1813 | p = (expr_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->kind = List_kind; |
| 1817 | p->v.List.elts = elts; |
| 1818 | p->v.List.ctx = ctx; |
| 1819 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1820 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1821 | return p; |
| 1822 | } |
| 1823 | |
| 1824 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1825 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1826 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1827 | { |
| 1828 | expr_ty p; |
| 1829 | if (!ctx) { |
| 1830 | PyErr_SetString(PyExc_ValueError, |
| 1831 | "field ctx is required for Tuple"); |
| 1832 | return NULL; |
| 1833 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1834 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1835 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1836 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1837 | p->kind = Tuple_kind; |
| 1838 | p->v.Tuple.elts = elts; |
| 1839 | p->v.Tuple.ctx = ctx; |
| 1840 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1841 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | return p; |
| 1843 | } |
| 1844 | |
| 1845 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1846 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1847 | { |
| 1848 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1849 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1850 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1851 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1852 | p->kind = Slice_kind; |
| 1853 | p->v.Slice.lower = lower; |
| 1854 | p->v.Slice.upper = upper; |
| 1855 | p->v.Slice.step = step; |
| 1856 | return p; |
| 1857 | } |
| 1858 | |
| 1859 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1860 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1861 | { |
| 1862 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1863 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1864 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1865 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1866 | p->kind = ExtSlice_kind; |
| 1867 | p->v.ExtSlice.dims = dims; |
| 1868 | return p; |
| 1869 | } |
| 1870 | |
| 1871 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1872 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1873 | { |
| 1874 | slice_ty p; |
| 1875 | if (!value) { |
| 1876 | PyErr_SetString(PyExc_ValueError, |
| 1877 | "field value is required for Index"); |
| 1878 | return NULL; |
| 1879 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1880 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1881 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1883 | p->kind = Index_kind; |
| 1884 | p->v.Index.value = value; |
| 1885 | return p; |
| 1886 | } |
| 1887 | |
| 1888 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1889 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
| 1891 | comprehension_ty p; |
| 1892 | if (!target) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field target is required for comprehension"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | if (!iter) { |
| 1898 | PyErr_SetString(PyExc_ValueError, |
| 1899 | "field iter is required for comprehension"); |
| 1900 | return NULL; |
| 1901 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1902 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1903 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1904 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1905 | p->target = target; |
| 1906 | p->iter = iter; |
| 1907 | p->ifs = ifs; |
| 1908 | return p; |
| 1909 | } |
| 1910 | |
| 1911 | excepthandler_ty |
Guido van Rossum | 16be03e | 2007-01-10 18:51:35 +0000 | [diff] [blame] | 1912 | excepthandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1913 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1914 | { |
| 1915 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1916 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1917 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1918 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1919 | p->type = type; |
| 1920 | p->name = name; |
| 1921 | p->body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1922 | p->lineno = lineno; |
| 1923 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1924 | return p; |
| 1925 | } |
| 1926 | |
| 1927 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1928 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 1929 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 1930 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1931 | { |
| 1932 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1933 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1934 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | p->args = args; |
| 1937 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1938 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 1939 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1940 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1941 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1942 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 1943 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1944 | return p; |
| 1945 | } |
| 1946 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1947 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 1948 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1949 | { |
| 1950 | arg_ty p; |
| 1951 | if (!arg) { |
| 1952 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 1953 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1954 | return NULL; |
| 1955 | } |
| 1956 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1957 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1958 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 1959 | p->arg = arg; |
| 1960 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1961 | return p; |
| 1962 | } |
| 1963 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1964 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1965 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | { |
| 1967 | keyword_ty p; |
| 1968 | if (!arg) { |
| 1969 | PyErr_SetString(PyExc_ValueError, |
| 1970 | "field arg is required for keyword"); |
| 1971 | return NULL; |
| 1972 | } |
| 1973 | if (!value) { |
| 1974 | PyErr_SetString(PyExc_ValueError, |
| 1975 | "field value is required for keyword"); |
| 1976 | return NULL; |
| 1977 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1978 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1979 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1980 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1981 | p->arg = arg; |
| 1982 | p->value = value; |
| 1983 | return p; |
| 1984 | } |
| 1985 | |
| 1986 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1987 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1988 | { |
| 1989 | alias_ty p; |
| 1990 | if (!name) { |
| 1991 | PyErr_SetString(PyExc_ValueError, |
| 1992 | "field name is required for alias"); |
| 1993 | return NULL; |
| 1994 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1995 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1996 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1997 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1998 | p->name = name; |
| 1999 | p->asname = asname; |
| 2000 | return p; |
| 2001 | } |
| 2002 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2003 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2004 | PyObject* |
| 2005 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2006 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2007 | mod_ty o = (mod_ty)_o; |
| 2008 | PyObject *result = NULL, *value = NULL; |
| 2009 | if (!o) { |
| 2010 | Py_INCREF(Py_None); |
| 2011 | return Py_None; |
| 2012 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2013 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | switch (o->kind) { |
| 2015 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2016 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2017 | if (!result) goto failed; |
| 2018 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2019 | if (!value) goto failed; |
| 2020 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2021 | goto failed; |
| 2022 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2023 | break; |
| 2024 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2025 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2026 | if (!result) goto failed; |
| 2027 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2028 | if (!value) goto failed; |
| 2029 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2030 | goto failed; |
| 2031 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2032 | break; |
| 2033 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2034 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2035 | if (!result) goto failed; |
| 2036 | value = ast2obj_expr(o->v.Expression.body); |
| 2037 | if (!value) goto failed; |
| 2038 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2039 | goto failed; |
| 2040 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2043 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2044 | if (!result) goto failed; |
| 2045 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2046 | if (!value) goto failed; |
| 2047 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2048 | goto failed; |
| 2049 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2052 | return result; |
| 2053 | failed: |
| 2054 | Py_XDECREF(value); |
| 2055 | Py_XDECREF(result); |
| 2056 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2059 | PyObject* |
| 2060 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2062 | stmt_ty o = (stmt_ty)_o; |
| 2063 | PyObject *result = NULL, *value = NULL; |
| 2064 | if (!o) { |
| 2065 | Py_INCREF(Py_None); |
| 2066 | return Py_None; |
| 2067 | } |
| 2068 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2069 | switch (o->kind) { |
| 2070 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2071 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2072 | if (!result) goto failed; |
| 2073 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2074 | if (!value) goto failed; |
| 2075 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2076 | goto failed; |
| 2077 | Py_DECREF(value); |
| 2078 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2079 | if (!value) goto failed; |
| 2080 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2081 | goto failed; |
| 2082 | Py_DECREF(value); |
| 2083 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2084 | if (!value) goto failed; |
| 2085 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2086 | goto failed; |
| 2087 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2088 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2089 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2090 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2091 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2092 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2093 | goto failed; |
| 2094 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2095 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2096 | if (!value) goto failed; |
| 2097 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2098 | goto failed; |
| 2099 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2102 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2103 | if (!result) goto failed; |
| 2104 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2105 | if (!value) goto failed; |
| 2106 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2107 | goto failed; |
| 2108 | Py_DECREF(value); |
| 2109 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2110 | if (!value) goto failed; |
| 2111 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2112 | goto failed; |
| 2113 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2114 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2115 | if (!value) goto failed; |
| 2116 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2117 | goto failed; |
| 2118 | Py_DECREF(value); |
| 2119 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2120 | if (!value) goto failed; |
| 2121 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2122 | goto failed; |
| 2123 | Py_DECREF(value); |
| 2124 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2125 | if (!value) goto failed; |
| 2126 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2127 | goto failed; |
| 2128 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2129 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2130 | if (!value) goto failed; |
| 2131 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2132 | goto failed; |
| 2133 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2134 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2135 | ast2obj_expr); |
| 2136 | if (!value) goto failed; |
| 2137 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2138 | -1) |
| 2139 | goto failed; |
| 2140 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2143 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2144 | if (!result) goto failed; |
| 2145 | value = ast2obj_expr(o->v.Return.value); |
| 2146 | if (!value) goto failed; |
| 2147 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2148 | goto failed; |
| 2149 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2150 | break; |
| 2151 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2152 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2153 | if (!result) goto failed; |
| 2154 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2155 | if (!value) goto failed; |
| 2156 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2157 | goto failed; |
| 2158 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2159 | break; |
| 2160 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2161 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2162 | if (!result) goto failed; |
| 2163 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2164 | if (!value) goto failed; |
| 2165 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2166 | goto failed; |
| 2167 | Py_DECREF(value); |
| 2168 | value = ast2obj_expr(o->v.Assign.value); |
| 2169 | if (!value) goto failed; |
| 2170 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2171 | goto failed; |
| 2172 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2173 | break; |
| 2174 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2175 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2176 | if (!result) goto failed; |
| 2177 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2178 | if (!value) goto failed; |
| 2179 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2180 | goto failed; |
| 2181 | Py_DECREF(value); |
| 2182 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2183 | if (!value) goto failed; |
| 2184 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2185 | goto failed; |
| 2186 | Py_DECREF(value); |
| 2187 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2188 | if (!value) goto failed; |
| 2189 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2190 | goto failed; |
| 2191 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2192 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2193 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2194 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2195 | if (!result) goto failed; |
| 2196 | value = ast2obj_expr(o->v.For.target); |
| 2197 | if (!value) goto failed; |
| 2198 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2199 | goto failed; |
| 2200 | Py_DECREF(value); |
| 2201 | value = ast2obj_expr(o->v.For.iter); |
| 2202 | if (!value) goto failed; |
| 2203 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2204 | goto failed; |
| 2205 | Py_DECREF(value); |
| 2206 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2207 | if (!value) goto failed; |
| 2208 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2209 | goto failed; |
| 2210 | Py_DECREF(value); |
| 2211 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2212 | if (!value) goto failed; |
| 2213 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2214 | goto failed; |
| 2215 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2218 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2219 | if (!result) goto failed; |
| 2220 | value = ast2obj_expr(o->v.While.test); |
| 2221 | if (!value) goto failed; |
| 2222 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2223 | goto failed; |
| 2224 | Py_DECREF(value); |
| 2225 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2226 | if (!value) goto failed; |
| 2227 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2228 | goto failed; |
| 2229 | Py_DECREF(value); |
| 2230 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2231 | if (!value) goto failed; |
| 2232 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2233 | goto failed; |
| 2234 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2237 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2238 | if (!result) goto failed; |
| 2239 | value = ast2obj_expr(o->v.If.test); |
| 2240 | if (!value) goto failed; |
| 2241 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2242 | goto failed; |
| 2243 | Py_DECREF(value); |
| 2244 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2245 | if (!value) goto failed; |
| 2246 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2247 | goto failed; |
| 2248 | Py_DECREF(value); |
| 2249 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2250 | if (!value) goto failed; |
| 2251 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2252 | goto failed; |
| 2253 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2254 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2255 | case With_kind: |
| 2256 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2257 | if (!result) goto failed; |
| 2258 | value = ast2obj_expr(o->v.With.context_expr); |
| 2259 | if (!value) goto failed; |
| 2260 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2261 | goto failed; |
| 2262 | Py_DECREF(value); |
| 2263 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2264 | if (!value) goto failed; |
| 2265 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2266 | -1) |
| 2267 | goto failed; |
| 2268 | Py_DECREF(value); |
| 2269 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2270 | if (!value) goto failed; |
| 2271 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2272 | goto failed; |
| 2273 | Py_DECREF(value); |
| 2274 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2275 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2276 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2277 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2278 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2279 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2280 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2281 | goto failed; |
| 2282 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2283 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2284 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2285 | if (PyObject_SetAttrString(result, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2286 | goto failed; |
| 2287 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2288 | break; |
| 2289 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2290 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2291 | if (!result) goto failed; |
| 2292 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2293 | if (!value) goto failed; |
| 2294 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2295 | goto failed; |
| 2296 | Py_DECREF(value); |
| 2297 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2298 | ast2obj_excepthandler); |
| 2299 | if (!value) goto failed; |
| 2300 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2301 | goto failed; |
| 2302 | Py_DECREF(value); |
| 2303 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2304 | if (!value) goto failed; |
| 2305 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2306 | goto failed; |
| 2307 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2310 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2311 | if (!result) goto failed; |
| 2312 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2313 | if (!value) goto failed; |
| 2314 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2315 | goto failed; |
| 2316 | Py_DECREF(value); |
| 2317 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2318 | if (!value) goto failed; |
| 2319 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2320 | goto failed; |
| 2321 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2322 | break; |
| 2323 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2324 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2325 | if (!result) goto failed; |
| 2326 | value = ast2obj_expr(o->v.Assert.test); |
| 2327 | if (!value) goto failed; |
| 2328 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2329 | goto failed; |
| 2330 | Py_DECREF(value); |
| 2331 | value = ast2obj_expr(o->v.Assert.msg); |
| 2332 | if (!value) goto failed; |
| 2333 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2334 | goto failed; |
| 2335 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2336 | break; |
| 2337 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2338 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2339 | if (!result) goto failed; |
| 2340 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2341 | if (!value) goto failed; |
| 2342 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2343 | goto failed; |
| 2344 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2347 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2348 | if (!result) goto failed; |
| 2349 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2350 | if (!value) goto failed; |
| 2351 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2352 | goto failed; |
| 2353 | Py_DECREF(value); |
| 2354 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2355 | if (!value) goto failed; |
| 2356 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2357 | goto failed; |
| 2358 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2359 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2360 | if (!value) goto failed; |
| 2361 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2362 | goto failed; |
| 2363 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2364 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2365 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2366 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2367 | if (!result) goto failed; |
| 2368 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2369 | if (!value) goto failed; |
| 2370 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2371 | goto failed; |
| 2372 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2373 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2374 | case Nonlocal_kind: |
| 2375 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2376 | if (!result) goto failed; |
| 2377 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2378 | if (!value) goto failed; |
| 2379 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2380 | goto failed; |
| 2381 | Py_DECREF(value); |
| 2382 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2384 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2385 | if (!result) goto failed; |
| 2386 | value = ast2obj_expr(o->v.Expr.value); |
| 2387 | if (!value) goto failed; |
| 2388 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2389 | goto failed; |
| 2390 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2393 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2394 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2397 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2398 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2399 | break; |
| 2400 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2401 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2402 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2403 | break; |
| 2404 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2405 | value = ast2obj_int(o->lineno); |
| 2406 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2407 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2408 | goto failed; |
| 2409 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2410 | value = ast2obj_int(o->col_offset); |
| 2411 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2412 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2413 | goto failed; |
| 2414 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2415 | return result; |
| 2416 | failed: |
| 2417 | Py_XDECREF(value); |
| 2418 | Py_XDECREF(result); |
| 2419 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2422 | PyObject* |
| 2423 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2424 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2425 | expr_ty o = (expr_ty)_o; |
| 2426 | PyObject *result = NULL, *value = NULL; |
| 2427 | if (!o) { |
| 2428 | Py_INCREF(Py_None); |
| 2429 | return Py_None; |
| 2430 | } |
| 2431 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2432 | switch (o->kind) { |
| 2433 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2434 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2435 | if (!result) goto failed; |
| 2436 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2437 | if (!value) goto failed; |
| 2438 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2439 | goto failed; |
| 2440 | Py_DECREF(value); |
| 2441 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2442 | if (!value) goto failed; |
| 2443 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2444 | goto failed; |
| 2445 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2448 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2449 | if (!result) goto failed; |
| 2450 | value = ast2obj_expr(o->v.BinOp.left); |
| 2451 | if (!value) goto failed; |
| 2452 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2453 | goto failed; |
| 2454 | Py_DECREF(value); |
| 2455 | value = ast2obj_operator(o->v.BinOp.op); |
| 2456 | if (!value) goto failed; |
| 2457 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2458 | goto failed; |
| 2459 | Py_DECREF(value); |
| 2460 | value = ast2obj_expr(o->v.BinOp.right); |
| 2461 | if (!value) goto failed; |
| 2462 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2467 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2468 | if (!result) goto failed; |
| 2469 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2470 | if (!value) goto failed; |
| 2471 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2472 | goto failed; |
| 2473 | Py_DECREF(value); |
| 2474 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2475 | if (!value) goto failed; |
| 2476 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2477 | goto failed; |
| 2478 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2481 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2482 | if (!result) goto failed; |
| 2483 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2484 | if (!value) goto failed; |
| 2485 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2486 | goto failed; |
| 2487 | Py_DECREF(value); |
| 2488 | value = ast2obj_expr(o->v.Lambda.body); |
| 2489 | if (!value) goto failed; |
| 2490 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2491 | goto failed; |
| 2492 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2493 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2494 | case IfExp_kind: |
| 2495 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2496 | if (!result) goto failed; |
| 2497 | value = ast2obj_expr(o->v.IfExp.test); |
| 2498 | if (!value) goto failed; |
| 2499 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2500 | goto failed; |
| 2501 | Py_DECREF(value); |
| 2502 | value = ast2obj_expr(o->v.IfExp.body); |
| 2503 | if (!value) goto failed; |
| 2504 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2505 | goto failed; |
| 2506 | Py_DECREF(value); |
| 2507 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2508 | if (!value) goto failed; |
| 2509 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2510 | goto failed; |
| 2511 | Py_DECREF(value); |
| 2512 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2513 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2514 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2515 | if (!result) goto failed; |
| 2516 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2517 | if (!value) goto failed; |
| 2518 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2519 | goto failed; |
| 2520 | Py_DECREF(value); |
| 2521 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2522 | if (!value) goto failed; |
| 2523 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2524 | goto failed; |
| 2525 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2526 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2527 | case Set_kind: |
| 2528 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2529 | if (!result) goto failed; |
| 2530 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2531 | if (!value) goto failed; |
| 2532 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2533 | goto failed; |
| 2534 | Py_DECREF(value); |
| 2535 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2536 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2537 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2538 | if (!result) goto failed; |
| 2539 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2540 | if (!value) goto failed; |
| 2541 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2542 | goto failed; |
| 2543 | Py_DECREF(value); |
| 2544 | value = ast2obj_list(o->v.ListComp.generators, |
| 2545 | ast2obj_comprehension); |
| 2546 | if (!value) goto failed; |
| 2547 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2548 | goto failed; |
| 2549 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2550 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2551 | case SetComp_kind: |
| 2552 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2553 | if (!result) goto failed; |
| 2554 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2555 | if (!value) goto failed; |
| 2556 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2557 | goto failed; |
| 2558 | Py_DECREF(value); |
| 2559 | value = ast2obj_list(o->v.SetComp.generators, |
| 2560 | ast2obj_comprehension); |
| 2561 | if (!value) goto failed; |
| 2562 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2563 | goto failed; |
| 2564 | Py_DECREF(value); |
| 2565 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2566 | case DictComp_kind: |
| 2567 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2568 | if (!result) goto failed; |
| 2569 | value = ast2obj_expr(o->v.DictComp.key); |
| 2570 | if (!value) goto failed; |
| 2571 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2572 | goto failed; |
| 2573 | Py_DECREF(value); |
| 2574 | value = ast2obj_expr(o->v.DictComp.value); |
| 2575 | if (!value) goto failed; |
| 2576 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2577 | goto failed; |
| 2578 | Py_DECREF(value); |
| 2579 | value = ast2obj_list(o->v.DictComp.generators, |
| 2580 | ast2obj_comprehension); |
| 2581 | if (!value) goto failed; |
| 2582 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2583 | goto failed; |
| 2584 | Py_DECREF(value); |
| 2585 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2586 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2587 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2588 | if (!result) goto failed; |
| 2589 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2590 | if (!value) goto failed; |
| 2591 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2592 | goto failed; |
| 2593 | Py_DECREF(value); |
| 2594 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2595 | ast2obj_comprehension); |
| 2596 | if (!value) goto failed; |
| 2597 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2598 | goto failed; |
| 2599 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2602 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2603 | if (!result) goto failed; |
| 2604 | value = ast2obj_expr(o->v.Yield.value); |
| 2605 | if (!value) goto failed; |
| 2606 | if (PyObject_SetAttrString(result, "value", 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 Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2611 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2612 | if (!result) goto failed; |
| 2613 | value = ast2obj_expr(o->v.Compare.left); |
| 2614 | if (!value) goto failed; |
| 2615 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2616 | goto failed; |
| 2617 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2618 | { |
| 2619 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2620 | value = PyList_New(n); |
| 2621 | if (!value) goto failed; |
| 2622 | for(i = 0; i < n; i++) |
| 2623 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2624 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2625 | if (!value) goto failed; |
| 2626 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2627 | goto failed; |
| 2628 | Py_DECREF(value); |
| 2629 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2630 | if (!value) goto failed; |
| 2631 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2636 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2637 | if (!result) goto failed; |
| 2638 | value = ast2obj_expr(o->v.Call.func); |
| 2639 | if (!value) goto failed; |
| 2640 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2641 | goto failed; |
| 2642 | Py_DECREF(value); |
| 2643 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2644 | if (!value) goto failed; |
| 2645 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2646 | goto failed; |
| 2647 | Py_DECREF(value); |
| 2648 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2649 | if (!value) goto failed; |
| 2650 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2651 | goto failed; |
| 2652 | Py_DECREF(value); |
| 2653 | value = ast2obj_expr(o->v.Call.starargs); |
| 2654 | if (!value) goto failed; |
| 2655 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2656 | goto failed; |
| 2657 | Py_DECREF(value); |
| 2658 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2659 | if (!value) goto failed; |
| 2660 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2661 | goto failed; |
| 2662 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2663 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2664 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2665 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2666 | if (!result) goto failed; |
| 2667 | value = ast2obj_object(o->v.Num.n); |
| 2668 | if (!value) goto failed; |
| 2669 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2670 | goto failed; |
| 2671 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2672 | break; |
| 2673 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2674 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2675 | if (!result) goto failed; |
| 2676 | value = ast2obj_string(o->v.Str.s); |
| 2677 | if (!value) goto failed; |
| 2678 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2681 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2682 | case Bytes_kind: |
| 2683 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2684 | if (!result) goto failed; |
| 2685 | value = ast2obj_string(o->v.Bytes.s); |
| 2686 | if (!value) goto failed; |
| 2687 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
| 2690 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2691 | case Ellipsis_kind: |
| 2692 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2693 | if (!result) goto failed; |
| 2694 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2695 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2696 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2697 | if (!result) goto failed; |
| 2698 | value = ast2obj_expr(o->v.Attribute.value); |
| 2699 | if (!value) goto failed; |
| 2700 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2701 | goto failed; |
| 2702 | Py_DECREF(value); |
| 2703 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2704 | if (!value) goto failed; |
| 2705 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2706 | goto failed; |
| 2707 | Py_DECREF(value); |
| 2708 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2709 | if (!value) goto failed; |
| 2710 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2713 | break; |
| 2714 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2715 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2716 | if (!result) goto failed; |
| 2717 | value = ast2obj_expr(o->v.Subscript.value); |
| 2718 | if (!value) goto failed; |
| 2719 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
| 2722 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2723 | if (!value) goto failed; |
| 2724 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2725 | goto failed; |
| 2726 | Py_DECREF(value); |
| 2727 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2728 | if (!value) goto failed; |
| 2729 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2730 | goto failed; |
| 2731 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2732 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2733 | case Starred_kind: |
| 2734 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2735 | if (!result) goto failed; |
| 2736 | value = ast2obj_expr(o->v.Starred.value); |
| 2737 | if (!value) goto failed; |
| 2738 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2739 | goto failed; |
| 2740 | Py_DECREF(value); |
| 2741 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2742 | if (!value) goto failed; |
| 2743 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2744 | goto failed; |
| 2745 | Py_DECREF(value); |
| 2746 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2747 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2748 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2749 | if (!result) goto failed; |
| 2750 | value = ast2obj_identifier(o->v.Name.id); |
| 2751 | if (!value) goto failed; |
| 2752 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2753 | goto failed; |
| 2754 | Py_DECREF(value); |
| 2755 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2756 | if (!value) goto failed; |
| 2757 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2758 | goto failed; |
| 2759 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2760 | break; |
| 2761 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2762 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2763 | if (!result) goto failed; |
| 2764 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2765 | if (!value) goto failed; |
| 2766 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2767 | goto failed; |
| 2768 | Py_DECREF(value); |
| 2769 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2770 | if (!value) goto failed; |
| 2771 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2772 | goto failed; |
| 2773 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2774 | break; |
| 2775 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2776 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2777 | if (!result) goto failed; |
| 2778 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2779 | if (!value) goto failed; |
| 2780 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2781 | goto failed; |
| 2782 | Py_DECREF(value); |
| 2783 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2784 | if (!value) goto failed; |
| 2785 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2786 | goto failed; |
| 2787 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2788 | break; |
| 2789 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2790 | value = ast2obj_int(o->lineno); |
| 2791 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2792 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2793 | goto failed; |
| 2794 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2795 | value = ast2obj_int(o->col_offset); |
| 2796 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2797 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2798 | goto failed; |
| 2799 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2800 | return result; |
| 2801 | failed: |
| 2802 | Py_XDECREF(value); |
| 2803 | Py_XDECREF(result); |
| 2804 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2807 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2808 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2809 | switch(o) { |
| 2810 | case Load: |
| 2811 | Py_INCREF(Load_singleton); |
| 2812 | return Load_singleton; |
| 2813 | case Store: |
| 2814 | Py_INCREF(Store_singleton); |
| 2815 | return Store_singleton; |
| 2816 | case Del: |
| 2817 | Py_INCREF(Del_singleton); |
| 2818 | return Del_singleton; |
| 2819 | case AugLoad: |
| 2820 | Py_INCREF(AugLoad_singleton); |
| 2821 | return AugLoad_singleton; |
| 2822 | case AugStore: |
| 2823 | Py_INCREF(AugStore_singleton); |
| 2824 | return AugStore_singleton; |
| 2825 | case Param: |
| 2826 | Py_INCREF(Param_singleton); |
| 2827 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2828 | default: |
| 2829 | /* should never happen, but just in case ... */ |
| 2830 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2831 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2832 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2833 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2834 | PyObject* |
| 2835 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2836 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2837 | slice_ty o = (slice_ty)_o; |
| 2838 | PyObject *result = NULL, *value = NULL; |
| 2839 | if (!o) { |
| 2840 | Py_INCREF(Py_None); |
| 2841 | return Py_None; |
| 2842 | } |
| 2843 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2844 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2845 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2846 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2847 | if (!result) goto failed; |
| 2848 | value = ast2obj_expr(o->v.Slice.lower); |
| 2849 | if (!value) goto failed; |
| 2850 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2851 | goto failed; |
| 2852 | Py_DECREF(value); |
| 2853 | value = ast2obj_expr(o->v.Slice.upper); |
| 2854 | if (!value) goto failed; |
| 2855 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2856 | goto failed; |
| 2857 | Py_DECREF(value); |
| 2858 | value = ast2obj_expr(o->v.Slice.step); |
| 2859 | if (!value) goto failed; |
| 2860 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2861 | goto failed; |
| 2862 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2865 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2866 | if (!result) goto failed; |
| 2867 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2868 | if (!value) goto failed; |
| 2869 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2870 | goto failed; |
| 2871 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2872 | break; |
| 2873 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2874 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2875 | if (!result) goto failed; |
| 2876 | value = ast2obj_expr(o->v.Index.value); |
| 2877 | if (!value) goto failed; |
| 2878 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2879 | goto failed; |
| 2880 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2881 | break; |
| 2882 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2883 | return result; |
| 2884 | failed: |
| 2885 | Py_XDECREF(value); |
| 2886 | Py_XDECREF(result); |
| 2887 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2890 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2891 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2892 | switch(o) { |
| 2893 | case And: |
| 2894 | Py_INCREF(And_singleton); |
| 2895 | return And_singleton; |
| 2896 | case Or: |
| 2897 | Py_INCREF(Or_singleton); |
| 2898 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2899 | default: |
| 2900 | /* should never happen, but just in case ... */ |
| 2901 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 2902 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2903 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2904 | } |
| 2905 | PyObject* ast2obj_operator(operator_ty o) |
| 2906 | { |
| 2907 | switch(o) { |
| 2908 | case Add: |
| 2909 | Py_INCREF(Add_singleton); |
| 2910 | return Add_singleton; |
| 2911 | case Sub: |
| 2912 | Py_INCREF(Sub_singleton); |
| 2913 | return Sub_singleton; |
| 2914 | case Mult: |
| 2915 | Py_INCREF(Mult_singleton); |
| 2916 | return Mult_singleton; |
| 2917 | case Div: |
| 2918 | Py_INCREF(Div_singleton); |
| 2919 | return Div_singleton; |
| 2920 | case Mod: |
| 2921 | Py_INCREF(Mod_singleton); |
| 2922 | return Mod_singleton; |
| 2923 | case Pow: |
| 2924 | Py_INCREF(Pow_singleton); |
| 2925 | return Pow_singleton; |
| 2926 | case LShift: |
| 2927 | Py_INCREF(LShift_singleton); |
| 2928 | return LShift_singleton; |
| 2929 | case RShift: |
| 2930 | Py_INCREF(RShift_singleton); |
| 2931 | return RShift_singleton; |
| 2932 | case BitOr: |
| 2933 | Py_INCREF(BitOr_singleton); |
| 2934 | return BitOr_singleton; |
| 2935 | case BitXor: |
| 2936 | Py_INCREF(BitXor_singleton); |
| 2937 | return BitXor_singleton; |
| 2938 | case BitAnd: |
| 2939 | Py_INCREF(BitAnd_singleton); |
| 2940 | return BitAnd_singleton; |
| 2941 | case FloorDiv: |
| 2942 | Py_INCREF(FloorDiv_singleton); |
| 2943 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2944 | default: |
| 2945 | /* should never happen, but just in case ... */ |
| 2946 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 2947 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2948 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2949 | } |
| 2950 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 2951 | { |
| 2952 | switch(o) { |
| 2953 | case Invert: |
| 2954 | Py_INCREF(Invert_singleton); |
| 2955 | return Invert_singleton; |
| 2956 | case Not: |
| 2957 | Py_INCREF(Not_singleton); |
| 2958 | return Not_singleton; |
| 2959 | case UAdd: |
| 2960 | Py_INCREF(UAdd_singleton); |
| 2961 | return UAdd_singleton; |
| 2962 | case USub: |
| 2963 | Py_INCREF(USub_singleton); |
| 2964 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2965 | default: |
| 2966 | /* should never happen, but just in case ... */ |
| 2967 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 2968 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2969 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2970 | } |
| 2971 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 2972 | { |
| 2973 | switch(o) { |
| 2974 | case Eq: |
| 2975 | Py_INCREF(Eq_singleton); |
| 2976 | return Eq_singleton; |
| 2977 | case NotEq: |
| 2978 | Py_INCREF(NotEq_singleton); |
| 2979 | return NotEq_singleton; |
| 2980 | case Lt: |
| 2981 | Py_INCREF(Lt_singleton); |
| 2982 | return Lt_singleton; |
| 2983 | case LtE: |
| 2984 | Py_INCREF(LtE_singleton); |
| 2985 | return LtE_singleton; |
| 2986 | case Gt: |
| 2987 | Py_INCREF(Gt_singleton); |
| 2988 | return Gt_singleton; |
| 2989 | case GtE: |
| 2990 | Py_INCREF(GtE_singleton); |
| 2991 | return GtE_singleton; |
| 2992 | case Is: |
| 2993 | Py_INCREF(Is_singleton); |
| 2994 | return Is_singleton; |
| 2995 | case IsNot: |
| 2996 | Py_INCREF(IsNot_singleton); |
| 2997 | return IsNot_singleton; |
| 2998 | case In: |
| 2999 | Py_INCREF(In_singleton); |
| 3000 | return In_singleton; |
| 3001 | case NotIn: |
| 3002 | Py_INCREF(NotIn_singleton); |
| 3003 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3004 | default: |
| 3005 | /* should never happen, but just in case ... */ |
| 3006 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3007 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3008 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3009 | } |
| 3010 | PyObject* |
| 3011 | ast2obj_comprehension(void* _o) |
| 3012 | { |
| 3013 | comprehension_ty o = (comprehension_ty)_o; |
| 3014 | PyObject *result = NULL, *value = NULL; |
| 3015 | if (!o) { |
| 3016 | Py_INCREF(Py_None); |
| 3017 | return Py_None; |
| 3018 | } |
| 3019 | |
| 3020 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3021 | if (!result) return NULL; |
| 3022 | value = ast2obj_expr(o->target); |
| 3023 | if (!value) goto failed; |
| 3024 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3025 | goto failed; |
| 3026 | Py_DECREF(value); |
| 3027 | value = ast2obj_expr(o->iter); |
| 3028 | if (!value) goto failed; |
| 3029 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3030 | goto failed; |
| 3031 | Py_DECREF(value); |
| 3032 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3033 | if (!value) goto failed; |
| 3034 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3035 | goto failed; |
| 3036 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3037 | return result; |
| 3038 | failed: |
| 3039 | Py_XDECREF(value); |
| 3040 | Py_XDECREF(result); |
| 3041 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3044 | PyObject* |
| 3045 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3046 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3047 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3048 | PyObject *result = NULL, *value = NULL; |
| 3049 | if (!o) { |
| 3050 | Py_INCREF(Py_None); |
| 3051 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3052 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3053 | |
| 3054 | result = PyType_GenericNew(excepthandler_type, NULL, NULL); |
| 3055 | if (!result) return NULL; |
| 3056 | value = ast2obj_expr(o->type); |
| 3057 | if (!value) goto failed; |
| 3058 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3059 | goto failed; |
| 3060 | Py_DECREF(value); |
Guido van Rossum | 16be03e | 2007-01-10 18:51:35 +0000 | [diff] [blame] | 3061 | value = ast2obj_identifier(o->name); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3062 | if (!value) goto failed; |
| 3063 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3064 | goto failed; |
| 3065 | Py_DECREF(value); |
| 3066 | value = ast2obj_list(o->body, ast2obj_stmt); |
| 3067 | if (!value) goto failed; |
| 3068 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3069 | goto failed; |
| 3070 | Py_DECREF(value); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3071 | value = ast2obj_int(o->lineno); |
| 3072 | if (!value) goto failed; |
| 3073 | if (PyObject_SetAttrString(result, "lineno", value) == -1) |
| 3074 | goto failed; |
| 3075 | Py_DECREF(value); |
| 3076 | value = ast2obj_int(o->col_offset); |
| 3077 | if (!value) goto failed; |
| 3078 | if (PyObject_SetAttrString(result, "col_offset", value) == -1) |
| 3079 | goto failed; |
| 3080 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | return result; |
| 3082 | failed: |
| 3083 | Py_XDECREF(value); |
| 3084 | Py_XDECREF(result); |
| 3085 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3088 | PyObject* |
| 3089 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3090 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3091 | arguments_ty o = (arguments_ty)_o; |
| 3092 | PyObject *result = NULL, *value = NULL; |
| 3093 | if (!o) { |
| 3094 | Py_INCREF(Py_None); |
| 3095 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3096 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3097 | |
| 3098 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3099 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3100 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3101 | if (!value) goto failed; |
| 3102 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3103 | goto failed; |
| 3104 | Py_DECREF(value); |
| 3105 | value = ast2obj_identifier(o->vararg); |
| 3106 | if (!value) goto failed; |
| 3107 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3108 | goto failed; |
| 3109 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3110 | value = ast2obj_expr(o->varargannotation); |
| 3111 | if (!value) goto failed; |
| 3112 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3113 | goto failed; |
| 3114 | Py_DECREF(value); |
| 3115 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3116 | if (!value) goto failed; |
| 3117 | if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) |
| 3118 | goto failed; |
| 3119 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3120 | value = ast2obj_identifier(o->kwarg); |
| 3121 | if (!value) goto failed; |
| 3122 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3123 | goto failed; |
| 3124 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3125 | value = ast2obj_expr(o->kwargannotation); |
| 3126 | if (!value) goto failed; |
| 3127 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3128 | goto failed; |
| 3129 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3130 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3131 | if (!value) goto failed; |
| 3132 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3133 | goto failed; |
| 3134 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3135 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3136 | if (!value) goto failed; |
| 3137 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3138 | goto failed; |
| 3139 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3140 | return result; |
| 3141 | failed: |
| 3142 | Py_XDECREF(value); |
| 3143 | Py_XDECREF(result); |
| 3144 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3147 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3148 | ast2obj_arg(void* _o) |
| 3149 | { |
| 3150 | arg_ty o = (arg_ty)_o; |
| 3151 | PyObject *result = NULL, *value = NULL; |
| 3152 | if (!o) { |
| 3153 | Py_INCREF(Py_None); |
| 3154 | return Py_None; |
| 3155 | } |
| 3156 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3157 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3158 | if (!result) return NULL; |
| 3159 | value = ast2obj_identifier(o->arg); |
| 3160 | if (!value) goto failed; |
| 3161 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3162 | goto failed; |
| 3163 | Py_DECREF(value); |
| 3164 | value = ast2obj_expr(o->annotation); |
| 3165 | if (!value) goto failed; |
| 3166 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3167 | goto failed; |
| 3168 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3169 | return result; |
| 3170 | failed: |
| 3171 | Py_XDECREF(value); |
| 3172 | Py_XDECREF(result); |
| 3173 | return NULL; |
| 3174 | } |
| 3175 | |
| 3176 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3177 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3178 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3179 | keyword_ty o = (keyword_ty)_o; |
| 3180 | PyObject *result = NULL, *value = NULL; |
| 3181 | if (!o) { |
| 3182 | Py_INCREF(Py_None); |
| 3183 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3184 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3185 | |
| 3186 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3187 | if (!result) return NULL; |
| 3188 | value = ast2obj_identifier(o->arg); |
| 3189 | if (!value) goto failed; |
| 3190 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3191 | goto failed; |
| 3192 | Py_DECREF(value); |
| 3193 | value = ast2obj_expr(o->value); |
| 3194 | if (!value) goto failed; |
| 3195 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3196 | goto failed; |
| 3197 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3198 | return result; |
| 3199 | failed: |
| 3200 | Py_XDECREF(value); |
| 3201 | Py_XDECREF(result); |
| 3202 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3205 | PyObject* |
| 3206 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3207 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3208 | alias_ty o = (alias_ty)_o; |
| 3209 | PyObject *result = NULL, *value = NULL; |
| 3210 | if (!o) { |
| 3211 | Py_INCREF(Py_None); |
| 3212 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3213 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3214 | |
| 3215 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3216 | if (!result) return NULL; |
| 3217 | value = ast2obj_identifier(o->name); |
| 3218 | if (!value) goto failed; |
| 3219 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3220 | goto failed; |
| 3221 | Py_DECREF(value); |
| 3222 | value = ast2obj_identifier(o->asname); |
| 3223 | if (!value) goto failed; |
| 3224 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3225 | goto failed; |
| 3226 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | return result; |
| 3228 | failed: |
| 3229 | Py_XDECREF(value); |
| 3230 | Py_XDECREF(result); |
| 3231 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3234 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3235 | int |
| 3236 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3237 | { |
| 3238 | PyObject* tmp = NULL; |
| 3239 | |
| 3240 | |
| 3241 | if (obj == Py_None) { |
| 3242 | *out = NULL; |
| 3243 | return 0; |
| 3244 | } |
| 3245 | if (PyObject_IsInstance(obj, (PyObject*)Module_type)) { |
| 3246 | asdl_seq* body; |
| 3247 | |
| 3248 | if (PyObject_HasAttrString(obj, "body")) { |
| 3249 | int res; |
| 3250 | Py_ssize_t len; |
| 3251 | Py_ssize_t i; |
| 3252 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3253 | if (tmp == NULL) goto failed; |
| 3254 | if (!PyList_Check(tmp)) { |
| 3255 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3256 | goto failed; |
| 3257 | } |
| 3258 | len = PyList_GET_SIZE(tmp); |
| 3259 | body = asdl_seq_new(len, arena); |
| 3260 | if (body == NULL) goto failed; |
| 3261 | for (i = 0; i < len; i++) { |
| 3262 | stmt_ty value; |
| 3263 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3264 | if (res != 0) goto failed; |
| 3265 | asdl_seq_SET(body, i, value); |
| 3266 | } |
| 3267 | Py_XDECREF(tmp); |
| 3268 | tmp = NULL; |
| 3269 | } else { |
| 3270 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3271 | return 1; |
| 3272 | } |
| 3273 | *out = Module(body, arena); |
| 3274 | if (*out == NULL) goto failed; |
| 3275 | return 0; |
| 3276 | } |
| 3277 | if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) { |
| 3278 | asdl_seq* body; |
| 3279 | |
| 3280 | if (PyObject_HasAttrString(obj, "body")) { |
| 3281 | int res; |
| 3282 | Py_ssize_t len; |
| 3283 | Py_ssize_t i; |
| 3284 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3285 | if (tmp == NULL) goto failed; |
| 3286 | if (!PyList_Check(tmp)) { |
| 3287 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3288 | goto failed; |
| 3289 | } |
| 3290 | len = PyList_GET_SIZE(tmp); |
| 3291 | body = asdl_seq_new(len, arena); |
| 3292 | if (body == NULL) goto failed; |
| 3293 | for (i = 0; i < len; i++) { |
| 3294 | stmt_ty value; |
| 3295 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3296 | if (res != 0) goto failed; |
| 3297 | asdl_seq_SET(body, i, value); |
| 3298 | } |
| 3299 | Py_XDECREF(tmp); |
| 3300 | tmp = NULL; |
| 3301 | } else { |
| 3302 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3303 | return 1; |
| 3304 | } |
| 3305 | *out = Interactive(body, arena); |
| 3306 | if (*out == NULL) goto failed; |
| 3307 | return 0; |
| 3308 | } |
| 3309 | if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) { |
| 3310 | expr_ty body; |
| 3311 | |
| 3312 | if (PyObject_HasAttrString(obj, "body")) { |
| 3313 | int res; |
| 3314 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3315 | if (tmp == NULL) goto failed; |
| 3316 | res = obj2ast_expr(tmp, &body, arena); |
| 3317 | if (res != 0) goto failed; |
| 3318 | Py_XDECREF(tmp); |
| 3319 | tmp = NULL; |
| 3320 | } else { |
| 3321 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3322 | return 1; |
| 3323 | } |
| 3324 | *out = Expression(body, arena); |
| 3325 | if (*out == NULL) goto failed; |
| 3326 | return 0; |
| 3327 | } |
| 3328 | if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) { |
| 3329 | asdl_seq* body; |
| 3330 | |
| 3331 | if (PyObject_HasAttrString(obj, "body")) { |
| 3332 | int res; |
| 3333 | Py_ssize_t len; |
| 3334 | Py_ssize_t i; |
| 3335 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3336 | if (tmp == NULL) goto failed; |
| 3337 | if (!PyList_Check(tmp)) { |
| 3338 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3339 | goto failed; |
| 3340 | } |
| 3341 | len = PyList_GET_SIZE(tmp); |
| 3342 | body = asdl_seq_new(len, arena); |
| 3343 | if (body == NULL) goto failed; |
| 3344 | for (i = 0; i < len; i++) { |
| 3345 | stmt_ty value; |
| 3346 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3347 | if (res != 0) goto failed; |
| 3348 | asdl_seq_SET(body, i, value); |
| 3349 | } |
| 3350 | Py_XDECREF(tmp); |
| 3351 | tmp = NULL; |
| 3352 | } else { |
| 3353 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3354 | return 1; |
| 3355 | } |
| 3356 | *out = Suite(body, arena); |
| 3357 | if (*out == NULL) goto failed; |
| 3358 | return 0; |
| 3359 | } |
| 3360 | |
| 3361 | tmp = PyObject_Repr(obj); |
| 3362 | if (tmp == NULL) goto failed; |
| 3363 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp)); |
| 3364 | failed: |
| 3365 | Py_XDECREF(tmp); |
| 3366 | return 1; |
| 3367 | } |
| 3368 | |
| 3369 | int |
| 3370 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3371 | { |
| 3372 | PyObject* tmp = NULL; |
| 3373 | |
| 3374 | int lineno; |
| 3375 | int col_offset; |
| 3376 | |
| 3377 | if (obj == Py_None) { |
| 3378 | *out = NULL; |
| 3379 | return 0; |
| 3380 | } |
| 3381 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3382 | int res; |
| 3383 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3384 | if (tmp == NULL) goto failed; |
| 3385 | res = obj2ast_int(tmp, &lineno, arena); |
| 3386 | if (res != 0) goto failed; |
| 3387 | Py_XDECREF(tmp); |
| 3388 | tmp = NULL; |
| 3389 | } else { |
| 3390 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3391 | return 1; |
| 3392 | } |
| 3393 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3394 | int res; |
| 3395 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3396 | if (tmp == NULL) goto failed; |
| 3397 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3398 | if (res != 0) goto failed; |
| 3399 | Py_XDECREF(tmp); |
| 3400 | tmp = NULL; |
| 3401 | } else { |
| 3402 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3403 | return 1; |
| 3404 | } |
| 3405 | if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) { |
| 3406 | identifier name; |
| 3407 | arguments_ty args; |
| 3408 | asdl_seq* body; |
| 3409 | asdl_seq* decorator_list; |
| 3410 | expr_ty returns; |
| 3411 | |
| 3412 | if (PyObject_HasAttrString(obj, "name")) { |
| 3413 | int res; |
| 3414 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3415 | if (tmp == NULL) goto failed; |
| 3416 | res = obj2ast_identifier(tmp, &name, arena); |
| 3417 | if (res != 0) goto failed; |
| 3418 | Py_XDECREF(tmp); |
| 3419 | tmp = NULL; |
| 3420 | } else { |
| 3421 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3422 | return 1; |
| 3423 | } |
| 3424 | if (PyObject_HasAttrString(obj, "args")) { |
| 3425 | int res; |
| 3426 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3427 | if (tmp == NULL) goto failed; |
| 3428 | res = obj2ast_arguments(tmp, &args, arena); |
| 3429 | if (res != 0) goto failed; |
| 3430 | Py_XDECREF(tmp); |
| 3431 | tmp = NULL; |
| 3432 | } else { |
| 3433 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3434 | return 1; |
| 3435 | } |
| 3436 | if (PyObject_HasAttrString(obj, "body")) { |
| 3437 | int res; |
| 3438 | Py_ssize_t len; |
| 3439 | Py_ssize_t i; |
| 3440 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3441 | if (tmp == NULL) goto failed; |
| 3442 | if (!PyList_Check(tmp)) { |
| 3443 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3444 | goto failed; |
| 3445 | } |
| 3446 | len = PyList_GET_SIZE(tmp); |
| 3447 | body = asdl_seq_new(len, arena); |
| 3448 | if (body == NULL) goto failed; |
| 3449 | for (i = 0; i < len; i++) { |
| 3450 | stmt_ty value; |
| 3451 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3452 | if (res != 0) goto failed; |
| 3453 | asdl_seq_SET(body, i, value); |
| 3454 | } |
| 3455 | Py_XDECREF(tmp); |
| 3456 | tmp = NULL; |
| 3457 | } else { |
| 3458 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3459 | return 1; |
| 3460 | } |
| 3461 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3462 | int res; |
| 3463 | Py_ssize_t len; |
| 3464 | Py_ssize_t i; |
| 3465 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3466 | if (tmp == NULL) goto failed; |
| 3467 | if (!PyList_Check(tmp)) { |
| 3468 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3469 | goto failed; |
| 3470 | } |
| 3471 | len = PyList_GET_SIZE(tmp); |
| 3472 | decorator_list = asdl_seq_new(len, arena); |
| 3473 | if (decorator_list == NULL) goto failed; |
| 3474 | for (i = 0; i < len; i++) { |
| 3475 | expr_ty value; |
| 3476 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3477 | if (res != 0) goto failed; |
| 3478 | asdl_seq_SET(decorator_list, i, value); |
| 3479 | } |
| 3480 | Py_XDECREF(tmp); |
| 3481 | tmp = NULL; |
| 3482 | } else { |
| 3483 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3484 | return 1; |
| 3485 | } |
| 3486 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3487 | int res; |
| 3488 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3489 | if (tmp == NULL) goto failed; |
| 3490 | res = obj2ast_expr(tmp, &returns, arena); |
| 3491 | if (res != 0) goto failed; |
| 3492 | Py_XDECREF(tmp); |
| 3493 | tmp = NULL; |
| 3494 | } else { |
| 3495 | returns = NULL; |
| 3496 | } |
| 3497 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3498 | lineno, col_offset, arena); |
| 3499 | if (*out == NULL) goto failed; |
| 3500 | return 0; |
| 3501 | } |
| 3502 | if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) { |
| 3503 | identifier name; |
| 3504 | asdl_seq* bases; |
| 3505 | asdl_seq* keywords; |
| 3506 | expr_ty starargs; |
| 3507 | expr_ty kwargs; |
| 3508 | asdl_seq* body; |
| 3509 | asdl_seq* decorator_list; |
| 3510 | |
| 3511 | if (PyObject_HasAttrString(obj, "name")) { |
| 3512 | int res; |
| 3513 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3514 | if (tmp == NULL) goto failed; |
| 3515 | res = obj2ast_identifier(tmp, &name, arena); |
| 3516 | if (res != 0) goto failed; |
| 3517 | Py_XDECREF(tmp); |
| 3518 | tmp = NULL; |
| 3519 | } else { |
| 3520 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3521 | return 1; |
| 3522 | } |
| 3523 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3524 | int res; |
| 3525 | Py_ssize_t len; |
| 3526 | Py_ssize_t i; |
| 3527 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3528 | if (tmp == NULL) goto failed; |
| 3529 | if (!PyList_Check(tmp)) { |
| 3530 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3531 | goto failed; |
| 3532 | } |
| 3533 | len = PyList_GET_SIZE(tmp); |
| 3534 | bases = asdl_seq_new(len, arena); |
| 3535 | if (bases == NULL) goto failed; |
| 3536 | for (i = 0; i < len; i++) { |
| 3537 | expr_ty value; |
| 3538 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3539 | if (res != 0) goto failed; |
| 3540 | asdl_seq_SET(bases, i, value); |
| 3541 | } |
| 3542 | Py_XDECREF(tmp); |
| 3543 | tmp = NULL; |
| 3544 | } else { |
| 3545 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3546 | return 1; |
| 3547 | } |
| 3548 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3549 | int res; |
| 3550 | Py_ssize_t len; |
| 3551 | Py_ssize_t i; |
| 3552 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3553 | if (tmp == NULL) goto failed; |
| 3554 | if (!PyList_Check(tmp)) { |
| 3555 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3556 | goto failed; |
| 3557 | } |
| 3558 | len = PyList_GET_SIZE(tmp); |
| 3559 | keywords = asdl_seq_new(len, arena); |
| 3560 | if (keywords == NULL) goto failed; |
| 3561 | for (i = 0; i < len; i++) { |
| 3562 | keyword_ty value; |
| 3563 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3564 | if (res != 0) goto failed; |
| 3565 | asdl_seq_SET(keywords, i, value); |
| 3566 | } |
| 3567 | Py_XDECREF(tmp); |
| 3568 | tmp = NULL; |
| 3569 | } else { |
| 3570 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3571 | return 1; |
| 3572 | } |
| 3573 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3574 | int res; |
| 3575 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3576 | if (tmp == NULL) goto failed; |
| 3577 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3578 | if (res != 0) goto failed; |
| 3579 | Py_XDECREF(tmp); |
| 3580 | tmp = NULL; |
| 3581 | } else { |
| 3582 | starargs = NULL; |
| 3583 | } |
| 3584 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3585 | int res; |
| 3586 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3587 | if (tmp == NULL) goto failed; |
| 3588 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3589 | if (res != 0) goto failed; |
| 3590 | Py_XDECREF(tmp); |
| 3591 | tmp = NULL; |
| 3592 | } else { |
| 3593 | kwargs = NULL; |
| 3594 | } |
| 3595 | if (PyObject_HasAttrString(obj, "body")) { |
| 3596 | int res; |
| 3597 | Py_ssize_t len; |
| 3598 | Py_ssize_t i; |
| 3599 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3600 | if (tmp == NULL) goto failed; |
| 3601 | if (!PyList_Check(tmp)) { |
| 3602 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3603 | goto failed; |
| 3604 | } |
| 3605 | len = PyList_GET_SIZE(tmp); |
| 3606 | body = asdl_seq_new(len, arena); |
| 3607 | if (body == NULL) goto failed; |
| 3608 | for (i = 0; i < len; i++) { |
| 3609 | stmt_ty value; |
| 3610 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3611 | if (res != 0) goto failed; |
| 3612 | asdl_seq_SET(body, i, value); |
| 3613 | } |
| 3614 | Py_XDECREF(tmp); |
| 3615 | tmp = NULL; |
| 3616 | } else { |
| 3617 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3618 | return 1; |
| 3619 | } |
| 3620 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3621 | int res; |
| 3622 | Py_ssize_t len; |
| 3623 | Py_ssize_t i; |
| 3624 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3625 | if (tmp == NULL) goto failed; |
| 3626 | if (!PyList_Check(tmp)) { |
| 3627 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3628 | goto failed; |
| 3629 | } |
| 3630 | len = PyList_GET_SIZE(tmp); |
| 3631 | decorator_list = asdl_seq_new(len, arena); |
| 3632 | if (decorator_list == NULL) goto failed; |
| 3633 | for (i = 0; i < len; i++) { |
| 3634 | expr_ty value; |
| 3635 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3636 | if (res != 0) goto failed; |
| 3637 | asdl_seq_SET(decorator_list, i, value); |
| 3638 | } |
| 3639 | Py_XDECREF(tmp); |
| 3640 | tmp = NULL; |
| 3641 | } else { |
| 3642 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3643 | return 1; |
| 3644 | } |
| 3645 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3646 | decorator_list, lineno, col_offset, arena); |
| 3647 | if (*out == NULL) goto failed; |
| 3648 | return 0; |
| 3649 | } |
| 3650 | if (PyObject_IsInstance(obj, (PyObject*)Return_type)) { |
| 3651 | expr_ty value; |
| 3652 | |
| 3653 | if (PyObject_HasAttrString(obj, "value")) { |
| 3654 | int res; |
| 3655 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3656 | if (tmp == NULL) goto failed; |
| 3657 | res = obj2ast_expr(tmp, &value, arena); |
| 3658 | if (res != 0) goto failed; |
| 3659 | Py_XDECREF(tmp); |
| 3660 | tmp = NULL; |
| 3661 | } else { |
| 3662 | value = NULL; |
| 3663 | } |
| 3664 | *out = Return(value, lineno, col_offset, arena); |
| 3665 | if (*out == NULL) goto failed; |
| 3666 | return 0; |
| 3667 | } |
| 3668 | if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) { |
| 3669 | asdl_seq* targets; |
| 3670 | |
| 3671 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3672 | int res; |
| 3673 | Py_ssize_t len; |
| 3674 | Py_ssize_t i; |
| 3675 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3676 | if (tmp == NULL) goto failed; |
| 3677 | if (!PyList_Check(tmp)) { |
| 3678 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3679 | goto failed; |
| 3680 | } |
| 3681 | len = PyList_GET_SIZE(tmp); |
| 3682 | targets = asdl_seq_new(len, arena); |
| 3683 | if (targets == NULL) goto failed; |
| 3684 | for (i = 0; i < len; i++) { |
| 3685 | expr_ty value; |
| 3686 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3687 | if (res != 0) goto failed; |
| 3688 | asdl_seq_SET(targets, i, value); |
| 3689 | } |
| 3690 | Py_XDECREF(tmp); |
| 3691 | tmp = NULL; |
| 3692 | } else { |
| 3693 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3694 | return 1; |
| 3695 | } |
| 3696 | *out = Delete(targets, lineno, col_offset, arena); |
| 3697 | if (*out == NULL) goto failed; |
| 3698 | return 0; |
| 3699 | } |
| 3700 | if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) { |
| 3701 | asdl_seq* targets; |
| 3702 | expr_ty value; |
| 3703 | |
| 3704 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3705 | int res; |
| 3706 | Py_ssize_t len; |
| 3707 | Py_ssize_t i; |
| 3708 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3709 | if (tmp == NULL) goto failed; |
| 3710 | if (!PyList_Check(tmp)) { |
| 3711 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3712 | goto failed; |
| 3713 | } |
| 3714 | len = PyList_GET_SIZE(tmp); |
| 3715 | targets = asdl_seq_new(len, arena); |
| 3716 | if (targets == NULL) goto failed; |
| 3717 | for (i = 0; i < len; i++) { |
| 3718 | expr_ty value; |
| 3719 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3720 | if (res != 0) goto failed; |
| 3721 | asdl_seq_SET(targets, i, value); |
| 3722 | } |
| 3723 | Py_XDECREF(tmp); |
| 3724 | tmp = NULL; |
| 3725 | } else { |
| 3726 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3727 | return 1; |
| 3728 | } |
| 3729 | if (PyObject_HasAttrString(obj, "value")) { |
| 3730 | int res; |
| 3731 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3732 | if (tmp == NULL) goto failed; |
| 3733 | res = obj2ast_expr(tmp, &value, arena); |
| 3734 | if (res != 0) goto failed; |
| 3735 | Py_XDECREF(tmp); |
| 3736 | tmp = NULL; |
| 3737 | } else { |
| 3738 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3739 | return 1; |
| 3740 | } |
| 3741 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3742 | if (*out == NULL) goto failed; |
| 3743 | return 0; |
| 3744 | } |
| 3745 | if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) { |
| 3746 | expr_ty target; |
| 3747 | operator_ty op; |
| 3748 | expr_ty value; |
| 3749 | |
| 3750 | if (PyObject_HasAttrString(obj, "target")) { |
| 3751 | int res; |
| 3752 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3753 | if (tmp == NULL) goto failed; |
| 3754 | res = obj2ast_expr(tmp, &target, arena); |
| 3755 | if (res != 0) goto failed; |
| 3756 | Py_XDECREF(tmp); |
| 3757 | tmp = NULL; |
| 3758 | } else { |
| 3759 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3760 | return 1; |
| 3761 | } |
| 3762 | if (PyObject_HasAttrString(obj, "op")) { |
| 3763 | int res; |
| 3764 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3765 | if (tmp == NULL) goto failed; |
| 3766 | res = obj2ast_operator(tmp, &op, arena); |
| 3767 | if (res != 0) goto failed; |
| 3768 | Py_XDECREF(tmp); |
| 3769 | tmp = NULL; |
| 3770 | } else { |
| 3771 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3772 | return 1; |
| 3773 | } |
| 3774 | if (PyObject_HasAttrString(obj, "value")) { |
| 3775 | int res; |
| 3776 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3777 | if (tmp == NULL) goto failed; |
| 3778 | res = obj2ast_expr(tmp, &value, arena); |
| 3779 | if (res != 0) goto failed; |
| 3780 | Py_XDECREF(tmp); |
| 3781 | tmp = NULL; |
| 3782 | } else { |
| 3783 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3784 | return 1; |
| 3785 | } |
| 3786 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3787 | if (*out == NULL) goto failed; |
| 3788 | return 0; |
| 3789 | } |
| 3790 | if (PyObject_IsInstance(obj, (PyObject*)For_type)) { |
| 3791 | expr_ty target; |
| 3792 | expr_ty iter; |
| 3793 | asdl_seq* body; |
| 3794 | asdl_seq* orelse; |
| 3795 | |
| 3796 | if (PyObject_HasAttrString(obj, "target")) { |
| 3797 | int res; |
| 3798 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3799 | if (tmp == NULL) goto failed; |
| 3800 | res = obj2ast_expr(tmp, &target, arena); |
| 3801 | if (res != 0) goto failed; |
| 3802 | Py_XDECREF(tmp); |
| 3803 | tmp = NULL; |
| 3804 | } else { |
| 3805 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3806 | return 1; |
| 3807 | } |
| 3808 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3809 | int res; |
| 3810 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3811 | if (tmp == NULL) goto failed; |
| 3812 | res = obj2ast_expr(tmp, &iter, arena); |
| 3813 | if (res != 0) goto failed; |
| 3814 | Py_XDECREF(tmp); |
| 3815 | tmp = NULL; |
| 3816 | } else { |
| 3817 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 3818 | return 1; |
| 3819 | } |
| 3820 | if (PyObject_HasAttrString(obj, "body")) { |
| 3821 | int res; |
| 3822 | Py_ssize_t len; |
| 3823 | Py_ssize_t i; |
| 3824 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3825 | if (tmp == NULL) goto failed; |
| 3826 | if (!PyList_Check(tmp)) { |
| 3827 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3828 | goto failed; |
| 3829 | } |
| 3830 | len = PyList_GET_SIZE(tmp); |
| 3831 | body = asdl_seq_new(len, arena); |
| 3832 | if (body == NULL) goto failed; |
| 3833 | for (i = 0; i < len; i++) { |
| 3834 | stmt_ty value; |
| 3835 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3836 | if (res != 0) goto failed; |
| 3837 | asdl_seq_SET(body, i, value); |
| 3838 | } |
| 3839 | Py_XDECREF(tmp); |
| 3840 | tmp = NULL; |
| 3841 | } else { |
| 3842 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 3843 | return 1; |
| 3844 | } |
| 3845 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3846 | int res; |
| 3847 | Py_ssize_t len; |
| 3848 | Py_ssize_t i; |
| 3849 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3850 | if (tmp == NULL) goto failed; |
| 3851 | if (!PyList_Check(tmp)) { |
| 3852 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3853 | goto failed; |
| 3854 | } |
| 3855 | len = PyList_GET_SIZE(tmp); |
| 3856 | orelse = asdl_seq_new(len, arena); |
| 3857 | if (orelse == NULL) goto failed; |
| 3858 | for (i = 0; i < len; i++) { |
| 3859 | stmt_ty value; |
| 3860 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3861 | if (res != 0) goto failed; |
| 3862 | asdl_seq_SET(orelse, i, value); |
| 3863 | } |
| 3864 | Py_XDECREF(tmp); |
| 3865 | tmp = NULL; |
| 3866 | } else { |
| 3867 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 3868 | return 1; |
| 3869 | } |
| 3870 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 3871 | arena); |
| 3872 | if (*out == NULL) goto failed; |
| 3873 | return 0; |
| 3874 | } |
| 3875 | if (PyObject_IsInstance(obj, (PyObject*)While_type)) { |
| 3876 | expr_ty test; |
| 3877 | asdl_seq* body; |
| 3878 | asdl_seq* orelse; |
| 3879 | |
| 3880 | if (PyObject_HasAttrString(obj, "test")) { |
| 3881 | int res; |
| 3882 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3883 | if (tmp == NULL) goto failed; |
| 3884 | res = obj2ast_expr(tmp, &test, arena); |
| 3885 | if (res != 0) goto failed; |
| 3886 | Py_XDECREF(tmp); |
| 3887 | tmp = NULL; |
| 3888 | } else { |
| 3889 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 3890 | return 1; |
| 3891 | } |
| 3892 | if (PyObject_HasAttrString(obj, "body")) { |
| 3893 | int res; |
| 3894 | Py_ssize_t len; |
| 3895 | Py_ssize_t i; |
| 3896 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3897 | if (tmp == NULL) goto failed; |
| 3898 | if (!PyList_Check(tmp)) { |
| 3899 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3900 | goto failed; |
| 3901 | } |
| 3902 | len = PyList_GET_SIZE(tmp); |
| 3903 | body = asdl_seq_new(len, arena); |
| 3904 | if (body == NULL) goto failed; |
| 3905 | for (i = 0; i < len; i++) { |
| 3906 | stmt_ty value; |
| 3907 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3908 | if (res != 0) goto failed; |
| 3909 | asdl_seq_SET(body, i, value); |
| 3910 | } |
| 3911 | Py_XDECREF(tmp); |
| 3912 | tmp = NULL; |
| 3913 | } else { |
| 3914 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 3915 | return 1; |
| 3916 | } |
| 3917 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3918 | int res; |
| 3919 | Py_ssize_t len; |
| 3920 | Py_ssize_t i; |
| 3921 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3922 | if (tmp == NULL) goto failed; |
| 3923 | if (!PyList_Check(tmp)) { |
| 3924 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3925 | goto failed; |
| 3926 | } |
| 3927 | len = PyList_GET_SIZE(tmp); |
| 3928 | orelse = asdl_seq_new(len, arena); |
| 3929 | if (orelse == NULL) goto failed; |
| 3930 | for (i = 0; i < len; i++) { |
| 3931 | stmt_ty value; |
| 3932 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3933 | if (res != 0) goto failed; |
| 3934 | asdl_seq_SET(orelse, i, value); |
| 3935 | } |
| 3936 | Py_XDECREF(tmp); |
| 3937 | tmp = NULL; |
| 3938 | } else { |
| 3939 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 3940 | return 1; |
| 3941 | } |
| 3942 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 3943 | if (*out == NULL) goto failed; |
| 3944 | return 0; |
| 3945 | } |
| 3946 | if (PyObject_IsInstance(obj, (PyObject*)If_type)) { |
| 3947 | expr_ty test; |
| 3948 | asdl_seq* body; |
| 3949 | asdl_seq* orelse; |
| 3950 | |
| 3951 | if (PyObject_HasAttrString(obj, "test")) { |
| 3952 | int res; |
| 3953 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3954 | if (tmp == NULL) goto failed; |
| 3955 | res = obj2ast_expr(tmp, &test, arena); |
| 3956 | if (res != 0) goto failed; |
| 3957 | Py_XDECREF(tmp); |
| 3958 | tmp = NULL; |
| 3959 | } else { |
| 3960 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 3961 | return 1; |
| 3962 | } |
| 3963 | if (PyObject_HasAttrString(obj, "body")) { |
| 3964 | int res; |
| 3965 | Py_ssize_t len; |
| 3966 | Py_ssize_t i; |
| 3967 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3968 | if (tmp == NULL) goto failed; |
| 3969 | if (!PyList_Check(tmp)) { |
| 3970 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3971 | goto failed; |
| 3972 | } |
| 3973 | len = PyList_GET_SIZE(tmp); |
| 3974 | body = asdl_seq_new(len, arena); |
| 3975 | if (body == NULL) goto failed; |
| 3976 | for (i = 0; i < len; i++) { |
| 3977 | stmt_ty value; |
| 3978 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3979 | if (res != 0) goto failed; |
| 3980 | asdl_seq_SET(body, i, value); |
| 3981 | } |
| 3982 | Py_XDECREF(tmp); |
| 3983 | tmp = NULL; |
| 3984 | } else { |
| 3985 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 3986 | return 1; |
| 3987 | } |
| 3988 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3989 | int res; |
| 3990 | Py_ssize_t len; |
| 3991 | Py_ssize_t i; |
| 3992 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3993 | if (tmp == NULL) goto failed; |
| 3994 | if (!PyList_Check(tmp)) { |
| 3995 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3996 | goto failed; |
| 3997 | } |
| 3998 | len = PyList_GET_SIZE(tmp); |
| 3999 | orelse = asdl_seq_new(len, arena); |
| 4000 | if (orelse == NULL) goto failed; |
| 4001 | for (i = 0; i < len; i++) { |
| 4002 | stmt_ty value; |
| 4003 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4004 | if (res != 0) goto failed; |
| 4005 | asdl_seq_SET(orelse, i, value); |
| 4006 | } |
| 4007 | Py_XDECREF(tmp); |
| 4008 | tmp = NULL; |
| 4009 | } else { |
| 4010 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4011 | return 1; |
| 4012 | } |
| 4013 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4014 | if (*out == NULL) goto failed; |
| 4015 | return 0; |
| 4016 | } |
| 4017 | if (PyObject_IsInstance(obj, (PyObject*)With_type)) { |
| 4018 | expr_ty context_expr; |
| 4019 | expr_ty optional_vars; |
| 4020 | asdl_seq* body; |
| 4021 | |
| 4022 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4023 | int res; |
| 4024 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4025 | if (tmp == NULL) goto failed; |
| 4026 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4027 | if (res != 0) goto failed; |
| 4028 | Py_XDECREF(tmp); |
| 4029 | tmp = NULL; |
| 4030 | } else { |
| 4031 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4032 | return 1; |
| 4033 | } |
| 4034 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4035 | int res; |
| 4036 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4037 | if (tmp == NULL) goto failed; |
| 4038 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4039 | if (res != 0) goto failed; |
| 4040 | Py_XDECREF(tmp); |
| 4041 | tmp = NULL; |
| 4042 | } else { |
| 4043 | optional_vars = NULL; |
| 4044 | } |
| 4045 | if (PyObject_HasAttrString(obj, "body")) { |
| 4046 | int res; |
| 4047 | Py_ssize_t len; |
| 4048 | Py_ssize_t i; |
| 4049 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4050 | if (tmp == NULL) goto failed; |
| 4051 | if (!PyList_Check(tmp)) { |
| 4052 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4053 | goto failed; |
| 4054 | } |
| 4055 | len = PyList_GET_SIZE(tmp); |
| 4056 | body = asdl_seq_new(len, arena); |
| 4057 | if (body == NULL) goto failed; |
| 4058 | for (i = 0; i < len; i++) { |
| 4059 | stmt_ty value; |
| 4060 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4061 | if (res != 0) goto failed; |
| 4062 | asdl_seq_SET(body, i, value); |
| 4063 | } |
| 4064 | Py_XDECREF(tmp); |
| 4065 | tmp = NULL; |
| 4066 | } else { |
| 4067 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4068 | return 1; |
| 4069 | } |
| 4070 | *out = With(context_expr, optional_vars, body, lineno, |
| 4071 | col_offset, arena); |
| 4072 | if (*out == NULL) goto failed; |
| 4073 | return 0; |
| 4074 | } |
| 4075 | if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) { |
| 4076 | expr_ty exc; |
| 4077 | expr_ty cause; |
| 4078 | |
| 4079 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4080 | int res; |
| 4081 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4082 | if (tmp == NULL) goto failed; |
| 4083 | res = obj2ast_expr(tmp, &exc, arena); |
| 4084 | if (res != 0) goto failed; |
| 4085 | Py_XDECREF(tmp); |
| 4086 | tmp = NULL; |
| 4087 | } else { |
| 4088 | exc = NULL; |
| 4089 | } |
| 4090 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4091 | int res; |
| 4092 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4093 | if (tmp == NULL) goto failed; |
| 4094 | res = obj2ast_expr(tmp, &cause, arena); |
| 4095 | if (res != 0) goto failed; |
| 4096 | Py_XDECREF(tmp); |
| 4097 | tmp = NULL; |
| 4098 | } else { |
| 4099 | cause = NULL; |
| 4100 | } |
| 4101 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4102 | if (*out == NULL) goto failed; |
| 4103 | return 0; |
| 4104 | } |
| 4105 | if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) { |
| 4106 | asdl_seq* body; |
| 4107 | asdl_seq* handlers; |
| 4108 | asdl_seq* orelse; |
| 4109 | |
| 4110 | if (PyObject_HasAttrString(obj, "body")) { |
| 4111 | int res; |
| 4112 | Py_ssize_t len; |
| 4113 | Py_ssize_t i; |
| 4114 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4115 | if (tmp == NULL) goto failed; |
| 4116 | if (!PyList_Check(tmp)) { |
| 4117 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4118 | goto failed; |
| 4119 | } |
| 4120 | len = PyList_GET_SIZE(tmp); |
| 4121 | body = asdl_seq_new(len, arena); |
| 4122 | if (body == NULL) goto failed; |
| 4123 | for (i = 0; i < len; i++) { |
| 4124 | stmt_ty value; |
| 4125 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4126 | if (res != 0) goto failed; |
| 4127 | asdl_seq_SET(body, i, value); |
| 4128 | } |
| 4129 | Py_XDECREF(tmp); |
| 4130 | tmp = NULL; |
| 4131 | } else { |
| 4132 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4133 | return 1; |
| 4134 | } |
| 4135 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4136 | int res; |
| 4137 | Py_ssize_t len; |
| 4138 | Py_ssize_t i; |
| 4139 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4140 | if (tmp == NULL) goto failed; |
| 4141 | if (!PyList_Check(tmp)) { |
| 4142 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4143 | goto failed; |
| 4144 | } |
| 4145 | len = PyList_GET_SIZE(tmp); |
| 4146 | handlers = asdl_seq_new(len, arena); |
| 4147 | if (handlers == NULL) goto failed; |
| 4148 | for (i = 0; i < len; i++) { |
| 4149 | excepthandler_ty value; |
| 4150 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4151 | if (res != 0) goto failed; |
| 4152 | asdl_seq_SET(handlers, i, value); |
| 4153 | } |
| 4154 | Py_XDECREF(tmp); |
| 4155 | tmp = NULL; |
| 4156 | } else { |
| 4157 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4158 | return 1; |
| 4159 | } |
| 4160 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4161 | int res; |
| 4162 | Py_ssize_t len; |
| 4163 | Py_ssize_t i; |
| 4164 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4165 | if (tmp == NULL) goto failed; |
| 4166 | if (!PyList_Check(tmp)) { |
| 4167 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4168 | goto failed; |
| 4169 | } |
| 4170 | len = PyList_GET_SIZE(tmp); |
| 4171 | orelse = asdl_seq_new(len, arena); |
| 4172 | if (orelse == NULL) goto failed; |
| 4173 | for (i = 0; i < len; i++) { |
| 4174 | stmt_ty value; |
| 4175 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4176 | if (res != 0) goto failed; |
| 4177 | asdl_seq_SET(orelse, i, value); |
| 4178 | } |
| 4179 | Py_XDECREF(tmp); |
| 4180 | tmp = NULL; |
| 4181 | } else { |
| 4182 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4183 | return 1; |
| 4184 | } |
| 4185 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4186 | arena); |
| 4187 | if (*out == NULL) goto failed; |
| 4188 | return 0; |
| 4189 | } |
| 4190 | if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) { |
| 4191 | asdl_seq* body; |
| 4192 | asdl_seq* finalbody; |
| 4193 | |
| 4194 | if (PyObject_HasAttrString(obj, "body")) { |
| 4195 | int res; |
| 4196 | Py_ssize_t len; |
| 4197 | Py_ssize_t i; |
| 4198 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4199 | if (tmp == NULL) goto failed; |
| 4200 | if (!PyList_Check(tmp)) { |
| 4201 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4202 | goto failed; |
| 4203 | } |
| 4204 | len = PyList_GET_SIZE(tmp); |
| 4205 | body = asdl_seq_new(len, arena); |
| 4206 | if (body == NULL) goto failed; |
| 4207 | for (i = 0; i < len; i++) { |
| 4208 | stmt_ty value; |
| 4209 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4210 | if (res != 0) goto failed; |
| 4211 | asdl_seq_SET(body, i, value); |
| 4212 | } |
| 4213 | Py_XDECREF(tmp); |
| 4214 | tmp = NULL; |
| 4215 | } else { |
| 4216 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4217 | return 1; |
| 4218 | } |
| 4219 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4220 | int res; |
| 4221 | Py_ssize_t len; |
| 4222 | Py_ssize_t i; |
| 4223 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4224 | if (tmp == NULL) goto failed; |
| 4225 | if (!PyList_Check(tmp)) { |
| 4226 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4227 | goto failed; |
| 4228 | } |
| 4229 | len = PyList_GET_SIZE(tmp); |
| 4230 | finalbody = asdl_seq_new(len, arena); |
| 4231 | if (finalbody == NULL) goto failed; |
| 4232 | for (i = 0; i < len; i++) { |
| 4233 | stmt_ty value; |
| 4234 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4235 | if (res != 0) goto failed; |
| 4236 | asdl_seq_SET(finalbody, i, value); |
| 4237 | } |
| 4238 | Py_XDECREF(tmp); |
| 4239 | tmp = NULL; |
| 4240 | } else { |
| 4241 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4242 | return 1; |
| 4243 | } |
| 4244 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4245 | if (*out == NULL) goto failed; |
| 4246 | return 0; |
| 4247 | } |
| 4248 | if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) { |
| 4249 | expr_ty test; |
| 4250 | expr_ty msg; |
| 4251 | |
| 4252 | if (PyObject_HasAttrString(obj, "test")) { |
| 4253 | int res; |
| 4254 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4255 | if (tmp == NULL) goto failed; |
| 4256 | res = obj2ast_expr(tmp, &test, arena); |
| 4257 | if (res != 0) goto failed; |
| 4258 | Py_XDECREF(tmp); |
| 4259 | tmp = NULL; |
| 4260 | } else { |
| 4261 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4262 | return 1; |
| 4263 | } |
| 4264 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4265 | int res; |
| 4266 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4267 | if (tmp == NULL) goto failed; |
| 4268 | res = obj2ast_expr(tmp, &msg, arena); |
| 4269 | if (res != 0) goto failed; |
| 4270 | Py_XDECREF(tmp); |
| 4271 | tmp = NULL; |
| 4272 | } else { |
| 4273 | msg = NULL; |
| 4274 | } |
| 4275 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4276 | if (*out == NULL) goto failed; |
| 4277 | return 0; |
| 4278 | } |
| 4279 | if (PyObject_IsInstance(obj, (PyObject*)Import_type)) { |
| 4280 | asdl_seq* names; |
| 4281 | |
| 4282 | if (PyObject_HasAttrString(obj, "names")) { |
| 4283 | int res; |
| 4284 | Py_ssize_t len; |
| 4285 | Py_ssize_t i; |
| 4286 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4287 | if (tmp == NULL) goto failed; |
| 4288 | if (!PyList_Check(tmp)) { |
| 4289 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4290 | goto failed; |
| 4291 | } |
| 4292 | len = PyList_GET_SIZE(tmp); |
| 4293 | names = asdl_seq_new(len, arena); |
| 4294 | if (names == NULL) goto failed; |
| 4295 | for (i = 0; i < len; i++) { |
| 4296 | alias_ty value; |
| 4297 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4298 | if (res != 0) goto failed; |
| 4299 | asdl_seq_SET(names, i, value); |
| 4300 | } |
| 4301 | Py_XDECREF(tmp); |
| 4302 | tmp = NULL; |
| 4303 | } else { |
| 4304 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4305 | return 1; |
| 4306 | } |
| 4307 | *out = Import(names, lineno, col_offset, arena); |
| 4308 | if (*out == NULL) goto failed; |
| 4309 | return 0; |
| 4310 | } |
| 4311 | if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) { |
| 4312 | identifier module; |
| 4313 | asdl_seq* names; |
| 4314 | int level; |
| 4315 | |
| 4316 | if (PyObject_HasAttrString(obj, "module")) { |
| 4317 | int res; |
| 4318 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4319 | if (tmp == NULL) goto failed; |
| 4320 | res = obj2ast_identifier(tmp, &module, arena); |
| 4321 | if (res != 0) goto failed; |
| 4322 | Py_XDECREF(tmp); |
| 4323 | tmp = NULL; |
| 4324 | } else { |
| 4325 | PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); |
| 4326 | return 1; |
| 4327 | } |
| 4328 | if (PyObject_HasAttrString(obj, "names")) { |
| 4329 | int res; |
| 4330 | Py_ssize_t len; |
| 4331 | Py_ssize_t i; |
| 4332 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4333 | if (tmp == NULL) goto failed; |
| 4334 | if (!PyList_Check(tmp)) { |
| 4335 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4336 | goto failed; |
| 4337 | } |
| 4338 | len = PyList_GET_SIZE(tmp); |
| 4339 | names = asdl_seq_new(len, arena); |
| 4340 | if (names == NULL) goto failed; |
| 4341 | for (i = 0; i < len; i++) { |
| 4342 | alias_ty value; |
| 4343 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4344 | if (res != 0) goto failed; |
| 4345 | asdl_seq_SET(names, i, value); |
| 4346 | } |
| 4347 | Py_XDECREF(tmp); |
| 4348 | tmp = NULL; |
| 4349 | } else { |
| 4350 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4351 | return 1; |
| 4352 | } |
| 4353 | if (PyObject_HasAttrString(obj, "level")) { |
| 4354 | int res; |
| 4355 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4356 | if (tmp == NULL) goto failed; |
| 4357 | res = obj2ast_int(tmp, &level, arena); |
| 4358 | if (res != 0) goto failed; |
| 4359 | Py_XDECREF(tmp); |
| 4360 | tmp = NULL; |
| 4361 | } else { |
| 4362 | level = 0; |
| 4363 | } |
| 4364 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4365 | arena); |
| 4366 | if (*out == NULL) goto failed; |
| 4367 | return 0; |
| 4368 | } |
| 4369 | if (PyObject_IsInstance(obj, (PyObject*)Global_type)) { |
| 4370 | asdl_seq* names; |
| 4371 | |
| 4372 | if (PyObject_HasAttrString(obj, "names")) { |
| 4373 | int res; |
| 4374 | Py_ssize_t len; |
| 4375 | Py_ssize_t i; |
| 4376 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4377 | if (tmp == NULL) goto failed; |
| 4378 | if (!PyList_Check(tmp)) { |
| 4379 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4380 | goto failed; |
| 4381 | } |
| 4382 | len = PyList_GET_SIZE(tmp); |
| 4383 | names = asdl_seq_new(len, arena); |
| 4384 | if (names == NULL) goto failed; |
| 4385 | for (i = 0; i < len; i++) { |
| 4386 | identifier value; |
| 4387 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4388 | if (res != 0) goto failed; |
| 4389 | asdl_seq_SET(names, i, value); |
| 4390 | } |
| 4391 | Py_XDECREF(tmp); |
| 4392 | tmp = NULL; |
| 4393 | } else { |
| 4394 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4395 | return 1; |
| 4396 | } |
| 4397 | *out = Global(names, lineno, col_offset, arena); |
| 4398 | if (*out == NULL) goto failed; |
| 4399 | return 0; |
| 4400 | } |
| 4401 | if (PyObject_IsInstance(obj, (PyObject*)Nonlocal_type)) { |
| 4402 | asdl_seq* names; |
| 4403 | |
| 4404 | if (PyObject_HasAttrString(obj, "names")) { |
| 4405 | int res; |
| 4406 | Py_ssize_t len; |
| 4407 | Py_ssize_t i; |
| 4408 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4409 | if (tmp == NULL) goto failed; |
| 4410 | if (!PyList_Check(tmp)) { |
| 4411 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4412 | goto failed; |
| 4413 | } |
| 4414 | len = PyList_GET_SIZE(tmp); |
| 4415 | names = asdl_seq_new(len, arena); |
| 4416 | if (names == NULL) goto failed; |
| 4417 | for (i = 0; i < len; i++) { |
| 4418 | identifier value; |
| 4419 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4420 | if (res != 0) goto failed; |
| 4421 | asdl_seq_SET(names, i, value); |
| 4422 | } |
| 4423 | Py_XDECREF(tmp); |
| 4424 | tmp = NULL; |
| 4425 | } else { |
| 4426 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4427 | return 1; |
| 4428 | } |
| 4429 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4430 | if (*out == NULL) goto failed; |
| 4431 | return 0; |
| 4432 | } |
| 4433 | if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) { |
| 4434 | expr_ty value; |
| 4435 | |
| 4436 | if (PyObject_HasAttrString(obj, "value")) { |
| 4437 | int res; |
| 4438 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4439 | if (tmp == NULL) goto failed; |
| 4440 | res = obj2ast_expr(tmp, &value, arena); |
| 4441 | if (res != 0) goto failed; |
| 4442 | Py_XDECREF(tmp); |
| 4443 | tmp = NULL; |
| 4444 | } else { |
| 4445 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4446 | return 1; |
| 4447 | } |
| 4448 | *out = Expr(value, lineno, col_offset, arena); |
| 4449 | if (*out == NULL) goto failed; |
| 4450 | return 0; |
| 4451 | } |
| 4452 | if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) { |
| 4453 | |
| 4454 | *out = Pass(lineno, col_offset, arena); |
| 4455 | if (*out == NULL) goto failed; |
| 4456 | return 0; |
| 4457 | } |
| 4458 | if (PyObject_IsInstance(obj, (PyObject*)Break_type)) { |
| 4459 | |
| 4460 | *out = Break(lineno, col_offset, arena); |
| 4461 | if (*out == NULL) goto failed; |
| 4462 | return 0; |
| 4463 | } |
| 4464 | if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) { |
| 4465 | |
| 4466 | *out = Continue(lineno, col_offset, arena); |
| 4467 | if (*out == NULL) goto failed; |
| 4468 | return 0; |
| 4469 | } |
| 4470 | |
| 4471 | tmp = PyObject_Repr(obj); |
| 4472 | if (tmp == NULL) goto failed; |
| 4473 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp)); |
| 4474 | failed: |
| 4475 | Py_XDECREF(tmp); |
| 4476 | return 1; |
| 4477 | } |
| 4478 | |
| 4479 | int |
| 4480 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4481 | { |
| 4482 | PyObject* tmp = NULL; |
| 4483 | |
| 4484 | int lineno; |
| 4485 | int col_offset; |
| 4486 | |
| 4487 | if (obj == Py_None) { |
| 4488 | *out = NULL; |
| 4489 | return 0; |
| 4490 | } |
| 4491 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4492 | int res; |
| 4493 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4494 | if (tmp == NULL) goto failed; |
| 4495 | res = obj2ast_int(tmp, &lineno, arena); |
| 4496 | if (res != 0) goto failed; |
| 4497 | Py_XDECREF(tmp); |
| 4498 | tmp = NULL; |
| 4499 | } else { |
| 4500 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4501 | return 1; |
| 4502 | } |
| 4503 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4504 | int res; |
| 4505 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4506 | if (tmp == NULL) goto failed; |
| 4507 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4508 | if (res != 0) goto failed; |
| 4509 | Py_XDECREF(tmp); |
| 4510 | tmp = NULL; |
| 4511 | } else { |
| 4512 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4513 | return 1; |
| 4514 | } |
| 4515 | if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) { |
| 4516 | boolop_ty op; |
| 4517 | asdl_seq* values; |
| 4518 | |
| 4519 | if (PyObject_HasAttrString(obj, "op")) { |
| 4520 | int res; |
| 4521 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4522 | if (tmp == NULL) goto failed; |
| 4523 | res = obj2ast_boolop(tmp, &op, arena); |
| 4524 | if (res != 0) goto failed; |
| 4525 | Py_XDECREF(tmp); |
| 4526 | tmp = NULL; |
| 4527 | } else { |
| 4528 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4529 | return 1; |
| 4530 | } |
| 4531 | if (PyObject_HasAttrString(obj, "values")) { |
| 4532 | int res; |
| 4533 | Py_ssize_t len; |
| 4534 | Py_ssize_t i; |
| 4535 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4536 | if (tmp == NULL) goto failed; |
| 4537 | if (!PyList_Check(tmp)) { |
| 4538 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4539 | goto failed; |
| 4540 | } |
| 4541 | len = PyList_GET_SIZE(tmp); |
| 4542 | values = asdl_seq_new(len, arena); |
| 4543 | if (values == NULL) goto failed; |
| 4544 | for (i = 0; i < len; i++) { |
| 4545 | expr_ty value; |
| 4546 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4547 | if (res != 0) goto failed; |
| 4548 | asdl_seq_SET(values, i, value); |
| 4549 | } |
| 4550 | Py_XDECREF(tmp); |
| 4551 | tmp = NULL; |
| 4552 | } else { |
| 4553 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4554 | return 1; |
| 4555 | } |
| 4556 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4557 | if (*out == NULL) goto failed; |
| 4558 | return 0; |
| 4559 | } |
| 4560 | if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) { |
| 4561 | expr_ty left; |
| 4562 | operator_ty op; |
| 4563 | expr_ty right; |
| 4564 | |
| 4565 | if (PyObject_HasAttrString(obj, "left")) { |
| 4566 | int res; |
| 4567 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4568 | if (tmp == NULL) goto failed; |
| 4569 | res = obj2ast_expr(tmp, &left, arena); |
| 4570 | if (res != 0) goto failed; |
| 4571 | Py_XDECREF(tmp); |
| 4572 | tmp = NULL; |
| 4573 | } else { |
| 4574 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4575 | return 1; |
| 4576 | } |
| 4577 | if (PyObject_HasAttrString(obj, "op")) { |
| 4578 | int res; |
| 4579 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4580 | if (tmp == NULL) goto failed; |
| 4581 | res = obj2ast_operator(tmp, &op, arena); |
| 4582 | if (res != 0) goto failed; |
| 4583 | Py_XDECREF(tmp); |
| 4584 | tmp = NULL; |
| 4585 | } else { |
| 4586 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4587 | return 1; |
| 4588 | } |
| 4589 | if (PyObject_HasAttrString(obj, "right")) { |
| 4590 | int res; |
| 4591 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4592 | if (tmp == NULL) goto failed; |
| 4593 | res = obj2ast_expr(tmp, &right, arena); |
| 4594 | if (res != 0) goto failed; |
| 4595 | Py_XDECREF(tmp); |
| 4596 | tmp = NULL; |
| 4597 | } else { |
| 4598 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4599 | return 1; |
| 4600 | } |
| 4601 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4602 | if (*out == NULL) goto failed; |
| 4603 | return 0; |
| 4604 | } |
| 4605 | if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) { |
| 4606 | unaryop_ty op; |
| 4607 | expr_ty operand; |
| 4608 | |
| 4609 | if (PyObject_HasAttrString(obj, "op")) { |
| 4610 | int res; |
| 4611 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4612 | if (tmp == NULL) goto failed; |
| 4613 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4614 | if (res != 0) goto failed; |
| 4615 | Py_XDECREF(tmp); |
| 4616 | tmp = NULL; |
| 4617 | } else { |
| 4618 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4619 | return 1; |
| 4620 | } |
| 4621 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4622 | int res; |
| 4623 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4624 | if (tmp == NULL) goto failed; |
| 4625 | res = obj2ast_expr(tmp, &operand, arena); |
| 4626 | if (res != 0) goto failed; |
| 4627 | Py_XDECREF(tmp); |
| 4628 | tmp = NULL; |
| 4629 | } else { |
| 4630 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4631 | return 1; |
| 4632 | } |
| 4633 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4634 | if (*out == NULL) goto failed; |
| 4635 | return 0; |
| 4636 | } |
| 4637 | if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) { |
| 4638 | arguments_ty args; |
| 4639 | expr_ty body; |
| 4640 | |
| 4641 | if (PyObject_HasAttrString(obj, "args")) { |
| 4642 | int res; |
| 4643 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4644 | if (tmp == NULL) goto failed; |
| 4645 | res = obj2ast_arguments(tmp, &args, arena); |
| 4646 | if (res != 0) goto failed; |
| 4647 | Py_XDECREF(tmp); |
| 4648 | tmp = NULL; |
| 4649 | } else { |
| 4650 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4651 | return 1; |
| 4652 | } |
| 4653 | if (PyObject_HasAttrString(obj, "body")) { |
| 4654 | int res; |
| 4655 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4656 | if (tmp == NULL) goto failed; |
| 4657 | res = obj2ast_expr(tmp, &body, arena); |
| 4658 | if (res != 0) goto failed; |
| 4659 | Py_XDECREF(tmp); |
| 4660 | tmp = NULL; |
| 4661 | } else { |
| 4662 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4663 | return 1; |
| 4664 | } |
| 4665 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4666 | if (*out == NULL) goto failed; |
| 4667 | return 0; |
| 4668 | } |
| 4669 | if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) { |
| 4670 | expr_ty test; |
| 4671 | expr_ty body; |
| 4672 | expr_ty orelse; |
| 4673 | |
| 4674 | if (PyObject_HasAttrString(obj, "test")) { |
| 4675 | int res; |
| 4676 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4677 | if (tmp == NULL) goto failed; |
| 4678 | res = obj2ast_expr(tmp, &test, arena); |
| 4679 | if (res != 0) goto failed; |
| 4680 | Py_XDECREF(tmp); |
| 4681 | tmp = NULL; |
| 4682 | } else { |
| 4683 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4684 | return 1; |
| 4685 | } |
| 4686 | if (PyObject_HasAttrString(obj, "body")) { |
| 4687 | int res; |
| 4688 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4689 | if (tmp == NULL) goto failed; |
| 4690 | res = obj2ast_expr(tmp, &body, arena); |
| 4691 | if (res != 0) goto failed; |
| 4692 | Py_XDECREF(tmp); |
| 4693 | tmp = NULL; |
| 4694 | } else { |
| 4695 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4696 | return 1; |
| 4697 | } |
| 4698 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4699 | int res; |
| 4700 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4701 | if (tmp == NULL) goto failed; |
| 4702 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4703 | if (res != 0) goto failed; |
| 4704 | Py_XDECREF(tmp); |
| 4705 | tmp = NULL; |
| 4706 | } else { |
| 4707 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4708 | return 1; |
| 4709 | } |
| 4710 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4711 | if (*out == NULL) goto failed; |
| 4712 | return 0; |
| 4713 | } |
| 4714 | if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) { |
| 4715 | asdl_seq* keys; |
| 4716 | asdl_seq* values; |
| 4717 | |
| 4718 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4719 | int res; |
| 4720 | Py_ssize_t len; |
| 4721 | Py_ssize_t i; |
| 4722 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4723 | if (tmp == NULL) goto failed; |
| 4724 | if (!PyList_Check(tmp)) { |
| 4725 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4726 | goto failed; |
| 4727 | } |
| 4728 | len = PyList_GET_SIZE(tmp); |
| 4729 | keys = asdl_seq_new(len, arena); |
| 4730 | if (keys == NULL) goto failed; |
| 4731 | for (i = 0; i < len; i++) { |
| 4732 | expr_ty value; |
| 4733 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4734 | if (res != 0) goto failed; |
| 4735 | asdl_seq_SET(keys, i, value); |
| 4736 | } |
| 4737 | Py_XDECREF(tmp); |
| 4738 | tmp = NULL; |
| 4739 | } else { |
| 4740 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4741 | return 1; |
| 4742 | } |
| 4743 | if (PyObject_HasAttrString(obj, "values")) { |
| 4744 | int res; |
| 4745 | Py_ssize_t len; |
| 4746 | Py_ssize_t i; |
| 4747 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4748 | if (tmp == NULL) goto failed; |
| 4749 | if (!PyList_Check(tmp)) { |
| 4750 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4751 | goto failed; |
| 4752 | } |
| 4753 | len = PyList_GET_SIZE(tmp); |
| 4754 | values = asdl_seq_new(len, arena); |
| 4755 | if (values == NULL) goto failed; |
| 4756 | for (i = 0; i < len; i++) { |
| 4757 | expr_ty value; |
| 4758 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4759 | if (res != 0) goto failed; |
| 4760 | asdl_seq_SET(values, i, value); |
| 4761 | } |
| 4762 | Py_XDECREF(tmp); |
| 4763 | tmp = NULL; |
| 4764 | } else { |
| 4765 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 4766 | return 1; |
| 4767 | } |
| 4768 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 4769 | if (*out == NULL) goto failed; |
| 4770 | return 0; |
| 4771 | } |
| 4772 | if (PyObject_IsInstance(obj, (PyObject*)Set_type)) { |
| 4773 | asdl_seq* elts; |
| 4774 | |
| 4775 | if (PyObject_HasAttrString(obj, "elts")) { |
| 4776 | int res; |
| 4777 | Py_ssize_t len; |
| 4778 | Py_ssize_t i; |
| 4779 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 4780 | if (tmp == NULL) goto failed; |
| 4781 | if (!PyList_Check(tmp)) { |
| 4782 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4783 | goto failed; |
| 4784 | } |
| 4785 | len = PyList_GET_SIZE(tmp); |
| 4786 | elts = asdl_seq_new(len, arena); |
| 4787 | if (elts == NULL) goto failed; |
| 4788 | for (i = 0; i < len; i++) { |
| 4789 | expr_ty value; |
| 4790 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4791 | if (res != 0) goto failed; |
| 4792 | asdl_seq_SET(elts, i, value); |
| 4793 | } |
| 4794 | Py_XDECREF(tmp); |
| 4795 | tmp = NULL; |
| 4796 | } else { |
| 4797 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 4798 | return 1; |
| 4799 | } |
| 4800 | *out = Set(elts, lineno, col_offset, arena); |
| 4801 | if (*out == NULL) goto failed; |
| 4802 | return 0; |
| 4803 | } |
| 4804 | if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) { |
| 4805 | expr_ty elt; |
| 4806 | asdl_seq* generators; |
| 4807 | |
| 4808 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4809 | int res; |
| 4810 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4811 | if (tmp == NULL) goto failed; |
| 4812 | res = obj2ast_expr(tmp, &elt, arena); |
| 4813 | if (res != 0) goto failed; |
| 4814 | Py_XDECREF(tmp); |
| 4815 | tmp = NULL; |
| 4816 | } else { |
| 4817 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 4818 | return 1; |
| 4819 | } |
| 4820 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4821 | int res; |
| 4822 | Py_ssize_t len; |
| 4823 | Py_ssize_t i; |
| 4824 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4825 | if (tmp == NULL) goto failed; |
| 4826 | if (!PyList_Check(tmp)) { |
| 4827 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4828 | goto failed; |
| 4829 | } |
| 4830 | len = PyList_GET_SIZE(tmp); |
| 4831 | generators = asdl_seq_new(len, arena); |
| 4832 | if (generators == NULL) goto failed; |
| 4833 | for (i = 0; i < len; i++) { |
| 4834 | comprehension_ty value; |
| 4835 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4836 | if (res != 0) goto failed; |
| 4837 | asdl_seq_SET(generators, i, value); |
| 4838 | } |
| 4839 | Py_XDECREF(tmp); |
| 4840 | tmp = NULL; |
| 4841 | } else { |
| 4842 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 4843 | return 1; |
| 4844 | } |
| 4845 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 4846 | if (*out == NULL) goto failed; |
| 4847 | return 0; |
| 4848 | } |
| 4849 | if (PyObject_IsInstance(obj, (PyObject*)SetComp_type)) { |
| 4850 | expr_ty elt; |
| 4851 | asdl_seq* generators; |
| 4852 | |
| 4853 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4854 | int res; |
| 4855 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4856 | if (tmp == NULL) goto failed; |
| 4857 | res = obj2ast_expr(tmp, &elt, arena); |
| 4858 | if (res != 0) goto failed; |
| 4859 | Py_XDECREF(tmp); |
| 4860 | tmp = NULL; |
| 4861 | } else { |
| 4862 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 4863 | return 1; |
| 4864 | } |
| 4865 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4866 | int res; |
| 4867 | Py_ssize_t len; |
| 4868 | Py_ssize_t i; |
| 4869 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4870 | if (tmp == NULL) goto failed; |
| 4871 | if (!PyList_Check(tmp)) { |
| 4872 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4873 | goto failed; |
| 4874 | } |
| 4875 | len = PyList_GET_SIZE(tmp); |
| 4876 | generators = asdl_seq_new(len, arena); |
| 4877 | if (generators == NULL) goto failed; |
| 4878 | for (i = 0; i < len; i++) { |
| 4879 | comprehension_ty value; |
| 4880 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4881 | if (res != 0) goto failed; |
| 4882 | asdl_seq_SET(generators, i, value); |
| 4883 | } |
| 4884 | Py_XDECREF(tmp); |
| 4885 | tmp = NULL; |
| 4886 | } else { |
| 4887 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 4888 | return 1; |
| 4889 | } |
| 4890 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 4891 | if (*out == NULL) goto failed; |
| 4892 | return 0; |
| 4893 | } |
| 4894 | if (PyObject_IsInstance(obj, (PyObject*)DictComp_type)) { |
| 4895 | expr_ty key; |
| 4896 | expr_ty value; |
| 4897 | asdl_seq* generators; |
| 4898 | |
| 4899 | if (PyObject_HasAttrString(obj, "key")) { |
| 4900 | int res; |
| 4901 | tmp = PyObject_GetAttrString(obj, "key"); |
| 4902 | if (tmp == NULL) goto failed; |
| 4903 | res = obj2ast_expr(tmp, &key, arena); |
| 4904 | if (res != 0) goto failed; |
| 4905 | Py_XDECREF(tmp); |
| 4906 | tmp = NULL; |
| 4907 | } else { |
| 4908 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 4909 | return 1; |
| 4910 | } |
| 4911 | if (PyObject_HasAttrString(obj, "value")) { |
| 4912 | int res; |
| 4913 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4914 | if (tmp == NULL) goto failed; |
| 4915 | res = obj2ast_expr(tmp, &value, arena); |
| 4916 | if (res != 0) goto failed; |
| 4917 | Py_XDECREF(tmp); |
| 4918 | tmp = NULL; |
| 4919 | } else { |
| 4920 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 4921 | return 1; |
| 4922 | } |
| 4923 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4924 | int res; |
| 4925 | Py_ssize_t len; |
| 4926 | Py_ssize_t i; |
| 4927 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4928 | if (tmp == NULL) goto failed; |
| 4929 | if (!PyList_Check(tmp)) { |
| 4930 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4931 | goto failed; |
| 4932 | } |
| 4933 | len = PyList_GET_SIZE(tmp); |
| 4934 | generators = asdl_seq_new(len, arena); |
| 4935 | if (generators == NULL) goto failed; |
| 4936 | for (i = 0; i < len; i++) { |
| 4937 | comprehension_ty value; |
| 4938 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4939 | if (res != 0) goto failed; |
| 4940 | asdl_seq_SET(generators, i, value); |
| 4941 | } |
| 4942 | Py_XDECREF(tmp); |
| 4943 | tmp = NULL; |
| 4944 | } else { |
| 4945 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 4946 | return 1; |
| 4947 | } |
| 4948 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 4949 | arena); |
| 4950 | if (*out == NULL) goto failed; |
| 4951 | return 0; |
| 4952 | } |
| 4953 | if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) { |
| 4954 | expr_ty elt; |
| 4955 | asdl_seq* generators; |
| 4956 | |
| 4957 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4958 | int res; |
| 4959 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4960 | if (tmp == NULL) goto failed; |
| 4961 | res = obj2ast_expr(tmp, &elt, arena); |
| 4962 | if (res != 0) goto failed; |
| 4963 | Py_XDECREF(tmp); |
| 4964 | tmp = NULL; |
| 4965 | } else { |
| 4966 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 4967 | return 1; |
| 4968 | } |
| 4969 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4970 | int res; |
| 4971 | Py_ssize_t len; |
| 4972 | Py_ssize_t i; |
| 4973 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4974 | if (tmp == NULL) goto failed; |
| 4975 | if (!PyList_Check(tmp)) { |
| 4976 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4977 | goto failed; |
| 4978 | } |
| 4979 | len = PyList_GET_SIZE(tmp); |
| 4980 | generators = asdl_seq_new(len, arena); |
| 4981 | if (generators == NULL) goto failed; |
| 4982 | for (i = 0; i < len; i++) { |
| 4983 | comprehension_ty value; |
| 4984 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4985 | if (res != 0) goto failed; |
| 4986 | asdl_seq_SET(generators, i, value); |
| 4987 | } |
| 4988 | Py_XDECREF(tmp); |
| 4989 | tmp = NULL; |
| 4990 | } else { |
| 4991 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 4992 | return 1; |
| 4993 | } |
| 4994 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 4995 | if (*out == NULL) goto failed; |
| 4996 | return 0; |
| 4997 | } |
| 4998 | if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) { |
| 4999 | expr_ty value; |
| 5000 | |
| 5001 | if (PyObject_HasAttrString(obj, "value")) { |
| 5002 | int res; |
| 5003 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5004 | if (tmp == NULL) goto failed; |
| 5005 | res = obj2ast_expr(tmp, &value, arena); |
| 5006 | if (res != 0) goto failed; |
| 5007 | Py_XDECREF(tmp); |
| 5008 | tmp = NULL; |
| 5009 | } else { |
| 5010 | value = NULL; |
| 5011 | } |
| 5012 | *out = Yield(value, lineno, col_offset, arena); |
| 5013 | if (*out == NULL) goto failed; |
| 5014 | return 0; |
| 5015 | } |
| 5016 | if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) { |
| 5017 | expr_ty left; |
| 5018 | asdl_int_seq* ops; |
| 5019 | asdl_seq* comparators; |
| 5020 | |
| 5021 | if (PyObject_HasAttrString(obj, "left")) { |
| 5022 | int res; |
| 5023 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5024 | if (tmp == NULL) goto failed; |
| 5025 | res = obj2ast_expr(tmp, &left, arena); |
| 5026 | if (res != 0) goto failed; |
| 5027 | Py_XDECREF(tmp); |
| 5028 | tmp = NULL; |
| 5029 | } else { |
| 5030 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5031 | return 1; |
| 5032 | } |
| 5033 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5034 | int res; |
| 5035 | Py_ssize_t len; |
| 5036 | Py_ssize_t i; |
| 5037 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5038 | if (tmp == NULL) goto failed; |
| 5039 | if (!PyList_Check(tmp)) { |
| 5040 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5041 | goto failed; |
| 5042 | } |
| 5043 | len = PyList_GET_SIZE(tmp); |
| 5044 | ops = asdl_int_seq_new(len, arena); |
| 5045 | if (ops == NULL) goto failed; |
| 5046 | for (i = 0; i < len; i++) { |
| 5047 | cmpop_ty value; |
| 5048 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5049 | if (res != 0) goto failed; |
| 5050 | asdl_seq_SET(ops, i, value); |
| 5051 | } |
| 5052 | Py_XDECREF(tmp); |
| 5053 | tmp = NULL; |
| 5054 | } else { |
| 5055 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5056 | return 1; |
| 5057 | } |
| 5058 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5059 | int res; |
| 5060 | Py_ssize_t len; |
| 5061 | Py_ssize_t i; |
| 5062 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5063 | if (tmp == NULL) goto failed; |
| 5064 | if (!PyList_Check(tmp)) { |
| 5065 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5066 | goto failed; |
| 5067 | } |
| 5068 | len = PyList_GET_SIZE(tmp); |
| 5069 | comparators = asdl_seq_new(len, arena); |
| 5070 | if (comparators == NULL) goto failed; |
| 5071 | for (i = 0; i < len; i++) { |
| 5072 | expr_ty value; |
| 5073 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5074 | if (res != 0) goto failed; |
| 5075 | asdl_seq_SET(comparators, i, value); |
| 5076 | } |
| 5077 | Py_XDECREF(tmp); |
| 5078 | tmp = NULL; |
| 5079 | } else { |
| 5080 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5081 | return 1; |
| 5082 | } |
| 5083 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5084 | arena); |
| 5085 | if (*out == NULL) goto failed; |
| 5086 | return 0; |
| 5087 | } |
| 5088 | if (PyObject_IsInstance(obj, (PyObject*)Call_type)) { |
| 5089 | expr_ty func; |
| 5090 | asdl_seq* args; |
| 5091 | asdl_seq* keywords; |
| 5092 | expr_ty starargs; |
| 5093 | expr_ty kwargs; |
| 5094 | |
| 5095 | if (PyObject_HasAttrString(obj, "func")) { |
| 5096 | int res; |
| 5097 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5098 | if (tmp == NULL) goto failed; |
| 5099 | res = obj2ast_expr(tmp, &func, arena); |
| 5100 | if (res != 0) goto failed; |
| 5101 | Py_XDECREF(tmp); |
| 5102 | tmp = NULL; |
| 5103 | } else { |
| 5104 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5105 | return 1; |
| 5106 | } |
| 5107 | if (PyObject_HasAttrString(obj, "args")) { |
| 5108 | int res; |
| 5109 | Py_ssize_t len; |
| 5110 | Py_ssize_t i; |
| 5111 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5112 | if (tmp == NULL) goto failed; |
| 5113 | if (!PyList_Check(tmp)) { |
| 5114 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5115 | goto failed; |
| 5116 | } |
| 5117 | len = PyList_GET_SIZE(tmp); |
| 5118 | args = asdl_seq_new(len, arena); |
| 5119 | if (args == NULL) goto failed; |
| 5120 | for (i = 0; i < len; i++) { |
| 5121 | expr_ty value; |
| 5122 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5123 | if (res != 0) goto failed; |
| 5124 | asdl_seq_SET(args, i, value); |
| 5125 | } |
| 5126 | Py_XDECREF(tmp); |
| 5127 | tmp = NULL; |
| 5128 | } else { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5130 | return 1; |
| 5131 | } |
| 5132 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5133 | int res; |
| 5134 | Py_ssize_t len; |
| 5135 | Py_ssize_t i; |
| 5136 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5137 | if (tmp == NULL) goto failed; |
| 5138 | if (!PyList_Check(tmp)) { |
| 5139 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5140 | goto failed; |
| 5141 | } |
| 5142 | len = PyList_GET_SIZE(tmp); |
| 5143 | keywords = asdl_seq_new(len, arena); |
| 5144 | if (keywords == NULL) goto failed; |
| 5145 | for (i = 0; i < len; i++) { |
| 5146 | keyword_ty value; |
| 5147 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5148 | if (res != 0) goto failed; |
| 5149 | asdl_seq_SET(keywords, i, value); |
| 5150 | } |
| 5151 | Py_XDECREF(tmp); |
| 5152 | tmp = NULL; |
| 5153 | } else { |
| 5154 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5155 | return 1; |
| 5156 | } |
| 5157 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5158 | int res; |
| 5159 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5160 | if (tmp == NULL) goto failed; |
| 5161 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5162 | if (res != 0) goto failed; |
| 5163 | Py_XDECREF(tmp); |
| 5164 | tmp = NULL; |
| 5165 | } else { |
| 5166 | starargs = NULL; |
| 5167 | } |
| 5168 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5169 | int res; |
| 5170 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5171 | if (tmp == NULL) goto failed; |
| 5172 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5173 | if (res != 0) goto failed; |
| 5174 | Py_XDECREF(tmp); |
| 5175 | tmp = NULL; |
| 5176 | } else { |
| 5177 | kwargs = NULL; |
| 5178 | } |
| 5179 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5180 | col_offset, arena); |
| 5181 | if (*out == NULL) goto failed; |
| 5182 | return 0; |
| 5183 | } |
| 5184 | if (PyObject_IsInstance(obj, (PyObject*)Num_type)) { |
| 5185 | object n; |
| 5186 | |
| 5187 | if (PyObject_HasAttrString(obj, "n")) { |
| 5188 | int res; |
| 5189 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5190 | if (tmp == NULL) goto failed; |
| 5191 | res = obj2ast_object(tmp, &n, arena); |
| 5192 | if (res != 0) goto failed; |
| 5193 | Py_XDECREF(tmp); |
| 5194 | tmp = NULL; |
| 5195 | } else { |
| 5196 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5197 | return 1; |
| 5198 | } |
| 5199 | *out = Num(n, lineno, col_offset, arena); |
| 5200 | if (*out == NULL) goto failed; |
| 5201 | return 0; |
| 5202 | } |
| 5203 | if (PyObject_IsInstance(obj, (PyObject*)Str_type)) { |
| 5204 | string s; |
| 5205 | |
| 5206 | if (PyObject_HasAttrString(obj, "s")) { |
| 5207 | int res; |
| 5208 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5209 | if (tmp == NULL) goto failed; |
| 5210 | res = obj2ast_string(tmp, &s, arena); |
| 5211 | if (res != 0) goto failed; |
| 5212 | Py_XDECREF(tmp); |
| 5213 | tmp = NULL; |
| 5214 | } else { |
| 5215 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5216 | return 1; |
| 5217 | } |
| 5218 | *out = Str(s, lineno, col_offset, arena); |
| 5219 | if (*out == NULL) goto failed; |
| 5220 | return 0; |
| 5221 | } |
| 5222 | if (PyObject_IsInstance(obj, (PyObject*)Bytes_type)) { |
| 5223 | string s; |
| 5224 | |
| 5225 | if (PyObject_HasAttrString(obj, "s")) { |
| 5226 | int res; |
| 5227 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5228 | if (tmp == NULL) goto failed; |
| 5229 | res = obj2ast_string(tmp, &s, arena); |
| 5230 | if (res != 0) goto failed; |
| 5231 | Py_XDECREF(tmp); |
| 5232 | tmp = NULL; |
| 5233 | } else { |
| 5234 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5235 | return 1; |
| 5236 | } |
| 5237 | *out = Bytes(s, lineno, col_offset, arena); |
| 5238 | if (*out == NULL) goto failed; |
| 5239 | return 0; |
| 5240 | } |
| 5241 | if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) { |
| 5242 | |
| 5243 | *out = Ellipsis(lineno, col_offset, arena); |
| 5244 | if (*out == NULL) goto failed; |
| 5245 | return 0; |
| 5246 | } |
| 5247 | if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) { |
| 5248 | expr_ty value; |
| 5249 | identifier attr; |
| 5250 | expr_context_ty ctx; |
| 5251 | |
| 5252 | if (PyObject_HasAttrString(obj, "value")) { |
| 5253 | int res; |
| 5254 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5255 | if (tmp == NULL) goto failed; |
| 5256 | res = obj2ast_expr(tmp, &value, arena); |
| 5257 | if (res != 0) goto failed; |
| 5258 | Py_XDECREF(tmp); |
| 5259 | tmp = NULL; |
| 5260 | } else { |
| 5261 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5262 | return 1; |
| 5263 | } |
| 5264 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5265 | int res; |
| 5266 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5267 | if (tmp == NULL) goto failed; |
| 5268 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5269 | if (res != 0) goto failed; |
| 5270 | Py_XDECREF(tmp); |
| 5271 | tmp = NULL; |
| 5272 | } else { |
| 5273 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5274 | return 1; |
| 5275 | } |
| 5276 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5277 | int res; |
| 5278 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5279 | if (tmp == NULL) goto failed; |
| 5280 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5281 | if (res != 0) goto failed; |
| 5282 | Py_XDECREF(tmp); |
| 5283 | tmp = NULL; |
| 5284 | } else { |
| 5285 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5286 | return 1; |
| 5287 | } |
| 5288 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5289 | if (*out == NULL) goto failed; |
| 5290 | return 0; |
| 5291 | } |
| 5292 | if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) { |
| 5293 | expr_ty value; |
| 5294 | slice_ty slice; |
| 5295 | expr_context_ty ctx; |
| 5296 | |
| 5297 | if (PyObject_HasAttrString(obj, "value")) { |
| 5298 | int res; |
| 5299 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5300 | if (tmp == NULL) goto failed; |
| 5301 | res = obj2ast_expr(tmp, &value, arena); |
| 5302 | if (res != 0) goto failed; |
| 5303 | Py_XDECREF(tmp); |
| 5304 | tmp = NULL; |
| 5305 | } else { |
| 5306 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5307 | return 1; |
| 5308 | } |
| 5309 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5310 | int res; |
| 5311 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5312 | if (tmp == NULL) goto failed; |
| 5313 | res = obj2ast_slice(tmp, &slice, arena); |
| 5314 | if (res != 0) goto failed; |
| 5315 | Py_XDECREF(tmp); |
| 5316 | tmp = NULL; |
| 5317 | } else { |
| 5318 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5319 | return 1; |
| 5320 | } |
| 5321 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5322 | int res; |
| 5323 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5324 | if (tmp == NULL) goto failed; |
| 5325 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5326 | if (res != 0) goto failed; |
| 5327 | Py_XDECREF(tmp); |
| 5328 | tmp = NULL; |
| 5329 | } else { |
| 5330 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5331 | return 1; |
| 5332 | } |
| 5333 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5334 | if (*out == NULL) goto failed; |
| 5335 | return 0; |
| 5336 | } |
| 5337 | if (PyObject_IsInstance(obj, (PyObject*)Starred_type)) { |
| 5338 | expr_ty value; |
| 5339 | expr_context_ty ctx; |
| 5340 | |
| 5341 | if (PyObject_HasAttrString(obj, "value")) { |
| 5342 | int res; |
| 5343 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5344 | if (tmp == NULL) goto failed; |
| 5345 | res = obj2ast_expr(tmp, &value, arena); |
| 5346 | if (res != 0) goto failed; |
| 5347 | Py_XDECREF(tmp); |
| 5348 | tmp = NULL; |
| 5349 | } else { |
| 5350 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5351 | return 1; |
| 5352 | } |
| 5353 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5354 | int res; |
| 5355 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5356 | if (tmp == NULL) goto failed; |
| 5357 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5358 | if (res != 0) goto failed; |
| 5359 | Py_XDECREF(tmp); |
| 5360 | tmp = NULL; |
| 5361 | } else { |
| 5362 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5363 | return 1; |
| 5364 | } |
| 5365 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5366 | if (*out == NULL) goto failed; |
| 5367 | return 0; |
| 5368 | } |
| 5369 | if (PyObject_IsInstance(obj, (PyObject*)Name_type)) { |
| 5370 | identifier id; |
| 5371 | expr_context_ty ctx; |
| 5372 | |
| 5373 | if (PyObject_HasAttrString(obj, "id")) { |
| 5374 | int res; |
| 5375 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5376 | if (tmp == NULL) goto failed; |
| 5377 | res = obj2ast_identifier(tmp, &id, arena); |
| 5378 | if (res != 0) goto failed; |
| 5379 | Py_XDECREF(tmp); |
| 5380 | tmp = NULL; |
| 5381 | } else { |
| 5382 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5383 | return 1; |
| 5384 | } |
| 5385 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5386 | int res; |
| 5387 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5388 | if (tmp == NULL) goto failed; |
| 5389 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5390 | if (res != 0) goto failed; |
| 5391 | Py_XDECREF(tmp); |
| 5392 | tmp = NULL; |
| 5393 | } else { |
| 5394 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5395 | return 1; |
| 5396 | } |
| 5397 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5398 | if (*out == NULL) goto failed; |
| 5399 | return 0; |
| 5400 | } |
| 5401 | if (PyObject_IsInstance(obj, (PyObject*)List_type)) { |
| 5402 | asdl_seq* elts; |
| 5403 | expr_context_ty ctx; |
| 5404 | |
| 5405 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5406 | int res; |
| 5407 | Py_ssize_t len; |
| 5408 | Py_ssize_t i; |
| 5409 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5410 | if (tmp == NULL) goto failed; |
| 5411 | if (!PyList_Check(tmp)) { |
| 5412 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5413 | goto failed; |
| 5414 | } |
| 5415 | len = PyList_GET_SIZE(tmp); |
| 5416 | elts = asdl_seq_new(len, arena); |
| 5417 | if (elts == NULL) goto failed; |
| 5418 | for (i = 0; i < len; i++) { |
| 5419 | expr_ty value; |
| 5420 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5421 | if (res != 0) goto failed; |
| 5422 | asdl_seq_SET(elts, i, value); |
| 5423 | } |
| 5424 | Py_XDECREF(tmp); |
| 5425 | tmp = NULL; |
| 5426 | } else { |
| 5427 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5428 | return 1; |
| 5429 | } |
| 5430 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5431 | int res; |
| 5432 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5433 | if (tmp == NULL) goto failed; |
| 5434 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5435 | if (res != 0) goto failed; |
| 5436 | Py_XDECREF(tmp); |
| 5437 | tmp = NULL; |
| 5438 | } else { |
| 5439 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5440 | return 1; |
| 5441 | } |
| 5442 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5443 | if (*out == NULL) goto failed; |
| 5444 | return 0; |
| 5445 | } |
| 5446 | if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) { |
| 5447 | asdl_seq* elts; |
| 5448 | expr_context_ty ctx; |
| 5449 | |
| 5450 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5451 | int res; |
| 5452 | Py_ssize_t len; |
| 5453 | Py_ssize_t i; |
| 5454 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5455 | if (tmp == NULL) goto failed; |
| 5456 | if (!PyList_Check(tmp)) { |
| 5457 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5458 | goto failed; |
| 5459 | } |
| 5460 | len = PyList_GET_SIZE(tmp); |
| 5461 | elts = asdl_seq_new(len, arena); |
| 5462 | if (elts == NULL) goto failed; |
| 5463 | for (i = 0; i < len; i++) { |
| 5464 | expr_ty value; |
| 5465 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5466 | if (res != 0) goto failed; |
| 5467 | asdl_seq_SET(elts, i, value); |
| 5468 | } |
| 5469 | Py_XDECREF(tmp); |
| 5470 | tmp = NULL; |
| 5471 | } else { |
| 5472 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5473 | return 1; |
| 5474 | } |
| 5475 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5476 | int res; |
| 5477 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5478 | if (tmp == NULL) goto failed; |
| 5479 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5480 | if (res != 0) goto failed; |
| 5481 | Py_XDECREF(tmp); |
| 5482 | tmp = NULL; |
| 5483 | } else { |
| 5484 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5485 | return 1; |
| 5486 | } |
| 5487 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5488 | if (*out == NULL) goto failed; |
| 5489 | return 0; |
| 5490 | } |
| 5491 | |
| 5492 | tmp = PyObject_Repr(obj); |
| 5493 | if (tmp == NULL) goto failed; |
| 5494 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp)); |
| 5495 | failed: |
| 5496 | Py_XDECREF(tmp); |
| 5497 | return 1; |
| 5498 | } |
| 5499 | |
| 5500 | int |
| 5501 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5502 | { |
| 5503 | PyObject* tmp = NULL; |
| 5504 | |
| 5505 | if (PyObject_IsInstance(obj, (PyObject*)Load_type)) { |
| 5506 | *out = Load; |
| 5507 | return 0; |
| 5508 | } |
| 5509 | if (PyObject_IsInstance(obj, (PyObject*)Store_type)) { |
| 5510 | *out = Store; |
| 5511 | return 0; |
| 5512 | } |
| 5513 | if (PyObject_IsInstance(obj, (PyObject*)Del_type)) { |
| 5514 | *out = Del; |
| 5515 | return 0; |
| 5516 | } |
| 5517 | if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) { |
| 5518 | *out = AugLoad; |
| 5519 | return 0; |
| 5520 | } |
| 5521 | if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) { |
| 5522 | *out = AugStore; |
| 5523 | return 0; |
| 5524 | } |
| 5525 | if (PyObject_IsInstance(obj, (PyObject*)Param_type)) { |
| 5526 | *out = Param; |
| 5527 | return 0; |
| 5528 | } |
| 5529 | |
| 5530 | tmp = PyObject_Repr(obj); |
| 5531 | if (tmp == NULL) goto failed; |
| 5532 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp)); |
| 5533 | failed: |
| 5534 | Py_XDECREF(tmp); |
| 5535 | return 1; |
| 5536 | } |
| 5537 | |
| 5538 | int |
| 5539 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5540 | { |
| 5541 | PyObject* tmp = NULL; |
| 5542 | |
| 5543 | |
| 5544 | if (obj == Py_None) { |
| 5545 | *out = NULL; |
| 5546 | return 0; |
| 5547 | } |
| 5548 | if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) { |
| 5549 | expr_ty lower; |
| 5550 | expr_ty upper; |
| 5551 | expr_ty step; |
| 5552 | |
| 5553 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5554 | int res; |
| 5555 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5556 | if (tmp == NULL) goto failed; |
| 5557 | res = obj2ast_expr(tmp, &lower, arena); |
| 5558 | if (res != 0) goto failed; |
| 5559 | Py_XDECREF(tmp); |
| 5560 | tmp = NULL; |
| 5561 | } else { |
| 5562 | lower = NULL; |
| 5563 | } |
| 5564 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5565 | int res; |
| 5566 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5567 | if (tmp == NULL) goto failed; |
| 5568 | res = obj2ast_expr(tmp, &upper, arena); |
| 5569 | if (res != 0) goto failed; |
| 5570 | Py_XDECREF(tmp); |
| 5571 | tmp = NULL; |
| 5572 | } else { |
| 5573 | upper = NULL; |
| 5574 | } |
| 5575 | if (PyObject_HasAttrString(obj, "step")) { |
| 5576 | int res; |
| 5577 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5578 | if (tmp == NULL) goto failed; |
| 5579 | res = obj2ast_expr(tmp, &step, arena); |
| 5580 | if (res != 0) goto failed; |
| 5581 | Py_XDECREF(tmp); |
| 5582 | tmp = NULL; |
| 5583 | } else { |
| 5584 | step = NULL; |
| 5585 | } |
| 5586 | *out = Slice(lower, upper, step, arena); |
| 5587 | if (*out == NULL) goto failed; |
| 5588 | return 0; |
| 5589 | } |
| 5590 | if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) { |
| 5591 | asdl_seq* dims; |
| 5592 | |
| 5593 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5594 | int res; |
| 5595 | Py_ssize_t len; |
| 5596 | Py_ssize_t i; |
| 5597 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5598 | if (tmp == NULL) goto failed; |
| 5599 | if (!PyList_Check(tmp)) { |
| 5600 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5601 | goto failed; |
| 5602 | } |
| 5603 | len = PyList_GET_SIZE(tmp); |
| 5604 | dims = asdl_seq_new(len, arena); |
| 5605 | if (dims == NULL) goto failed; |
| 5606 | for (i = 0; i < len; i++) { |
| 5607 | slice_ty value; |
| 5608 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5609 | if (res != 0) goto failed; |
| 5610 | asdl_seq_SET(dims, i, value); |
| 5611 | } |
| 5612 | Py_XDECREF(tmp); |
| 5613 | tmp = NULL; |
| 5614 | } else { |
| 5615 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5616 | return 1; |
| 5617 | } |
| 5618 | *out = ExtSlice(dims, arena); |
| 5619 | if (*out == NULL) goto failed; |
| 5620 | return 0; |
| 5621 | } |
| 5622 | if (PyObject_IsInstance(obj, (PyObject*)Index_type)) { |
| 5623 | expr_ty value; |
| 5624 | |
| 5625 | if (PyObject_HasAttrString(obj, "value")) { |
| 5626 | int res; |
| 5627 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5628 | if (tmp == NULL) goto failed; |
| 5629 | res = obj2ast_expr(tmp, &value, arena); |
| 5630 | if (res != 0) goto failed; |
| 5631 | Py_XDECREF(tmp); |
| 5632 | tmp = NULL; |
| 5633 | } else { |
| 5634 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5635 | return 1; |
| 5636 | } |
| 5637 | *out = Index(value, arena); |
| 5638 | if (*out == NULL) goto failed; |
| 5639 | return 0; |
| 5640 | } |
| 5641 | |
| 5642 | tmp = PyObject_Repr(obj); |
| 5643 | if (tmp == NULL) goto failed; |
| 5644 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp)); |
| 5645 | failed: |
| 5646 | Py_XDECREF(tmp); |
| 5647 | return 1; |
| 5648 | } |
| 5649 | |
| 5650 | int |
| 5651 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5652 | { |
| 5653 | PyObject* tmp = NULL; |
| 5654 | |
| 5655 | if (PyObject_IsInstance(obj, (PyObject*)And_type)) { |
| 5656 | *out = And; |
| 5657 | return 0; |
| 5658 | } |
| 5659 | if (PyObject_IsInstance(obj, (PyObject*)Or_type)) { |
| 5660 | *out = Or; |
| 5661 | return 0; |
| 5662 | } |
| 5663 | |
| 5664 | tmp = PyObject_Repr(obj); |
| 5665 | if (tmp == NULL) goto failed; |
| 5666 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5667 | failed: |
| 5668 | Py_XDECREF(tmp); |
| 5669 | return 1; |
| 5670 | } |
| 5671 | |
| 5672 | int |
| 5673 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 5674 | { |
| 5675 | PyObject* tmp = NULL; |
| 5676 | |
| 5677 | if (PyObject_IsInstance(obj, (PyObject*)Add_type)) { |
| 5678 | *out = Add; |
| 5679 | return 0; |
| 5680 | } |
| 5681 | if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) { |
| 5682 | *out = Sub; |
| 5683 | return 0; |
| 5684 | } |
| 5685 | if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) { |
| 5686 | *out = Mult; |
| 5687 | return 0; |
| 5688 | } |
| 5689 | if (PyObject_IsInstance(obj, (PyObject*)Div_type)) { |
| 5690 | *out = Div; |
| 5691 | return 0; |
| 5692 | } |
| 5693 | if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) { |
| 5694 | *out = Mod; |
| 5695 | return 0; |
| 5696 | } |
| 5697 | if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) { |
| 5698 | *out = Pow; |
| 5699 | return 0; |
| 5700 | } |
| 5701 | if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) { |
| 5702 | *out = LShift; |
| 5703 | return 0; |
| 5704 | } |
| 5705 | if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) { |
| 5706 | *out = RShift; |
| 5707 | return 0; |
| 5708 | } |
| 5709 | if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) { |
| 5710 | *out = BitOr; |
| 5711 | return 0; |
| 5712 | } |
| 5713 | if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) { |
| 5714 | *out = BitXor; |
| 5715 | return 0; |
| 5716 | } |
| 5717 | if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) { |
| 5718 | *out = BitAnd; |
| 5719 | return 0; |
| 5720 | } |
| 5721 | if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) { |
| 5722 | *out = FloorDiv; |
| 5723 | return 0; |
| 5724 | } |
| 5725 | |
| 5726 | tmp = PyObject_Repr(obj); |
| 5727 | if (tmp == NULL) goto failed; |
| 5728 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp)); |
| 5729 | failed: |
| 5730 | Py_XDECREF(tmp); |
| 5731 | return 1; |
| 5732 | } |
| 5733 | |
| 5734 | int |
| 5735 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 5736 | { |
| 5737 | PyObject* tmp = NULL; |
| 5738 | |
| 5739 | if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) { |
| 5740 | *out = Invert; |
| 5741 | return 0; |
| 5742 | } |
| 5743 | if (PyObject_IsInstance(obj, (PyObject*)Not_type)) { |
| 5744 | *out = Not; |
| 5745 | return 0; |
| 5746 | } |
| 5747 | if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) { |
| 5748 | *out = UAdd; |
| 5749 | return 0; |
| 5750 | } |
| 5751 | if (PyObject_IsInstance(obj, (PyObject*)USub_type)) { |
| 5752 | *out = USub; |
| 5753 | return 0; |
| 5754 | } |
| 5755 | |
| 5756 | tmp = PyObject_Repr(obj); |
| 5757 | if (tmp == NULL) goto failed; |
| 5758 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5759 | failed: |
| 5760 | Py_XDECREF(tmp); |
| 5761 | return 1; |
| 5762 | } |
| 5763 | |
| 5764 | int |
| 5765 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 5766 | { |
| 5767 | PyObject* tmp = NULL; |
| 5768 | |
| 5769 | if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) { |
| 5770 | *out = Eq; |
| 5771 | return 0; |
| 5772 | } |
| 5773 | if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) { |
| 5774 | *out = NotEq; |
| 5775 | return 0; |
| 5776 | } |
| 5777 | if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) { |
| 5778 | *out = Lt; |
| 5779 | return 0; |
| 5780 | } |
| 5781 | if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) { |
| 5782 | *out = LtE; |
| 5783 | return 0; |
| 5784 | } |
| 5785 | if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) { |
| 5786 | *out = Gt; |
| 5787 | return 0; |
| 5788 | } |
| 5789 | if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) { |
| 5790 | *out = GtE; |
| 5791 | return 0; |
| 5792 | } |
| 5793 | if (PyObject_IsInstance(obj, (PyObject*)Is_type)) { |
| 5794 | *out = Is; |
| 5795 | return 0; |
| 5796 | } |
| 5797 | if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) { |
| 5798 | *out = IsNot; |
| 5799 | return 0; |
| 5800 | } |
| 5801 | if (PyObject_IsInstance(obj, (PyObject*)In_type)) { |
| 5802 | *out = In; |
| 5803 | return 0; |
| 5804 | } |
| 5805 | if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) { |
| 5806 | *out = NotIn; |
| 5807 | return 0; |
| 5808 | } |
| 5809 | |
| 5810 | tmp = PyObject_Repr(obj); |
| 5811 | if (tmp == NULL) goto failed; |
| 5812 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5813 | failed: |
| 5814 | Py_XDECREF(tmp); |
| 5815 | return 1; |
| 5816 | } |
| 5817 | |
| 5818 | int |
| 5819 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 5820 | { |
| 5821 | PyObject* tmp = NULL; |
| 5822 | expr_ty target; |
| 5823 | expr_ty iter; |
| 5824 | asdl_seq* ifs; |
| 5825 | |
| 5826 | if (PyObject_HasAttrString(obj, "target")) { |
| 5827 | int res; |
| 5828 | tmp = PyObject_GetAttrString(obj, "target"); |
| 5829 | if (tmp == NULL) goto failed; |
| 5830 | res = obj2ast_expr(tmp, &target, arena); |
| 5831 | if (res != 0) goto failed; |
| 5832 | Py_XDECREF(tmp); |
| 5833 | tmp = NULL; |
| 5834 | } else { |
| 5835 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 5836 | return 1; |
| 5837 | } |
| 5838 | if (PyObject_HasAttrString(obj, "iter")) { |
| 5839 | int res; |
| 5840 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 5841 | if (tmp == NULL) goto failed; |
| 5842 | res = obj2ast_expr(tmp, &iter, arena); |
| 5843 | if (res != 0) goto failed; |
| 5844 | Py_XDECREF(tmp); |
| 5845 | tmp = NULL; |
| 5846 | } else { |
| 5847 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 5848 | return 1; |
| 5849 | } |
| 5850 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 5851 | int res; |
| 5852 | Py_ssize_t len; |
| 5853 | Py_ssize_t i; |
| 5854 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 5855 | if (tmp == NULL) goto failed; |
| 5856 | if (!PyList_Check(tmp)) { |
| 5857 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5858 | goto failed; |
| 5859 | } |
| 5860 | len = PyList_GET_SIZE(tmp); |
| 5861 | ifs = asdl_seq_new(len, arena); |
| 5862 | if (ifs == NULL) goto failed; |
| 5863 | for (i = 0; i < len; i++) { |
| 5864 | expr_ty value; |
| 5865 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5866 | if (res != 0) goto failed; |
| 5867 | asdl_seq_SET(ifs, i, value); |
| 5868 | } |
| 5869 | Py_XDECREF(tmp); |
| 5870 | tmp = NULL; |
| 5871 | } else { |
| 5872 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 5873 | return 1; |
| 5874 | } |
| 5875 | *out = comprehension(target, iter, ifs, arena); |
| 5876 | return 0; |
| 5877 | failed: |
| 5878 | Py_XDECREF(tmp); |
| 5879 | return 1; |
| 5880 | } |
| 5881 | |
| 5882 | int |
| 5883 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 5884 | { |
| 5885 | PyObject* tmp = NULL; |
| 5886 | expr_ty type; |
| 5887 | identifier name; |
| 5888 | asdl_seq* body; |
| 5889 | int lineno; |
| 5890 | int col_offset; |
| 5891 | |
| 5892 | if (PyObject_HasAttrString(obj, "type")) { |
| 5893 | int res; |
| 5894 | tmp = PyObject_GetAttrString(obj, "type"); |
| 5895 | if (tmp == NULL) goto failed; |
| 5896 | res = obj2ast_expr(tmp, &type, arena); |
| 5897 | if (res != 0) goto failed; |
| 5898 | Py_XDECREF(tmp); |
| 5899 | tmp = NULL; |
| 5900 | } else { |
| 5901 | type = NULL; |
| 5902 | } |
| 5903 | if (PyObject_HasAttrString(obj, "name")) { |
| 5904 | int res; |
| 5905 | tmp = PyObject_GetAttrString(obj, "name"); |
| 5906 | if (tmp == NULL) goto failed; |
| 5907 | res = obj2ast_identifier(tmp, &name, arena); |
| 5908 | if (res != 0) goto failed; |
| 5909 | Py_XDECREF(tmp); |
| 5910 | tmp = NULL; |
| 5911 | } else { |
| 5912 | name = NULL; |
| 5913 | } |
| 5914 | if (PyObject_HasAttrString(obj, "body")) { |
| 5915 | int res; |
| 5916 | Py_ssize_t len; |
| 5917 | Py_ssize_t i; |
| 5918 | tmp = PyObject_GetAttrString(obj, "body"); |
| 5919 | if (tmp == NULL) goto failed; |
| 5920 | if (!PyList_Check(tmp)) { |
| 5921 | PyErr_Format(PyExc_TypeError, "excepthandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5922 | goto failed; |
| 5923 | } |
| 5924 | len = PyList_GET_SIZE(tmp); |
| 5925 | body = asdl_seq_new(len, arena); |
| 5926 | if (body == NULL) goto failed; |
| 5927 | for (i = 0; i < len; i++) { |
| 5928 | stmt_ty value; |
| 5929 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5930 | if (res != 0) goto failed; |
| 5931 | asdl_seq_SET(body, i, value); |
| 5932 | } |
| 5933 | Py_XDECREF(tmp); |
| 5934 | tmp = NULL; |
| 5935 | } else { |
| 5936 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from excepthandler"); |
| 5937 | return 1; |
| 5938 | } |
| 5939 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 5940 | int res; |
| 5941 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 5942 | if (tmp == NULL) goto failed; |
| 5943 | res = obj2ast_int(tmp, &lineno, arena); |
| 5944 | if (res != 0) goto failed; |
| 5945 | Py_XDECREF(tmp); |
| 5946 | tmp = NULL; |
| 5947 | } else { |
| 5948 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 5949 | return 1; |
| 5950 | } |
| 5951 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 5952 | int res; |
| 5953 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 5954 | if (tmp == NULL) goto failed; |
| 5955 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5956 | if (res != 0) goto failed; |
| 5957 | Py_XDECREF(tmp); |
| 5958 | tmp = NULL; |
| 5959 | } else { |
| 5960 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 5961 | return 1; |
| 5962 | } |
| 5963 | *out = excepthandler(type, name, body, lineno, col_offset, arena); |
| 5964 | return 0; |
| 5965 | failed: |
| 5966 | Py_XDECREF(tmp); |
| 5967 | return 1; |
| 5968 | } |
| 5969 | |
| 5970 | int |
| 5971 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 5972 | { |
| 5973 | PyObject* tmp = NULL; |
| 5974 | asdl_seq* args; |
| 5975 | identifier vararg; |
| 5976 | expr_ty varargannotation; |
| 5977 | asdl_seq* kwonlyargs; |
| 5978 | identifier kwarg; |
| 5979 | expr_ty kwargannotation; |
| 5980 | asdl_seq* defaults; |
| 5981 | asdl_seq* kw_defaults; |
| 5982 | |
| 5983 | if (PyObject_HasAttrString(obj, "args")) { |
| 5984 | int res; |
| 5985 | Py_ssize_t len; |
| 5986 | Py_ssize_t i; |
| 5987 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5988 | if (tmp == NULL) goto failed; |
| 5989 | if (!PyList_Check(tmp)) { |
| 5990 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5991 | goto failed; |
| 5992 | } |
| 5993 | len = PyList_GET_SIZE(tmp); |
| 5994 | args = asdl_seq_new(len, arena); |
| 5995 | if (args == NULL) goto failed; |
| 5996 | for (i = 0; i < len; i++) { |
| 5997 | arg_ty value; |
| 5998 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5999 | if (res != 0) goto failed; |
| 6000 | asdl_seq_SET(args, i, value); |
| 6001 | } |
| 6002 | Py_XDECREF(tmp); |
| 6003 | tmp = NULL; |
| 6004 | } else { |
| 6005 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6006 | return 1; |
| 6007 | } |
| 6008 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6009 | int res; |
| 6010 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6011 | if (tmp == NULL) goto failed; |
| 6012 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6013 | if (res != 0) goto failed; |
| 6014 | Py_XDECREF(tmp); |
| 6015 | tmp = NULL; |
| 6016 | } else { |
| 6017 | vararg = NULL; |
| 6018 | } |
| 6019 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6020 | int res; |
| 6021 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6022 | if (tmp == NULL) goto failed; |
| 6023 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6024 | if (res != 0) goto failed; |
| 6025 | Py_XDECREF(tmp); |
| 6026 | tmp = NULL; |
| 6027 | } else { |
| 6028 | varargannotation = NULL; |
| 6029 | } |
| 6030 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6031 | int res; |
| 6032 | Py_ssize_t len; |
| 6033 | Py_ssize_t i; |
| 6034 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6035 | if (tmp == NULL) goto failed; |
| 6036 | if (!PyList_Check(tmp)) { |
| 6037 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6038 | goto failed; |
| 6039 | } |
| 6040 | len = PyList_GET_SIZE(tmp); |
| 6041 | kwonlyargs = asdl_seq_new(len, arena); |
| 6042 | if (kwonlyargs == NULL) goto failed; |
| 6043 | for (i = 0; i < len; i++) { |
| 6044 | arg_ty value; |
| 6045 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6046 | if (res != 0) goto failed; |
| 6047 | asdl_seq_SET(kwonlyargs, i, value); |
| 6048 | } |
| 6049 | Py_XDECREF(tmp); |
| 6050 | tmp = NULL; |
| 6051 | } else { |
| 6052 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6053 | return 1; |
| 6054 | } |
| 6055 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6056 | int res; |
| 6057 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6058 | if (tmp == NULL) goto failed; |
| 6059 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6060 | if (res != 0) goto failed; |
| 6061 | Py_XDECREF(tmp); |
| 6062 | tmp = NULL; |
| 6063 | } else { |
| 6064 | kwarg = NULL; |
| 6065 | } |
| 6066 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6067 | int res; |
| 6068 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6069 | if (tmp == NULL) goto failed; |
| 6070 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6071 | if (res != 0) goto failed; |
| 6072 | Py_XDECREF(tmp); |
| 6073 | tmp = NULL; |
| 6074 | } else { |
| 6075 | kwargannotation = NULL; |
| 6076 | } |
| 6077 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6078 | int res; |
| 6079 | Py_ssize_t len; |
| 6080 | Py_ssize_t i; |
| 6081 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6082 | if (tmp == NULL) goto failed; |
| 6083 | if (!PyList_Check(tmp)) { |
| 6084 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6085 | goto failed; |
| 6086 | } |
| 6087 | len = PyList_GET_SIZE(tmp); |
| 6088 | defaults = asdl_seq_new(len, arena); |
| 6089 | if (defaults == NULL) goto failed; |
| 6090 | for (i = 0; i < len; i++) { |
| 6091 | expr_ty value; |
| 6092 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6093 | if (res != 0) goto failed; |
| 6094 | asdl_seq_SET(defaults, i, value); |
| 6095 | } |
| 6096 | Py_XDECREF(tmp); |
| 6097 | tmp = NULL; |
| 6098 | } else { |
| 6099 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6100 | return 1; |
| 6101 | } |
| 6102 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6103 | int res; |
| 6104 | Py_ssize_t len; |
| 6105 | Py_ssize_t i; |
| 6106 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6107 | if (tmp == NULL) goto failed; |
| 6108 | if (!PyList_Check(tmp)) { |
| 6109 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6110 | goto failed; |
| 6111 | } |
| 6112 | len = PyList_GET_SIZE(tmp); |
| 6113 | kw_defaults = asdl_seq_new(len, arena); |
| 6114 | if (kw_defaults == NULL) goto failed; |
| 6115 | for (i = 0; i < len; i++) { |
| 6116 | expr_ty value; |
| 6117 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6118 | if (res != 0) goto failed; |
| 6119 | asdl_seq_SET(kw_defaults, i, value); |
| 6120 | } |
| 6121 | Py_XDECREF(tmp); |
| 6122 | tmp = NULL; |
| 6123 | } else { |
| 6124 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6125 | return 1; |
| 6126 | } |
| 6127 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6128 | kwargannotation, defaults, kw_defaults, arena); |
| 6129 | return 0; |
| 6130 | failed: |
| 6131 | Py_XDECREF(tmp); |
| 6132 | return 1; |
| 6133 | } |
| 6134 | |
| 6135 | int |
| 6136 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6137 | { |
| 6138 | PyObject* tmp = NULL; |
| 6139 | identifier arg; |
| 6140 | expr_ty annotation; |
| 6141 | |
| 6142 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6143 | int res; |
| 6144 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6145 | if (tmp == NULL) goto failed; |
| 6146 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6147 | if (res != 0) goto failed; |
| 6148 | Py_XDECREF(tmp); |
| 6149 | tmp = NULL; |
| 6150 | } else { |
| 6151 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6152 | return 1; |
| 6153 | } |
| 6154 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6155 | int res; |
| 6156 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6157 | if (tmp == NULL) goto failed; |
| 6158 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6159 | if (res != 0) goto failed; |
| 6160 | Py_XDECREF(tmp); |
| 6161 | tmp = NULL; |
| 6162 | } else { |
| 6163 | annotation = NULL; |
| 6164 | } |
| 6165 | *out = arg(arg, annotation, arena); |
| 6166 | return 0; |
| 6167 | failed: |
| 6168 | Py_XDECREF(tmp); |
| 6169 | return 1; |
| 6170 | } |
| 6171 | |
| 6172 | int |
| 6173 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6174 | { |
| 6175 | PyObject* tmp = NULL; |
| 6176 | identifier arg; |
| 6177 | expr_ty value; |
| 6178 | |
| 6179 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6180 | int res; |
| 6181 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6182 | if (tmp == NULL) goto failed; |
| 6183 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6184 | if (res != 0) goto failed; |
| 6185 | Py_XDECREF(tmp); |
| 6186 | tmp = NULL; |
| 6187 | } else { |
| 6188 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6189 | return 1; |
| 6190 | } |
| 6191 | if (PyObject_HasAttrString(obj, "value")) { |
| 6192 | int res; |
| 6193 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6194 | if (tmp == NULL) goto failed; |
| 6195 | res = obj2ast_expr(tmp, &value, arena); |
| 6196 | if (res != 0) goto failed; |
| 6197 | Py_XDECREF(tmp); |
| 6198 | tmp = NULL; |
| 6199 | } else { |
| 6200 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6201 | return 1; |
| 6202 | } |
| 6203 | *out = keyword(arg, value, arena); |
| 6204 | return 0; |
| 6205 | failed: |
| 6206 | Py_XDECREF(tmp); |
| 6207 | return 1; |
| 6208 | } |
| 6209 | |
| 6210 | int |
| 6211 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6212 | { |
| 6213 | PyObject* tmp = NULL; |
| 6214 | identifier name; |
| 6215 | identifier asname; |
| 6216 | |
| 6217 | if (PyObject_HasAttrString(obj, "name")) { |
| 6218 | int res; |
| 6219 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6220 | if (tmp == NULL) goto failed; |
| 6221 | res = obj2ast_identifier(tmp, &name, arena); |
| 6222 | if (res != 0) goto failed; |
| 6223 | Py_XDECREF(tmp); |
| 6224 | tmp = NULL; |
| 6225 | } else { |
| 6226 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6227 | return 1; |
| 6228 | } |
| 6229 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6230 | int res; |
| 6231 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6232 | if (tmp == NULL) goto failed; |
| 6233 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6234 | if (res != 0) goto failed; |
| 6235 | Py_XDECREF(tmp); |
| 6236 | tmp = NULL; |
| 6237 | } else { |
| 6238 | asname = NULL; |
| 6239 | } |
| 6240 | *out = alias(name, asname, arena); |
| 6241 | return 0; |
| 6242 | failed: |
| 6243 | Py_XDECREF(tmp); |
| 6244 | return 1; |
| 6245 | } |
| 6246 | |
| 6247 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6248 | PyMODINIT_FUNC |
| 6249 | init_ast(void) |
| 6250 | { |
| 6251 | PyObject *m, *d; |
| 6252 | if (!init_types()) return; |
| 6253 | m = Py_InitModule3("_ast", NULL, NULL); |
| 6254 | if (!m) return; |
| 6255 | d = PyModule_GetDict(m); |
| 6256 | if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; |
| 6257 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6258 | return; |
Christian Heimes | d3eb5a15 | 2008-02-24 00:38:49 +0000 | [diff] [blame] | 6259 | if (PyModule_AddStringConstant(m, "__version__", "57783") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 6260 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6261 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 6262 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 6263 | return; |
| 6264 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 6265 | < 0) return; |
| 6266 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 6267 | 0) return; |
| 6268 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 6269 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 6270 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 6271 | < 0) return; |
| 6272 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 6273 | return; |
| 6274 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 6275 | return; |
| 6276 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 6277 | return; |
| 6278 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 6279 | return; |
| 6280 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 6281 | 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6282 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 6283 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 6284 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 6285 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 6286 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 6287 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 6288 | 0) return; |
| 6289 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 6290 | 0) return; |
| 6291 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 6292 | return; |
| 6293 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 6294 | return; |
| 6295 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 6296 | 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6297 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 6298 | return; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6299 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 6300 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6301 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 6302 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 6303 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 6304 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 6305 | return; |
| 6306 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 6307 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 6308 | return; |
| 6309 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 6310 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 6311 | return; |
| 6312 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 6313 | return; |
| 6314 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 6315 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 6316 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6317 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 6318 | return; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6319 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
| 6320 | return; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6321 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 6322 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6323 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 6324 | (PyObject*)GeneratorExp_type) < 0) return; |
| 6325 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 6326 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 6327 | return; |
| 6328 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6329 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 6330 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 6331 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6332 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 6333 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6334 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 6335 | 0) return; |
| 6336 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 6337 | 0) return; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6338 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
| 6339 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6340 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 6341 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 6342 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 6343 | if (PyDict_SetItemString(d, "expr_context", |
| 6344 | (PyObject*)expr_context_type) < 0) return; |
| 6345 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 6346 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 6347 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 6348 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 6349 | return; |
| 6350 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 6351 | return; |
| 6352 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 6353 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6354 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 6355 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 6356 | return; |
| 6357 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 6358 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 6359 | return; |
| 6360 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 6361 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 6362 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 6363 | return; |
| 6364 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 6365 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 6366 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 6367 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 6368 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 6369 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 6370 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 6371 | return; |
| 6372 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 6373 | return; |
| 6374 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 6375 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 6376 | return; |
| 6377 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 6378 | return; |
| 6379 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 6380 | return; |
| 6381 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 6382 | return; |
| 6383 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 6384 | return; |
| 6385 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 6386 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 6387 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 6388 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 6389 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 6390 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 6391 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 6392 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 6393 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 6394 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 6395 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 6396 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 6397 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 6398 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 6399 | if (PyDict_SetItemString(d, "comprehension", |
| 6400 | (PyObject*)comprehension_type) < 0) return; |
| 6401 | if (PyDict_SetItemString(d, "excepthandler", |
| 6402 | (PyObject*)excepthandler_type) < 0) return; |
| 6403 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 6404 | 0) return; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 6405 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6406 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 6407 | return; |
| 6408 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6411 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6412 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6413 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6414 | init_types(); |
| 6415 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6416 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6417 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6418 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena) |
| 6419 | { |
| 6420 | mod_ty res; |
| 6421 | init_types(); |
Martin v. Löwis | 617fa91 | 2008-03-30 20:29:36 +0000 | [diff] [blame] | 6422 | if (!PyObject_IsInstance(ast, (PyObject*)mod_type)) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6423 | PyErr_SetString(PyExc_TypeError, "expected either Module, Interactive " |
| 6424 | "or Expression node"); |
| 6425 | return NULL; |
| 6426 | } |
| 6427 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6428 | return NULL; |
| 6429 | else |
| 6430 | return res; |
| 6431 | } |
| 6432 | |
| 6433 | int PyAST_Check(PyObject* obj) |
| 6434 | { |
| 6435 | init_types(); |
| 6436 | return PyObject_IsInstance(obj, (PyObject*)AST_type); |
| 6437 | } |
| 6438 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6439 | |