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