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 | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 15 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 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; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 354 | static char *excepthandler_attributes[] = { |
| 355 | "lineno", |
| 356 | "col_offset", |
| 357 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 358 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 359 | static PyTypeObject *ExceptHandler_type; |
| 360 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 361 | "type", |
| 362 | "name", |
| 363 | "body", |
| 364 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 365 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 366 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 367 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 368 | "args", |
| 369 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 370 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 371 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 372 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 373 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 375 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 376 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 377 | static PyTypeObject *arg_type; |
| 378 | static PyObject* ast2obj_arg(void*); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 379 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 380 | "arg", |
| 381 | "annotation", |
| 382 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 383 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 384 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 385 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 386 | "arg", |
| 387 | "value", |
| 388 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 390 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 391 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 392 | "name", |
| 393 | "asname", |
| 394 | }; |
| 395 | |
| 396 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 397 | static int |
| 398 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 399 | { |
| 400 | Py_ssize_t i, numfields = 0; |
| 401 | int res = -1; |
| 402 | PyObject *key, *value, *fields; |
| 403 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); |
| 404 | if (!fields) |
| 405 | PyErr_Clear(); |
| 406 | if (fields) { |
| 407 | numfields = PySequence_Size(fields); |
| 408 | if (numfields == -1) |
| 409 | goto cleanup; |
| 410 | } |
| 411 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 412 | if (PyTuple_GET_SIZE(args) > 0) { |
| 413 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 414 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
| 415 | "%" PY_FORMAT_SIZE_T "d positional argument%s", |
| 416 | Py_TYPE(self)->tp_name, |
| 417 | numfields == 0 ? "" : "either 0 or ", |
| 418 | numfields, numfields == 1 ? "" : "s"); |
| 419 | res = -1; |
| 420 | goto cleanup; |
| 421 | } |
| 422 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 423 | /* cannot be reached when fields is NULL */ |
| 424 | PyObject *name = PySequence_GetItem(fields, i); |
| 425 | if (!name) { |
| 426 | res = -1; |
| 427 | goto cleanup; |
| 428 | } |
| 429 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 430 | Py_DECREF(name); |
| 431 | if (res < 0) |
| 432 | goto cleanup; |
| 433 | } |
| 434 | } |
| 435 | if (kw) { |
| 436 | i = 0; /* needed by PyDict_Next */ |
| 437 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 438 | res = PyObject_SetAttr(self, key, value); |
| 439 | if (res < 0) |
| 440 | goto cleanup; |
| 441 | } |
| 442 | } |
| 443 | cleanup: |
| 444 | Py_XDECREF(fields); |
| 445 | return res; |
| 446 | } |
| 447 | |
| 448 | static PyTypeObject AST_type = { |
| 449 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 450 | "AST", |
| 451 | sizeof(PyObject), |
| 452 | 0, |
| 453 | 0, /* tp_dealloc */ |
| 454 | 0, /* tp_print */ |
| 455 | 0, /* tp_getattr */ |
| 456 | 0, /* tp_setattr */ |
| 457 | 0, /* tp_compare */ |
| 458 | 0, /* tp_repr */ |
| 459 | 0, /* tp_as_number */ |
| 460 | 0, /* tp_as_sequence */ |
| 461 | 0, /* tp_as_mapping */ |
| 462 | 0, /* tp_hash */ |
| 463 | 0, /* tp_call */ |
| 464 | 0, /* tp_str */ |
| 465 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 466 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 467 | 0, /* tp_as_buffer */ |
| 468 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 469 | 0, /* tp_doc */ |
| 470 | 0, /* tp_traverse */ |
| 471 | 0, /* tp_clear */ |
| 472 | 0, /* tp_richcompare */ |
| 473 | 0, /* tp_weaklistoffset */ |
| 474 | 0, /* tp_iter */ |
| 475 | 0, /* tp_iternext */ |
| 476 | 0, /* tp_methods */ |
| 477 | 0, /* tp_members */ |
| 478 | 0, /* tp_getset */ |
| 479 | 0, /* tp_base */ |
| 480 | 0, /* tp_dict */ |
| 481 | 0, /* tp_descr_get */ |
| 482 | 0, /* tp_descr_set */ |
| 483 | 0, /* tp_dictoffset */ |
| 484 | (initproc)ast_type_init, /* tp_init */ |
| 485 | PyType_GenericAlloc, /* tp_alloc */ |
| 486 | PyType_GenericNew, /* tp_new */ |
| 487 | PyObject_Del, /* tp_free */ |
| 488 | }; |
| 489 | |
| 490 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 491 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 492 | { |
| 493 | PyObject *fnames, *result; |
| 494 | int i; |
| 495 | if (num_fields) { |
| 496 | fnames = PyTuple_New(num_fields); |
| 497 | if (!fnames) return NULL; |
| 498 | } else { |
| 499 | fnames = Py_None; |
| 500 | Py_INCREF(Py_None); |
| 501 | } |
| 502 | for(i=0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 503 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 504 | if (!field) { |
| 505 | Py_DECREF(fnames); |
| 506 | return NULL; |
| 507 | } |
| 508 | PyTuple_SET_ITEM(fnames, i, field); |
| 509 | } |
Guido van Rossum | e845c0f | 2007-11-02 23:07:07 +0000 | [diff] [blame] | 510 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 511 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 512 | Py_DECREF(fnames); |
| 513 | return (PyTypeObject*)result; |
| 514 | } |
| 515 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 516 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 517 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 518 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 519 | PyObject *s, *l = PyTuple_New(num_fields); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 520 | if (!l) return 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 521 | for(i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 522 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 523 | if (!s) { |
| 524 | Py_DECREF(l); |
| 525 | return 0; |
| 526 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 527 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 528 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 529 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 530 | Py_DECREF(l); |
| 531 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 534 | /* Conversion AST -> Python */ |
| 535 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 536 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 537 | { |
| 538 | int i, n = asdl_seq_LEN(seq); |
| 539 | PyObject *result = PyList_New(n); |
| 540 | PyObject *value; |
| 541 | if (!result) |
| 542 | return NULL; |
| 543 | for (i = 0; i < n; i++) { |
| 544 | value = func(asdl_seq_GET(seq, i)); |
| 545 | if (!value) { |
| 546 | Py_DECREF(result); |
| 547 | return NULL; |
| 548 | } |
| 549 | PyList_SET_ITEM(result, i, value); |
| 550 | } |
| 551 | return result; |
| 552 | } |
| 553 | |
| 554 | static PyObject* ast2obj_object(void *o) |
| 555 | { |
| 556 | if (!o) |
| 557 | o = Py_None; |
| 558 | Py_INCREF((PyObject*)o); |
| 559 | return (PyObject*)o; |
| 560 | } |
| 561 | #define ast2obj_identifier ast2obj_object |
| 562 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 563 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 564 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 565 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 566 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 569 | /* Conversion Python -> AST */ |
| 570 | |
| 571 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 572 | { |
| 573 | if (obj == Py_None) |
| 574 | obj = NULL; |
| 575 | if (obj) |
| 576 | PyArena_AddPyObject(arena, obj); |
| 577 | Py_XINCREF(obj); |
| 578 | *out = obj; |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | #define obj2ast_identifier obj2ast_object |
| 583 | #define obj2ast_string obj2ast_object |
| 584 | |
| 585 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 586 | { |
| 587 | int i; |
| 588 | if (!PyLong_Check(obj)) { |
| 589 | PyObject *s = PyObject_Repr(obj); |
| 590 | if (s == NULL) return 1; |
| 591 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
| 592 | PyString_AS_STRING(s)); |
| 593 | Py_DECREF(s); |
| 594 | return 1; |
| 595 | } |
| 596 | |
| 597 | i = (int)PyLong_AsLong(obj); |
| 598 | if (i == -1 && PyErr_Occurred()) |
| 599 | return 1; |
| 600 | *out = i; |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 605 | static int init_types(void) |
| 606 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 607 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 608 | if (initialized) return 1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 609 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 610 | if (!mod_type) return 0; |
| 611 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 612 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 613 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 614 | Interactive_type = make_type("Interactive", mod_type, |
| 615 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 616 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 617 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 618 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 619 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 620 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 621 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 622 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 623 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 624 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 625 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 626 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 627 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 628 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 629 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 630 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 631 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 632 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 633 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 634 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 635 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 636 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 637 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 638 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 639 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 640 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 641 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 642 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 643 | if (!If_type) return 0; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 644 | With_type = make_type("With", stmt_type, With_fields, 3); |
| 645 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 646 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 647 | if (!Raise_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 648 | TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 649 | if (!TryExcept_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 650 | TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, |
| 651 | 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 652 | if (!TryFinally_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 654 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 655 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 656 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 657 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 658 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 661 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 662 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 663 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 664 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 666 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 668 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 670 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 671 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 672 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 674 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 675 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 676 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 677 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 678 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 679 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 680 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 681 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 682 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 683 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 684 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 685 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 686 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 687 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 688 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 689 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 690 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 691 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 692 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 693 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 694 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 696 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 700 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 701 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 702 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 704 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 705 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 706 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 708 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 709 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 710 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 711 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 712 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 713 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 714 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 715 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 716 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 717 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 718 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 719 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 720 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 721 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 723 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 724 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!expr_context_type) return 0; |
| 726 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 727 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 728 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 729 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 730 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 731 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 732 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 733 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 734 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 735 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 736 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 737 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 738 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 739 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 740 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 741 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 742 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 743 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 744 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 745 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 746 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 747 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 748 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 749 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 750 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 751 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 752 | if (!slice_type) return 0; |
| 753 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 754 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 755 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 756 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 757 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 759 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 760 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 761 | if (!boolop_type) return 0; |
| 762 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 763 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 764 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 767 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 770 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 771 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!operator_type) return 0; |
| 773 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 774 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 775 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 776 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 777 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 778 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 779 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 780 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 782 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 784 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 786 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 788 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 790 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 794 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 798 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 800 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 802 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 803 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 804 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 805 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 806 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 810 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 814 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 816 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 818 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 819 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 822 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!unaryop_type) return 0; |
| 824 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 825 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 826 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 827 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 829 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 831 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 832 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 833 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 837 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 841 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 842 | if (!cmpop_type) return 0; |
| 843 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 844 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 845 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 846 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 847 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 848 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 849 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 851 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 852 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 853 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 854 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 855 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 856 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 857 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 858 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 859 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 860 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 861 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 862 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 863 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 864 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 865 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 866 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 867 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 868 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 869 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 870 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 871 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 872 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 873 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 874 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 875 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 876 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 878 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 880 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 884 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 885 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 886 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 887 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 888 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 889 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 890 | return 0; |
| 891 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 892 | ExceptHandler_fields, 3); |
| 893 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 894 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 896 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 897 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 898 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 899 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 900 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 901 | if (!alias_type) return 0; |
| 902 | initialized = 1; |
| 903 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 904 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 905 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 906 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 907 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 908 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 909 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 910 | arena); |
| 911 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 912 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 913 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 914 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 915 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 916 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 917 | arena); |
| 918 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 919 | arena); |
| 920 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 921 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 922 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 923 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
| 924 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 925 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 926 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 927 | { |
| 928 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 929 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 930 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 931 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 932 | p->kind = Module_kind; |
| 933 | p->v.Module.body = body; |
| 934 | return p; |
| 935 | } |
| 936 | |
| 937 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 938 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 939 | { |
| 940 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 941 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 942 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 943 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 944 | p->kind = Interactive_kind; |
| 945 | p->v.Interactive.body = body; |
| 946 | return p; |
| 947 | } |
| 948 | |
| 949 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 950 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 951 | { |
| 952 | mod_ty p; |
| 953 | if (!body) { |
| 954 | PyErr_SetString(PyExc_ValueError, |
| 955 | "field body is required for Expression"); |
| 956 | return NULL; |
| 957 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 958 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 959 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 960 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 961 | p->kind = Expression_kind; |
| 962 | p->v.Expression.body = body; |
| 963 | return p; |
| 964 | } |
| 965 | |
| 966 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 967 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 968 | { |
| 969 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 970 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 971 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 972 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 973 | p->kind = Suite_kind; |
| 974 | p->v.Suite.body = body; |
| 975 | return p; |
| 976 | } |
| 977 | |
| 978 | stmt_ty |
| 979 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 980 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 981 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 982 | { |
| 983 | stmt_ty p; |
| 984 | if (!name) { |
| 985 | PyErr_SetString(PyExc_ValueError, |
| 986 | "field name is required for FunctionDef"); |
| 987 | return NULL; |
| 988 | } |
| 989 | if (!args) { |
| 990 | PyErr_SetString(PyExc_ValueError, |
| 991 | "field args is required for FunctionDef"); |
| 992 | return NULL; |
| 993 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 994 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 995 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 996 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 997 | p->kind = FunctionDef_kind; |
| 998 | p->v.FunctionDef.name = name; |
| 999 | p->v.FunctionDef.args = args; |
| 1000 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1001 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1002 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1003 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1004 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1005 | return p; |
| 1006 | } |
| 1007 | |
| 1008 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1009 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1010 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1011 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1012 | { |
| 1013 | stmt_ty p; |
| 1014 | if (!name) { |
| 1015 | PyErr_SetString(PyExc_ValueError, |
| 1016 | "field name is required for ClassDef"); |
| 1017 | return NULL; |
| 1018 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1019 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1020 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1021 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1022 | p->kind = ClassDef_kind; |
| 1023 | p->v.ClassDef.name = name; |
| 1024 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1025 | p->v.ClassDef.keywords = keywords; |
| 1026 | p->v.ClassDef.starargs = starargs; |
| 1027 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1028 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1029 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1030 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1031 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1032 | return p; |
| 1033 | } |
| 1034 | |
| 1035 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1036 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1037 | { |
| 1038 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1039 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1040 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1041 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1042 | p->kind = Return_kind; |
| 1043 | p->v.Return.value = value; |
| 1044 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1045 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1046 | return p; |
| 1047 | } |
| 1048 | |
| 1049 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1050 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1051 | { |
| 1052 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1053 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1054 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1055 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1056 | p->kind = Delete_kind; |
| 1057 | p->v.Delete.targets = targets; |
| 1058 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1059 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1060 | return p; |
| 1061 | } |
| 1062 | |
| 1063 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1064 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1065 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1066 | { |
| 1067 | stmt_ty p; |
| 1068 | if (!value) { |
| 1069 | PyErr_SetString(PyExc_ValueError, |
| 1070 | "field value is required for Assign"); |
| 1071 | return NULL; |
| 1072 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1073 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1074 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1075 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1076 | p->kind = Assign_kind; |
| 1077 | p->v.Assign.targets = targets; |
| 1078 | p->v.Assign.value = value; |
| 1079 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1080 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1081 | return p; |
| 1082 | } |
| 1083 | |
| 1084 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1085 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1086 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1087 | { |
| 1088 | stmt_ty p; |
| 1089 | if (!target) { |
| 1090 | PyErr_SetString(PyExc_ValueError, |
| 1091 | "field target is required for AugAssign"); |
| 1092 | return NULL; |
| 1093 | } |
| 1094 | if (!op) { |
| 1095 | PyErr_SetString(PyExc_ValueError, |
| 1096 | "field op is required for AugAssign"); |
| 1097 | return NULL; |
| 1098 | } |
| 1099 | if (!value) { |
| 1100 | PyErr_SetString(PyExc_ValueError, |
| 1101 | "field value is required for AugAssign"); |
| 1102 | return NULL; |
| 1103 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1104 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1105 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1106 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1107 | p->kind = AugAssign_kind; |
| 1108 | p->v.AugAssign.target = target; |
| 1109 | p->v.AugAssign.op = op; |
| 1110 | p->v.AugAssign.value = value; |
| 1111 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1112 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1113 | return p; |
| 1114 | } |
| 1115 | |
| 1116 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1117 | 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] | 1118 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1119 | { |
| 1120 | stmt_ty p; |
| 1121 | if (!target) { |
| 1122 | PyErr_SetString(PyExc_ValueError, |
| 1123 | "field target is required for For"); |
| 1124 | return NULL; |
| 1125 | } |
| 1126 | if (!iter) { |
| 1127 | PyErr_SetString(PyExc_ValueError, |
| 1128 | "field iter is required for For"); |
| 1129 | return NULL; |
| 1130 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1131 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1132 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1134 | p->kind = For_kind; |
| 1135 | p->v.For.target = target; |
| 1136 | p->v.For.iter = iter; |
| 1137 | p->v.For.body = body; |
| 1138 | p->v.For.orelse = orelse; |
| 1139 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1140 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1141 | return p; |
| 1142 | } |
| 1143 | |
| 1144 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1145 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1146 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1147 | { |
| 1148 | stmt_ty p; |
| 1149 | if (!test) { |
| 1150 | PyErr_SetString(PyExc_ValueError, |
| 1151 | "field test is required for While"); |
| 1152 | return NULL; |
| 1153 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1154 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1155 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1156 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1157 | p->kind = While_kind; |
| 1158 | p->v.While.test = test; |
| 1159 | p->v.While.body = body; |
| 1160 | p->v.While.orelse = orelse; |
| 1161 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1162 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1163 | return p; |
| 1164 | } |
| 1165 | |
| 1166 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1167 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1168 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | { |
| 1170 | stmt_ty p; |
| 1171 | if (!test) { |
| 1172 | PyErr_SetString(PyExc_ValueError, |
| 1173 | "field test is required for If"); |
| 1174 | return NULL; |
| 1175 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1176 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1177 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1178 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1179 | p->kind = If_kind; |
| 1180 | p->v.If.test = test; |
| 1181 | p->v.If.body = body; |
| 1182 | p->v.If.orelse = orelse; |
| 1183 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1184 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1185 | return p; |
| 1186 | } |
| 1187 | |
| 1188 | stmt_ty |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1189 | 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] | 1190 | int col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1191 | { |
| 1192 | stmt_ty p; |
| 1193 | if (!context_expr) { |
| 1194 | PyErr_SetString(PyExc_ValueError, |
| 1195 | "field context_expr is required for With"); |
| 1196 | return NULL; |
| 1197 | } |
| 1198 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1199 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1200 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1201 | p->kind = With_kind; |
| 1202 | p->v.With.context_expr = context_expr; |
| 1203 | p->v.With.optional_vars = optional_vars; |
| 1204 | p->v.With.body = body; |
| 1205 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1206 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1207 | return p; |
| 1208 | } |
| 1209 | |
| 1210 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1211 | 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] | 1212 | { |
| 1213 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1214 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1215 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1217 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1218 | p->v.Raise.exc = exc; |
| 1219 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1220 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1221 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | return p; |
| 1223 | } |
| 1224 | |
| 1225 | stmt_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1226 | 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] | 1227 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1228 | { |
| 1229 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1230 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1231 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1232 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1233 | p->kind = TryExcept_kind; |
| 1234 | p->v.TryExcept.body = body; |
| 1235 | p->v.TryExcept.handlers = handlers; |
| 1236 | p->v.TryExcept.orelse = orelse; |
| 1237 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1238 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1239 | return p; |
| 1240 | } |
| 1241 | |
| 1242 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1243 | TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, |
| 1244 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1245 | { |
| 1246 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1247 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1248 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1249 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1250 | p->kind = TryFinally_kind; |
| 1251 | p->v.TryFinally.body = body; |
| 1252 | p->v.TryFinally.finalbody = finalbody; |
| 1253 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1254 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1255 | return p; |
| 1256 | } |
| 1257 | |
| 1258 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1259 | 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] | 1260 | { |
| 1261 | stmt_ty p; |
| 1262 | if (!test) { |
| 1263 | PyErr_SetString(PyExc_ValueError, |
| 1264 | "field test is required for Assert"); |
| 1265 | return NULL; |
| 1266 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1267 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1268 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1269 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | p->kind = Assert_kind; |
| 1271 | p->v.Assert.test = test; |
| 1272 | p->v.Assert.msg = msg; |
| 1273 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1274 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1275 | return p; |
| 1276 | } |
| 1277 | |
| 1278 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1279 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1280 | { |
| 1281 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1282 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1283 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1284 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1285 | p->kind = Import_kind; |
| 1286 | p->v.Import.names = names; |
| 1287 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1288 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1289 | return p; |
| 1290 | } |
| 1291 | |
| 1292 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1293 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1294 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1295 | { |
| 1296 | stmt_ty p; |
| 1297 | if (!module) { |
| 1298 | PyErr_SetString(PyExc_ValueError, |
| 1299 | "field module is required for ImportFrom"); |
| 1300 | return NULL; |
| 1301 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1302 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1303 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1304 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | p->kind = ImportFrom_kind; |
| 1306 | p->v.ImportFrom.module = module; |
| 1307 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1308 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1309 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1310 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1311 | return p; |
| 1312 | } |
| 1313 | |
| 1314 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1315 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1316 | { |
| 1317 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1318 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1319 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1321 | p->kind = Global_kind; |
| 1322 | p->v.Global.names = names; |
| 1323 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1324 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1325 | return p; |
| 1326 | } |
| 1327 | |
| 1328 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1329 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1330 | { |
| 1331 | stmt_ty p; |
| 1332 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1333 | if (!p) |
| 1334 | return NULL; |
| 1335 | p->kind = Nonlocal_kind; |
| 1336 | p->v.Nonlocal.names = names; |
| 1337 | p->lineno = lineno; |
| 1338 | p->col_offset = col_offset; |
| 1339 | return p; |
| 1340 | } |
| 1341 | |
| 1342 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1343 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1344 | { |
| 1345 | stmt_ty p; |
| 1346 | if (!value) { |
| 1347 | PyErr_SetString(PyExc_ValueError, |
| 1348 | "field value is required for Expr"); |
| 1349 | return NULL; |
| 1350 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1351 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1352 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1353 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1354 | p->kind = Expr_kind; |
| 1355 | p->v.Expr.value = value; |
| 1356 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1357 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1358 | return p; |
| 1359 | } |
| 1360 | |
| 1361 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1362 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1363 | { |
| 1364 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1365 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1366 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1367 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1368 | p->kind = Pass_kind; |
| 1369 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1370 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1371 | return p; |
| 1372 | } |
| 1373 | |
| 1374 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1375 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1376 | { |
| 1377 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1378 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1379 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1380 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1381 | p->kind = Break_kind; |
| 1382 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1383 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | return p; |
| 1385 | } |
| 1386 | |
| 1387 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1388 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1389 | { |
| 1390 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1391 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1392 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1393 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1394 | p->kind = Continue_kind; |
| 1395 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1396 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | return p; |
| 1398 | } |
| 1399 | |
| 1400 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1401 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1402 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1403 | { |
| 1404 | expr_ty p; |
| 1405 | if (!op) { |
| 1406 | PyErr_SetString(PyExc_ValueError, |
| 1407 | "field op is required for BoolOp"); |
| 1408 | return NULL; |
| 1409 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1410 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1411 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1412 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1413 | p->kind = BoolOp_kind; |
| 1414 | p->v.BoolOp.op = op; |
| 1415 | p->v.BoolOp.values = values; |
| 1416 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1417 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1418 | return p; |
| 1419 | } |
| 1420 | |
| 1421 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1422 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1423 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1424 | { |
| 1425 | expr_ty p; |
| 1426 | if (!left) { |
| 1427 | PyErr_SetString(PyExc_ValueError, |
| 1428 | "field left is required for BinOp"); |
| 1429 | return NULL; |
| 1430 | } |
| 1431 | if (!op) { |
| 1432 | PyErr_SetString(PyExc_ValueError, |
| 1433 | "field op is required for BinOp"); |
| 1434 | return NULL; |
| 1435 | } |
| 1436 | if (!right) { |
| 1437 | PyErr_SetString(PyExc_ValueError, |
| 1438 | "field right is required for BinOp"); |
| 1439 | return NULL; |
| 1440 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1441 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1442 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1443 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1444 | p->kind = BinOp_kind; |
| 1445 | p->v.BinOp.left = left; |
| 1446 | p->v.BinOp.op = op; |
| 1447 | p->v.BinOp.right = right; |
| 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1454 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1455 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1456 | { |
| 1457 | expr_ty p; |
| 1458 | if (!op) { |
| 1459 | PyErr_SetString(PyExc_ValueError, |
| 1460 | "field op is required for UnaryOp"); |
| 1461 | return NULL; |
| 1462 | } |
| 1463 | if (!operand) { |
| 1464 | PyErr_SetString(PyExc_ValueError, |
| 1465 | "field operand is required for UnaryOp"); |
| 1466 | return NULL; |
| 1467 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1468 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1469 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1471 | p->kind = UnaryOp_kind; |
| 1472 | p->v.UnaryOp.op = op; |
| 1473 | p->v.UnaryOp.operand = operand; |
| 1474 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1475 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1476 | return p; |
| 1477 | } |
| 1478 | |
| 1479 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1480 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1481 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1482 | { |
| 1483 | expr_ty p; |
| 1484 | if (!args) { |
| 1485 | PyErr_SetString(PyExc_ValueError, |
| 1486 | "field args is required for Lambda"); |
| 1487 | return NULL; |
| 1488 | } |
| 1489 | if (!body) { |
| 1490 | PyErr_SetString(PyExc_ValueError, |
| 1491 | "field body is required for Lambda"); |
| 1492 | return NULL; |
| 1493 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1494 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1495 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1496 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1497 | p->kind = Lambda_kind; |
| 1498 | p->v.Lambda.args = args; |
| 1499 | p->v.Lambda.body = body; |
| 1500 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1501 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1502 | return p; |
| 1503 | } |
| 1504 | |
| 1505 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1506 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1507 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1508 | { |
| 1509 | expr_ty p; |
| 1510 | if (!test) { |
| 1511 | PyErr_SetString(PyExc_ValueError, |
| 1512 | "field test is required for IfExp"); |
| 1513 | return NULL; |
| 1514 | } |
| 1515 | if (!body) { |
| 1516 | PyErr_SetString(PyExc_ValueError, |
| 1517 | "field body is required for IfExp"); |
| 1518 | return NULL; |
| 1519 | } |
| 1520 | if (!orelse) { |
| 1521 | PyErr_SetString(PyExc_ValueError, |
| 1522 | "field orelse is required for IfExp"); |
| 1523 | return NULL; |
| 1524 | } |
| 1525 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1526 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1527 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1528 | p->kind = IfExp_kind; |
| 1529 | p->v.IfExp.test = test; |
| 1530 | p->v.IfExp.body = body; |
| 1531 | p->v.IfExp.orelse = orelse; |
| 1532 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1533 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1534 | return p; |
| 1535 | } |
| 1536 | |
| 1537 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1538 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1539 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1540 | { |
| 1541 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1542 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1543 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1544 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1545 | p->kind = Dict_kind; |
| 1546 | p->v.Dict.keys = keys; |
| 1547 | p->v.Dict.values = values; |
| 1548 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1549 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1550 | return p; |
| 1551 | } |
| 1552 | |
| 1553 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1554 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1555 | { |
| 1556 | expr_ty p; |
| 1557 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1558 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1559 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1560 | p->kind = Set_kind; |
| 1561 | p->v.Set.elts = elts; |
| 1562 | p->lineno = lineno; |
| 1563 | p->col_offset = col_offset; |
| 1564 | return p; |
| 1565 | } |
| 1566 | |
| 1567 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1568 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1569 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | { |
| 1571 | expr_ty p; |
| 1572 | if (!elt) { |
| 1573 | PyErr_SetString(PyExc_ValueError, |
| 1574 | "field elt is required for ListComp"); |
| 1575 | return NULL; |
| 1576 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1577 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1578 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1579 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1580 | p->kind = ListComp_kind; |
| 1581 | p->v.ListComp.elt = elt; |
| 1582 | p->v.ListComp.generators = generators; |
| 1583 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1584 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1585 | return p; |
| 1586 | } |
| 1587 | |
| 1588 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1589 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1590 | *arena) |
| 1591 | { |
| 1592 | expr_ty p; |
| 1593 | if (!elt) { |
| 1594 | PyErr_SetString(PyExc_ValueError, |
| 1595 | "field elt is required for SetComp"); |
| 1596 | return NULL; |
| 1597 | } |
| 1598 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1599 | if (!p) |
| 1600 | return NULL; |
| 1601 | p->kind = SetComp_kind; |
| 1602 | p->v.SetComp.elt = elt; |
| 1603 | p->v.SetComp.generators = generators; |
| 1604 | p->lineno = lineno; |
| 1605 | p->col_offset = col_offset; |
| 1606 | return p; |
| 1607 | } |
| 1608 | |
| 1609 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1610 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1611 | col_offset, PyArena *arena) |
| 1612 | { |
| 1613 | expr_ty p; |
| 1614 | if (!key) { |
| 1615 | PyErr_SetString(PyExc_ValueError, |
| 1616 | "field key is required for DictComp"); |
| 1617 | return NULL; |
| 1618 | } |
| 1619 | if (!value) { |
| 1620 | PyErr_SetString(PyExc_ValueError, |
| 1621 | "field value is required for DictComp"); |
| 1622 | return NULL; |
| 1623 | } |
| 1624 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1625 | if (!p) |
| 1626 | return NULL; |
| 1627 | p->kind = DictComp_kind; |
| 1628 | p->v.DictComp.key = key; |
| 1629 | p->v.DictComp.value = value; |
| 1630 | p->v.DictComp.generators = generators; |
| 1631 | p->lineno = lineno; |
| 1632 | p->col_offset = col_offset; |
| 1633 | return p; |
| 1634 | } |
| 1635 | |
| 1636 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1637 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1638 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1639 | { |
| 1640 | expr_ty p; |
| 1641 | if (!elt) { |
| 1642 | PyErr_SetString(PyExc_ValueError, |
| 1643 | "field elt is required for GeneratorExp"); |
| 1644 | return NULL; |
| 1645 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1646 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1647 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1648 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1649 | p->kind = GeneratorExp_kind; |
| 1650 | p->v.GeneratorExp.elt = elt; |
| 1651 | p->v.GeneratorExp.generators = generators; |
| 1652 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1653 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1654 | return p; |
| 1655 | } |
| 1656 | |
| 1657 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1658 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1659 | { |
| 1660 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1661 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1662 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1663 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1664 | p->kind = Yield_kind; |
| 1665 | p->v.Yield.value = value; |
| 1666 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1667 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1668 | return p; |
| 1669 | } |
| 1670 | |
| 1671 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1672 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1673 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1674 | { |
| 1675 | expr_ty p; |
| 1676 | if (!left) { |
| 1677 | PyErr_SetString(PyExc_ValueError, |
| 1678 | "field left is required for Compare"); |
| 1679 | return NULL; |
| 1680 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1681 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1682 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1683 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1684 | p->kind = Compare_kind; |
| 1685 | p->v.Compare.left = left; |
| 1686 | p->v.Compare.ops = ops; |
| 1687 | p->v.Compare.comparators = comparators; |
| 1688 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1689 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1690 | return p; |
| 1691 | } |
| 1692 | |
| 1693 | expr_ty |
| 1694 | 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] | 1695 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | { |
| 1697 | expr_ty p; |
| 1698 | if (!func) { |
| 1699 | PyErr_SetString(PyExc_ValueError, |
| 1700 | "field func is required for Call"); |
| 1701 | return NULL; |
| 1702 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1703 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1704 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1705 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1706 | p->kind = Call_kind; |
| 1707 | p->v.Call.func = func; |
| 1708 | p->v.Call.args = args; |
| 1709 | p->v.Call.keywords = keywords; |
| 1710 | p->v.Call.starargs = starargs; |
| 1711 | p->v.Call.kwargs = kwargs; |
| 1712 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1713 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1714 | return p; |
| 1715 | } |
| 1716 | |
| 1717 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1718 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1719 | { |
| 1720 | expr_ty p; |
| 1721 | if (!n) { |
| 1722 | PyErr_SetString(PyExc_ValueError, |
| 1723 | "field n is required for Num"); |
| 1724 | return NULL; |
| 1725 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1726 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1727 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1728 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1729 | p->kind = Num_kind; |
| 1730 | p->v.Num.n = n; |
| 1731 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1732 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1733 | return p; |
| 1734 | } |
| 1735 | |
| 1736 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1737 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1738 | { |
| 1739 | expr_ty p; |
| 1740 | if (!s) { |
| 1741 | PyErr_SetString(PyExc_ValueError, |
| 1742 | "field s is required for Str"); |
| 1743 | return NULL; |
| 1744 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1745 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1746 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | p->kind = Str_kind; |
| 1749 | p->v.Str.s = s; |
| 1750 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1751 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1752 | return p; |
| 1753 | } |
| 1754 | |
| 1755 | expr_ty |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1756 | Bytes(string s, int lineno, int col_offset, PyArena *arena) |
| 1757 | { |
| 1758 | expr_ty p; |
| 1759 | if (!s) { |
| 1760 | PyErr_SetString(PyExc_ValueError, |
| 1761 | "field s is required for Bytes"); |
| 1762 | return NULL; |
| 1763 | } |
| 1764 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1765 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1766 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1767 | p->kind = Bytes_kind; |
| 1768 | p->v.Bytes.s = s; |
| 1769 | p->lineno = lineno; |
| 1770 | p->col_offset = col_offset; |
| 1771 | return p; |
| 1772 | } |
| 1773 | |
| 1774 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1775 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1776 | { |
| 1777 | expr_ty p; |
| 1778 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1779 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1780 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1781 | p->kind = Ellipsis_kind; |
| 1782 | p->lineno = lineno; |
| 1783 | p->col_offset = col_offset; |
| 1784 | return p; |
| 1785 | } |
| 1786 | |
| 1787 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1788 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1789 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1790 | { |
| 1791 | expr_ty p; |
| 1792 | if (!value) { |
| 1793 | PyErr_SetString(PyExc_ValueError, |
| 1794 | "field value is required for Attribute"); |
| 1795 | return NULL; |
| 1796 | } |
| 1797 | if (!attr) { |
| 1798 | PyErr_SetString(PyExc_ValueError, |
| 1799 | "field attr is required for Attribute"); |
| 1800 | return NULL; |
| 1801 | } |
| 1802 | if (!ctx) { |
| 1803 | PyErr_SetString(PyExc_ValueError, |
| 1804 | "field ctx is required for Attribute"); |
| 1805 | return NULL; |
| 1806 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1807 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1808 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1809 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1810 | p->kind = Attribute_kind; |
| 1811 | p->v.Attribute.value = value; |
| 1812 | p->v.Attribute.attr = attr; |
| 1813 | p->v.Attribute.ctx = ctx; |
| 1814 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1815 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1816 | return p; |
| 1817 | } |
| 1818 | |
| 1819 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1820 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1821 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1822 | { |
| 1823 | expr_ty p; |
| 1824 | if (!value) { |
| 1825 | PyErr_SetString(PyExc_ValueError, |
| 1826 | "field value is required for Subscript"); |
| 1827 | return NULL; |
| 1828 | } |
| 1829 | if (!slice) { |
| 1830 | PyErr_SetString(PyExc_ValueError, |
| 1831 | "field slice is required for Subscript"); |
| 1832 | return NULL; |
| 1833 | } |
| 1834 | if (!ctx) { |
| 1835 | PyErr_SetString(PyExc_ValueError, |
| 1836 | "field ctx is required for Subscript"); |
| 1837 | return NULL; |
| 1838 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1839 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1840 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1841 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | p->kind = Subscript_kind; |
| 1843 | p->v.Subscript.value = value; |
| 1844 | p->v.Subscript.slice = slice; |
| 1845 | p->v.Subscript.ctx = ctx; |
| 1846 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1847 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1848 | return p; |
| 1849 | } |
| 1850 | |
| 1851 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1852 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1853 | *arena) |
| 1854 | { |
| 1855 | expr_ty p; |
| 1856 | if (!value) { |
| 1857 | PyErr_SetString(PyExc_ValueError, |
| 1858 | "field value is required for Starred"); |
| 1859 | return NULL; |
| 1860 | } |
| 1861 | if (!ctx) { |
| 1862 | PyErr_SetString(PyExc_ValueError, |
| 1863 | "field ctx is required for Starred"); |
| 1864 | return NULL; |
| 1865 | } |
| 1866 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1867 | if (!p) |
| 1868 | return NULL; |
| 1869 | p->kind = Starred_kind; |
| 1870 | p->v.Starred.value = value; |
| 1871 | p->v.Starred.ctx = ctx; |
| 1872 | p->lineno = lineno; |
| 1873 | p->col_offset = col_offset; |
| 1874 | return p; |
| 1875 | } |
| 1876 | |
| 1877 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1878 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1879 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1880 | { |
| 1881 | expr_ty p; |
| 1882 | if (!id) { |
| 1883 | PyErr_SetString(PyExc_ValueError, |
| 1884 | "field id is required for Name"); |
| 1885 | return NULL; |
| 1886 | } |
| 1887 | if (!ctx) { |
| 1888 | PyErr_SetString(PyExc_ValueError, |
| 1889 | "field ctx is required for Name"); |
| 1890 | return NULL; |
| 1891 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1892 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1893 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1894 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1895 | p->kind = Name_kind; |
| 1896 | p->v.Name.id = id; |
| 1897 | p->v.Name.ctx = ctx; |
| 1898 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1899 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1900 | return p; |
| 1901 | } |
| 1902 | |
| 1903 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1904 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1905 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1906 | { |
| 1907 | expr_ty p; |
| 1908 | if (!ctx) { |
| 1909 | PyErr_SetString(PyExc_ValueError, |
| 1910 | "field ctx is required for List"); |
| 1911 | return NULL; |
| 1912 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1913 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1914 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1916 | p->kind = List_kind; |
| 1917 | p->v.List.elts = elts; |
| 1918 | p->v.List.ctx = ctx; |
| 1919 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1920 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1921 | return p; |
| 1922 | } |
| 1923 | |
| 1924 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1925 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1926 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1927 | { |
| 1928 | expr_ty p; |
| 1929 | if (!ctx) { |
| 1930 | PyErr_SetString(PyExc_ValueError, |
| 1931 | "field ctx is required for Tuple"); |
| 1932 | return NULL; |
| 1933 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1934 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1935 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1937 | p->kind = Tuple_kind; |
| 1938 | p->v.Tuple.elts = elts; |
| 1939 | p->v.Tuple.ctx = ctx; |
| 1940 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1941 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1942 | return p; |
| 1943 | } |
| 1944 | |
| 1945 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1946 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1947 | { |
| 1948 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1949 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1950 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1951 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1952 | p->kind = Slice_kind; |
| 1953 | p->v.Slice.lower = lower; |
| 1954 | p->v.Slice.upper = upper; |
| 1955 | p->v.Slice.step = step; |
| 1956 | return p; |
| 1957 | } |
| 1958 | |
| 1959 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1960 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1961 | { |
| 1962 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1963 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1964 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1965 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | p->kind = ExtSlice_kind; |
| 1967 | p->v.ExtSlice.dims = dims; |
| 1968 | return p; |
| 1969 | } |
| 1970 | |
| 1971 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1972 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1973 | { |
| 1974 | slice_ty p; |
| 1975 | if (!value) { |
| 1976 | PyErr_SetString(PyExc_ValueError, |
| 1977 | "field value is required for Index"); |
| 1978 | return NULL; |
| 1979 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1980 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1981 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1982 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1983 | p->kind = Index_kind; |
| 1984 | p->v.Index.value = value; |
| 1985 | return p; |
| 1986 | } |
| 1987 | |
| 1988 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1989 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1990 | { |
| 1991 | comprehension_ty p; |
| 1992 | if (!target) { |
| 1993 | PyErr_SetString(PyExc_ValueError, |
| 1994 | "field target is required for comprehension"); |
| 1995 | return NULL; |
| 1996 | } |
| 1997 | if (!iter) { |
| 1998 | PyErr_SetString(PyExc_ValueError, |
| 1999 | "field iter is required for comprehension"); |
| 2000 | return NULL; |
| 2001 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2002 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2003 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2004 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2005 | p->target = target; |
| 2006 | p->iter = iter; |
| 2007 | p->ifs = ifs; |
| 2008 | return p; |
| 2009 | } |
| 2010 | |
| 2011 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 2012 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2013 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | { |
| 2015 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2016 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2017 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2018 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 2019 | p->kind = ExceptHandler_kind; |
| 2020 | p->v.ExceptHandler.type = type; |
| 2021 | p->v.ExceptHandler.name = name; |
| 2022 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2023 | p->lineno = lineno; |
| 2024 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2025 | return p; |
| 2026 | } |
| 2027 | |
| 2028 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2029 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2030 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2031 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2032 | { |
| 2033 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2034 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2035 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2036 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2037 | p->args = args; |
| 2038 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2039 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2040 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2041 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2042 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2043 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2044 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | return p; |
| 2046 | } |
| 2047 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2048 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2049 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2050 | { |
| 2051 | arg_ty p; |
| 2052 | if (!arg) { |
| 2053 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2054 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2055 | return NULL; |
| 2056 | } |
| 2057 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2058 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2059 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2060 | p->arg = arg; |
| 2061 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2062 | return p; |
| 2063 | } |
| 2064 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2066 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2067 | { |
| 2068 | keyword_ty p; |
| 2069 | if (!arg) { |
| 2070 | PyErr_SetString(PyExc_ValueError, |
| 2071 | "field arg is required for keyword"); |
| 2072 | return NULL; |
| 2073 | } |
| 2074 | if (!value) { |
| 2075 | PyErr_SetString(PyExc_ValueError, |
| 2076 | "field value is required for keyword"); |
| 2077 | return NULL; |
| 2078 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2079 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2080 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2081 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2082 | p->arg = arg; |
| 2083 | p->value = value; |
| 2084 | return p; |
| 2085 | } |
| 2086 | |
| 2087 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2088 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2089 | { |
| 2090 | alias_ty p; |
| 2091 | if (!name) { |
| 2092 | PyErr_SetString(PyExc_ValueError, |
| 2093 | "field name is required for alias"); |
| 2094 | return NULL; |
| 2095 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2096 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2097 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2098 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2099 | p->name = name; |
| 2100 | p->asname = asname; |
| 2101 | return p; |
| 2102 | } |
| 2103 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2104 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2105 | PyObject* |
| 2106 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2107 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2108 | mod_ty o = (mod_ty)_o; |
| 2109 | PyObject *result = NULL, *value = NULL; |
| 2110 | if (!o) { |
| 2111 | Py_INCREF(Py_None); |
| 2112 | return Py_None; |
| 2113 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2114 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | switch (o->kind) { |
| 2116 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2117 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2118 | if (!result) goto failed; |
| 2119 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2120 | if (!value) goto failed; |
| 2121 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2122 | goto failed; |
| 2123 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2126 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2127 | if (!result) goto failed; |
| 2128 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2129 | if (!value) goto failed; |
| 2130 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2131 | goto failed; |
| 2132 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2135 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2136 | if (!result) goto failed; |
| 2137 | value = ast2obj_expr(o->v.Expression.body); |
| 2138 | if (!value) goto failed; |
| 2139 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2140 | goto failed; |
| 2141 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2144 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2145 | if (!result) goto failed; |
| 2146 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2147 | if (!value) goto failed; |
| 2148 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2149 | goto failed; |
| 2150 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2153 | return result; |
| 2154 | failed: |
| 2155 | Py_XDECREF(value); |
| 2156 | Py_XDECREF(result); |
| 2157 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2160 | PyObject* |
| 2161 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2163 | stmt_ty o = (stmt_ty)_o; |
| 2164 | PyObject *result = NULL, *value = NULL; |
| 2165 | if (!o) { |
| 2166 | Py_INCREF(Py_None); |
| 2167 | return Py_None; |
| 2168 | } |
| 2169 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2170 | switch (o->kind) { |
| 2171 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2172 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2173 | if (!result) goto failed; |
| 2174 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2175 | if (!value) goto failed; |
| 2176 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2177 | goto failed; |
| 2178 | Py_DECREF(value); |
| 2179 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2180 | if (!value) goto failed; |
| 2181 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2182 | goto failed; |
| 2183 | Py_DECREF(value); |
| 2184 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2185 | if (!value) goto failed; |
| 2186 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2187 | goto failed; |
| 2188 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2189 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2190 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2191 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2192 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2193 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2194 | goto failed; |
| 2195 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2196 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2197 | if (!value) goto failed; |
| 2198 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2199 | goto failed; |
| 2200 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2203 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2204 | if (!result) goto failed; |
| 2205 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2206 | if (!value) goto failed; |
| 2207 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2208 | goto failed; |
| 2209 | Py_DECREF(value); |
| 2210 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2211 | if (!value) goto failed; |
| 2212 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2213 | goto failed; |
| 2214 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2215 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2216 | if (!value) goto failed; |
| 2217 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2218 | goto failed; |
| 2219 | Py_DECREF(value); |
| 2220 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2221 | if (!value) goto failed; |
| 2222 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2223 | goto failed; |
| 2224 | Py_DECREF(value); |
| 2225 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2226 | if (!value) goto failed; |
| 2227 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2228 | goto failed; |
| 2229 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2230 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2231 | if (!value) goto failed; |
| 2232 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2233 | goto failed; |
| 2234 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2235 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2236 | ast2obj_expr); |
| 2237 | if (!value) goto failed; |
| 2238 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2239 | -1) |
| 2240 | goto failed; |
| 2241 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2244 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2245 | if (!result) goto failed; |
| 2246 | value = ast2obj_expr(o->v.Return.value); |
| 2247 | if (!value) goto failed; |
| 2248 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2249 | goto failed; |
| 2250 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2253 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2254 | if (!result) goto failed; |
| 2255 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2256 | if (!value) goto failed; |
| 2257 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2258 | goto failed; |
| 2259 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2260 | break; |
| 2261 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2262 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2263 | if (!result) goto failed; |
| 2264 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2265 | if (!value) goto failed; |
| 2266 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2267 | goto failed; |
| 2268 | Py_DECREF(value); |
| 2269 | value = ast2obj_expr(o->v.Assign.value); |
| 2270 | if (!value) goto failed; |
| 2271 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2272 | goto failed; |
| 2273 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2274 | break; |
| 2275 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2276 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2277 | if (!result) goto failed; |
| 2278 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2279 | if (!value) goto failed; |
| 2280 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2281 | goto failed; |
| 2282 | Py_DECREF(value); |
| 2283 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2284 | if (!value) goto failed; |
| 2285 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2286 | goto failed; |
| 2287 | Py_DECREF(value); |
| 2288 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2289 | if (!value) goto failed; |
| 2290 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2291 | goto failed; |
| 2292 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2293 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2294 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2295 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2296 | if (!result) goto failed; |
| 2297 | value = ast2obj_expr(o->v.For.target); |
| 2298 | if (!value) goto failed; |
| 2299 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2300 | goto failed; |
| 2301 | Py_DECREF(value); |
| 2302 | value = ast2obj_expr(o->v.For.iter); |
| 2303 | if (!value) goto failed; |
| 2304 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2305 | goto failed; |
| 2306 | Py_DECREF(value); |
| 2307 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2308 | if (!value) goto failed; |
| 2309 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2310 | goto failed; |
| 2311 | Py_DECREF(value); |
| 2312 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2313 | if (!value) goto failed; |
| 2314 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2315 | goto failed; |
| 2316 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2317 | break; |
| 2318 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2319 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2320 | if (!result) goto failed; |
| 2321 | value = ast2obj_expr(o->v.While.test); |
| 2322 | if (!value) goto failed; |
| 2323 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2324 | goto failed; |
| 2325 | Py_DECREF(value); |
| 2326 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2327 | if (!value) goto failed; |
| 2328 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2329 | goto failed; |
| 2330 | Py_DECREF(value); |
| 2331 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2332 | if (!value) goto failed; |
| 2333 | if (PyObject_SetAttrString(result, "orelse", 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 If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2338 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2339 | if (!result) goto failed; |
| 2340 | value = ast2obj_expr(o->v.If.test); |
| 2341 | if (!value) goto failed; |
| 2342 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2343 | goto failed; |
| 2344 | Py_DECREF(value); |
| 2345 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2346 | if (!value) goto failed; |
| 2347 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2348 | goto failed; |
| 2349 | Py_DECREF(value); |
| 2350 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2351 | if (!value) goto failed; |
| 2352 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2353 | goto failed; |
| 2354 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2355 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2356 | case With_kind: |
| 2357 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2358 | if (!result) goto failed; |
| 2359 | value = ast2obj_expr(o->v.With.context_expr); |
| 2360 | if (!value) goto failed; |
| 2361 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 2362 | goto failed; |
| 2363 | Py_DECREF(value); |
| 2364 | value = ast2obj_expr(o->v.With.optional_vars); |
| 2365 | if (!value) goto failed; |
| 2366 | if (PyObject_SetAttrString(result, "optional_vars", value) == |
| 2367 | -1) |
| 2368 | goto failed; |
| 2369 | Py_DECREF(value); |
| 2370 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2371 | if (!value) goto failed; |
| 2372 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2373 | goto failed; |
| 2374 | Py_DECREF(value); |
| 2375 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2376 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2377 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2378 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2379 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2380 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2381 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2382 | goto failed; |
| 2383 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2384 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2385 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2386 | if (PyObject_SetAttrString(result, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2387 | goto failed; |
| 2388 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | case TryExcept_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2391 | result = PyType_GenericNew(TryExcept_type, NULL, NULL); |
| 2392 | if (!result) goto failed; |
| 2393 | value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); |
| 2394 | if (!value) goto failed; |
| 2395 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2396 | goto failed; |
| 2397 | Py_DECREF(value); |
| 2398 | value = ast2obj_list(o->v.TryExcept.handlers, |
| 2399 | ast2obj_excepthandler); |
| 2400 | if (!value) goto failed; |
| 2401 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2402 | goto failed; |
| 2403 | Py_DECREF(value); |
| 2404 | value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); |
| 2405 | if (!value) goto failed; |
| 2406 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2407 | goto failed; |
| 2408 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2409 | break; |
| 2410 | case TryFinally_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2411 | result = PyType_GenericNew(TryFinally_type, NULL, NULL); |
| 2412 | if (!result) goto failed; |
| 2413 | value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); |
| 2414 | if (!value) goto failed; |
| 2415 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2416 | goto failed; |
| 2417 | Py_DECREF(value); |
| 2418 | value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); |
| 2419 | if (!value) goto failed; |
| 2420 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2421 | goto failed; |
| 2422 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2425 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2426 | if (!result) goto failed; |
| 2427 | value = ast2obj_expr(o->v.Assert.test); |
| 2428 | if (!value) goto failed; |
| 2429 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2430 | goto failed; |
| 2431 | Py_DECREF(value); |
| 2432 | value = ast2obj_expr(o->v.Assert.msg); |
| 2433 | if (!value) goto failed; |
| 2434 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2435 | goto failed; |
| 2436 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2439 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2440 | if (!result) goto failed; |
| 2441 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2442 | if (!value) goto failed; |
| 2443 | if (PyObject_SetAttrString(result, "names", 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 ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2448 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2449 | if (!result) goto failed; |
| 2450 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2451 | if (!value) goto failed; |
| 2452 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2453 | goto failed; |
| 2454 | Py_DECREF(value); |
| 2455 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2456 | if (!value) goto failed; |
| 2457 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2458 | goto failed; |
| 2459 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2460 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2461 | if (!value) goto failed; |
| 2462 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2463 | goto failed; |
| 2464 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2466 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2467 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2468 | if (!result) goto failed; |
| 2469 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2470 | if (!value) goto failed; |
| 2471 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2472 | goto failed; |
| 2473 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2474 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2475 | case Nonlocal_kind: |
| 2476 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2477 | if (!result) goto failed; |
| 2478 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2479 | if (!value) goto failed; |
| 2480 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2481 | goto failed; |
| 2482 | Py_DECREF(value); |
| 2483 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2484 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2485 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2486 | if (!result) goto failed; |
| 2487 | value = ast2obj_expr(o->v.Expr.value); |
| 2488 | if (!value) goto failed; |
| 2489 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2490 | goto failed; |
| 2491 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2492 | break; |
| 2493 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2494 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2495 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2496 | break; |
| 2497 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2498 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2499 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2500 | break; |
| 2501 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2502 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2503 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2504 | break; |
| 2505 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2506 | value = ast2obj_int(o->lineno); |
| 2507 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2508 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2509 | goto failed; |
| 2510 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2511 | value = ast2obj_int(o->col_offset); |
| 2512 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2513 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2514 | goto failed; |
| 2515 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2516 | return result; |
| 2517 | failed: |
| 2518 | Py_XDECREF(value); |
| 2519 | Py_XDECREF(result); |
| 2520 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2523 | PyObject* |
| 2524 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2525 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2526 | expr_ty o = (expr_ty)_o; |
| 2527 | PyObject *result = NULL, *value = NULL; |
| 2528 | if (!o) { |
| 2529 | Py_INCREF(Py_None); |
| 2530 | return Py_None; |
| 2531 | } |
| 2532 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | switch (o->kind) { |
| 2534 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2535 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2536 | if (!result) goto failed; |
| 2537 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2538 | if (!value) goto failed; |
| 2539 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2540 | goto failed; |
| 2541 | Py_DECREF(value); |
| 2542 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2543 | if (!value) goto failed; |
| 2544 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2545 | goto failed; |
| 2546 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2547 | break; |
| 2548 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2549 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2550 | if (!result) goto failed; |
| 2551 | value = ast2obj_expr(o->v.BinOp.left); |
| 2552 | if (!value) goto failed; |
| 2553 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2554 | goto failed; |
| 2555 | Py_DECREF(value); |
| 2556 | value = ast2obj_operator(o->v.BinOp.op); |
| 2557 | if (!value) goto failed; |
| 2558 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2559 | goto failed; |
| 2560 | Py_DECREF(value); |
| 2561 | value = ast2obj_expr(o->v.BinOp.right); |
| 2562 | if (!value) goto failed; |
| 2563 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2564 | goto failed; |
| 2565 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2568 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2569 | if (!result) goto failed; |
| 2570 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2571 | if (!value) goto failed; |
| 2572 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2573 | goto failed; |
| 2574 | Py_DECREF(value); |
| 2575 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2576 | if (!value) goto failed; |
| 2577 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2580 | break; |
| 2581 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2582 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2583 | if (!result) goto failed; |
| 2584 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2585 | if (!value) goto failed; |
| 2586 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2587 | goto failed; |
| 2588 | Py_DECREF(value); |
| 2589 | value = ast2obj_expr(o->v.Lambda.body); |
| 2590 | if (!value) goto failed; |
| 2591 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2592 | goto failed; |
| 2593 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2594 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2595 | case IfExp_kind: |
| 2596 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2597 | if (!result) goto failed; |
| 2598 | value = ast2obj_expr(o->v.IfExp.test); |
| 2599 | if (!value) goto failed; |
| 2600 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2601 | goto failed; |
| 2602 | Py_DECREF(value); |
| 2603 | value = ast2obj_expr(o->v.IfExp.body); |
| 2604 | if (!value) goto failed; |
| 2605 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2606 | goto failed; |
| 2607 | Py_DECREF(value); |
| 2608 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2609 | if (!value) goto failed; |
| 2610 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2611 | goto failed; |
| 2612 | Py_DECREF(value); |
| 2613 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2614 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2615 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2616 | if (!result) goto failed; |
| 2617 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2618 | if (!value) goto failed; |
| 2619 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2620 | goto failed; |
| 2621 | Py_DECREF(value); |
| 2622 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2623 | if (!value) goto failed; |
| 2624 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2625 | goto failed; |
| 2626 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2627 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2628 | case Set_kind: |
| 2629 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2630 | if (!result) goto failed; |
| 2631 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2632 | if (!value) goto failed; |
| 2633 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2634 | goto failed; |
| 2635 | Py_DECREF(value); |
| 2636 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2637 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2638 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2639 | if (!result) goto failed; |
| 2640 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2641 | if (!value) goto failed; |
| 2642 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2643 | goto failed; |
| 2644 | Py_DECREF(value); |
| 2645 | value = ast2obj_list(o->v.ListComp.generators, |
| 2646 | ast2obj_comprehension); |
| 2647 | if (!value) goto failed; |
| 2648 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2649 | goto failed; |
| 2650 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2651 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2652 | case SetComp_kind: |
| 2653 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2654 | if (!result) goto failed; |
| 2655 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2656 | if (!value) goto failed; |
| 2657 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2658 | goto failed; |
| 2659 | Py_DECREF(value); |
| 2660 | value = ast2obj_list(o->v.SetComp.generators, |
| 2661 | ast2obj_comprehension); |
| 2662 | if (!value) goto failed; |
| 2663 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2664 | goto failed; |
| 2665 | Py_DECREF(value); |
| 2666 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2667 | case DictComp_kind: |
| 2668 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2669 | if (!result) goto failed; |
| 2670 | value = ast2obj_expr(o->v.DictComp.key); |
| 2671 | if (!value) goto failed; |
| 2672 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2673 | goto failed; |
| 2674 | Py_DECREF(value); |
| 2675 | value = ast2obj_expr(o->v.DictComp.value); |
| 2676 | if (!value) goto failed; |
| 2677 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2678 | goto failed; |
| 2679 | Py_DECREF(value); |
| 2680 | value = ast2obj_list(o->v.DictComp.generators, |
| 2681 | ast2obj_comprehension); |
| 2682 | if (!value) goto failed; |
| 2683 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2684 | goto failed; |
| 2685 | Py_DECREF(value); |
| 2686 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2687 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2688 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2689 | if (!result) goto failed; |
| 2690 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2691 | if (!value) goto failed; |
| 2692 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2693 | goto failed; |
| 2694 | Py_DECREF(value); |
| 2695 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2696 | ast2obj_comprehension); |
| 2697 | if (!value) goto failed; |
| 2698 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2699 | goto failed; |
| 2700 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2701 | break; |
| 2702 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2703 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2704 | if (!result) goto failed; |
| 2705 | value = ast2obj_expr(o->v.Yield.value); |
| 2706 | if (!value) goto failed; |
| 2707 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2708 | goto failed; |
| 2709 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2710 | break; |
| 2711 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2712 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2713 | if (!result) goto failed; |
| 2714 | value = ast2obj_expr(o->v.Compare.left); |
| 2715 | if (!value) goto failed; |
| 2716 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2717 | goto failed; |
| 2718 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2719 | { |
| 2720 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2721 | value = PyList_New(n); |
| 2722 | if (!value) goto failed; |
| 2723 | for(i = 0; i < n; i++) |
| 2724 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2725 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2726 | if (!value) goto failed; |
| 2727 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2728 | goto failed; |
| 2729 | Py_DECREF(value); |
| 2730 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2731 | if (!value) goto failed; |
| 2732 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2733 | goto failed; |
| 2734 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2735 | break; |
| 2736 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2737 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2738 | if (!result) goto failed; |
| 2739 | value = ast2obj_expr(o->v.Call.func); |
| 2740 | if (!value) goto failed; |
| 2741 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2742 | goto failed; |
| 2743 | Py_DECREF(value); |
| 2744 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2745 | if (!value) goto failed; |
| 2746 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2747 | goto failed; |
| 2748 | Py_DECREF(value); |
| 2749 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2750 | if (!value) goto failed; |
| 2751 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2752 | goto failed; |
| 2753 | Py_DECREF(value); |
| 2754 | value = ast2obj_expr(o->v.Call.starargs); |
| 2755 | if (!value) goto failed; |
| 2756 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2757 | goto failed; |
| 2758 | Py_DECREF(value); |
| 2759 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2760 | if (!value) goto failed; |
| 2761 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2762 | goto failed; |
| 2763 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2764 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2765 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2766 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2767 | if (!result) goto failed; |
| 2768 | value = ast2obj_object(o->v.Num.n); |
| 2769 | if (!value) goto failed; |
| 2770 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2773 | break; |
| 2774 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2775 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2776 | if (!result) goto failed; |
| 2777 | value = ast2obj_string(o->v.Str.s); |
| 2778 | if (!value) goto failed; |
| 2779 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2782 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2783 | case Bytes_kind: |
| 2784 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2785 | if (!result) goto failed; |
| 2786 | value = ast2obj_string(o->v.Bytes.s); |
| 2787 | if (!value) goto failed; |
| 2788 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2792 | case Ellipsis_kind: |
| 2793 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2794 | if (!result) goto failed; |
| 2795 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2796 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2797 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2798 | if (!result) goto failed; |
| 2799 | value = ast2obj_expr(o->v.Attribute.value); |
| 2800 | if (!value) goto failed; |
| 2801 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2802 | goto failed; |
| 2803 | Py_DECREF(value); |
| 2804 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2805 | if (!value) goto failed; |
| 2806 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2807 | goto failed; |
| 2808 | Py_DECREF(value); |
| 2809 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2810 | if (!value) goto failed; |
| 2811 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2812 | goto failed; |
| 2813 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2816 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2817 | if (!result) goto failed; |
| 2818 | value = ast2obj_expr(o->v.Subscript.value); |
| 2819 | if (!value) goto failed; |
| 2820 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2821 | goto failed; |
| 2822 | Py_DECREF(value); |
| 2823 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2824 | if (!value) goto failed; |
| 2825 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2826 | goto failed; |
| 2827 | Py_DECREF(value); |
| 2828 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2829 | if (!value) goto failed; |
| 2830 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2831 | goto failed; |
| 2832 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2833 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2834 | case Starred_kind: |
| 2835 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2836 | if (!result) goto failed; |
| 2837 | value = ast2obj_expr(o->v.Starred.value); |
| 2838 | if (!value) goto failed; |
| 2839 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2843 | if (!value) goto failed; |
| 2844 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2848 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2849 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2850 | if (!result) goto failed; |
| 2851 | value = ast2obj_identifier(o->v.Name.id); |
| 2852 | if (!value) goto failed; |
| 2853 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2854 | goto failed; |
| 2855 | Py_DECREF(value); |
| 2856 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2857 | if (!value) goto failed; |
| 2858 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2863 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2864 | if (!result) goto failed; |
| 2865 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2866 | if (!value) goto failed; |
| 2867 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
| 2870 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2871 | if (!value) goto failed; |
| 2872 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2873 | goto failed; |
| 2874 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2877 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2878 | if (!result) goto failed; |
| 2879 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2880 | if (!value) goto failed; |
| 2881 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2885 | if (!value) goto failed; |
| 2886 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2887 | goto failed; |
| 2888 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2891 | value = ast2obj_int(o->lineno); |
| 2892 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2893 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2894 | goto failed; |
| 2895 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2896 | value = ast2obj_int(o->col_offset); |
| 2897 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2898 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2899 | goto failed; |
| 2900 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2901 | return result; |
| 2902 | failed: |
| 2903 | Py_XDECREF(value); |
| 2904 | Py_XDECREF(result); |
| 2905 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2908 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2909 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2910 | switch(o) { |
| 2911 | case Load: |
| 2912 | Py_INCREF(Load_singleton); |
| 2913 | return Load_singleton; |
| 2914 | case Store: |
| 2915 | Py_INCREF(Store_singleton); |
| 2916 | return Store_singleton; |
| 2917 | case Del: |
| 2918 | Py_INCREF(Del_singleton); |
| 2919 | return Del_singleton; |
| 2920 | case AugLoad: |
| 2921 | Py_INCREF(AugLoad_singleton); |
| 2922 | return AugLoad_singleton; |
| 2923 | case AugStore: |
| 2924 | Py_INCREF(AugStore_singleton); |
| 2925 | return AugStore_singleton; |
| 2926 | case Param: |
| 2927 | Py_INCREF(Param_singleton); |
| 2928 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2929 | default: |
| 2930 | /* should never happen, but just in case ... */ |
| 2931 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2932 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2933 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2934 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2935 | PyObject* |
| 2936 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2937 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2938 | slice_ty o = (slice_ty)_o; |
| 2939 | PyObject *result = NULL, *value = NULL; |
| 2940 | if (!o) { |
| 2941 | Py_INCREF(Py_None); |
| 2942 | return Py_None; |
| 2943 | } |
| 2944 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2945 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2946 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2947 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2948 | if (!result) goto failed; |
| 2949 | value = ast2obj_expr(o->v.Slice.lower); |
| 2950 | if (!value) goto failed; |
| 2951 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2952 | goto failed; |
| 2953 | Py_DECREF(value); |
| 2954 | value = ast2obj_expr(o->v.Slice.upper); |
| 2955 | if (!value) goto failed; |
| 2956 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2957 | goto failed; |
| 2958 | Py_DECREF(value); |
| 2959 | value = ast2obj_expr(o->v.Slice.step); |
| 2960 | if (!value) goto failed; |
| 2961 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2962 | goto failed; |
| 2963 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2966 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2967 | if (!result) goto failed; |
| 2968 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2969 | if (!value) goto failed; |
| 2970 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2971 | goto failed; |
| 2972 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2973 | break; |
| 2974 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2975 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2976 | if (!result) goto failed; |
| 2977 | value = ast2obj_expr(o->v.Index.value); |
| 2978 | if (!value) goto failed; |
| 2979 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2980 | goto failed; |
| 2981 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2984 | return result; |
| 2985 | failed: |
| 2986 | Py_XDECREF(value); |
| 2987 | Py_XDECREF(result); |
| 2988 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2991 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2992 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2993 | switch(o) { |
| 2994 | case And: |
| 2995 | Py_INCREF(And_singleton); |
| 2996 | return And_singleton; |
| 2997 | case Or: |
| 2998 | Py_INCREF(Or_singleton); |
| 2999 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3000 | default: |
| 3001 | /* should never happen, but just in case ... */ |
| 3002 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3003 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3004 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3005 | } |
| 3006 | PyObject* ast2obj_operator(operator_ty o) |
| 3007 | { |
| 3008 | switch(o) { |
| 3009 | case Add: |
| 3010 | Py_INCREF(Add_singleton); |
| 3011 | return Add_singleton; |
| 3012 | case Sub: |
| 3013 | Py_INCREF(Sub_singleton); |
| 3014 | return Sub_singleton; |
| 3015 | case Mult: |
| 3016 | Py_INCREF(Mult_singleton); |
| 3017 | return Mult_singleton; |
| 3018 | case Div: |
| 3019 | Py_INCREF(Div_singleton); |
| 3020 | return Div_singleton; |
| 3021 | case Mod: |
| 3022 | Py_INCREF(Mod_singleton); |
| 3023 | return Mod_singleton; |
| 3024 | case Pow: |
| 3025 | Py_INCREF(Pow_singleton); |
| 3026 | return Pow_singleton; |
| 3027 | case LShift: |
| 3028 | Py_INCREF(LShift_singleton); |
| 3029 | return LShift_singleton; |
| 3030 | case RShift: |
| 3031 | Py_INCREF(RShift_singleton); |
| 3032 | return RShift_singleton; |
| 3033 | case BitOr: |
| 3034 | Py_INCREF(BitOr_singleton); |
| 3035 | return BitOr_singleton; |
| 3036 | case BitXor: |
| 3037 | Py_INCREF(BitXor_singleton); |
| 3038 | return BitXor_singleton; |
| 3039 | case BitAnd: |
| 3040 | Py_INCREF(BitAnd_singleton); |
| 3041 | return BitAnd_singleton; |
| 3042 | case FloorDiv: |
| 3043 | Py_INCREF(FloorDiv_singleton); |
| 3044 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3045 | default: |
| 3046 | /* should never happen, but just in case ... */ |
| 3047 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3048 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3049 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3050 | } |
| 3051 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3052 | { |
| 3053 | switch(o) { |
| 3054 | case Invert: |
| 3055 | Py_INCREF(Invert_singleton); |
| 3056 | return Invert_singleton; |
| 3057 | case Not: |
| 3058 | Py_INCREF(Not_singleton); |
| 3059 | return Not_singleton; |
| 3060 | case UAdd: |
| 3061 | Py_INCREF(UAdd_singleton); |
| 3062 | return UAdd_singleton; |
| 3063 | case USub: |
| 3064 | Py_INCREF(USub_singleton); |
| 3065 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3066 | default: |
| 3067 | /* should never happen, but just in case ... */ |
| 3068 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3069 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3070 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3071 | } |
| 3072 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3073 | { |
| 3074 | switch(o) { |
| 3075 | case Eq: |
| 3076 | Py_INCREF(Eq_singleton); |
| 3077 | return Eq_singleton; |
| 3078 | case NotEq: |
| 3079 | Py_INCREF(NotEq_singleton); |
| 3080 | return NotEq_singleton; |
| 3081 | case Lt: |
| 3082 | Py_INCREF(Lt_singleton); |
| 3083 | return Lt_singleton; |
| 3084 | case LtE: |
| 3085 | Py_INCREF(LtE_singleton); |
| 3086 | return LtE_singleton; |
| 3087 | case Gt: |
| 3088 | Py_INCREF(Gt_singleton); |
| 3089 | return Gt_singleton; |
| 3090 | case GtE: |
| 3091 | Py_INCREF(GtE_singleton); |
| 3092 | return GtE_singleton; |
| 3093 | case Is: |
| 3094 | Py_INCREF(Is_singleton); |
| 3095 | return Is_singleton; |
| 3096 | case IsNot: |
| 3097 | Py_INCREF(IsNot_singleton); |
| 3098 | return IsNot_singleton; |
| 3099 | case In: |
| 3100 | Py_INCREF(In_singleton); |
| 3101 | return In_singleton; |
| 3102 | case NotIn: |
| 3103 | Py_INCREF(NotIn_singleton); |
| 3104 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3105 | default: |
| 3106 | /* should never happen, but just in case ... */ |
| 3107 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3108 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3109 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3110 | } |
| 3111 | PyObject* |
| 3112 | ast2obj_comprehension(void* _o) |
| 3113 | { |
| 3114 | comprehension_ty o = (comprehension_ty)_o; |
| 3115 | PyObject *result = NULL, *value = NULL; |
| 3116 | if (!o) { |
| 3117 | Py_INCREF(Py_None); |
| 3118 | return Py_None; |
| 3119 | } |
| 3120 | |
| 3121 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3122 | if (!result) return NULL; |
| 3123 | value = ast2obj_expr(o->target); |
| 3124 | if (!value) goto failed; |
| 3125 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3126 | goto failed; |
| 3127 | Py_DECREF(value); |
| 3128 | value = ast2obj_expr(o->iter); |
| 3129 | if (!value) goto failed; |
| 3130 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3131 | goto failed; |
| 3132 | Py_DECREF(value); |
| 3133 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3134 | if (!value) goto failed; |
| 3135 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3136 | goto failed; |
| 3137 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3138 | return result; |
| 3139 | failed: |
| 3140 | Py_XDECREF(value); |
| 3141 | Py_XDECREF(result); |
| 3142 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3145 | PyObject* |
| 3146 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3147 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3148 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3149 | PyObject *result = NULL, *value = NULL; |
| 3150 | if (!o) { |
| 3151 | Py_INCREF(Py_None); |
| 3152 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3153 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3154 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 3155 | switch (o->kind) { |
| 3156 | case ExceptHandler_kind: |
| 3157 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3158 | if (!result) goto failed; |
| 3159 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3160 | if (!value) goto failed; |
| 3161 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3162 | goto failed; |
| 3163 | Py_DECREF(value); |
| 3164 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3165 | if (!value) goto failed; |
| 3166 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3167 | goto failed; |
| 3168 | Py_DECREF(value); |
| 3169 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3170 | if (!value) goto failed; |
| 3171 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3172 | goto failed; |
| 3173 | Py_DECREF(value); |
| 3174 | break; |
| 3175 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3176 | value = ast2obj_int(o->lineno); |
| 3177 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 3178 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3179 | goto failed; |
| 3180 | Py_DECREF(value); |
| 3181 | value = ast2obj_int(o->col_offset); |
| 3182 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 3183 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3184 | goto failed; |
| 3185 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3186 | return result; |
| 3187 | failed: |
| 3188 | Py_XDECREF(value); |
| 3189 | Py_XDECREF(result); |
| 3190 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3193 | PyObject* |
| 3194 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3195 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3196 | arguments_ty o = (arguments_ty)_o; |
| 3197 | PyObject *result = NULL, *value = NULL; |
| 3198 | if (!o) { |
| 3199 | Py_INCREF(Py_None); |
| 3200 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3201 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3202 | |
| 3203 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3204 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3205 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3206 | if (!value) goto failed; |
| 3207 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3208 | goto failed; |
| 3209 | Py_DECREF(value); |
| 3210 | value = ast2obj_identifier(o->vararg); |
| 3211 | if (!value) goto failed; |
| 3212 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3213 | goto failed; |
| 3214 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3215 | value = ast2obj_expr(o->varargannotation); |
| 3216 | if (!value) goto failed; |
| 3217 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3218 | goto failed; |
| 3219 | Py_DECREF(value); |
| 3220 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3221 | if (!value) goto failed; |
| 3222 | if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) |
| 3223 | goto failed; |
| 3224 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3225 | value = ast2obj_identifier(o->kwarg); |
| 3226 | if (!value) goto failed; |
| 3227 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3228 | goto failed; |
| 3229 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3230 | value = ast2obj_expr(o->kwargannotation); |
| 3231 | if (!value) goto failed; |
| 3232 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3233 | goto failed; |
| 3234 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3235 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3236 | if (!value) goto failed; |
| 3237 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3238 | goto failed; |
| 3239 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3240 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3241 | if (!value) goto failed; |
| 3242 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3243 | goto failed; |
| 3244 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3245 | return result; |
| 3246 | failed: |
| 3247 | Py_XDECREF(value); |
| 3248 | Py_XDECREF(result); |
| 3249 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3252 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3253 | ast2obj_arg(void* _o) |
| 3254 | { |
| 3255 | arg_ty o = (arg_ty)_o; |
| 3256 | PyObject *result = NULL, *value = NULL; |
| 3257 | if (!o) { |
| 3258 | Py_INCREF(Py_None); |
| 3259 | return Py_None; |
| 3260 | } |
| 3261 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3262 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3263 | if (!result) return NULL; |
| 3264 | value = ast2obj_identifier(o->arg); |
| 3265 | if (!value) goto failed; |
| 3266 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3267 | goto failed; |
| 3268 | Py_DECREF(value); |
| 3269 | value = ast2obj_expr(o->annotation); |
| 3270 | if (!value) goto failed; |
| 3271 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3272 | goto failed; |
| 3273 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3274 | return result; |
| 3275 | failed: |
| 3276 | Py_XDECREF(value); |
| 3277 | Py_XDECREF(result); |
| 3278 | return NULL; |
| 3279 | } |
| 3280 | |
| 3281 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3282 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3283 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3284 | keyword_ty o = (keyword_ty)_o; |
| 3285 | PyObject *result = NULL, *value = NULL; |
| 3286 | if (!o) { |
| 3287 | Py_INCREF(Py_None); |
| 3288 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3289 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3290 | |
| 3291 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3292 | if (!result) return NULL; |
| 3293 | value = ast2obj_identifier(o->arg); |
| 3294 | if (!value) goto failed; |
| 3295 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3296 | goto failed; |
| 3297 | Py_DECREF(value); |
| 3298 | value = ast2obj_expr(o->value); |
| 3299 | if (!value) goto failed; |
| 3300 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3301 | goto failed; |
| 3302 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3303 | return result; |
| 3304 | failed: |
| 3305 | Py_XDECREF(value); |
| 3306 | Py_XDECREF(result); |
| 3307 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3308 | } |
| 3309 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3310 | PyObject* |
| 3311 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3312 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3313 | alias_ty o = (alias_ty)_o; |
| 3314 | PyObject *result = NULL, *value = NULL; |
| 3315 | if (!o) { |
| 3316 | Py_INCREF(Py_None); |
| 3317 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3318 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3319 | |
| 3320 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3321 | if (!result) return NULL; |
| 3322 | value = ast2obj_identifier(o->name); |
| 3323 | if (!value) goto failed; |
| 3324 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3325 | goto failed; |
| 3326 | Py_DECREF(value); |
| 3327 | value = ast2obj_identifier(o->asname); |
| 3328 | if (!value) goto failed; |
| 3329 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3330 | goto failed; |
| 3331 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3332 | return result; |
| 3333 | failed: |
| 3334 | Py_XDECREF(value); |
| 3335 | Py_XDECREF(result); |
| 3336 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3337 | } |
| 3338 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3339 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3340 | int |
| 3341 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3342 | { |
| 3343 | PyObject* tmp = NULL; |
| 3344 | |
| 3345 | |
| 3346 | if (obj == Py_None) { |
| 3347 | *out = NULL; |
| 3348 | return 0; |
| 3349 | } |
| 3350 | if (PyObject_IsInstance(obj, (PyObject*)Module_type)) { |
| 3351 | asdl_seq* body; |
| 3352 | |
| 3353 | if (PyObject_HasAttrString(obj, "body")) { |
| 3354 | int res; |
| 3355 | Py_ssize_t len; |
| 3356 | Py_ssize_t i; |
| 3357 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3358 | if (tmp == NULL) goto failed; |
| 3359 | if (!PyList_Check(tmp)) { |
| 3360 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3361 | goto failed; |
| 3362 | } |
| 3363 | len = PyList_GET_SIZE(tmp); |
| 3364 | body = asdl_seq_new(len, arena); |
| 3365 | if (body == NULL) goto failed; |
| 3366 | for (i = 0; i < len; i++) { |
| 3367 | stmt_ty value; |
| 3368 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3369 | if (res != 0) goto failed; |
| 3370 | asdl_seq_SET(body, i, value); |
| 3371 | } |
| 3372 | Py_XDECREF(tmp); |
| 3373 | tmp = NULL; |
| 3374 | } else { |
| 3375 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3376 | return 1; |
| 3377 | } |
| 3378 | *out = Module(body, arena); |
| 3379 | if (*out == NULL) goto failed; |
| 3380 | return 0; |
| 3381 | } |
| 3382 | if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) { |
| 3383 | asdl_seq* body; |
| 3384 | |
| 3385 | if (PyObject_HasAttrString(obj, "body")) { |
| 3386 | int res; |
| 3387 | Py_ssize_t len; |
| 3388 | Py_ssize_t i; |
| 3389 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3390 | if (tmp == NULL) goto failed; |
| 3391 | if (!PyList_Check(tmp)) { |
| 3392 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3393 | goto failed; |
| 3394 | } |
| 3395 | len = PyList_GET_SIZE(tmp); |
| 3396 | body = asdl_seq_new(len, arena); |
| 3397 | if (body == NULL) goto failed; |
| 3398 | for (i = 0; i < len; i++) { |
| 3399 | stmt_ty value; |
| 3400 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3401 | if (res != 0) goto failed; |
| 3402 | asdl_seq_SET(body, i, value); |
| 3403 | } |
| 3404 | Py_XDECREF(tmp); |
| 3405 | tmp = NULL; |
| 3406 | } else { |
| 3407 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3408 | return 1; |
| 3409 | } |
| 3410 | *out = Interactive(body, arena); |
| 3411 | if (*out == NULL) goto failed; |
| 3412 | return 0; |
| 3413 | } |
| 3414 | if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) { |
| 3415 | expr_ty body; |
| 3416 | |
| 3417 | if (PyObject_HasAttrString(obj, "body")) { |
| 3418 | int res; |
| 3419 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3420 | if (tmp == NULL) goto failed; |
| 3421 | res = obj2ast_expr(tmp, &body, arena); |
| 3422 | if (res != 0) goto failed; |
| 3423 | Py_XDECREF(tmp); |
| 3424 | tmp = NULL; |
| 3425 | } else { |
| 3426 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3427 | return 1; |
| 3428 | } |
| 3429 | *out = Expression(body, arena); |
| 3430 | if (*out == NULL) goto failed; |
| 3431 | return 0; |
| 3432 | } |
| 3433 | if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) { |
| 3434 | asdl_seq* body; |
| 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, "Suite 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 Suite"); |
| 3459 | return 1; |
| 3460 | } |
| 3461 | *out = Suite(body, arena); |
| 3462 | if (*out == NULL) goto failed; |
| 3463 | return 0; |
| 3464 | } |
| 3465 | |
| 3466 | tmp = PyObject_Repr(obj); |
| 3467 | if (tmp == NULL) goto failed; |
| 3468 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp)); |
| 3469 | failed: |
| 3470 | Py_XDECREF(tmp); |
| 3471 | return 1; |
| 3472 | } |
| 3473 | |
| 3474 | int |
| 3475 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3476 | { |
| 3477 | PyObject* tmp = NULL; |
| 3478 | |
| 3479 | int lineno; |
| 3480 | int col_offset; |
| 3481 | |
| 3482 | if (obj == Py_None) { |
| 3483 | *out = NULL; |
| 3484 | return 0; |
| 3485 | } |
| 3486 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3487 | int res; |
| 3488 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3489 | if (tmp == NULL) goto failed; |
| 3490 | res = obj2ast_int(tmp, &lineno, arena); |
| 3491 | if (res != 0) goto failed; |
| 3492 | Py_XDECREF(tmp); |
| 3493 | tmp = NULL; |
| 3494 | } else { |
| 3495 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3496 | return 1; |
| 3497 | } |
| 3498 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3499 | int res; |
| 3500 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3501 | if (tmp == NULL) goto failed; |
| 3502 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3503 | if (res != 0) goto failed; |
| 3504 | Py_XDECREF(tmp); |
| 3505 | tmp = NULL; |
| 3506 | } else { |
| 3507 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3508 | return 1; |
| 3509 | } |
| 3510 | if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) { |
| 3511 | identifier name; |
| 3512 | arguments_ty args; |
| 3513 | asdl_seq* body; |
| 3514 | asdl_seq* decorator_list; |
| 3515 | expr_ty returns; |
| 3516 | |
| 3517 | if (PyObject_HasAttrString(obj, "name")) { |
| 3518 | int res; |
| 3519 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3520 | if (tmp == NULL) goto failed; |
| 3521 | res = obj2ast_identifier(tmp, &name, arena); |
| 3522 | if (res != 0) goto failed; |
| 3523 | Py_XDECREF(tmp); |
| 3524 | tmp = NULL; |
| 3525 | } else { |
| 3526 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3527 | return 1; |
| 3528 | } |
| 3529 | if (PyObject_HasAttrString(obj, "args")) { |
| 3530 | int res; |
| 3531 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3532 | if (tmp == NULL) goto failed; |
| 3533 | res = obj2ast_arguments(tmp, &args, arena); |
| 3534 | if (res != 0) goto failed; |
| 3535 | Py_XDECREF(tmp); |
| 3536 | tmp = NULL; |
| 3537 | } else { |
| 3538 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3539 | return 1; |
| 3540 | } |
| 3541 | if (PyObject_HasAttrString(obj, "body")) { |
| 3542 | int res; |
| 3543 | Py_ssize_t len; |
| 3544 | Py_ssize_t i; |
| 3545 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3546 | if (tmp == NULL) goto failed; |
| 3547 | if (!PyList_Check(tmp)) { |
| 3548 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3549 | goto failed; |
| 3550 | } |
| 3551 | len = PyList_GET_SIZE(tmp); |
| 3552 | body = asdl_seq_new(len, arena); |
| 3553 | if (body == NULL) goto failed; |
| 3554 | for (i = 0; i < len; i++) { |
| 3555 | stmt_ty value; |
| 3556 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3557 | if (res != 0) goto failed; |
| 3558 | asdl_seq_SET(body, i, value); |
| 3559 | } |
| 3560 | Py_XDECREF(tmp); |
| 3561 | tmp = NULL; |
| 3562 | } else { |
| 3563 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3564 | return 1; |
| 3565 | } |
| 3566 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3567 | int res; |
| 3568 | Py_ssize_t len; |
| 3569 | Py_ssize_t i; |
| 3570 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3571 | if (tmp == NULL) goto failed; |
| 3572 | if (!PyList_Check(tmp)) { |
| 3573 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3574 | goto failed; |
| 3575 | } |
| 3576 | len = PyList_GET_SIZE(tmp); |
| 3577 | decorator_list = asdl_seq_new(len, arena); |
| 3578 | if (decorator_list == NULL) goto failed; |
| 3579 | for (i = 0; i < len; i++) { |
| 3580 | expr_ty value; |
| 3581 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3582 | if (res != 0) goto failed; |
| 3583 | asdl_seq_SET(decorator_list, i, value); |
| 3584 | } |
| 3585 | Py_XDECREF(tmp); |
| 3586 | tmp = NULL; |
| 3587 | } else { |
| 3588 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3589 | return 1; |
| 3590 | } |
| 3591 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3592 | int res; |
| 3593 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3594 | if (tmp == NULL) goto failed; |
| 3595 | res = obj2ast_expr(tmp, &returns, arena); |
| 3596 | if (res != 0) goto failed; |
| 3597 | Py_XDECREF(tmp); |
| 3598 | tmp = NULL; |
| 3599 | } else { |
| 3600 | returns = NULL; |
| 3601 | } |
| 3602 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3603 | lineno, col_offset, arena); |
| 3604 | if (*out == NULL) goto failed; |
| 3605 | return 0; |
| 3606 | } |
| 3607 | if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) { |
| 3608 | identifier name; |
| 3609 | asdl_seq* bases; |
| 3610 | asdl_seq* keywords; |
| 3611 | expr_ty starargs; |
| 3612 | expr_ty kwargs; |
| 3613 | asdl_seq* body; |
| 3614 | asdl_seq* decorator_list; |
| 3615 | |
| 3616 | if (PyObject_HasAttrString(obj, "name")) { |
| 3617 | int res; |
| 3618 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3619 | if (tmp == NULL) goto failed; |
| 3620 | res = obj2ast_identifier(tmp, &name, arena); |
| 3621 | if (res != 0) goto failed; |
| 3622 | Py_XDECREF(tmp); |
| 3623 | tmp = NULL; |
| 3624 | } else { |
| 3625 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3626 | return 1; |
| 3627 | } |
| 3628 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3629 | int res; |
| 3630 | Py_ssize_t len; |
| 3631 | Py_ssize_t i; |
| 3632 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3633 | if (tmp == NULL) goto failed; |
| 3634 | if (!PyList_Check(tmp)) { |
| 3635 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3636 | goto failed; |
| 3637 | } |
| 3638 | len = PyList_GET_SIZE(tmp); |
| 3639 | bases = asdl_seq_new(len, arena); |
| 3640 | if (bases == NULL) goto failed; |
| 3641 | for (i = 0; i < len; i++) { |
| 3642 | expr_ty value; |
| 3643 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3644 | if (res != 0) goto failed; |
| 3645 | asdl_seq_SET(bases, i, value); |
| 3646 | } |
| 3647 | Py_XDECREF(tmp); |
| 3648 | tmp = NULL; |
| 3649 | } else { |
| 3650 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3651 | return 1; |
| 3652 | } |
| 3653 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3654 | int res; |
| 3655 | Py_ssize_t len; |
| 3656 | Py_ssize_t i; |
| 3657 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3658 | if (tmp == NULL) goto failed; |
| 3659 | if (!PyList_Check(tmp)) { |
| 3660 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3661 | goto failed; |
| 3662 | } |
| 3663 | len = PyList_GET_SIZE(tmp); |
| 3664 | keywords = asdl_seq_new(len, arena); |
| 3665 | if (keywords == NULL) goto failed; |
| 3666 | for (i = 0; i < len; i++) { |
| 3667 | keyword_ty value; |
| 3668 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3669 | if (res != 0) goto failed; |
| 3670 | asdl_seq_SET(keywords, i, value); |
| 3671 | } |
| 3672 | Py_XDECREF(tmp); |
| 3673 | tmp = NULL; |
| 3674 | } else { |
| 3675 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3676 | return 1; |
| 3677 | } |
| 3678 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3679 | int res; |
| 3680 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3681 | if (tmp == NULL) goto failed; |
| 3682 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3683 | if (res != 0) goto failed; |
| 3684 | Py_XDECREF(tmp); |
| 3685 | tmp = NULL; |
| 3686 | } else { |
| 3687 | starargs = NULL; |
| 3688 | } |
| 3689 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3690 | int res; |
| 3691 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3692 | if (tmp == NULL) goto failed; |
| 3693 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3694 | if (res != 0) goto failed; |
| 3695 | Py_XDECREF(tmp); |
| 3696 | tmp = NULL; |
| 3697 | } else { |
| 3698 | kwargs = NULL; |
| 3699 | } |
| 3700 | if (PyObject_HasAttrString(obj, "body")) { |
| 3701 | int res; |
| 3702 | Py_ssize_t len; |
| 3703 | Py_ssize_t i; |
| 3704 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3705 | if (tmp == NULL) goto failed; |
| 3706 | if (!PyList_Check(tmp)) { |
| 3707 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3708 | goto failed; |
| 3709 | } |
| 3710 | len = PyList_GET_SIZE(tmp); |
| 3711 | body = asdl_seq_new(len, arena); |
| 3712 | if (body == NULL) goto failed; |
| 3713 | for (i = 0; i < len; i++) { |
| 3714 | stmt_ty value; |
| 3715 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3716 | if (res != 0) goto failed; |
| 3717 | asdl_seq_SET(body, i, value); |
| 3718 | } |
| 3719 | Py_XDECREF(tmp); |
| 3720 | tmp = NULL; |
| 3721 | } else { |
| 3722 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3723 | return 1; |
| 3724 | } |
| 3725 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3726 | int res; |
| 3727 | Py_ssize_t len; |
| 3728 | Py_ssize_t i; |
| 3729 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3730 | if (tmp == NULL) goto failed; |
| 3731 | if (!PyList_Check(tmp)) { |
| 3732 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3733 | goto failed; |
| 3734 | } |
| 3735 | len = PyList_GET_SIZE(tmp); |
| 3736 | decorator_list = asdl_seq_new(len, arena); |
| 3737 | if (decorator_list == NULL) goto failed; |
| 3738 | for (i = 0; i < len; i++) { |
| 3739 | expr_ty value; |
| 3740 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3741 | if (res != 0) goto failed; |
| 3742 | asdl_seq_SET(decorator_list, i, value); |
| 3743 | } |
| 3744 | Py_XDECREF(tmp); |
| 3745 | tmp = NULL; |
| 3746 | } else { |
| 3747 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3748 | return 1; |
| 3749 | } |
| 3750 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3751 | decorator_list, lineno, col_offset, arena); |
| 3752 | if (*out == NULL) goto failed; |
| 3753 | return 0; |
| 3754 | } |
| 3755 | if (PyObject_IsInstance(obj, (PyObject*)Return_type)) { |
| 3756 | expr_ty value; |
| 3757 | |
| 3758 | if (PyObject_HasAttrString(obj, "value")) { |
| 3759 | int res; |
| 3760 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3761 | if (tmp == NULL) goto failed; |
| 3762 | res = obj2ast_expr(tmp, &value, arena); |
| 3763 | if (res != 0) goto failed; |
| 3764 | Py_XDECREF(tmp); |
| 3765 | tmp = NULL; |
| 3766 | } else { |
| 3767 | value = NULL; |
| 3768 | } |
| 3769 | *out = Return(value, lineno, col_offset, arena); |
| 3770 | if (*out == NULL) goto failed; |
| 3771 | return 0; |
| 3772 | } |
| 3773 | if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) { |
| 3774 | asdl_seq* targets; |
| 3775 | |
| 3776 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3777 | int res; |
| 3778 | Py_ssize_t len; |
| 3779 | Py_ssize_t i; |
| 3780 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3781 | if (tmp == NULL) goto failed; |
| 3782 | if (!PyList_Check(tmp)) { |
| 3783 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3784 | goto failed; |
| 3785 | } |
| 3786 | len = PyList_GET_SIZE(tmp); |
| 3787 | targets = asdl_seq_new(len, arena); |
| 3788 | if (targets == NULL) goto failed; |
| 3789 | for (i = 0; i < len; i++) { |
| 3790 | expr_ty value; |
| 3791 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3792 | if (res != 0) goto failed; |
| 3793 | asdl_seq_SET(targets, i, value); |
| 3794 | } |
| 3795 | Py_XDECREF(tmp); |
| 3796 | tmp = NULL; |
| 3797 | } else { |
| 3798 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3799 | return 1; |
| 3800 | } |
| 3801 | *out = Delete(targets, lineno, col_offset, arena); |
| 3802 | if (*out == NULL) goto failed; |
| 3803 | return 0; |
| 3804 | } |
| 3805 | if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) { |
| 3806 | asdl_seq* targets; |
| 3807 | expr_ty value; |
| 3808 | |
| 3809 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3810 | int res; |
| 3811 | Py_ssize_t len; |
| 3812 | Py_ssize_t i; |
| 3813 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3814 | if (tmp == NULL) goto failed; |
| 3815 | if (!PyList_Check(tmp)) { |
| 3816 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3817 | goto failed; |
| 3818 | } |
| 3819 | len = PyList_GET_SIZE(tmp); |
| 3820 | targets = asdl_seq_new(len, arena); |
| 3821 | if (targets == NULL) goto failed; |
| 3822 | for (i = 0; i < len; i++) { |
| 3823 | expr_ty value; |
| 3824 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3825 | if (res != 0) goto failed; |
| 3826 | asdl_seq_SET(targets, i, value); |
| 3827 | } |
| 3828 | Py_XDECREF(tmp); |
| 3829 | tmp = NULL; |
| 3830 | } else { |
| 3831 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3832 | return 1; |
| 3833 | } |
| 3834 | if (PyObject_HasAttrString(obj, "value")) { |
| 3835 | int res; |
| 3836 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3837 | if (tmp == NULL) goto failed; |
| 3838 | res = obj2ast_expr(tmp, &value, arena); |
| 3839 | if (res != 0) goto failed; |
| 3840 | Py_XDECREF(tmp); |
| 3841 | tmp = NULL; |
| 3842 | } else { |
| 3843 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3844 | return 1; |
| 3845 | } |
| 3846 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3847 | if (*out == NULL) goto failed; |
| 3848 | return 0; |
| 3849 | } |
| 3850 | if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) { |
| 3851 | expr_ty target; |
| 3852 | operator_ty op; |
| 3853 | expr_ty value; |
| 3854 | |
| 3855 | if (PyObject_HasAttrString(obj, "target")) { |
| 3856 | int res; |
| 3857 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3858 | if (tmp == NULL) goto failed; |
| 3859 | res = obj2ast_expr(tmp, &target, arena); |
| 3860 | if (res != 0) goto failed; |
| 3861 | Py_XDECREF(tmp); |
| 3862 | tmp = NULL; |
| 3863 | } else { |
| 3864 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3865 | return 1; |
| 3866 | } |
| 3867 | if (PyObject_HasAttrString(obj, "op")) { |
| 3868 | int res; |
| 3869 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3870 | if (tmp == NULL) goto failed; |
| 3871 | res = obj2ast_operator(tmp, &op, arena); |
| 3872 | if (res != 0) goto failed; |
| 3873 | Py_XDECREF(tmp); |
| 3874 | tmp = NULL; |
| 3875 | } else { |
| 3876 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3877 | return 1; |
| 3878 | } |
| 3879 | if (PyObject_HasAttrString(obj, "value")) { |
| 3880 | int res; |
| 3881 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3882 | if (tmp == NULL) goto failed; |
| 3883 | res = obj2ast_expr(tmp, &value, arena); |
| 3884 | if (res != 0) goto failed; |
| 3885 | Py_XDECREF(tmp); |
| 3886 | tmp = NULL; |
| 3887 | } else { |
| 3888 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3889 | return 1; |
| 3890 | } |
| 3891 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3892 | if (*out == NULL) goto failed; |
| 3893 | return 0; |
| 3894 | } |
| 3895 | if (PyObject_IsInstance(obj, (PyObject*)For_type)) { |
| 3896 | expr_ty target; |
| 3897 | expr_ty iter; |
| 3898 | asdl_seq* body; |
| 3899 | asdl_seq* orelse; |
| 3900 | |
| 3901 | if (PyObject_HasAttrString(obj, "target")) { |
| 3902 | int res; |
| 3903 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3904 | if (tmp == NULL) goto failed; |
| 3905 | res = obj2ast_expr(tmp, &target, arena); |
| 3906 | if (res != 0) goto failed; |
| 3907 | Py_XDECREF(tmp); |
| 3908 | tmp = NULL; |
| 3909 | } else { |
| 3910 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 3911 | return 1; |
| 3912 | } |
| 3913 | if (PyObject_HasAttrString(obj, "iter")) { |
| 3914 | int res; |
| 3915 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 3916 | if (tmp == NULL) goto failed; |
| 3917 | res = obj2ast_expr(tmp, &iter, arena); |
| 3918 | if (res != 0) goto failed; |
| 3919 | Py_XDECREF(tmp); |
| 3920 | tmp = NULL; |
| 3921 | } else { |
| 3922 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 3923 | return 1; |
| 3924 | } |
| 3925 | if (PyObject_HasAttrString(obj, "body")) { |
| 3926 | int res; |
| 3927 | Py_ssize_t len; |
| 3928 | Py_ssize_t i; |
| 3929 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3930 | if (tmp == NULL) goto failed; |
| 3931 | if (!PyList_Check(tmp)) { |
| 3932 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3933 | goto failed; |
| 3934 | } |
| 3935 | len = PyList_GET_SIZE(tmp); |
| 3936 | body = asdl_seq_new(len, arena); |
| 3937 | if (body == NULL) goto failed; |
| 3938 | for (i = 0; i < len; i++) { |
| 3939 | stmt_ty value; |
| 3940 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3941 | if (res != 0) goto failed; |
| 3942 | asdl_seq_SET(body, i, value); |
| 3943 | } |
| 3944 | Py_XDECREF(tmp); |
| 3945 | tmp = NULL; |
| 3946 | } else { |
| 3947 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 3948 | return 1; |
| 3949 | } |
| 3950 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 3951 | int res; |
| 3952 | Py_ssize_t len; |
| 3953 | Py_ssize_t i; |
| 3954 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 3955 | if (tmp == NULL) goto failed; |
| 3956 | if (!PyList_Check(tmp)) { |
| 3957 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3958 | goto failed; |
| 3959 | } |
| 3960 | len = PyList_GET_SIZE(tmp); |
| 3961 | orelse = asdl_seq_new(len, arena); |
| 3962 | if (orelse == NULL) goto failed; |
| 3963 | for (i = 0; i < len; i++) { |
| 3964 | stmt_ty value; |
| 3965 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3966 | if (res != 0) goto failed; |
| 3967 | asdl_seq_SET(orelse, i, value); |
| 3968 | } |
| 3969 | Py_XDECREF(tmp); |
| 3970 | tmp = NULL; |
| 3971 | } else { |
| 3972 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 3973 | return 1; |
| 3974 | } |
| 3975 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 3976 | arena); |
| 3977 | if (*out == NULL) goto failed; |
| 3978 | return 0; |
| 3979 | } |
| 3980 | if (PyObject_IsInstance(obj, (PyObject*)While_type)) { |
| 3981 | expr_ty test; |
| 3982 | asdl_seq* body; |
| 3983 | asdl_seq* orelse; |
| 3984 | |
| 3985 | if (PyObject_HasAttrString(obj, "test")) { |
| 3986 | int res; |
| 3987 | tmp = PyObject_GetAttrString(obj, "test"); |
| 3988 | if (tmp == NULL) goto failed; |
| 3989 | res = obj2ast_expr(tmp, &test, arena); |
| 3990 | if (res != 0) goto failed; |
| 3991 | Py_XDECREF(tmp); |
| 3992 | tmp = NULL; |
| 3993 | } else { |
| 3994 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 3995 | return 1; |
| 3996 | } |
| 3997 | if (PyObject_HasAttrString(obj, "body")) { |
| 3998 | int res; |
| 3999 | Py_ssize_t len; |
| 4000 | Py_ssize_t i; |
| 4001 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4002 | if (tmp == NULL) goto failed; |
| 4003 | if (!PyList_Check(tmp)) { |
| 4004 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4005 | goto failed; |
| 4006 | } |
| 4007 | len = PyList_GET_SIZE(tmp); |
| 4008 | body = asdl_seq_new(len, arena); |
| 4009 | if (body == NULL) goto failed; |
| 4010 | for (i = 0; i < len; i++) { |
| 4011 | stmt_ty value; |
| 4012 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4013 | if (res != 0) goto failed; |
| 4014 | asdl_seq_SET(body, i, value); |
| 4015 | } |
| 4016 | Py_XDECREF(tmp); |
| 4017 | tmp = NULL; |
| 4018 | } else { |
| 4019 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4020 | return 1; |
| 4021 | } |
| 4022 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4023 | int res; |
| 4024 | Py_ssize_t len; |
| 4025 | Py_ssize_t i; |
| 4026 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4027 | if (tmp == NULL) goto failed; |
| 4028 | if (!PyList_Check(tmp)) { |
| 4029 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4030 | goto failed; |
| 4031 | } |
| 4032 | len = PyList_GET_SIZE(tmp); |
| 4033 | orelse = asdl_seq_new(len, arena); |
| 4034 | if (orelse == NULL) goto failed; |
| 4035 | for (i = 0; i < len; i++) { |
| 4036 | stmt_ty value; |
| 4037 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4038 | if (res != 0) goto failed; |
| 4039 | asdl_seq_SET(orelse, i, value); |
| 4040 | } |
| 4041 | Py_XDECREF(tmp); |
| 4042 | tmp = NULL; |
| 4043 | } else { |
| 4044 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4045 | return 1; |
| 4046 | } |
| 4047 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4048 | if (*out == NULL) goto failed; |
| 4049 | return 0; |
| 4050 | } |
| 4051 | if (PyObject_IsInstance(obj, (PyObject*)If_type)) { |
| 4052 | expr_ty test; |
| 4053 | asdl_seq* body; |
| 4054 | asdl_seq* orelse; |
| 4055 | |
| 4056 | if (PyObject_HasAttrString(obj, "test")) { |
| 4057 | int res; |
| 4058 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4059 | if (tmp == NULL) goto failed; |
| 4060 | res = obj2ast_expr(tmp, &test, arena); |
| 4061 | if (res != 0) goto failed; |
| 4062 | Py_XDECREF(tmp); |
| 4063 | tmp = NULL; |
| 4064 | } else { |
| 4065 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4066 | return 1; |
| 4067 | } |
| 4068 | if (PyObject_HasAttrString(obj, "body")) { |
| 4069 | int res; |
| 4070 | Py_ssize_t len; |
| 4071 | Py_ssize_t i; |
| 4072 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4073 | if (tmp == NULL) goto failed; |
| 4074 | if (!PyList_Check(tmp)) { |
| 4075 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4076 | goto failed; |
| 4077 | } |
| 4078 | len = PyList_GET_SIZE(tmp); |
| 4079 | body = asdl_seq_new(len, arena); |
| 4080 | if (body == NULL) goto failed; |
| 4081 | for (i = 0; i < len; i++) { |
| 4082 | stmt_ty value; |
| 4083 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4084 | if (res != 0) goto failed; |
| 4085 | asdl_seq_SET(body, i, value); |
| 4086 | } |
| 4087 | Py_XDECREF(tmp); |
| 4088 | tmp = NULL; |
| 4089 | } else { |
| 4090 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4091 | return 1; |
| 4092 | } |
| 4093 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4094 | int res; |
| 4095 | Py_ssize_t len; |
| 4096 | Py_ssize_t i; |
| 4097 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4098 | if (tmp == NULL) goto failed; |
| 4099 | if (!PyList_Check(tmp)) { |
| 4100 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4101 | goto failed; |
| 4102 | } |
| 4103 | len = PyList_GET_SIZE(tmp); |
| 4104 | orelse = asdl_seq_new(len, arena); |
| 4105 | if (orelse == NULL) goto failed; |
| 4106 | for (i = 0; i < len; i++) { |
| 4107 | stmt_ty value; |
| 4108 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4109 | if (res != 0) goto failed; |
| 4110 | asdl_seq_SET(orelse, i, value); |
| 4111 | } |
| 4112 | Py_XDECREF(tmp); |
| 4113 | tmp = NULL; |
| 4114 | } else { |
| 4115 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4116 | return 1; |
| 4117 | } |
| 4118 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4119 | if (*out == NULL) goto failed; |
| 4120 | return 0; |
| 4121 | } |
| 4122 | if (PyObject_IsInstance(obj, (PyObject*)With_type)) { |
| 4123 | expr_ty context_expr; |
| 4124 | expr_ty optional_vars; |
| 4125 | asdl_seq* body; |
| 4126 | |
| 4127 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 4128 | int res; |
| 4129 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 4130 | if (tmp == NULL) goto failed; |
| 4131 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 4132 | if (res != 0) goto failed; |
| 4133 | Py_XDECREF(tmp); |
| 4134 | tmp = NULL; |
| 4135 | } else { |
| 4136 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); |
| 4137 | return 1; |
| 4138 | } |
| 4139 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 4140 | int res; |
| 4141 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 4142 | if (tmp == NULL) goto failed; |
| 4143 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 4144 | if (res != 0) goto failed; |
| 4145 | Py_XDECREF(tmp); |
| 4146 | tmp = NULL; |
| 4147 | } else { |
| 4148 | optional_vars = NULL; |
| 4149 | } |
| 4150 | if (PyObject_HasAttrString(obj, "body")) { |
| 4151 | int res; |
| 4152 | Py_ssize_t len; |
| 4153 | Py_ssize_t i; |
| 4154 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4155 | if (tmp == NULL) goto failed; |
| 4156 | if (!PyList_Check(tmp)) { |
| 4157 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4158 | goto failed; |
| 4159 | } |
| 4160 | len = PyList_GET_SIZE(tmp); |
| 4161 | body = asdl_seq_new(len, arena); |
| 4162 | if (body == NULL) goto failed; |
| 4163 | for (i = 0; i < len; i++) { |
| 4164 | stmt_ty value; |
| 4165 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4166 | if (res != 0) goto failed; |
| 4167 | asdl_seq_SET(body, i, value); |
| 4168 | } |
| 4169 | Py_XDECREF(tmp); |
| 4170 | tmp = NULL; |
| 4171 | } else { |
| 4172 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4173 | return 1; |
| 4174 | } |
| 4175 | *out = With(context_expr, optional_vars, body, lineno, |
| 4176 | col_offset, arena); |
| 4177 | if (*out == NULL) goto failed; |
| 4178 | return 0; |
| 4179 | } |
| 4180 | if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) { |
| 4181 | expr_ty exc; |
| 4182 | expr_ty cause; |
| 4183 | |
| 4184 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4185 | int res; |
| 4186 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4187 | if (tmp == NULL) goto failed; |
| 4188 | res = obj2ast_expr(tmp, &exc, arena); |
| 4189 | if (res != 0) goto failed; |
| 4190 | Py_XDECREF(tmp); |
| 4191 | tmp = NULL; |
| 4192 | } else { |
| 4193 | exc = NULL; |
| 4194 | } |
| 4195 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4196 | int res; |
| 4197 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4198 | if (tmp == NULL) goto failed; |
| 4199 | res = obj2ast_expr(tmp, &cause, arena); |
| 4200 | if (res != 0) goto failed; |
| 4201 | Py_XDECREF(tmp); |
| 4202 | tmp = NULL; |
| 4203 | } else { |
| 4204 | cause = NULL; |
| 4205 | } |
| 4206 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4207 | if (*out == NULL) goto failed; |
| 4208 | return 0; |
| 4209 | } |
| 4210 | if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) { |
| 4211 | asdl_seq* body; |
| 4212 | asdl_seq* handlers; |
| 4213 | asdl_seq* orelse; |
| 4214 | |
| 4215 | if (PyObject_HasAttrString(obj, "body")) { |
| 4216 | int res; |
| 4217 | Py_ssize_t len; |
| 4218 | Py_ssize_t i; |
| 4219 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4220 | if (tmp == NULL) goto failed; |
| 4221 | if (!PyList_Check(tmp)) { |
| 4222 | PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4223 | goto failed; |
| 4224 | } |
| 4225 | len = PyList_GET_SIZE(tmp); |
| 4226 | body = asdl_seq_new(len, arena); |
| 4227 | if (body == NULL) goto failed; |
| 4228 | for (i = 0; i < len; i++) { |
| 4229 | stmt_ty value; |
| 4230 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4231 | if (res != 0) goto failed; |
| 4232 | asdl_seq_SET(body, i, value); |
| 4233 | } |
| 4234 | Py_XDECREF(tmp); |
| 4235 | tmp = NULL; |
| 4236 | } else { |
| 4237 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); |
| 4238 | return 1; |
| 4239 | } |
| 4240 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4241 | int res; |
| 4242 | Py_ssize_t len; |
| 4243 | Py_ssize_t i; |
| 4244 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4245 | if (tmp == NULL) goto failed; |
| 4246 | if (!PyList_Check(tmp)) { |
| 4247 | PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4248 | goto failed; |
| 4249 | } |
| 4250 | len = PyList_GET_SIZE(tmp); |
| 4251 | handlers = asdl_seq_new(len, arena); |
| 4252 | if (handlers == NULL) goto failed; |
| 4253 | for (i = 0; i < len; i++) { |
| 4254 | excepthandler_ty value; |
| 4255 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4256 | if (res != 0) goto failed; |
| 4257 | asdl_seq_SET(handlers, i, value); |
| 4258 | } |
| 4259 | Py_XDECREF(tmp); |
| 4260 | tmp = NULL; |
| 4261 | } else { |
| 4262 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); |
| 4263 | return 1; |
| 4264 | } |
| 4265 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4266 | int res; |
| 4267 | Py_ssize_t len; |
| 4268 | Py_ssize_t i; |
| 4269 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4270 | if (tmp == NULL) goto failed; |
| 4271 | if (!PyList_Check(tmp)) { |
| 4272 | PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4273 | goto failed; |
| 4274 | } |
| 4275 | len = PyList_GET_SIZE(tmp); |
| 4276 | orelse = asdl_seq_new(len, arena); |
| 4277 | if (orelse == NULL) goto failed; |
| 4278 | for (i = 0; i < len; i++) { |
| 4279 | stmt_ty value; |
| 4280 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4281 | if (res != 0) goto failed; |
| 4282 | asdl_seq_SET(orelse, i, value); |
| 4283 | } |
| 4284 | Py_XDECREF(tmp); |
| 4285 | tmp = NULL; |
| 4286 | } else { |
| 4287 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); |
| 4288 | return 1; |
| 4289 | } |
| 4290 | *out = TryExcept(body, handlers, orelse, lineno, col_offset, |
| 4291 | arena); |
| 4292 | if (*out == NULL) goto failed; |
| 4293 | return 0; |
| 4294 | } |
| 4295 | if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) { |
| 4296 | asdl_seq* body; |
| 4297 | asdl_seq* finalbody; |
| 4298 | |
| 4299 | if (PyObject_HasAttrString(obj, "body")) { |
| 4300 | int res; |
| 4301 | Py_ssize_t len; |
| 4302 | Py_ssize_t i; |
| 4303 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4304 | if (tmp == NULL) goto failed; |
| 4305 | if (!PyList_Check(tmp)) { |
| 4306 | PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4307 | goto failed; |
| 4308 | } |
| 4309 | len = PyList_GET_SIZE(tmp); |
| 4310 | body = asdl_seq_new(len, arena); |
| 4311 | if (body == NULL) goto failed; |
| 4312 | for (i = 0; i < len; i++) { |
| 4313 | stmt_ty value; |
| 4314 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4315 | if (res != 0) goto failed; |
| 4316 | asdl_seq_SET(body, i, value); |
| 4317 | } |
| 4318 | Py_XDECREF(tmp); |
| 4319 | tmp = NULL; |
| 4320 | } else { |
| 4321 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); |
| 4322 | return 1; |
| 4323 | } |
| 4324 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4325 | int res; |
| 4326 | Py_ssize_t len; |
| 4327 | Py_ssize_t i; |
| 4328 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4329 | if (tmp == NULL) goto failed; |
| 4330 | if (!PyList_Check(tmp)) { |
| 4331 | PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4332 | goto failed; |
| 4333 | } |
| 4334 | len = PyList_GET_SIZE(tmp); |
| 4335 | finalbody = asdl_seq_new(len, arena); |
| 4336 | if (finalbody == NULL) goto failed; |
| 4337 | for (i = 0; i < len; i++) { |
| 4338 | stmt_ty value; |
| 4339 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4340 | if (res != 0) goto failed; |
| 4341 | asdl_seq_SET(finalbody, i, value); |
| 4342 | } |
| 4343 | Py_XDECREF(tmp); |
| 4344 | tmp = NULL; |
| 4345 | } else { |
| 4346 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); |
| 4347 | return 1; |
| 4348 | } |
| 4349 | *out = TryFinally(body, finalbody, lineno, col_offset, arena); |
| 4350 | if (*out == NULL) goto failed; |
| 4351 | return 0; |
| 4352 | } |
| 4353 | if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) { |
| 4354 | expr_ty test; |
| 4355 | expr_ty msg; |
| 4356 | |
| 4357 | if (PyObject_HasAttrString(obj, "test")) { |
| 4358 | int res; |
| 4359 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4360 | if (tmp == NULL) goto failed; |
| 4361 | res = obj2ast_expr(tmp, &test, arena); |
| 4362 | if (res != 0) goto failed; |
| 4363 | Py_XDECREF(tmp); |
| 4364 | tmp = NULL; |
| 4365 | } else { |
| 4366 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4367 | return 1; |
| 4368 | } |
| 4369 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4370 | int res; |
| 4371 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4372 | if (tmp == NULL) goto failed; |
| 4373 | res = obj2ast_expr(tmp, &msg, arena); |
| 4374 | if (res != 0) goto failed; |
| 4375 | Py_XDECREF(tmp); |
| 4376 | tmp = NULL; |
| 4377 | } else { |
| 4378 | msg = NULL; |
| 4379 | } |
| 4380 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4381 | if (*out == NULL) goto failed; |
| 4382 | return 0; |
| 4383 | } |
| 4384 | if (PyObject_IsInstance(obj, (PyObject*)Import_type)) { |
| 4385 | asdl_seq* names; |
| 4386 | |
| 4387 | if (PyObject_HasAttrString(obj, "names")) { |
| 4388 | int res; |
| 4389 | Py_ssize_t len; |
| 4390 | Py_ssize_t i; |
| 4391 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4392 | if (tmp == NULL) goto failed; |
| 4393 | if (!PyList_Check(tmp)) { |
| 4394 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4395 | goto failed; |
| 4396 | } |
| 4397 | len = PyList_GET_SIZE(tmp); |
| 4398 | names = asdl_seq_new(len, arena); |
| 4399 | if (names == NULL) goto failed; |
| 4400 | for (i = 0; i < len; i++) { |
| 4401 | alias_ty value; |
| 4402 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4403 | if (res != 0) goto failed; |
| 4404 | asdl_seq_SET(names, i, value); |
| 4405 | } |
| 4406 | Py_XDECREF(tmp); |
| 4407 | tmp = NULL; |
| 4408 | } else { |
| 4409 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4410 | return 1; |
| 4411 | } |
| 4412 | *out = Import(names, lineno, col_offset, arena); |
| 4413 | if (*out == NULL) goto failed; |
| 4414 | return 0; |
| 4415 | } |
| 4416 | if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) { |
| 4417 | identifier module; |
| 4418 | asdl_seq* names; |
| 4419 | int level; |
| 4420 | |
| 4421 | if (PyObject_HasAttrString(obj, "module")) { |
| 4422 | int res; |
| 4423 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4424 | if (tmp == NULL) goto failed; |
| 4425 | res = obj2ast_identifier(tmp, &module, arena); |
| 4426 | if (res != 0) goto failed; |
| 4427 | Py_XDECREF(tmp); |
| 4428 | tmp = NULL; |
| 4429 | } else { |
| 4430 | PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); |
| 4431 | return 1; |
| 4432 | } |
| 4433 | if (PyObject_HasAttrString(obj, "names")) { |
| 4434 | int res; |
| 4435 | Py_ssize_t len; |
| 4436 | Py_ssize_t i; |
| 4437 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4438 | if (tmp == NULL) goto failed; |
| 4439 | if (!PyList_Check(tmp)) { |
| 4440 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4441 | goto failed; |
| 4442 | } |
| 4443 | len = PyList_GET_SIZE(tmp); |
| 4444 | names = asdl_seq_new(len, arena); |
| 4445 | if (names == NULL) goto failed; |
| 4446 | for (i = 0; i < len; i++) { |
| 4447 | alias_ty value; |
| 4448 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4449 | if (res != 0) goto failed; |
| 4450 | asdl_seq_SET(names, i, value); |
| 4451 | } |
| 4452 | Py_XDECREF(tmp); |
| 4453 | tmp = NULL; |
| 4454 | } else { |
| 4455 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4456 | return 1; |
| 4457 | } |
| 4458 | if (PyObject_HasAttrString(obj, "level")) { |
| 4459 | int res; |
| 4460 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4461 | if (tmp == NULL) goto failed; |
| 4462 | res = obj2ast_int(tmp, &level, arena); |
| 4463 | if (res != 0) goto failed; |
| 4464 | Py_XDECREF(tmp); |
| 4465 | tmp = NULL; |
| 4466 | } else { |
| 4467 | level = 0; |
| 4468 | } |
| 4469 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4470 | arena); |
| 4471 | if (*out == NULL) goto failed; |
| 4472 | return 0; |
| 4473 | } |
| 4474 | if (PyObject_IsInstance(obj, (PyObject*)Global_type)) { |
| 4475 | asdl_seq* names; |
| 4476 | |
| 4477 | if (PyObject_HasAttrString(obj, "names")) { |
| 4478 | int res; |
| 4479 | Py_ssize_t len; |
| 4480 | Py_ssize_t i; |
| 4481 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4482 | if (tmp == NULL) goto failed; |
| 4483 | if (!PyList_Check(tmp)) { |
| 4484 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4485 | goto failed; |
| 4486 | } |
| 4487 | len = PyList_GET_SIZE(tmp); |
| 4488 | names = asdl_seq_new(len, arena); |
| 4489 | if (names == NULL) goto failed; |
| 4490 | for (i = 0; i < len; i++) { |
| 4491 | identifier value; |
| 4492 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4493 | if (res != 0) goto failed; |
| 4494 | asdl_seq_SET(names, i, value); |
| 4495 | } |
| 4496 | Py_XDECREF(tmp); |
| 4497 | tmp = NULL; |
| 4498 | } else { |
| 4499 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4500 | return 1; |
| 4501 | } |
| 4502 | *out = Global(names, lineno, col_offset, arena); |
| 4503 | if (*out == NULL) goto failed; |
| 4504 | return 0; |
| 4505 | } |
| 4506 | if (PyObject_IsInstance(obj, (PyObject*)Nonlocal_type)) { |
| 4507 | asdl_seq* names; |
| 4508 | |
| 4509 | if (PyObject_HasAttrString(obj, "names")) { |
| 4510 | int res; |
| 4511 | Py_ssize_t len; |
| 4512 | Py_ssize_t i; |
| 4513 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4514 | if (tmp == NULL) goto failed; |
| 4515 | if (!PyList_Check(tmp)) { |
| 4516 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4517 | goto failed; |
| 4518 | } |
| 4519 | len = PyList_GET_SIZE(tmp); |
| 4520 | names = asdl_seq_new(len, arena); |
| 4521 | if (names == NULL) goto failed; |
| 4522 | for (i = 0; i < len; i++) { |
| 4523 | identifier value; |
| 4524 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4525 | if (res != 0) goto failed; |
| 4526 | asdl_seq_SET(names, i, value); |
| 4527 | } |
| 4528 | Py_XDECREF(tmp); |
| 4529 | tmp = NULL; |
| 4530 | } else { |
| 4531 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4532 | return 1; |
| 4533 | } |
| 4534 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4535 | if (*out == NULL) goto failed; |
| 4536 | return 0; |
| 4537 | } |
| 4538 | if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) { |
| 4539 | expr_ty value; |
| 4540 | |
| 4541 | if (PyObject_HasAttrString(obj, "value")) { |
| 4542 | int res; |
| 4543 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4544 | if (tmp == NULL) goto failed; |
| 4545 | res = obj2ast_expr(tmp, &value, arena); |
| 4546 | if (res != 0) goto failed; |
| 4547 | Py_XDECREF(tmp); |
| 4548 | tmp = NULL; |
| 4549 | } else { |
| 4550 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4551 | return 1; |
| 4552 | } |
| 4553 | *out = Expr(value, lineno, col_offset, arena); |
| 4554 | if (*out == NULL) goto failed; |
| 4555 | return 0; |
| 4556 | } |
| 4557 | if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) { |
| 4558 | |
| 4559 | *out = Pass(lineno, col_offset, arena); |
| 4560 | if (*out == NULL) goto failed; |
| 4561 | return 0; |
| 4562 | } |
| 4563 | if (PyObject_IsInstance(obj, (PyObject*)Break_type)) { |
| 4564 | |
| 4565 | *out = Break(lineno, col_offset, arena); |
| 4566 | if (*out == NULL) goto failed; |
| 4567 | return 0; |
| 4568 | } |
| 4569 | if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) { |
| 4570 | |
| 4571 | *out = Continue(lineno, col_offset, arena); |
| 4572 | if (*out == NULL) goto failed; |
| 4573 | return 0; |
| 4574 | } |
| 4575 | |
| 4576 | tmp = PyObject_Repr(obj); |
| 4577 | if (tmp == NULL) goto failed; |
| 4578 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp)); |
| 4579 | failed: |
| 4580 | Py_XDECREF(tmp); |
| 4581 | return 1; |
| 4582 | } |
| 4583 | |
| 4584 | int |
| 4585 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4586 | { |
| 4587 | PyObject* tmp = NULL; |
| 4588 | |
| 4589 | int lineno; |
| 4590 | int col_offset; |
| 4591 | |
| 4592 | if (obj == Py_None) { |
| 4593 | *out = NULL; |
| 4594 | return 0; |
| 4595 | } |
| 4596 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4597 | int res; |
| 4598 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4599 | if (tmp == NULL) goto failed; |
| 4600 | res = obj2ast_int(tmp, &lineno, arena); |
| 4601 | if (res != 0) goto failed; |
| 4602 | Py_XDECREF(tmp); |
| 4603 | tmp = NULL; |
| 4604 | } else { |
| 4605 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4606 | return 1; |
| 4607 | } |
| 4608 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4609 | int res; |
| 4610 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4611 | if (tmp == NULL) goto failed; |
| 4612 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4613 | if (res != 0) goto failed; |
| 4614 | Py_XDECREF(tmp); |
| 4615 | tmp = NULL; |
| 4616 | } else { |
| 4617 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4618 | return 1; |
| 4619 | } |
| 4620 | if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) { |
| 4621 | boolop_ty op; |
| 4622 | asdl_seq* values; |
| 4623 | |
| 4624 | if (PyObject_HasAttrString(obj, "op")) { |
| 4625 | int res; |
| 4626 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4627 | if (tmp == NULL) goto failed; |
| 4628 | res = obj2ast_boolop(tmp, &op, arena); |
| 4629 | if (res != 0) goto failed; |
| 4630 | Py_XDECREF(tmp); |
| 4631 | tmp = NULL; |
| 4632 | } else { |
| 4633 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4634 | return 1; |
| 4635 | } |
| 4636 | if (PyObject_HasAttrString(obj, "values")) { |
| 4637 | int res; |
| 4638 | Py_ssize_t len; |
| 4639 | Py_ssize_t i; |
| 4640 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4641 | if (tmp == NULL) goto failed; |
| 4642 | if (!PyList_Check(tmp)) { |
| 4643 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4644 | goto failed; |
| 4645 | } |
| 4646 | len = PyList_GET_SIZE(tmp); |
| 4647 | values = asdl_seq_new(len, arena); |
| 4648 | if (values == NULL) goto failed; |
| 4649 | for (i = 0; i < len; i++) { |
| 4650 | expr_ty value; |
| 4651 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4652 | if (res != 0) goto failed; |
| 4653 | asdl_seq_SET(values, i, value); |
| 4654 | } |
| 4655 | Py_XDECREF(tmp); |
| 4656 | tmp = NULL; |
| 4657 | } else { |
| 4658 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4659 | return 1; |
| 4660 | } |
| 4661 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4662 | if (*out == NULL) goto failed; |
| 4663 | return 0; |
| 4664 | } |
| 4665 | if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) { |
| 4666 | expr_ty left; |
| 4667 | operator_ty op; |
| 4668 | expr_ty right; |
| 4669 | |
| 4670 | if (PyObject_HasAttrString(obj, "left")) { |
| 4671 | int res; |
| 4672 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4673 | if (tmp == NULL) goto failed; |
| 4674 | res = obj2ast_expr(tmp, &left, arena); |
| 4675 | if (res != 0) goto failed; |
| 4676 | Py_XDECREF(tmp); |
| 4677 | tmp = NULL; |
| 4678 | } else { |
| 4679 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4680 | return 1; |
| 4681 | } |
| 4682 | if (PyObject_HasAttrString(obj, "op")) { |
| 4683 | int res; |
| 4684 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4685 | if (tmp == NULL) goto failed; |
| 4686 | res = obj2ast_operator(tmp, &op, arena); |
| 4687 | if (res != 0) goto failed; |
| 4688 | Py_XDECREF(tmp); |
| 4689 | tmp = NULL; |
| 4690 | } else { |
| 4691 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4692 | return 1; |
| 4693 | } |
| 4694 | if (PyObject_HasAttrString(obj, "right")) { |
| 4695 | int res; |
| 4696 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4697 | if (tmp == NULL) goto failed; |
| 4698 | res = obj2ast_expr(tmp, &right, arena); |
| 4699 | if (res != 0) goto failed; |
| 4700 | Py_XDECREF(tmp); |
| 4701 | tmp = NULL; |
| 4702 | } else { |
| 4703 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4704 | return 1; |
| 4705 | } |
| 4706 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4707 | if (*out == NULL) goto failed; |
| 4708 | return 0; |
| 4709 | } |
| 4710 | if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) { |
| 4711 | unaryop_ty op; |
| 4712 | expr_ty operand; |
| 4713 | |
| 4714 | if (PyObject_HasAttrString(obj, "op")) { |
| 4715 | int res; |
| 4716 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4717 | if (tmp == NULL) goto failed; |
| 4718 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4719 | if (res != 0) goto failed; |
| 4720 | Py_XDECREF(tmp); |
| 4721 | tmp = NULL; |
| 4722 | } else { |
| 4723 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4724 | return 1; |
| 4725 | } |
| 4726 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4727 | int res; |
| 4728 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4729 | if (tmp == NULL) goto failed; |
| 4730 | res = obj2ast_expr(tmp, &operand, arena); |
| 4731 | if (res != 0) goto failed; |
| 4732 | Py_XDECREF(tmp); |
| 4733 | tmp = NULL; |
| 4734 | } else { |
| 4735 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4736 | return 1; |
| 4737 | } |
| 4738 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4739 | if (*out == NULL) goto failed; |
| 4740 | return 0; |
| 4741 | } |
| 4742 | if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) { |
| 4743 | arguments_ty args; |
| 4744 | expr_ty body; |
| 4745 | |
| 4746 | if (PyObject_HasAttrString(obj, "args")) { |
| 4747 | int res; |
| 4748 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4749 | if (tmp == NULL) goto failed; |
| 4750 | res = obj2ast_arguments(tmp, &args, arena); |
| 4751 | if (res != 0) goto failed; |
| 4752 | Py_XDECREF(tmp); |
| 4753 | tmp = NULL; |
| 4754 | } else { |
| 4755 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4756 | return 1; |
| 4757 | } |
| 4758 | if (PyObject_HasAttrString(obj, "body")) { |
| 4759 | int res; |
| 4760 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4761 | if (tmp == NULL) goto failed; |
| 4762 | res = obj2ast_expr(tmp, &body, arena); |
| 4763 | if (res != 0) goto failed; |
| 4764 | Py_XDECREF(tmp); |
| 4765 | tmp = NULL; |
| 4766 | } else { |
| 4767 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4768 | return 1; |
| 4769 | } |
| 4770 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4771 | if (*out == NULL) goto failed; |
| 4772 | return 0; |
| 4773 | } |
| 4774 | if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) { |
| 4775 | expr_ty test; |
| 4776 | expr_ty body; |
| 4777 | expr_ty orelse; |
| 4778 | |
| 4779 | if (PyObject_HasAttrString(obj, "test")) { |
| 4780 | int res; |
| 4781 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4782 | if (tmp == NULL) goto failed; |
| 4783 | res = obj2ast_expr(tmp, &test, arena); |
| 4784 | if (res != 0) goto failed; |
| 4785 | Py_XDECREF(tmp); |
| 4786 | tmp = NULL; |
| 4787 | } else { |
| 4788 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4789 | return 1; |
| 4790 | } |
| 4791 | if (PyObject_HasAttrString(obj, "body")) { |
| 4792 | int res; |
| 4793 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4794 | if (tmp == NULL) goto failed; |
| 4795 | res = obj2ast_expr(tmp, &body, arena); |
| 4796 | if (res != 0) goto failed; |
| 4797 | Py_XDECREF(tmp); |
| 4798 | tmp = NULL; |
| 4799 | } else { |
| 4800 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4801 | return 1; |
| 4802 | } |
| 4803 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4804 | int res; |
| 4805 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4806 | if (tmp == NULL) goto failed; |
| 4807 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4808 | if (res != 0) goto failed; |
| 4809 | Py_XDECREF(tmp); |
| 4810 | tmp = NULL; |
| 4811 | } else { |
| 4812 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4813 | return 1; |
| 4814 | } |
| 4815 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4816 | if (*out == NULL) goto failed; |
| 4817 | return 0; |
| 4818 | } |
| 4819 | if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) { |
| 4820 | asdl_seq* keys; |
| 4821 | asdl_seq* values; |
| 4822 | |
| 4823 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4824 | int res; |
| 4825 | Py_ssize_t len; |
| 4826 | Py_ssize_t i; |
| 4827 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4828 | if (tmp == NULL) goto failed; |
| 4829 | if (!PyList_Check(tmp)) { |
| 4830 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4831 | goto failed; |
| 4832 | } |
| 4833 | len = PyList_GET_SIZE(tmp); |
| 4834 | keys = asdl_seq_new(len, arena); |
| 4835 | if (keys == NULL) goto failed; |
| 4836 | for (i = 0; i < len; i++) { |
| 4837 | expr_ty value; |
| 4838 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4839 | if (res != 0) goto failed; |
| 4840 | asdl_seq_SET(keys, i, value); |
| 4841 | } |
| 4842 | Py_XDECREF(tmp); |
| 4843 | tmp = NULL; |
| 4844 | } else { |
| 4845 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4846 | return 1; |
| 4847 | } |
| 4848 | if (PyObject_HasAttrString(obj, "values")) { |
| 4849 | int res; |
| 4850 | Py_ssize_t len; |
| 4851 | Py_ssize_t i; |
| 4852 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4853 | if (tmp == NULL) goto failed; |
| 4854 | if (!PyList_Check(tmp)) { |
| 4855 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4856 | goto failed; |
| 4857 | } |
| 4858 | len = PyList_GET_SIZE(tmp); |
| 4859 | values = asdl_seq_new(len, arena); |
| 4860 | if (values == NULL) goto failed; |
| 4861 | for (i = 0; i < len; i++) { |
| 4862 | expr_ty value; |
| 4863 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4864 | if (res != 0) goto failed; |
| 4865 | asdl_seq_SET(values, i, value); |
| 4866 | } |
| 4867 | Py_XDECREF(tmp); |
| 4868 | tmp = NULL; |
| 4869 | } else { |
| 4870 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 4871 | return 1; |
| 4872 | } |
| 4873 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 4874 | if (*out == NULL) goto failed; |
| 4875 | return 0; |
| 4876 | } |
| 4877 | if (PyObject_IsInstance(obj, (PyObject*)Set_type)) { |
| 4878 | asdl_seq* elts; |
| 4879 | |
| 4880 | if (PyObject_HasAttrString(obj, "elts")) { |
| 4881 | int res; |
| 4882 | Py_ssize_t len; |
| 4883 | Py_ssize_t i; |
| 4884 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 4885 | if (tmp == NULL) goto failed; |
| 4886 | if (!PyList_Check(tmp)) { |
| 4887 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4888 | goto failed; |
| 4889 | } |
| 4890 | len = PyList_GET_SIZE(tmp); |
| 4891 | elts = asdl_seq_new(len, arena); |
| 4892 | if (elts == NULL) goto failed; |
| 4893 | for (i = 0; i < len; i++) { |
| 4894 | expr_ty value; |
| 4895 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4896 | if (res != 0) goto failed; |
| 4897 | asdl_seq_SET(elts, i, value); |
| 4898 | } |
| 4899 | Py_XDECREF(tmp); |
| 4900 | tmp = NULL; |
| 4901 | } else { |
| 4902 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 4903 | return 1; |
| 4904 | } |
| 4905 | *out = Set(elts, lineno, col_offset, arena); |
| 4906 | if (*out == NULL) goto failed; |
| 4907 | return 0; |
| 4908 | } |
| 4909 | if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) { |
| 4910 | expr_ty elt; |
| 4911 | asdl_seq* generators; |
| 4912 | |
| 4913 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4914 | int res; |
| 4915 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4916 | if (tmp == NULL) goto failed; |
| 4917 | res = obj2ast_expr(tmp, &elt, arena); |
| 4918 | if (res != 0) goto failed; |
| 4919 | Py_XDECREF(tmp); |
| 4920 | tmp = NULL; |
| 4921 | } else { |
| 4922 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 4923 | return 1; |
| 4924 | } |
| 4925 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4926 | int res; |
| 4927 | Py_ssize_t len; |
| 4928 | Py_ssize_t i; |
| 4929 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4930 | if (tmp == NULL) goto failed; |
| 4931 | if (!PyList_Check(tmp)) { |
| 4932 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4933 | goto failed; |
| 4934 | } |
| 4935 | len = PyList_GET_SIZE(tmp); |
| 4936 | generators = asdl_seq_new(len, arena); |
| 4937 | if (generators == NULL) goto failed; |
| 4938 | for (i = 0; i < len; i++) { |
| 4939 | comprehension_ty value; |
| 4940 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4941 | if (res != 0) goto failed; |
| 4942 | asdl_seq_SET(generators, i, value); |
| 4943 | } |
| 4944 | Py_XDECREF(tmp); |
| 4945 | tmp = NULL; |
| 4946 | } else { |
| 4947 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 4948 | return 1; |
| 4949 | } |
| 4950 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 4951 | if (*out == NULL) goto failed; |
| 4952 | return 0; |
| 4953 | } |
| 4954 | if (PyObject_IsInstance(obj, (PyObject*)SetComp_type)) { |
| 4955 | expr_ty elt; |
| 4956 | asdl_seq* generators; |
| 4957 | |
| 4958 | if (PyObject_HasAttrString(obj, "elt")) { |
| 4959 | int res; |
| 4960 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 4961 | if (tmp == NULL) goto failed; |
| 4962 | res = obj2ast_expr(tmp, &elt, arena); |
| 4963 | if (res != 0) goto failed; |
| 4964 | Py_XDECREF(tmp); |
| 4965 | tmp = NULL; |
| 4966 | } else { |
| 4967 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 4968 | return 1; |
| 4969 | } |
| 4970 | if (PyObject_HasAttrString(obj, "generators")) { |
| 4971 | int res; |
| 4972 | Py_ssize_t len; |
| 4973 | Py_ssize_t i; |
| 4974 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 4975 | if (tmp == NULL) goto failed; |
| 4976 | if (!PyList_Check(tmp)) { |
| 4977 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4978 | goto failed; |
| 4979 | } |
| 4980 | len = PyList_GET_SIZE(tmp); |
| 4981 | generators = asdl_seq_new(len, arena); |
| 4982 | if (generators == NULL) goto failed; |
| 4983 | for (i = 0; i < len; i++) { |
| 4984 | comprehension_ty value; |
| 4985 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4986 | if (res != 0) goto failed; |
| 4987 | asdl_seq_SET(generators, i, value); |
| 4988 | } |
| 4989 | Py_XDECREF(tmp); |
| 4990 | tmp = NULL; |
| 4991 | } else { |
| 4992 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 4993 | return 1; |
| 4994 | } |
| 4995 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 4996 | if (*out == NULL) goto failed; |
| 4997 | return 0; |
| 4998 | } |
| 4999 | if (PyObject_IsInstance(obj, (PyObject*)DictComp_type)) { |
| 5000 | expr_ty key; |
| 5001 | expr_ty value; |
| 5002 | asdl_seq* generators; |
| 5003 | |
| 5004 | if (PyObject_HasAttrString(obj, "key")) { |
| 5005 | int res; |
| 5006 | tmp = PyObject_GetAttrString(obj, "key"); |
| 5007 | if (tmp == NULL) goto failed; |
| 5008 | res = obj2ast_expr(tmp, &key, arena); |
| 5009 | if (res != 0) goto failed; |
| 5010 | Py_XDECREF(tmp); |
| 5011 | tmp = NULL; |
| 5012 | } else { |
| 5013 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5014 | return 1; |
| 5015 | } |
| 5016 | if (PyObject_HasAttrString(obj, "value")) { |
| 5017 | int res; |
| 5018 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5019 | if (tmp == NULL) goto failed; |
| 5020 | res = obj2ast_expr(tmp, &value, arena); |
| 5021 | if (res != 0) goto failed; |
| 5022 | Py_XDECREF(tmp); |
| 5023 | tmp = NULL; |
| 5024 | } else { |
| 5025 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5026 | return 1; |
| 5027 | } |
| 5028 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5029 | int res; |
| 5030 | Py_ssize_t len; |
| 5031 | Py_ssize_t i; |
| 5032 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5033 | if (tmp == NULL) goto failed; |
| 5034 | if (!PyList_Check(tmp)) { |
| 5035 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5036 | goto failed; |
| 5037 | } |
| 5038 | len = PyList_GET_SIZE(tmp); |
| 5039 | generators = asdl_seq_new(len, arena); |
| 5040 | if (generators == NULL) goto failed; |
| 5041 | for (i = 0; i < len; i++) { |
| 5042 | comprehension_ty value; |
| 5043 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5044 | if (res != 0) goto failed; |
| 5045 | asdl_seq_SET(generators, i, value); |
| 5046 | } |
| 5047 | Py_XDECREF(tmp); |
| 5048 | tmp = NULL; |
| 5049 | } else { |
| 5050 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5051 | return 1; |
| 5052 | } |
| 5053 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5054 | arena); |
| 5055 | if (*out == NULL) goto failed; |
| 5056 | return 0; |
| 5057 | } |
| 5058 | if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) { |
| 5059 | expr_ty elt; |
| 5060 | asdl_seq* generators; |
| 5061 | |
| 5062 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5063 | int res; |
| 5064 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5065 | if (tmp == NULL) goto failed; |
| 5066 | res = obj2ast_expr(tmp, &elt, arena); |
| 5067 | if (res != 0) goto failed; |
| 5068 | Py_XDECREF(tmp); |
| 5069 | tmp = NULL; |
| 5070 | } else { |
| 5071 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5072 | return 1; |
| 5073 | } |
| 5074 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5075 | int res; |
| 5076 | Py_ssize_t len; |
| 5077 | Py_ssize_t i; |
| 5078 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5079 | if (tmp == NULL) goto failed; |
| 5080 | if (!PyList_Check(tmp)) { |
| 5081 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5082 | goto failed; |
| 5083 | } |
| 5084 | len = PyList_GET_SIZE(tmp); |
| 5085 | generators = asdl_seq_new(len, arena); |
| 5086 | if (generators == NULL) goto failed; |
| 5087 | for (i = 0; i < len; i++) { |
| 5088 | comprehension_ty value; |
| 5089 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5090 | if (res != 0) goto failed; |
| 5091 | asdl_seq_SET(generators, i, value); |
| 5092 | } |
| 5093 | Py_XDECREF(tmp); |
| 5094 | tmp = NULL; |
| 5095 | } else { |
| 5096 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5097 | return 1; |
| 5098 | } |
| 5099 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5100 | if (*out == NULL) goto failed; |
| 5101 | return 0; |
| 5102 | } |
| 5103 | if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) { |
| 5104 | expr_ty value; |
| 5105 | |
| 5106 | if (PyObject_HasAttrString(obj, "value")) { |
| 5107 | int res; |
| 5108 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5109 | if (tmp == NULL) goto failed; |
| 5110 | res = obj2ast_expr(tmp, &value, arena); |
| 5111 | if (res != 0) goto failed; |
| 5112 | Py_XDECREF(tmp); |
| 5113 | tmp = NULL; |
| 5114 | } else { |
| 5115 | value = NULL; |
| 5116 | } |
| 5117 | *out = Yield(value, lineno, col_offset, arena); |
| 5118 | if (*out == NULL) goto failed; |
| 5119 | return 0; |
| 5120 | } |
| 5121 | if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) { |
| 5122 | expr_ty left; |
| 5123 | asdl_int_seq* ops; |
| 5124 | asdl_seq* comparators; |
| 5125 | |
| 5126 | if (PyObject_HasAttrString(obj, "left")) { |
| 5127 | int res; |
| 5128 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5129 | if (tmp == NULL) goto failed; |
| 5130 | res = obj2ast_expr(tmp, &left, arena); |
| 5131 | if (res != 0) goto failed; |
| 5132 | Py_XDECREF(tmp); |
| 5133 | tmp = NULL; |
| 5134 | } else { |
| 5135 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5136 | return 1; |
| 5137 | } |
| 5138 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5139 | int res; |
| 5140 | Py_ssize_t len; |
| 5141 | Py_ssize_t i; |
| 5142 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5143 | if (tmp == NULL) goto failed; |
| 5144 | if (!PyList_Check(tmp)) { |
| 5145 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5146 | goto failed; |
| 5147 | } |
| 5148 | len = PyList_GET_SIZE(tmp); |
| 5149 | ops = asdl_int_seq_new(len, arena); |
| 5150 | if (ops == NULL) goto failed; |
| 5151 | for (i = 0; i < len; i++) { |
| 5152 | cmpop_ty value; |
| 5153 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5154 | if (res != 0) goto failed; |
| 5155 | asdl_seq_SET(ops, i, value); |
| 5156 | } |
| 5157 | Py_XDECREF(tmp); |
| 5158 | tmp = NULL; |
| 5159 | } else { |
| 5160 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5161 | return 1; |
| 5162 | } |
| 5163 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5164 | int res; |
| 5165 | Py_ssize_t len; |
| 5166 | Py_ssize_t i; |
| 5167 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5168 | if (tmp == NULL) goto failed; |
| 5169 | if (!PyList_Check(tmp)) { |
| 5170 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5171 | goto failed; |
| 5172 | } |
| 5173 | len = PyList_GET_SIZE(tmp); |
| 5174 | comparators = asdl_seq_new(len, arena); |
| 5175 | if (comparators == NULL) goto failed; |
| 5176 | for (i = 0; i < len; i++) { |
| 5177 | expr_ty value; |
| 5178 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5179 | if (res != 0) goto failed; |
| 5180 | asdl_seq_SET(comparators, i, value); |
| 5181 | } |
| 5182 | Py_XDECREF(tmp); |
| 5183 | tmp = NULL; |
| 5184 | } else { |
| 5185 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5186 | return 1; |
| 5187 | } |
| 5188 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5189 | arena); |
| 5190 | if (*out == NULL) goto failed; |
| 5191 | return 0; |
| 5192 | } |
| 5193 | if (PyObject_IsInstance(obj, (PyObject*)Call_type)) { |
| 5194 | expr_ty func; |
| 5195 | asdl_seq* args; |
| 5196 | asdl_seq* keywords; |
| 5197 | expr_ty starargs; |
| 5198 | expr_ty kwargs; |
| 5199 | |
| 5200 | if (PyObject_HasAttrString(obj, "func")) { |
| 5201 | int res; |
| 5202 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5203 | if (tmp == NULL) goto failed; |
| 5204 | res = obj2ast_expr(tmp, &func, arena); |
| 5205 | if (res != 0) goto failed; |
| 5206 | Py_XDECREF(tmp); |
| 5207 | tmp = NULL; |
| 5208 | } else { |
| 5209 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5210 | return 1; |
| 5211 | } |
| 5212 | if (PyObject_HasAttrString(obj, "args")) { |
| 5213 | int res; |
| 5214 | Py_ssize_t len; |
| 5215 | Py_ssize_t i; |
| 5216 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5217 | if (tmp == NULL) goto failed; |
| 5218 | if (!PyList_Check(tmp)) { |
| 5219 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5220 | goto failed; |
| 5221 | } |
| 5222 | len = PyList_GET_SIZE(tmp); |
| 5223 | args = asdl_seq_new(len, arena); |
| 5224 | if (args == NULL) goto failed; |
| 5225 | for (i = 0; i < len; i++) { |
| 5226 | expr_ty value; |
| 5227 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5228 | if (res != 0) goto failed; |
| 5229 | asdl_seq_SET(args, i, value); |
| 5230 | } |
| 5231 | Py_XDECREF(tmp); |
| 5232 | tmp = NULL; |
| 5233 | } else { |
| 5234 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5235 | return 1; |
| 5236 | } |
| 5237 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5238 | int res; |
| 5239 | Py_ssize_t len; |
| 5240 | Py_ssize_t i; |
| 5241 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5242 | if (tmp == NULL) goto failed; |
| 5243 | if (!PyList_Check(tmp)) { |
| 5244 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5245 | goto failed; |
| 5246 | } |
| 5247 | len = PyList_GET_SIZE(tmp); |
| 5248 | keywords = asdl_seq_new(len, arena); |
| 5249 | if (keywords == NULL) goto failed; |
| 5250 | for (i = 0; i < len; i++) { |
| 5251 | keyword_ty value; |
| 5252 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5253 | if (res != 0) goto failed; |
| 5254 | asdl_seq_SET(keywords, i, value); |
| 5255 | } |
| 5256 | Py_XDECREF(tmp); |
| 5257 | tmp = NULL; |
| 5258 | } else { |
| 5259 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5260 | return 1; |
| 5261 | } |
| 5262 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5263 | int res; |
| 5264 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5265 | if (tmp == NULL) goto failed; |
| 5266 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5267 | if (res != 0) goto failed; |
| 5268 | Py_XDECREF(tmp); |
| 5269 | tmp = NULL; |
| 5270 | } else { |
| 5271 | starargs = NULL; |
| 5272 | } |
| 5273 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5274 | int res; |
| 5275 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5276 | if (tmp == NULL) goto failed; |
| 5277 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5278 | if (res != 0) goto failed; |
| 5279 | Py_XDECREF(tmp); |
| 5280 | tmp = NULL; |
| 5281 | } else { |
| 5282 | kwargs = NULL; |
| 5283 | } |
| 5284 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5285 | col_offset, arena); |
| 5286 | if (*out == NULL) goto failed; |
| 5287 | return 0; |
| 5288 | } |
| 5289 | if (PyObject_IsInstance(obj, (PyObject*)Num_type)) { |
| 5290 | object n; |
| 5291 | |
| 5292 | if (PyObject_HasAttrString(obj, "n")) { |
| 5293 | int res; |
| 5294 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5295 | if (tmp == NULL) goto failed; |
| 5296 | res = obj2ast_object(tmp, &n, arena); |
| 5297 | if (res != 0) goto failed; |
| 5298 | Py_XDECREF(tmp); |
| 5299 | tmp = NULL; |
| 5300 | } else { |
| 5301 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5302 | return 1; |
| 5303 | } |
| 5304 | *out = Num(n, lineno, col_offset, arena); |
| 5305 | if (*out == NULL) goto failed; |
| 5306 | return 0; |
| 5307 | } |
| 5308 | if (PyObject_IsInstance(obj, (PyObject*)Str_type)) { |
| 5309 | string s; |
| 5310 | |
| 5311 | if (PyObject_HasAttrString(obj, "s")) { |
| 5312 | int res; |
| 5313 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5314 | if (tmp == NULL) goto failed; |
| 5315 | res = obj2ast_string(tmp, &s, arena); |
| 5316 | if (res != 0) goto failed; |
| 5317 | Py_XDECREF(tmp); |
| 5318 | tmp = NULL; |
| 5319 | } else { |
| 5320 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5321 | return 1; |
| 5322 | } |
| 5323 | *out = Str(s, lineno, col_offset, arena); |
| 5324 | if (*out == NULL) goto failed; |
| 5325 | return 0; |
| 5326 | } |
| 5327 | if (PyObject_IsInstance(obj, (PyObject*)Bytes_type)) { |
| 5328 | string s; |
| 5329 | |
| 5330 | if (PyObject_HasAttrString(obj, "s")) { |
| 5331 | int res; |
| 5332 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5333 | if (tmp == NULL) goto failed; |
| 5334 | res = obj2ast_string(tmp, &s, arena); |
| 5335 | if (res != 0) goto failed; |
| 5336 | Py_XDECREF(tmp); |
| 5337 | tmp = NULL; |
| 5338 | } else { |
| 5339 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5340 | return 1; |
| 5341 | } |
| 5342 | *out = Bytes(s, lineno, col_offset, arena); |
| 5343 | if (*out == NULL) goto failed; |
| 5344 | return 0; |
| 5345 | } |
| 5346 | if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) { |
| 5347 | |
| 5348 | *out = Ellipsis(lineno, col_offset, arena); |
| 5349 | if (*out == NULL) goto failed; |
| 5350 | return 0; |
| 5351 | } |
| 5352 | if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) { |
| 5353 | expr_ty value; |
| 5354 | identifier attr; |
| 5355 | expr_context_ty ctx; |
| 5356 | |
| 5357 | if (PyObject_HasAttrString(obj, "value")) { |
| 5358 | int res; |
| 5359 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5360 | if (tmp == NULL) goto failed; |
| 5361 | res = obj2ast_expr(tmp, &value, arena); |
| 5362 | if (res != 0) goto failed; |
| 5363 | Py_XDECREF(tmp); |
| 5364 | tmp = NULL; |
| 5365 | } else { |
| 5366 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5367 | return 1; |
| 5368 | } |
| 5369 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5370 | int res; |
| 5371 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5372 | if (tmp == NULL) goto failed; |
| 5373 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5374 | if (res != 0) goto failed; |
| 5375 | Py_XDECREF(tmp); |
| 5376 | tmp = NULL; |
| 5377 | } else { |
| 5378 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5379 | return 1; |
| 5380 | } |
| 5381 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5382 | int res; |
| 5383 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5384 | if (tmp == NULL) goto failed; |
| 5385 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5386 | if (res != 0) goto failed; |
| 5387 | Py_XDECREF(tmp); |
| 5388 | tmp = NULL; |
| 5389 | } else { |
| 5390 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5391 | return 1; |
| 5392 | } |
| 5393 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5394 | if (*out == NULL) goto failed; |
| 5395 | return 0; |
| 5396 | } |
| 5397 | if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) { |
| 5398 | expr_ty value; |
| 5399 | slice_ty slice; |
| 5400 | expr_context_ty ctx; |
| 5401 | |
| 5402 | if (PyObject_HasAttrString(obj, "value")) { |
| 5403 | int res; |
| 5404 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5405 | if (tmp == NULL) goto failed; |
| 5406 | res = obj2ast_expr(tmp, &value, arena); |
| 5407 | if (res != 0) goto failed; |
| 5408 | Py_XDECREF(tmp); |
| 5409 | tmp = NULL; |
| 5410 | } else { |
| 5411 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5412 | return 1; |
| 5413 | } |
| 5414 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5415 | int res; |
| 5416 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5417 | if (tmp == NULL) goto failed; |
| 5418 | res = obj2ast_slice(tmp, &slice, arena); |
| 5419 | if (res != 0) goto failed; |
| 5420 | Py_XDECREF(tmp); |
| 5421 | tmp = NULL; |
| 5422 | } else { |
| 5423 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5424 | return 1; |
| 5425 | } |
| 5426 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5427 | int res; |
| 5428 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5429 | if (tmp == NULL) goto failed; |
| 5430 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5431 | if (res != 0) goto failed; |
| 5432 | Py_XDECREF(tmp); |
| 5433 | tmp = NULL; |
| 5434 | } else { |
| 5435 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5436 | return 1; |
| 5437 | } |
| 5438 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5439 | if (*out == NULL) goto failed; |
| 5440 | return 0; |
| 5441 | } |
| 5442 | if (PyObject_IsInstance(obj, (PyObject*)Starred_type)) { |
| 5443 | expr_ty value; |
| 5444 | expr_context_ty ctx; |
| 5445 | |
| 5446 | if (PyObject_HasAttrString(obj, "value")) { |
| 5447 | int res; |
| 5448 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5449 | if (tmp == NULL) goto failed; |
| 5450 | res = obj2ast_expr(tmp, &value, arena); |
| 5451 | if (res != 0) goto failed; |
| 5452 | Py_XDECREF(tmp); |
| 5453 | tmp = NULL; |
| 5454 | } else { |
| 5455 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5456 | return 1; |
| 5457 | } |
| 5458 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5459 | int res; |
| 5460 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5461 | if (tmp == NULL) goto failed; |
| 5462 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5463 | if (res != 0) goto failed; |
| 5464 | Py_XDECREF(tmp); |
| 5465 | tmp = NULL; |
| 5466 | } else { |
| 5467 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5468 | return 1; |
| 5469 | } |
| 5470 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5471 | if (*out == NULL) goto failed; |
| 5472 | return 0; |
| 5473 | } |
| 5474 | if (PyObject_IsInstance(obj, (PyObject*)Name_type)) { |
| 5475 | identifier id; |
| 5476 | expr_context_ty ctx; |
| 5477 | |
| 5478 | if (PyObject_HasAttrString(obj, "id")) { |
| 5479 | int res; |
| 5480 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5481 | if (tmp == NULL) goto failed; |
| 5482 | res = obj2ast_identifier(tmp, &id, arena); |
| 5483 | if (res != 0) goto failed; |
| 5484 | Py_XDECREF(tmp); |
| 5485 | tmp = NULL; |
| 5486 | } else { |
| 5487 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5488 | return 1; |
| 5489 | } |
| 5490 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5491 | int res; |
| 5492 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5493 | if (tmp == NULL) goto failed; |
| 5494 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5495 | if (res != 0) goto failed; |
| 5496 | Py_XDECREF(tmp); |
| 5497 | tmp = NULL; |
| 5498 | } else { |
| 5499 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5500 | return 1; |
| 5501 | } |
| 5502 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5503 | if (*out == NULL) goto failed; |
| 5504 | return 0; |
| 5505 | } |
| 5506 | if (PyObject_IsInstance(obj, (PyObject*)List_type)) { |
| 5507 | asdl_seq* elts; |
| 5508 | expr_context_ty ctx; |
| 5509 | |
| 5510 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5511 | int res; |
| 5512 | Py_ssize_t len; |
| 5513 | Py_ssize_t i; |
| 5514 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5515 | if (tmp == NULL) goto failed; |
| 5516 | if (!PyList_Check(tmp)) { |
| 5517 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5518 | goto failed; |
| 5519 | } |
| 5520 | len = PyList_GET_SIZE(tmp); |
| 5521 | elts = asdl_seq_new(len, arena); |
| 5522 | if (elts == NULL) goto failed; |
| 5523 | for (i = 0; i < len; i++) { |
| 5524 | expr_ty value; |
| 5525 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5526 | if (res != 0) goto failed; |
| 5527 | asdl_seq_SET(elts, i, value); |
| 5528 | } |
| 5529 | Py_XDECREF(tmp); |
| 5530 | tmp = NULL; |
| 5531 | } else { |
| 5532 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5533 | return 1; |
| 5534 | } |
| 5535 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5536 | int res; |
| 5537 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5538 | if (tmp == NULL) goto failed; |
| 5539 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5540 | if (res != 0) goto failed; |
| 5541 | Py_XDECREF(tmp); |
| 5542 | tmp = NULL; |
| 5543 | } else { |
| 5544 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5545 | return 1; |
| 5546 | } |
| 5547 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5548 | if (*out == NULL) goto failed; |
| 5549 | return 0; |
| 5550 | } |
| 5551 | if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) { |
| 5552 | asdl_seq* elts; |
| 5553 | expr_context_ty ctx; |
| 5554 | |
| 5555 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5556 | int res; |
| 5557 | Py_ssize_t len; |
| 5558 | Py_ssize_t i; |
| 5559 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5560 | if (tmp == NULL) goto failed; |
| 5561 | if (!PyList_Check(tmp)) { |
| 5562 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5563 | goto failed; |
| 5564 | } |
| 5565 | len = PyList_GET_SIZE(tmp); |
| 5566 | elts = asdl_seq_new(len, arena); |
| 5567 | if (elts == NULL) goto failed; |
| 5568 | for (i = 0; i < len; i++) { |
| 5569 | expr_ty value; |
| 5570 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5571 | if (res != 0) goto failed; |
| 5572 | asdl_seq_SET(elts, i, value); |
| 5573 | } |
| 5574 | Py_XDECREF(tmp); |
| 5575 | tmp = NULL; |
| 5576 | } else { |
| 5577 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5578 | return 1; |
| 5579 | } |
| 5580 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5581 | int res; |
| 5582 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5583 | if (tmp == NULL) goto failed; |
| 5584 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5585 | if (res != 0) goto failed; |
| 5586 | Py_XDECREF(tmp); |
| 5587 | tmp = NULL; |
| 5588 | } else { |
| 5589 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5590 | return 1; |
| 5591 | } |
| 5592 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5593 | if (*out == NULL) goto failed; |
| 5594 | return 0; |
| 5595 | } |
| 5596 | |
| 5597 | tmp = PyObject_Repr(obj); |
| 5598 | if (tmp == NULL) goto failed; |
| 5599 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp)); |
| 5600 | failed: |
| 5601 | Py_XDECREF(tmp); |
| 5602 | return 1; |
| 5603 | } |
| 5604 | |
| 5605 | int |
| 5606 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5607 | { |
| 5608 | PyObject* tmp = NULL; |
| 5609 | |
| 5610 | if (PyObject_IsInstance(obj, (PyObject*)Load_type)) { |
| 5611 | *out = Load; |
| 5612 | return 0; |
| 5613 | } |
| 5614 | if (PyObject_IsInstance(obj, (PyObject*)Store_type)) { |
| 5615 | *out = Store; |
| 5616 | return 0; |
| 5617 | } |
| 5618 | if (PyObject_IsInstance(obj, (PyObject*)Del_type)) { |
| 5619 | *out = Del; |
| 5620 | return 0; |
| 5621 | } |
| 5622 | if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) { |
| 5623 | *out = AugLoad; |
| 5624 | return 0; |
| 5625 | } |
| 5626 | if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) { |
| 5627 | *out = AugStore; |
| 5628 | return 0; |
| 5629 | } |
| 5630 | if (PyObject_IsInstance(obj, (PyObject*)Param_type)) { |
| 5631 | *out = Param; |
| 5632 | return 0; |
| 5633 | } |
| 5634 | |
| 5635 | tmp = PyObject_Repr(obj); |
| 5636 | if (tmp == NULL) goto failed; |
| 5637 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp)); |
| 5638 | failed: |
| 5639 | Py_XDECREF(tmp); |
| 5640 | return 1; |
| 5641 | } |
| 5642 | |
| 5643 | int |
| 5644 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5645 | { |
| 5646 | PyObject* tmp = NULL; |
| 5647 | |
| 5648 | |
| 5649 | if (obj == Py_None) { |
| 5650 | *out = NULL; |
| 5651 | return 0; |
| 5652 | } |
| 5653 | if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) { |
| 5654 | expr_ty lower; |
| 5655 | expr_ty upper; |
| 5656 | expr_ty step; |
| 5657 | |
| 5658 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5659 | int res; |
| 5660 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5661 | if (tmp == NULL) goto failed; |
| 5662 | res = obj2ast_expr(tmp, &lower, arena); |
| 5663 | if (res != 0) goto failed; |
| 5664 | Py_XDECREF(tmp); |
| 5665 | tmp = NULL; |
| 5666 | } else { |
| 5667 | lower = NULL; |
| 5668 | } |
| 5669 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5670 | int res; |
| 5671 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5672 | if (tmp == NULL) goto failed; |
| 5673 | res = obj2ast_expr(tmp, &upper, arena); |
| 5674 | if (res != 0) goto failed; |
| 5675 | Py_XDECREF(tmp); |
| 5676 | tmp = NULL; |
| 5677 | } else { |
| 5678 | upper = NULL; |
| 5679 | } |
| 5680 | if (PyObject_HasAttrString(obj, "step")) { |
| 5681 | int res; |
| 5682 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5683 | if (tmp == NULL) goto failed; |
| 5684 | res = obj2ast_expr(tmp, &step, arena); |
| 5685 | if (res != 0) goto failed; |
| 5686 | Py_XDECREF(tmp); |
| 5687 | tmp = NULL; |
| 5688 | } else { |
| 5689 | step = NULL; |
| 5690 | } |
| 5691 | *out = Slice(lower, upper, step, arena); |
| 5692 | if (*out == NULL) goto failed; |
| 5693 | return 0; |
| 5694 | } |
| 5695 | if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) { |
| 5696 | asdl_seq* dims; |
| 5697 | |
| 5698 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5699 | int res; |
| 5700 | Py_ssize_t len; |
| 5701 | Py_ssize_t i; |
| 5702 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5703 | if (tmp == NULL) goto failed; |
| 5704 | if (!PyList_Check(tmp)) { |
| 5705 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5706 | goto failed; |
| 5707 | } |
| 5708 | len = PyList_GET_SIZE(tmp); |
| 5709 | dims = asdl_seq_new(len, arena); |
| 5710 | if (dims == NULL) goto failed; |
| 5711 | for (i = 0; i < len; i++) { |
| 5712 | slice_ty value; |
| 5713 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5714 | if (res != 0) goto failed; |
| 5715 | asdl_seq_SET(dims, i, value); |
| 5716 | } |
| 5717 | Py_XDECREF(tmp); |
| 5718 | tmp = NULL; |
| 5719 | } else { |
| 5720 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5721 | return 1; |
| 5722 | } |
| 5723 | *out = ExtSlice(dims, arena); |
| 5724 | if (*out == NULL) goto failed; |
| 5725 | return 0; |
| 5726 | } |
| 5727 | if (PyObject_IsInstance(obj, (PyObject*)Index_type)) { |
| 5728 | expr_ty value; |
| 5729 | |
| 5730 | if (PyObject_HasAttrString(obj, "value")) { |
| 5731 | int res; |
| 5732 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5733 | if (tmp == NULL) goto failed; |
| 5734 | res = obj2ast_expr(tmp, &value, arena); |
| 5735 | if (res != 0) goto failed; |
| 5736 | Py_XDECREF(tmp); |
| 5737 | tmp = NULL; |
| 5738 | } else { |
| 5739 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5740 | return 1; |
| 5741 | } |
| 5742 | *out = Index(value, arena); |
| 5743 | if (*out == NULL) goto failed; |
| 5744 | return 0; |
| 5745 | } |
| 5746 | |
| 5747 | tmp = PyObject_Repr(obj); |
| 5748 | if (tmp == NULL) goto failed; |
| 5749 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp)); |
| 5750 | failed: |
| 5751 | Py_XDECREF(tmp); |
| 5752 | return 1; |
| 5753 | } |
| 5754 | |
| 5755 | int |
| 5756 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5757 | { |
| 5758 | PyObject* tmp = NULL; |
| 5759 | |
| 5760 | if (PyObject_IsInstance(obj, (PyObject*)And_type)) { |
| 5761 | *out = And; |
| 5762 | return 0; |
| 5763 | } |
| 5764 | if (PyObject_IsInstance(obj, (PyObject*)Or_type)) { |
| 5765 | *out = Or; |
| 5766 | return 0; |
| 5767 | } |
| 5768 | |
| 5769 | tmp = PyObject_Repr(obj); |
| 5770 | if (tmp == NULL) goto failed; |
| 5771 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5772 | failed: |
| 5773 | Py_XDECREF(tmp); |
| 5774 | return 1; |
| 5775 | } |
| 5776 | |
| 5777 | int |
| 5778 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 5779 | { |
| 5780 | PyObject* tmp = NULL; |
| 5781 | |
| 5782 | if (PyObject_IsInstance(obj, (PyObject*)Add_type)) { |
| 5783 | *out = Add; |
| 5784 | return 0; |
| 5785 | } |
| 5786 | if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) { |
| 5787 | *out = Sub; |
| 5788 | return 0; |
| 5789 | } |
| 5790 | if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) { |
| 5791 | *out = Mult; |
| 5792 | return 0; |
| 5793 | } |
| 5794 | if (PyObject_IsInstance(obj, (PyObject*)Div_type)) { |
| 5795 | *out = Div; |
| 5796 | return 0; |
| 5797 | } |
| 5798 | if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) { |
| 5799 | *out = Mod; |
| 5800 | return 0; |
| 5801 | } |
| 5802 | if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) { |
| 5803 | *out = Pow; |
| 5804 | return 0; |
| 5805 | } |
| 5806 | if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) { |
| 5807 | *out = LShift; |
| 5808 | return 0; |
| 5809 | } |
| 5810 | if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) { |
| 5811 | *out = RShift; |
| 5812 | return 0; |
| 5813 | } |
| 5814 | if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) { |
| 5815 | *out = BitOr; |
| 5816 | return 0; |
| 5817 | } |
| 5818 | if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) { |
| 5819 | *out = BitXor; |
| 5820 | return 0; |
| 5821 | } |
| 5822 | if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) { |
| 5823 | *out = BitAnd; |
| 5824 | return 0; |
| 5825 | } |
| 5826 | if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) { |
| 5827 | *out = FloorDiv; |
| 5828 | return 0; |
| 5829 | } |
| 5830 | |
| 5831 | tmp = PyObject_Repr(obj); |
| 5832 | if (tmp == NULL) goto failed; |
| 5833 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp)); |
| 5834 | failed: |
| 5835 | Py_XDECREF(tmp); |
| 5836 | return 1; |
| 5837 | } |
| 5838 | |
| 5839 | int |
| 5840 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 5841 | { |
| 5842 | PyObject* tmp = NULL; |
| 5843 | |
| 5844 | if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) { |
| 5845 | *out = Invert; |
| 5846 | return 0; |
| 5847 | } |
| 5848 | if (PyObject_IsInstance(obj, (PyObject*)Not_type)) { |
| 5849 | *out = Not; |
| 5850 | return 0; |
| 5851 | } |
| 5852 | if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) { |
| 5853 | *out = UAdd; |
| 5854 | return 0; |
| 5855 | } |
| 5856 | if (PyObject_IsInstance(obj, (PyObject*)USub_type)) { |
| 5857 | *out = USub; |
| 5858 | return 0; |
| 5859 | } |
| 5860 | |
| 5861 | tmp = PyObject_Repr(obj); |
| 5862 | if (tmp == NULL) goto failed; |
| 5863 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5864 | failed: |
| 5865 | Py_XDECREF(tmp); |
| 5866 | return 1; |
| 5867 | } |
| 5868 | |
| 5869 | int |
| 5870 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 5871 | { |
| 5872 | PyObject* tmp = NULL; |
| 5873 | |
| 5874 | if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) { |
| 5875 | *out = Eq; |
| 5876 | return 0; |
| 5877 | } |
| 5878 | if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) { |
| 5879 | *out = NotEq; |
| 5880 | return 0; |
| 5881 | } |
| 5882 | if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) { |
| 5883 | *out = Lt; |
| 5884 | return 0; |
| 5885 | } |
| 5886 | if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) { |
| 5887 | *out = LtE; |
| 5888 | return 0; |
| 5889 | } |
| 5890 | if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) { |
| 5891 | *out = Gt; |
| 5892 | return 0; |
| 5893 | } |
| 5894 | if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) { |
| 5895 | *out = GtE; |
| 5896 | return 0; |
| 5897 | } |
| 5898 | if (PyObject_IsInstance(obj, (PyObject*)Is_type)) { |
| 5899 | *out = Is; |
| 5900 | return 0; |
| 5901 | } |
| 5902 | if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) { |
| 5903 | *out = IsNot; |
| 5904 | return 0; |
| 5905 | } |
| 5906 | if (PyObject_IsInstance(obj, (PyObject*)In_type)) { |
| 5907 | *out = In; |
| 5908 | return 0; |
| 5909 | } |
| 5910 | if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) { |
| 5911 | *out = NotIn; |
| 5912 | return 0; |
| 5913 | } |
| 5914 | |
| 5915 | tmp = PyObject_Repr(obj); |
| 5916 | if (tmp == NULL) goto failed; |
| 5917 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp)); |
| 5918 | failed: |
| 5919 | Py_XDECREF(tmp); |
| 5920 | return 1; |
| 5921 | } |
| 5922 | |
| 5923 | int |
| 5924 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 5925 | { |
| 5926 | PyObject* tmp = NULL; |
| 5927 | expr_ty target; |
| 5928 | expr_ty iter; |
| 5929 | asdl_seq* ifs; |
| 5930 | |
| 5931 | if (PyObject_HasAttrString(obj, "target")) { |
| 5932 | int res; |
| 5933 | tmp = PyObject_GetAttrString(obj, "target"); |
| 5934 | if (tmp == NULL) goto failed; |
| 5935 | res = obj2ast_expr(tmp, &target, arena); |
| 5936 | if (res != 0) goto failed; |
| 5937 | Py_XDECREF(tmp); |
| 5938 | tmp = NULL; |
| 5939 | } else { |
| 5940 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 5941 | return 1; |
| 5942 | } |
| 5943 | if (PyObject_HasAttrString(obj, "iter")) { |
| 5944 | int res; |
| 5945 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 5946 | if (tmp == NULL) goto failed; |
| 5947 | res = obj2ast_expr(tmp, &iter, arena); |
| 5948 | if (res != 0) goto failed; |
| 5949 | Py_XDECREF(tmp); |
| 5950 | tmp = NULL; |
| 5951 | } else { |
| 5952 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 5953 | return 1; |
| 5954 | } |
| 5955 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 5956 | int res; |
| 5957 | Py_ssize_t len; |
| 5958 | Py_ssize_t i; |
| 5959 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 5960 | if (tmp == NULL) goto failed; |
| 5961 | if (!PyList_Check(tmp)) { |
| 5962 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5963 | goto failed; |
| 5964 | } |
| 5965 | len = PyList_GET_SIZE(tmp); |
| 5966 | ifs = asdl_seq_new(len, arena); |
| 5967 | if (ifs == NULL) goto failed; |
| 5968 | for (i = 0; i < len; i++) { |
| 5969 | expr_ty value; |
| 5970 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5971 | if (res != 0) goto failed; |
| 5972 | asdl_seq_SET(ifs, i, value); |
| 5973 | } |
| 5974 | Py_XDECREF(tmp); |
| 5975 | tmp = NULL; |
| 5976 | } else { |
| 5977 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 5978 | return 1; |
| 5979 | } |
| 5980 | *out = comprehension(target, iter, ifs, arena); |
| 5981 | return 0; |
| 5982 | failed: |
| 5983 | Py_XDECREF(tmp); |
| 5984 | return 1; |
| 5985 | } |
| 5986 | |
| 5987 | int |
| 5988 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 5989 | { |
| 5990 | PyObject* tmp = NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 5991 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5992 | int lineno; |
| 5993 | int col_offset; |
| 5994 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 5995 | if (obj == Py_None) { |
| 5996 | *out = NULL; |
| 5997 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5998 | } |
| 5999 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6000 | int res; |
| 6001 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6002 | if (tmp == NULL) goto failed; |
| 6003 | res = obj2ast_int(tmp, &lineno, arena); |
| 6004 | if (res != 0) goto failed; |
| 6005 | Py_XDECREF(tmp); |
| 6006 | tmp = NULL; |
| 6007 | } else { |
| 6008 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6009 | return 1; |
| 6010 | } |
| 6011 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6012 | int res; |
| 6013 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6014 | if (tmp == NULL) goto failed; |
| 6015 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6016 | if (res != 0) goto failed; |
| 6017 | Py_XDECREF(tmp); |
| 6018 | tmp = NULL; |
| 6019 | } else { |
| 6020 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6021 | return 1; |
| 6022 | } |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 6023 | if (PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type)) { |
| 6024 | expr_ty type; |
| 6025 | identifier name; |
| 6026 | asdl_seq* body; |
| 6027 | |
| 6028 | if (PyObject_HasAttrString(obj, "type")) { |
| 6029 | int res; |
| 6030 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6031 | if (tmp == NULL) goto failed; |
| 6032 | res = obj2ast_expr(tmp, &type, arena); |
| 6033 | if (res != 0) goto failed; |
| 6034 | Py_XDECREF(tmp); |
| 6035 | tmp = NULL; |
| 6036 | } else { |
| 6037 | type = NULL; |
| 6038 | } |
| 6039 | if (PyObject_HasAttrString(obj, "name")) { |
| 6040 | int res; |
| 6041 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6042 | if (tmp == NULL) goto failed; |
| 6043 | res = obj2ast_identifier(tmp, &name, arena); |
| 6044 | if (res != 0) goto failed; |
| 6045 | Py_XDECREF(tmp); |
| 6046 | tmp = NULL; |
| 6047 | } else { |
| 6048 | name = NULL; |
| 6049 | } |
| 6050 | if (PyObject_HasAttrString(obj, "body")) { |
| 6051 | int res; |
| 6052 | Py_ssize_t len; |
| 6053 | Py_ssize_t i; |
| 6054 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6055 | if (tmp == NULL) goto failed; |
| 6056 | if (!PyList_Check(tmp)) { |
| 6057 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6058 | goto failed; |
| 6059 | } |
| 6060 | len = PyList_GET_SIZE(tmp); |
| 6061 | body = asdl_seq_new(len, arena); |
| 6062 | if (body == NULL) goto failed; |
| 6063 | for (i = 0; i < len; i++) { |
| 6064 | stmt_ty value; |
| 6065 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6066 | if (res != 0) goto failed; |
| 6067 | asdl_seq_SET(body, i, value); |
| 6068 | } |
| 6069 | Py_XDECREF(tmp); |
| 6070 | tmp = NULL; |
| 6071 | } else { |
| 6072 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6073 | return 1; |
| 6074 | } |
| 6075 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6076 | arena); |
| 6077 | if (*out == NULL) goto failed; |
| 6078 | return 0; |
| 6079 | } |
| 6080 | |
| 6081 | tmp = PyObject_Repr(obj); |
| 6082 | if (tmp == NULL) goto failed; |
| 6083 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6084 | failed: |
| 6085 | Py_XDECREF(tmp); |
| 6086 | return 1; |
| 6087 | } |
| 6088 | |
| 6089 | int |
| 6090 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6091 | { |
| 6092 | PyObject* tmp = NULL; |
| 6093 | asdl_seq* args; |
| 6094 | identifier vararg; |
| 6095 | expr_ty varargannotation; |
| 6096 | asdl_seq* kwonlyargs; |
| 6097 | identifier kwarg; |
| 6098 | expr_ty kwargannotation; |
| 6099 | asdl_seq* defaults; |
| 6100 | asdl_seq* kw_defaults; |
| 6101 | |
| 6102 | if (PyObject_HasAttrString(obj, "args")) { |
| 6103 | int res; |
| 6104 | Py_ssize_t len; |
| 6105 | Py_ssize_t i; |
| 6106 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6107 | if (tmp == NULL) goto failed; |
| 6108 | if (!PyList_Check(tmp)) { |
| 6109 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6110 | goto failed; |
| 6111 | } |
| 6112 | len = PyList_GET_SIZE(tmp); |
| 6113 | args = asdl_seq_new(len, arena); |
| 6114 | if (args == NULL) goto failed; |
| 6115 | for (i = 0; i < len; i++) { |
| 6116 | arg_ty value; |
| 6117 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6118 | if (res != 0) goto failed; |
| 6119 | asdl_seq_SET(args, i, value); |
| 6120 | } |
| 6121 | Py_XDECREF(tmp); |
| 6122 | tmp = NULL; |
| 6123 | } else { |
| 6124 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6125 | return 1; |
| 6126 | } |
| 6127 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6128 | int res; |
| 6129 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6130 | if (tmp == NULL) goto failed; |
| 6131 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6132 | if (res != 0) goto failed; |
| 6133 | Py_XDECREF(tmp); |
| 6134 | tmp = NULL; |
| 6135 | } else { |
| 6136 | vararg = NULL; |
| 6137 | } |
| 6138 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6139 | int res; |
| 6140 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6141 | if (tmp == NULL) goto failed; |
| 6142 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6143 | if (res != 0) goto failed; |
| 6144 | Py_XDECREF(tmp); |
| 6145 | tmp = NULL; |
| 6146 | } else { |
| 6147 | varargannotation = NULL; |
| 6148 | } |
| 6149 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6150 | int res; |
| 6151 | Py_ssize_t len; |
| 6152 | Py_ssize_t i; |
| 6153 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6154 | if (tmp == NULL) goto failed; |
| 6155 | if (!PyList_Check(tmp)) { |
| 6156 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6157 | goto failed; |
| 6158 | } |
| 6159 | len = PyList_GET_SIZE(tmp); |
| 6160 | kwonlyargs = asdl_seq_new(len, arena); |
| 6161 | if (kwonlyargs == NULL) goto failed; |
| 6162 | for (i = 0; i < len; i++) { |
| 6163 | arg_ty value; |
| 6164 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6165 | if (res != 0) goto failed; |
| 6166 | asdl_seq_SET(kwonlyargs, i, value); |
| 6167 | } |
| 6168 | Py_XDECREF(tmp); |
| 6169 | tmp = NULL; |
| 6170 | } else { |
| 6171 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6175 | int res; |
| 6176 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6177 | if (tmp == NULL) goto failed; |
| 6178 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6179 | if (res != 0) goto failed; |
| 6180 | Py_XDECREF(tmp); |
| 6181 | tmp = NULL; |
| 6182 | } else { |
| 6183 | kwarg = NULL; |
| 6184 | } |
| 6185 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6186 | int res; |
| 6187 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6188 | if (tmp == NULL) goto failed; |
| 6189 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6190 | if (res != 0) goto failed; |
| 6191 | Py_XDECREF(tmp); |
| 6192 | tmp = NULL; |
| 6193 | } else { |
| 6194 | kwargannotation = NULL; |
| 6195 | } |
| 6196 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6197 | int res; |
| 6198 | Py_ssize_t len; |
| 6199 | Py_ssize_t i; |
| 6200 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6201 | if (tmp == NULL) goto failed; |
| 6202 | if (!PyList_Check(tmp)) { |
| 6203 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6204 | goto failed; |
| 6205 | } |
| 6206 | len = PyList_GET_SIZE(tmp); |
| 6207 | defaults = asdl_seq_new(len, arena); |
| 6208 | if (defaults == NULL) goto failed; |
| 6209 | for (i = 0; i < len; i++) { |
| 6210 | expr_ty value; |
| 6211 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6212 | if (res != 0) goto failed; |
| 6213 | asdl_seq_SET(defaults, i, value); |
| 6214 | } |
| 6215 | Py_XDECREF(tmp); |
| 6216 | tmp = NULL; |
| 6217 | } else { |
| 6218 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6219 | return 1; |
| 6220 | } |
| 6221 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6222 | int res; |
| 6223 | Py_ssize_t len; |
| 6224 | Py_ssize_t i; |
| 6225 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6226 | if (tmp == NULL) goto failed; |
| 6227 | if (!PyList_Check(tmp)) { |
| 6228 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6229 | goto failed; |
| 6230 | } |
| 6231 | len = PyList_GET_SIZE(tmp); |
| 6232 | kw_defaults = asdl_seq_new(len, arena); |
| 6233 | if (kw_defaults == NULL) goto failed; |
| 6234 | for (i = 0; i < len; i++) { |
| 6235 | expr_ty value; |
| 6236 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6237 | if (res != 0) goto failed; |
| 6238 | asdl_seq_SET(kw_defaults, i, value); |
| 6239 | } |
| 6240 | Py_XDECREF(tmp); |
| 6241 | tmp = NULL; |
| 6242 | } else { |
| 6243 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6244 | return 1; |
| 6245 | } |
| 6246 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6247 | kwargannotation, defaults, kw_defaults, arena); |
| 6248 | return 0; |
| 6249 | failed: |
| 6250 | Py_XDECREF(tmp); |
| 6251 | return 1; |
| 6252 | } |
| 6253 | |
| 6254 | int |
| 6255 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6256 | { |
| 6257 | PyObject* tmp = NULL; |
| 6258 | identifier arg; |
| 6259 | expr_ty annotation; |
| 6260 | |
| 6261 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6262 | int res; |
| 6263 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6264 | if (tmp == NULL) goto failed; |
| 6265 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6266 | if (res != 0) goto failed; |
| 6267 | Py_XDECREF(tmp); |
| 6268 | tmp = NULL; |
| 6269 | } else { |
| 6270 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6271 | return 1; |
| 6272 | } |
| 6273 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6274 | int res; |
| 6275 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6276 | if (tmp == NULL) goto failed; |
| 6277 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6278 | if (res != 0) goto failed; |
| 6279 | Py_XDECREF(tmp); |
| 6280 | tmp = NULL; |
| 6281 | } else { |
| 6282 | annotation = NULL; |
| 6283 | } |
| 6284 | *out = arg(arg, annotation, arena); |
| 6285 | return 0; |
| 6286 | failed: |
| 6287 | Py_XDECREF(tmp); |
| 6288 | return 1; |
| 6289 | } |
| 6290 | |
| 6291 | int |
| 6292 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6293 | { |
| 6294 | PyObject* tmp = NULL; |
| 6295 | identifier arg; |
| 6296 | expr_ty value; |
| 6297 | |
| 6298 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6299 | int res; |
| 6300 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6301 | if (tmp == NULL) goto failed; |
| 6302 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6303 | if (res != 0) goto failed; |
| 6304 | Py_XDECREF(tmp); |
| 6305 | tmp = NULL; |
| 6306 | } else { |
| 6307 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6308 | return 1; |
| 6309 | } |
| 6310 | if (PyObject_HasAttrString(obj, "value")) { |
| 6311 | int res; |
| 6312 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6313 | if (tmp == NULL) goto failed; |
| 6314 | res = obj2ast_expr(tmp, &value, arena); |
| 6315 | if (res != 0) goto failed; |
| 6316 | Py_XDECREF(tmp); |
| 6317 | tmp = NULL; |
| 6318 | } else { |
| 6319 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6320 | return 1; |
| 6321 | } |
| 6322 | *out = keyword(arg, value, arena); |
| 6323 | return 0; |
| 6324 | failed: |
| 6325 | Py_XDECREF(tmp); |
| 6326 | return 1; |
| 6327 | } |
| 6328 | |
| 6329 | int |
| 6330 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6331 | { |
| 6332 | PyObject* tmp = NULL; |
| 6333 | identifier name; |
| 6334 | identifier asname; |
| 6335 | |
| 6336 | if (PyObject_HasAttrString(obj, "name")) { |
| 6337 | int res; |
| 6338 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6339 | if (tmp == NULL) goto failed; |
| 6340 | res = obj2ast_identifier(tmp, &name, arena); |
| 6341 | if (res != 0) goto failed; |
| 6342 | Py_XDECREF(tmp); |
| 6343 | tmp = NULL; |
| 6344 | } else { |
| 6345 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6346 | return 1; |
| 6347 | } |
| 6348 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6349 | int res; |
| 6350 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6351 | if (tmp == NULL) goto failed; |
| 6352 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6353 | if (res != 0) goto failed; |
| 6354 | Py_XDECREF(tmp); |
| 6355 | tmp = NULL; |
| 6356 | } else { |
| 6357 | asname = NULL; |
| 6358 | } |
| 6359 | *out = alias(name, asname, arena); |
| 6360 | return 0; |
| 6361 | failed: |
| 6362 | Py_XDECREF(tmp); |
| 6363 | return 1; |
| 6364 | } |
| 6365 | |
| 6366 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6367 | PyMODINIT_FUNC |
| 6368 | init_ast(void) |
| 6369 | { |
| 6370 | PyObject *m, *d; |
| 6371 | if (!init_types()) return; |
| 6372 | m = Py_InitModule3("_ast", NULL, NULL); |
| 6373 | if (!m) return; |
| 6374 | d = PyModule_GetDict(m); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6375 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6376 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6377 | return; |
Christian Heimes | d3eb5a15 | 2008-02-24 00:38:49 +0000 | [diff] [blame] | 6378 | if (PyModule_AddStringConstant(m, "__version__", "57783") < 0) |
Martin v. Löwis | ace990c | 2006-02-28 00:32:31 +0000 | [diff] [blame] | 6379 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6380 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; |
| 6381 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 6382 | return; |
| 6383 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
| 6384 | < 0) return; |
| 6385 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
| 6386 | 0) return; |
| 6387 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return; |
| 6388 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return; |
| 6389 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
| 6390 | < 0) return; |
| 6391 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 6392 | return; |
| 6393 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
| 6394 | return; |
| 6395 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
| 6396 | return; |
| 6397 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
| 6398 | return; |
| 6399 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
| 6400 | 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6401 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; |
| 6402 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; |
| 6403 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; |
| 6404 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; |
| 6405 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; |
| 6406 | if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
| 6407 | 0) return; |
| 6408 | if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
| 6409 | 0) return; |
| 6410 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
| 6411 | return; |
| 6412 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
| 6413 | return; |
| 6414 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
| 6415 | 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6416 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
| 6417 | return; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6418 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 6419 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6420 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return; |
| 6421 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return; |
| 6422 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return; |
| 6423 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 6424 | return; |
| 6425 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return; |
| 6426 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
| 6427 | return; |
| 6428 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return; |
| 6429 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
| 6430 | return; |
| 6431 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 6432 | return; |
| 6433 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 6434 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 6435 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6436 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 6437 | return; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6438 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
| 6439 | return; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6440 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 6441 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6442 | if (PyDict_SetItemString(d, "GeneratorExp", |
| 6443 | (PyObject*)GeneratorExp_type) < 0) return; |
| 6444 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
| 6445 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 6446 | return; |
| 6447 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6448 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; |
| 6449 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 6450 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6451 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 6452 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6453 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
| 6454 | 0) return; |
| 6455 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
| 6456 | 0) return; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6457 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
| 6458 | return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6459 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; |
| 6460 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return; |
| 6461 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return; |
| 6462 | if (PyDict_SetItemString(d, "expr_context", |
| 6463 | (PyObject*)expr_context_type) < 0) return; |
| 6464 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return; |
| 6465 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return; |
| 6466 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return; |
| 6467 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
| 6468 | return; |
| 6469 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 6470 | return; |
| 6471 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; |
| 6472 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6473 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; |
| 6474 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 6475 | return; |
| 6476 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; |
| 6477 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
| 6478 | return; |
| 6479 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return; |
| 6480 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return; |
| 6481 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 6482 | return; |
| 6483 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return; |
| 6484 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return; |
| 6485 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return; |
| 6486 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return; |
| 6487 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return; |
| 6488 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return; |
| 6489 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
| 6490 | return; |
| 6491 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
| 6492 | return; |
| 6493 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return; |
| 6494 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
| 6495 | return; |
| 6496 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
| 6497 | return; |
| 6498 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 6499 | return; |
| 6500 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
| 6501 | return; |
| 6502 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
| 6503 | return; |
| 6504 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return; |
| 6505 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return; |
| 6506 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return; |
| 6507 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return; |
| 6508 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return; |
| 6509 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return; |
| 6510 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return; |
| 6511 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return; |
| 6512 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return; |
| 6513 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return; |
| 6514 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return; |
| 6515 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return; |
| 6516 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return; |
| 6517 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return; |
| 6518 | if (PyDict_SetItemString(d, "comprehension", |
| 6519 | (PyObject*)comprehension_type) < 0) return; |
| 6520 | if (PyDict_SetItemString(d, "excepthandler", |
| 6521 | (PyObject*)excepthandler_type) < 0) return; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame^] | 6522 | if (PyDict_SetItemString(d, "ExceptHandler", |
| 6523 | (PyObject*)ExceptHandler_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6524 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
| 6525 | 0) return; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 6526 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6527 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
| 6528 | return; |
| 6529 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6532 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6533 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6534 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6535 | init_types(); |
| 6536 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6537 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6538 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6539 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6540 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6541 | { |
| 6542 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6543 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6544 | (PyObject*)Interactive_type}; |
| 6545 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
| 6546 | assert(0 <= mode && mode <= 2); |
| 6547 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6548 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6549 | |
| 6550 | if (!PyObject_IsInstance(ast, req_type[mode])) { |
| 6551 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6552 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6553 | return NULL; |
| 6554 | } |
| 6555 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6556 | return NULL; |
| 6557 | else |
| 6558 | return res; |
| 6559 | } |
| 6560 | |
| 6561 | int PyAST_Check(PyObject* obj) |
| 6562 | { |
| 6563 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6564 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6567 | |