Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3 | #include "Python.h" |
| 4 | #include "Python-ast.h" |
| 5 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6 | static PyTypeObject AST_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 7 | static PyTypeObject *mod_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8 | static PyObject* ast2obj_mod(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 9 | static PyTypeObject *Module_type; |
| 10 | static char *Module_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 11 | "body", |
| 12 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 13 | static PyTypeObject *Interactive_type; |
| 14 | static char *Interactive_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 15 | "body", |
| 16 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 17 | static PyTypeObject *Expression_type; |
| 18 | static char *Expression_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 19 | "body", |
| 20 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 21 | static PyTypeObject *Suite_type; |
| 22 | static char *Suite_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 23 | "body", |
| 24 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 25 | static PyTypeObject *stmt_type; |
| 26 | static char *stmt_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 27 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 28 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 29 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 30 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 31 | static PyTypeObject *FunctionDef_type; |
| 32 | static char *FunctionDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 33 | "name", |
| 34 | "args", |
| 35 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 36 | "decorator_list", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 37 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 38 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 39 | static PyTypeObject *ClassDef_type; |
| 40 | static char *ClassDef_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 41 | "name", |
| 42 | "bases", |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 43 | "keywords", |
| 44 | "starargs", |
| 45 | "kwargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 46 | "body", |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 47 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 48 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 49 | static PyTypeObject *Return_type; |
| 50 | static char *Return_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 51 | "value", |
| 52 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 53 | static PyTypeObject *Delete_type; |
| 54 | static char *Delete_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 55 | "targets", |
| 56 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 57 | static PyTypeObject *Assign_type; |
| 58 | static char *Assign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 59 | "targets", |
| 60 | "value", |
| 61 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 62 | static PyTypeObject *AugAssign_type; |
| 63 | static char *AugAssign_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 64 | "target", |
| 65 | "op", |
| 66 | "value", |
| 67 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 68 | static PyTypeObject *For_type; |
| 69 | static char *For_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 70 | "target", |
| 71 | "iter", |
| 72 | "body", |
| 73 | "orelse", |
| 74 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 75 | static PyTypeObject *While_type; |
| 76 | static char *While_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 77 | "test", |
| 78 | "body", |
| 79 | "orelse", |
| 80 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 81 | static PyTypeObject *If_type; |
| 82 | static char *If_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 83 | "test", |
| 84 | "body", |
| 85 | "orelse", |
| 86 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 87 | static PyTypeObject *With_type; |
| 88 | static char *With_fields[]={ |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 89 | "items", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 90 | "body", |
| 91 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static PyTypeObject *Raise_type; |
| 93 | static char *Raise_fields[]={ |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 94 | "exc", |
| 95 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 96 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 97 | static PyTypeObject *Try_type; |
| 98 | static char *Try_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 99 | "body", |
| 100 | "handlers", |
| 101 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 102 | "finalbody", |
| 103 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 104 | static PyTypeObject *Assert_type; |
| 105 | static char *Assert_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 106 | "test", |
| 107 | "msg", |
| 108 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 109 | static PyTypeObject *Import_type; |
| 110 | static char *Import_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 111 | "names", |
| 112 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 113 | static PyTypeObject *ImportFrom_type; |
| 114 | static char *ImportFrom_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 115 | "module", |
| 116 | "names", |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 117 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 118 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 119 | static PyTypeObject *Global_type; |
| 120 | static char *Global_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 121 | "names", |
| 122 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 123 | static PyTypeObject *Nonlocal_type; |
| 124 | static char *Nonlocal_fields[]={ |
| 125 | "names", |
| 126 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 127 | static PyTypeObject *Expr_type; |
| 128 | static char *Expr_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 129 | "value", |
| 130 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 131 | static PyTypeObject *Pass_type; |
| 132 | static PyTypeObject *Break_type; |
| 133 | static PyTypeObject *Continue_type; |
| 134 | static PyTypeObject *expr_type; |
| 135 | static char *expr_attributes[] = { |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 136 | "lineno", |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 137 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 138 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 139 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 140 | static PyTypeObject *BoolOp_type; |
| 141 | static char *BoolOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 142 | "op", |
| 143 | "values", |
| 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *BinOp_type; |
| 146 | static char *BinOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 147 | "left", |
| 148 | "op", |
| 149 | "right", |
| 150 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 151 | static PyTypeObject *UnaryOp_type; |
| 152 | static char *UnaryOp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 153 | "op", |
| 154 | "operand", |
| 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *Lambda_type; |
| 157 | static char *Lambda_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | "args", |
| 159 | "body", |
| 160 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 161 | static PyTypeObject *IfExp_type; |
| 162 | static char *IfExp_fields[]={ |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 163 | "test", |
| 164 | "body", |
| 165 | "orelse", |
| 166 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 167 | static PyTypeObject *Dict_type; |
| 168 | static char *Dict_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 169 | "keys", |
| 170 | "values", |
| 171 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 172 | static PyTypeObject *Set_type; |
| 173 | static char *Set_fields[]={ |
| 174 | "elts", |
| 175 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 176 | static PyTypeObject *ListComp_type; |
| 177 | static char *ListComp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 178 | "elt", |
| 179 | "generators", |
| 180 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 181 | static PyTypeObject *SetComp_type; |
| 182 | static char *SetComp_fields[]={ |
| 183 | "elt", |
| 184 | "generators", |
| 185 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 186 | static PyTypeObject *DictComp_type; |
| 187 | static char *DictComp_fields[]={ |
| 188 | "key", |
| 189 | "value", |
| 190 | "generators", |
| 191 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 192 | static PyTypeObject *GeneratorExp_type; |
| 193 | static char *GeneratorExp_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 194 | "elt", |
| 195 | "generators", |
| 196 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 197 | static PyTypeObject *Yield_type; |
| 198 | static char *Yield_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 199 | "value", |
| 200 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static PyTypeObject *Compare_type; |
| 202 | static char *Compare_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 203 | "left", |
| 204 | "ops", |
| 205 | "comparators", |
| 206 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 207 | static PyTypeObject *Call_type; |
| 208 | static char *Call_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 209 | "func", |
| 210 | "args", |
| 211 | "keywords", |
| 212 | "starargs", |
| 213 | "kwargs", |
| 214 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 215 | static PyTypeObject *Num_type; |
| 216 | static char *Num_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 217 | "n", |
| 218 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 219 | static PyTypeObject *Str_type; |
| 220 | static char *Str_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | "s", |
| 222 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 223 | static PyTypeObject *Bytes_type; |
| 224 | static char *Bytes_fields[]={ |
| 225 | "s", |
| 226 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 227 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 228 | static PyTypeObject *Attribute_type; |
| 229 | static char *Attribute_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 230 | "value", |
| 231 | "attr", |
| 232 | "ctx", |
| 233 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 234 | static PyTypeObject *Subscript_type; |
| 235 | static char *Subscript_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 236 | "value", |
| 237 | "slice", |
| 238 | "ctx", |
| 239 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 240 | static PyTypeObject *Starred_type; |
| 241 | static char *Starred_fields[]={ |
| 242 | "value", |
| 243 | "ctx", |
| 244 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 245 | static PyTypeObject *Name_type; |
| 246 | static char *Name_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 247 | "id", |
| 248 | "ctx", |
| 249 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 250 | static PyTypeObject *List_type; |
| 251 | static char *List_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 252 | "elts", |
| 253 | "ctx", |
| 254 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 255 | static PyTypeObject *Tuple_type; |
| 256 | static char *Tuple_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 257 | "elts", |
| 258 | "ctx", |
| 259 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 260 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 261 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 262 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 263 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 264 | static PyTypeObject *Load_type; |
| 265 | static PyTypeObject *Store_type; |
| 266 | static PyTypeObject *Del_type; |
| 267 | static PyTypeObject *AugLoad_type; |
| 268 | static PyTypeObject *AugStore_type; |
| 269 | static PyTypeObject *Param_type; |
| 270 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 271 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 272 | static PyTypeObject *Slice_type; |
| 273 | static char *Slice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 274 | "lower", |
| 275 | "upper", |
| 276 | "step", |
| 277 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *ExtSlice_type; |
| 279 | static char *ExtSlice_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 280 | "dims", |
| 281 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 282 | static PyTypeObject *Index_type; |
| 283 | static char *Index_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 284 | "value", |
| 285 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 286 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 287 | static PyObject *And_singleton, *Or_singleton; |
| 288 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 289 | static PyTypeObject *And_type; |
| 290 | static PyTypeObject *Or_type; |
| 291 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 292 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
| 293 | *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton, |
| 294 | *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton, |
| 295 | *FloorDiv_singleton; |
| 296 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 297 | static PyTypeObject *Add_type; |
| 298 | static PyTypeObject *Sub_type; |
| 299 | static PyTypeObject *Mult_type; |
| 300 | static PyTypeObject *Div_type; |
| 301 | static PyTypeObject *Mod_type; |
| 302 | static PyTypeObject *Pow_type; |
| 303 | static PyTypeObject *LShift_type; |
| 304 | static PyTypeObject *RShift_type; |
| 305 | static PyTypeObject *BitOr_type; |
| 306 | static PyTypeObject *BitXor_type; |
| 307 | static PyTypeObject *BitAnd_type; |
| 308 | static PyTypeObject *FloorDiv_type; |
| 309 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 310 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 311 | *USub_singleton; |
| 312 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 313 | static PyTypeObject *Invert_type; |
| 314 | static PyTypeObject *Not_type; |
| 315 | static PyTypeObject *UAdd_type; |
| 316 | static PyTypeObject *USub_type; |
| 317 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 318 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 319 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 320 | *NotIn_singleton; |
| 321 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 322 | static PyTypeObject *Eq_type; |
| 323 | static PyTypeObject *NotEq_type; |
| 324 | static PyTypeObject *Lt_type; |
| 325 | static PyTypeObject *LtE_type; |
| 326 | static PyTypeObject *Gt_type; |
| 327 | static PyTypeObject *GtE_type; |
| 328 | static PyTypeObject *Is_type; |
| 329 | static PyTypeObject *IsNot_type; |
| 330 | static PyTypeObject *In_type; |
| 331 | static PyTypeObject *NotIn_type; |
| 332 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 333 | static PyObject* ast2obj_comprehension(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 334 | static char *comprehension_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 335 | "target", |
| 336 | "iter", |
| 337 | "ifs", |
| 338 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 339 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 340 | static char *excepthandler_attributes[] = { |
| 341 | "lineno", |
| 342 | "col_offset", |
| 343 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 344 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 345 | static PyTypeObject *ExceptHandler_type; |
| 346 | static char *ExceptHandler_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 347 | "type", |
| 348 | "name", |
| 349 | "body", |
| 350 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 351 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 352 | static PyObject* ast2obj_arguments(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 353 | static char *arguments_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 354 | "args", |
| 355 | "vararg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 356 | "varargannotation", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 357 | "kwonlyargs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 358 | "kwarg", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 359 | "kwargannotation", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 360 | "defaults", |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 361 | "kw_defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 362 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 363 | static PyTypeObject *arg_type; |
| 364 | static PyObject* ast2obj_arg(void*); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 365 | static char *arg_fields[]={ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 366 | "arg", |
| 367 | "annotation", |
| 368 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 369 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 370 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 371 | static char *keyword_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 372 | "arg", |
| 373 | "value", |
| 374 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 376 | static PyObject* ast2obj_alias(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 377 | static char *alias_fields[]={ |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 378 | "name", |
| 379 | "asname", |
| 380 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 381 | static PyTypeObject *withitem_type; |
| 382 | static PyObject* ast2obj_withitem(void*); |
| 383 | static char *withitem_fields[]={ |
| 384 | "context_expr", |
| 385 | "optional_vars", |
| 386 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 387 | |
| 388 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 389 | static int |
| 390 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 391 | { |
| 392 | Py_ssize_t i, numfields = 0; |
| 393 | int res = -1; |
| 394 | PyObject *key, *value, *fields; |
| 395 | fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); |
| 396 | if (!fields) |
| 397 | PyErr_Clear(); |
| 398 | if (fields) { |
| 399 | numfields = PySequence_Size(fields); |
| 400 | if (numfields == -1) |
| 401 | goto cleanup; |
| 402 | } |
| 403 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 404 | if (PyTuple_GET_SIZE(args) > 0) { |
| 405 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 406 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 407 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 408 | Py_TYPE(self)->tp_name, |
| 409 | numfields == 0 ? "" : "either 0 or ", |
| 410 | numfields, numfields == 1 ? "" : "s"); |
| 411 | res = -1; |
| 412 | goto cleanup; |
| 413 | } |
| 414 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 415 | /* cannot be reached when fields is NULL */ |
| 416 | PyObject *name = PySequence_GetItem(fields, i); |
| 417 | if (!name) { |
| 418 | res = -1; |
| 419 | goto cleanup; |
| 420 | } |
| 421 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 422 | Py_DECREF(name); |
| 423 | if (res < 0) |
| 424 | goto cleanup; |
| 425 | } |
| 426 | } |
| 427 | if (kw) { |
| 428 | i = 0; /* needed by PyDict_Next */ |
| 429 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 430 | res = PyObject_SetAttr(self, key, value); |
| 431 | if (res < 0) |
| 432 | goto cleanup; |
| 433 | } |
| 434 | } |
| 435 | cleanup: |
| 436 | Py_XDECREF(fields); |
| 437 | return res; |
| 438 | } |
| 439 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 440 | /* Pickling support */ |
| 441 | static PyObject * |
| 442 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 443 | { |
| 444 | PyObject *res; |
| 445 | PyObject *dict = PyObject_GetAttrString(self, "__dict__"); |
| 446 | if (dict == NULL) { |
| 447 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 448 | PyErr_Clear(); |
| 449 | else |
| 450 | return NULL; |
| 451 | } |
| 452 | if (dict) { |
| 453 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 454 | Py_DECREF(dict); |
| 455 | return res; |
| 456 | } |
| 457 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 458 | } |
| 459 | |
| 460 | static PyMethodDef ast_type_methods[] = { |
| 461 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 462 | {NULL} |
| 463 | }; |
| 464 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 465 | static PyTypeObject AST_type = { |
| 466 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 467 | "_ast.AST", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 468 | sizeof(PyObject), |
| 469 | 0, |
| 470 | 0, /* tp_dealloc */ |
| 471 | 0, /* tp_print */ |
| 472 | 0, /* tp_getattr */ |
| 473 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 474 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 475 | 0, /* tp_repr */ |
| 476 | 0, /* tp_as_number */ |
| 477 | 0, /* tp_as_sequence */ |
| 478 | 0, /* tp_as_mapping */ |
| 479 | 0, /* tp_hash */ |
| 480 | 0, /* tp_call */ |
| 481 | 0, /* tp_str */ |
| 482 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 483 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 484 | 0, /* tp_as_buffer */ |
| 485 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 486 | 0, /* tp_doc */ |
| 487 | 0, /* tp_traverse */ |
| 488 | 0, /* tp_clear */ |
| 489 | 0, /* tp_richcompare */ |
| 490 | 0, /* tp_weaklistoffset */ |
| 491 | 0, /* tp_iter */ |
| 492 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 493 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 494 | 0, /* tp_members */ |
| 495 | 0, /* tp_getset */ |
| 496 | 0, /* tp_base */ |
| 497 | 0, /* tp_dict */ |
| 498 | 0, /* tp_descr_get */ |
| 499 | 0, /* tp_descr_set */ |
| 500 | 0, /* tp_dictoffset */ |
| 501 | (initproc)ast_type_init, /* tp_init */ |
| 502 | PyType_GenericAlloc, /* tp_alloc */ |
| 503 | PyType_GenericNew, /* tp_new */ |
| 504 | PyObject_Del, /* tp_free */ |
| 505 | }; |
| 506 | |
| 507 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 508 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 509 | { |
| 510 | PyObject *fnames, *result; |
| 511 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 512 | fnames = PyTuple_New(num_fields); |
| 513 | if (!fnames) return NULL; |
| 514 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 515 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 516 | if (!field) { |
| 517 | Py_DECREF(fnames); |
| 518 | return NULL; |
| 519 | } |
| 520 | PyTuple_SET_ITEM(fnames, i, field); |
| 521 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 522 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 523 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 524 | Py_DECREF(fnames); |
| 525 | return (PyTypeObject*)result; |
| 526 | } |
| 527 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 528 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 529 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 530 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 531 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 532 | if (!l) |
| 533 | return 0; |
| 534 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 535 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 536 | if (!s) { |
| 537 | Py_DECREF(l); |
| 538 | return 0; |
| 539 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 540 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 541 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 542 | result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
| 543 | Py_DECREF(l); |
| 544 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 547 | /* Conversion AST -> Python */ |
| 548 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 549 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 550 | { |
| 551 | int i, n = asdl_seq_LEN(seq); |
| 552 | PyObject *result = PyList_New(n); |
| 553 | PyObject *value; |
| 554 | if (!result) |
| 555 | return NULL; |
| 556 | for (i = 0; i < n; i++) { |
| 557 | value = func(asdl_seq_GET(seq, i)); |
| 558 | if (!value) { |
| 559 | Py_DECREF(result); |
| 560 | return NULL; |
| 561 | } |
| 562 | PyList_SET_ITEM(result, i, value); |
| 563 | } |
| 564 | return result; |
| 565 | } |
| 566 | |
| 567 | static PyObject* ast2obj_object(void *o) |
| 568 | { |
| 569 | if (!o) |
| 570 | o = Py_None; |
| 571 | Py_INCREF((PyObject*)o); |
| 572 | return (PyObject*)o; |
| 573 | } |
| 574 | #define ast2obj_identifier ast2obj_object |
| 575 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 576 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 577 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 578 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 579 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 582 | /* Conversion Python -> AST */ |
| 583 | |
| 584 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 585 | { |
| 586 | if (obj == Py_None) |
| 587 | obj = NULL; |
| 588 | if (obj) |
| 589 | PyArena_AddPyObject(arena, obj); |
| 590 | Py_XINCREF(obj); |
| 591 | *out = obj; |
| 592 | return 0; |
| 593 | } |
| 594 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 595 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 596 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 597 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 598 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 599 | return 1; |
| 600 | } |
| 601 | return obj2ast_object(obj, out, arena); |
| 602 | } |
| 603 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 604 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 605 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 606 | if (!PyUnicode_CheckExact(obj)) { |
| 607 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 608 | return 1; |
| 609 | } |
| 610 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 611 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 612 | |
| 613 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 614 | { |
| 615 | int i; |
| 616 | if (!PyLong_Check(obj)) { |
| 617 | PyObject *s = PyObject_Repr(obj); |
| 618 | if (s == NULL) return 1; |
| 619 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 620 | PyBytes_AS_STRING(s)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 621 | Py_DECREF(s); |
| 622 | return 1; |
| 623 | } |
| 624 | |
| 625 | i = (int)PyLong_AsLong(obj); |
| 626 | if (i == -1 && PyErr_Occurred()) |
| 627 | return 1; |
| 628 | *out = i; |
| 629 | return 0; |
| 630 | } |
| 631 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 632 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 633 | { |
| 634 | PyObject *empty_tuple, *d; |
| 635 | if (PyType_Ready(&AST_type) < 0) |
| 636 | return -1; |
| 637 | d = AST_type.tp_dict; |
| 638 | empty_tuple = PyTuple_New(0); |
| 639 | if (!empty_tuple || |
| 640 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 641 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 642 | Py_XDECREF(empty_tuple); |
| 643 | return -1; |
| 644 | } |
| 645 | Py_DECREF(empty_tuple); |
| 646 | return 0; |
| 647 | } |
| 648 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 649 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 650 | static int init_types(void) |
| 651 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 652 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 653 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 654 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 655 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 656 | if (!mod_type) return 0; |
| 657 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 658 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | Interactive_type = make_type("Interactive", mod_type, |
| 661 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 662 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 663 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 664 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 665 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 666 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 667 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 668 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 670 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 671 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 672 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 674 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 678 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 681 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 682 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 683 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 685 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 688 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 689 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 690 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 691 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 692 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 693 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 694 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 695 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 696 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 700 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 701 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 702 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 703 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 704 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 705 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 706 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 707 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 708 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 709 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 710 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 711 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 713 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 715 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 717 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 718 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 719 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 720 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 721 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 723 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 724 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 725 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 726 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 727 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 728 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 729 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 730 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 731 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 734 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 735 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 736 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 737 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 739 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 740 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 741 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 742 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 743 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 744 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 745 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 746 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 747 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 748 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 749 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 750 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 751 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 752 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 753 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 754 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 755 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 756 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 757 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 758 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 759 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 760 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 761 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 762 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 763 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 764 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 767 | 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] | 768 | if (!expr_context_type) return 0; |
| 769 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 770 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 771 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 773 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 774 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 775 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 776 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 777 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 778 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 779 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 780 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 782 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 784 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 786 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 788 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 790 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 794 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!slice_type) return 0; |
| 796 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 797 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 798 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 799 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 800 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 801 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 802 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 803 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 804 | if (!boolop_type) return 0; |
| 805 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 806 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 807 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 809 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 810 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 811 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 813 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 814 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 815 | if (!operator_type) return 0; |
| 816 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 817 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 818 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 819 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 820 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 821 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 822 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 823 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 824 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 825 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 826 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 827 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 829 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 831 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 832 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 833 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 837 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 841 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 842 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 843 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 844 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 845 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 846 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 847 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 848 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 849 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 850 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 851 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 852 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 853 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 854 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 856 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 857 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 859 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 860 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 861 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 862 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 863 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 865 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!unaryop_type) return 0; |
| 867 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 868 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 869 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 870 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 871 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 872 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 873 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 874 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 875 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 876 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 877 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 878 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 880 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 884 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!cmpop_type) return 0; |
| 886 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 887 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 888 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 889 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 890 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 891 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 892 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 893 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 894 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 895 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 896 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 897 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 898 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 899 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 901 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 903 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 905 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 907 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 911 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 913 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 915 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 919 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 921 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 923 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 925 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 927 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 928 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 930 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 931 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 932 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 933 | return 0; |
| 934 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 935 | ExceptHandler_fields, 3); |
| 936 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 937 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 938 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 939 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 940 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 941 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 942 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 943 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 944 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 945 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 946 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 947 | initialized = 1; |
| 948 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 949 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 950 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 951 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 952 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 953 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 954 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 955 | arena); |
| 956 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 957 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 958 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 959 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 960 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 961 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 962 | arena); |
| 963 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 964 | arena); |
| 965 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 966 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 967 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 968 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 969 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 970 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 971 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 972 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 973 | { |
| 974 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 975 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 976 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 977 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 978 | p->kind = Module_kind; |
| 979 | p->v.Module.body = body; |
| 980 | return p; |
| 981 | } |
| 982 | |
| 983 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 984 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 985 | { |
| 986 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 987 | p = (mod_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 = Interactive_kind; |
| 991 | p->v.Interactive.body = body; |
| 992 | return p; |
| 993 | } |
| 994 | |
| 995 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 996 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 997 | { |
| 998 | mod_ty p; |
| 999 | if (!body) { |
| 1000 | PyErr_SetString(PyExc_ValueError, |
| 1001 | "field body is required for Expression"); |
| 1002 | return NULL; |
| 1003 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1004 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1005 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1006 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1007 | p->kind = Expression_kind; |
| 1008 | p->v.Expression.body = body; |
| 1009 | return p; |
| 1010 | } |
| 1011 | |
| 1012 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1013 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1014 | { |
| 1015 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1016 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1017 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1018 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1019 | p->kind = Suite_kind; |
| 1020 | p->v.Suite.body = body; |
| 1021 | return p; |
| 1022 | } |
| 1023 | |
| 1024 | stmt_ty |
| 1025 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1026 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1027 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1028 | { |
| 1029 | stmt_ty p; |
| 1030 | if (!name) { |
| 1031 | PyErr_SetString(PyExc_ValueError, |
| 1032 | "field name is required for FunctionDef"); |
| 1033 | return NULL; |
| 1034 | } |
| 1035 | if (!args) { |
| 1036 | PyErr_SetString(PyExc_ValueError, |
| 1037 | "field args is required for FunctionDef"); |
| 1038 | return NULL; |
| 1039 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1040 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1041 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1042 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1043 | p->kind = FunctionDef_kind; |
| 1044 | p->v.FunctionDef.name = name; |
| 1045 | p->v.FunctionDef.args = args; |
| 1046 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1047 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1048 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1049 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1050 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1051 | return p; |
| 1052 | } |
| 1053 | |
| 1054 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1055 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1056 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1057 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1058 | { |
| 1059 | stmt_ty p; |
| 1060 | if (!name) { |
| 1061 | PyErr_SetString(PyExc_ValueError, |
| 1062 | "field name is required for ClassDef"); |
| 1063 | return NULL; |
| 1064 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1065 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1066 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1067 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1068 | p->kind = ClassDef_kind; |
| 1069 | p->v.ClassDef.name = name; |
| 1070 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1071 | p->v.ClassDef.keywords = keywords; |
| 1072 | p->v.ClassDef.starargs = starargs; |
| 1073 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1074 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1075 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1076 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1077 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1078 | return p; |
| 1079 | } |
| 1080 | |
| 1081 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1082 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1083 | { |
| 1084 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1085 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1086 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1087 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1088 | p->kind = Return_kind; |
| 1089 | p->v.Return.value = value; |
| 1090 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1091 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1092 | return p; |
| 1093 | } |
| 1094 | |
| 1095 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1096 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1097 | { |
| 1098 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1099 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1100 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1101 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1102 | p->kind = Delete_kind; |
| 1103 | p->v.Delete.targets = targets; |
| 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1110 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1111 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1112 | { |
| 1113 | stmt_ty p; |
| 1114 | if (!value) { |
| 1115 | PyErr_SetString(PyExc_ValueError, |
| 1116 | "field value is required for Assign"); |
| 1117 | return NULL; |
| 1118 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1119 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1120 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1121 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1122 | p->kind = Assign_kind; |
| 1123 | p->v.Assign.targets = targets; |
| 1124 | p->v.Assign.value = value; |
| 1125 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1126 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1127 | return p; |
| 1128 | } |
| 1129 | |
| 1130 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1131 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1132 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1133 | { |
| 1134 | stmt_ty p; |
| 1135 | if (!target) { |
| 1136 | PyErr_SetString(PyExc_ValueError, |
| 1137 | "field target is required for AugAssign"); |
| 1138 | return NULL; |
| 1139 | } |
| 1140 | if (!op) { |
| 1141 | PyErr_SetString(PyExc_ValueError, |
| 1142 | "field op is required for AugAssign"); |
| 1143 | return NULL; |
| 1144 | } |
| 1145 | if (!value) { |
| 1146 | PyErr_SetString(PyExc_ValueError, |
| 1147 | "field value is required for AugAssign"); |
| 1148 | return NULL; |
| 1149 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1150 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1151 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1152 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1153 | p->kind = AugAssign_kind; |
| 1154 | p->v.AugAssign.target = target; |
| 1155 | p->v.AugAssign.op = op; |
| 1156 | p->v.AugAssign.value = value; |
| 1157 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1158 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1159 | return p; |
| 1160 | } |
| 1161 | |
| 1162 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1163 | 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] | 1164 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1165 | { |
| 1166 | stmt_ty p; |
| 1167 | if (!target) { |
| 1168 | PyErr_SetString(PyExc_ValueError, |
| 1169 | "field target is required for For"); |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | if (!iter) { |
| 1173 | PyErr_SetString(PyExc_ValueError, |
| 1174 | "field iter is required for For"); |
| 1175 | return NULL; |
| 1176 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1177 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1178 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1179 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1180 | p->kind = For_kind; |
| 1181 | p->v.For.target = target; |
| 1182 | p->v.For.iter = iter; |
| 1183 | p->v.For.body = body; |
| 1184 | p->v.For.orelse = orelse; |
| 1185 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1186 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1187 | return p; |
| 1188 | } |
| 1189 | |
| 1190 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1191 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1192 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1193 | { |
| 1194 | stmt_ty p; |
| 1195 | if (!test) { |
| 1196 | PyErr_SetString(PyExc_ValueError, |
| 1197 | "field test is required for While"); |
| 1198 | return NULL; |
| 1199 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1200 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1201 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1202 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | p->kind = While_kind; |
| 1204 | p->v.While.test = test; |
| 1205 | p->v.While.body = body; |
| 1206 | p->v.While.orelse = orelse; |
| 1207 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1208 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | return p; |
| 1210 | } |
| 1211 | |
| 1212 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1213 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1214 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1215 | { |
| 1216 | stmt_ty p; |
| 1217 | if (!test) { |
| 1218 | PyErr_SetString(PyExc_ValueError, |
| 1219 | "field test is required for If"); |
| 1220 | return NULL; |
| 1221 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1222 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1223 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1224 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1225 | p->kind = If_kind; |
| 1226 | p->v.If.test = test; |
| 1227 | p->v.If.body = body; |
| 1228 | p->v.If.orelse = orelse; |
| 1229 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1230 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | return p; |
| 1232 | } |
| 1233 | |
| 1234 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1235 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1236 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1237 | { |
| 1238 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1239 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1240 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1241 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1242 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1243 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1244 | p->v.With.body = body; |
| 1245 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1246 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1247 | return p; |
| 1248 | } |
| 1249 | |
| 1250 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1251 | 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] | 1252 | { |
| 1253 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1254 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1255 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1256 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1257 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1258 | p->v.Raise.exc = exc; |
| 1259 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1260 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1261 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1262 | return p; |
| 1263 | } |
| 1264 | |
| 1265 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1266 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1267 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1268 | { |
| 1269 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1270 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1271 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1272 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1273 | p->kind = Try_kind; |
| 1274 | p->v.Try.body = body; |
| 1275 | p->v.Try.handlers = handlers; |
| 1276 | p->v.Try.orelse = orelse; |
| 1277 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1278 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1279 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1280 | return p; |
| 1281 | } |
| 1282 | |
| 1283 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1284 | 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] | 1285 | { |
| 1286 | stmt_ty p; |
| 1287 | if (!test) { |
| 1288 | PyErr_SetString(PyExc_ValueError, |
| 1289 | "field test is required for Assert"); |
| 1290 | return NULL; |
| 1291 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1292 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1293 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1294 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1295 | p->kind = Assert_kind; |
| 1296 | p->v.Assert.test = test; |
| 1297 | p->v.Assert.msg = msg; |
| 1298 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1299 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1300 | return p; |
| 1301 | } |
| 1302 | |
| 1303 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1304 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | { |
| 1306 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1307 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1308 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1309 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1310 | p->kind = Import_kind; |
| 1311 | p->v.Import.names = names; |
| 1312 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1313 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1314 | return p; |
| 1315 | } |
| 1316 | |
| 1317 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1318 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1319 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | { |
| 1321 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1322 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1323 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1324 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1325 | p->kind = ImportFrom_kind; |
| 1326 | p->v.ImportFrom.module = module; |
| 1327 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1328 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1329 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1330 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1331 | return p; |
| 1332 | } |
| 1333 | |
| 1334 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1335 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1336 | { |
| 1337 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1338 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1339 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1340 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1341 | p->kind = Global_kind; |
| 1342 | p->v.Global.names = names; |
| 1343 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1344 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1345 | return p; |
| 1346 | } |
| 1347 | |
| 1348 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1349 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1350 | { |
| 1351 | stmt_ty p; |
| 1352 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1353 | if (!p) |
| 1354 | return NULL; |
| 1355 | p->kind = Nonlocal_kind; |
| 1356 | p->v.Nonlocal.names = names; |
| 1357 | p->lineno = lineno; |
| 1358 | p->col_offset = col_offset; |
| 1359 | return p; |
| 1360 | } |
| 1361 | |
| 1362 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1363 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1364 | { |
| 1365 | stmt_ty p; |
| 1366 | if (!value) { |
| 1367 | PyErr_SetString(PyExc_ValueError, |
| 1368 | "field value is required for Expr"); |
| 1369 | return NULL; |
| 1370 | } |
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 = Expr_kind; |
| 1375 | p->v.Expr.value = value; |
| 1376 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1377 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1378 | return p; |
| 1379 | } |
| 1380 | |
| 1381 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1382 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | { |
| 1384 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1385 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1386 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1387 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1388 | p->kind = Pass_kind; |
| 1389 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1390 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1391 | return p; |
| 1392 | } |
| 1393 | |
| 1394 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1395 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1396 | { |
| 1397 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1398 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1399 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1400 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | p->kind = Break_kind; |
| 1402 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1403 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1404 | return p; |
| 1405 | } |
| 1406 | |
| 1407 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1408 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | { |
| 1410 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1411 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1412 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1413 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | p->kind = Continue_kind; |
| 1415 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1416 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1417 | return p; |
| 1418 | } |
| 1419 | |
| 1420 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1421 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1422 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1423 | { |
| 1424 | expr_ty p; |
| 1425 | if (!op) { |
| 1426 | PyErr_SetString(PyExc_ValueError, |
| 1427 | "field op is required for BoolOp"); |
| 1428 | return NULL; |
| 1429 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1430 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1431 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1432 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1433 | p->kind = BoolOp_kind; |
| 1434 | p->v.BoolOp.op = op; |
| 1435 | p->v.BoolOp.values = values; |
| 1436 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1437 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1438 | return p; |
| 1439 | } |
| 1440 | |
| 1441 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1442 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1443 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1444 | { |
| 1445 | expr_ty p; |
| 1446 | if (!left) { |
| 1447 | PyErr_SetString(PyExc_ValueError, |
| 1448 | "field left is required for BinOp"); |
| 1449 | return NULL; |
| 1450 | } |
| 1451 | if (!op) { |
| 1452 | PyErr_SetString(PyExc_ValueError, |
| 1453 | "field op is required for BinOp"); |
| 1454 | return NULL; |
| 1455 | } |
| 1456 | if (!right) { |
| 1457 | PyErr_SetString(PyExc_ValueError, |
| 1458 | "field right is required for BinOp"); |
| 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 = BinOp_kind; |
| 1465 | p->v.BinOp.left = left; |
| 1466 | p->v.BinOp.op = op; |
| 1467 | p->v.BinOp.right = right; |
| 1468 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1469 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | return p; |
| 1471 | } |
| 1472 | |
| 1473 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1474 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1475 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1476 | { |
| 1477 | expr_ty p; |
| 1478 | if (!op) { |
| 1479 | PyErr_SetString(PyExc_ValueError, |
| 1480 | "field op is required for UnaryOp"); |
| 1481 | return NULL; |
| 1482 | } |
| 1483 | if (!operand) { |
| 1484 | PyErr_SetString(PyExc_ValueError, |
| 1485 | "field operand is required for UnaryOp"); |
| 1486 | return NULL; |
| 1487 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1488 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1489 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1490 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1491 | p->kind = UnaryOp_kind; |
| 1492 | p->v.UnaryOp.op = op; |
| 1493 | p->v.UnaryOp.operand = operand; |
| 1494 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1495 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1496 | return p; |
| 1497 | } |
| 1498 | |
| 1499 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1500 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1501 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1502 | { |
| 1503 | expr_ty p; |
| 1504 | if (!args) { |
| 1505 | PyErr_SetString(PyExc_ValueError, |
| 1506 | "field args is required for Lambda"); |
| 1507 | return NULL; |
| 1508 | } |
| 1509 | if (!body) { |
| 1510 | PyErr_SetString(PyExc_ValueError, |
| 1511 | "field body is required for Lambda"); |
| 1512 | return NULL; |
| 1513 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1514 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1515 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1516 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1517 | p->kind = Lambda_kind; |
| 1518 | p->v.Lambda.args = args; |
| 1519 | p->v.Lambda.body = body; |
| 1520 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1521 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1522 | return p; |
| 1523 | } |
| 1524 | |
| 1525 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1526 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1527 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1528 | { |
| 1529 | expr_ty p; |
| 1530 | if (!test) { |
| 1531 | PyErr_SetString(PyExc_ValueError, |
| 1532 | "field test is required for IfExp"); |
| 1533 | return NULL; |
| 1534 | } |
| 1535 | if (!body) { |
| 1536 | PyErr_SetString(PyExc_ValueError, |
| 1537 | "field body is required for IfExp"); |
| 1538 | return NULL; |
| 1539 | } |
| 1540 | if (!orelse) { |
| 1541 | PyErr_SetString(PyExc_ValueError, |
| 1542 | "field orelse is required for IfExp"); |
| 1543 | return NULL; |
| 1544 | } |
| 1545 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1546 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1547 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1548 | p->kind = IfExp_kind; |
| 1549 | p->v.IfExp.test = test; |
| 1550 | p->v.IfExp.body = body; |
| 1551 | p->v.IfExp.orelse = orelse; |
| 1552 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1553 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1554 | return p; |
| 1555 | } |
| 1556 | |
| 1557 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1558 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1559 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1560 | { |
| 1561 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1562 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1563 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1564 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1565 | p->kind = Dict_kind; |
| 1566 | p->v.Dict.keys = keys; |
| 1567 | p->v.Dict.values = values; |
| 1568 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1569 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | return p; |
| 1571 | } |
| 1572 | |
| 1573 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1574 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1575 | { |
| 1576 | expr_ty p; |
| 1577 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1578 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1579 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1580 | p->kind = Set_kind; |
| 1581 | p->v.Set.elts = elts; |
| 1582 | p->lineno = lineno; |
| 1583 | p->col_offset = col_offset; |
| 1584 | return p; |
| 1585 | } |
| 1586 | |
| 1587 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1588 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1589 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1590 | { |
| 1591 | expr_ty p; |
| 1592 | if (!elt) { |
| 1593 | PyErr_SetString(PyExc_ValueError, |
| 1594 | "field elt is required for ListComp"); |
| 1595 | return NULL; |
| 1596 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1597 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1598 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1599 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1600 | p->kind = ListComp_kind; |
| 1601 | p->v.ListComp.elt = elt; |
| 1602 | p->v.ListComp.generators = generators; |
| 1603 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1604 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1605 | return p; |
| 1606 | } |
| 1607 | |
| 1608 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1609 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1610 | *arena) |
| 1611 | { |
| 1612 | expr_ty p; |
| 1613 | if (!elt) { |
| 1614 | PyErr_SetString(PyExc_ValueError, |
| 1615 | "field elt is required for SetComp"); |
| 1616 | return NULL; |
| 1617 | } |
| 1618 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1619 | if (!p) |
| 1620 | return NULL; |
| 1621 | p->kind = SetComp_kind; |
| 1622 | p->v.SetComp.elt = elt; |
| 1623 | p->v.SetComp.generators = generators; |
| 1624 | p->lineno = lineno; |
| 1625 | p->col_offset = col_offset; |
| 1626 | return p; |
| 1627 | } |
| 1628 | |
| 1629 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1630 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1631 | col_offset, PyArena *arena) |
| 1632 | { |
| 1633 | expr_ty p; |
| 1634 | if (!key) { |
| 1635 | PyErr_SetString(PyExc_ValueError, |
| 1636 | "field key is required for DictComp"); |
| 1637 | return NULL; |
| 1638 | } |
| 1639 | if (!value) { |
| 1640 | PyErr_SetString(PyExc_ValueError, |
| 1641 | "field value is required for DictComp"); |
| 1642 | return NULL; |
| 1643 | } |
| 1644 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1645 | if (!p) |
| 1646 | return NULL; |
| 1647 | p->kind = DictComp_kind; |
| 1648 | p->v.DictComp.key = key; |
| 1649 | p->v.DictComp.value = value; |
| 1650 | p->v.DictComp.generators = generators; |
| 1651 | p->lineno = lineno; |
| 1652 | p->col_offset = col_offset; |
| 1653 | return p; |
| 1654 | } |
| 1655 | |
| 1656 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1657 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1658 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1659 | { |
| 1660 | expr_ty p; |
| 1661 | if (!elt) { |
| 1662 | PyErr_SetString(PyExc_ValueError, |
| 1663 | "field elt is required for GeneratorExp"); |
| 1664 | return NULL; |
| 1665 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1666 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1667 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1668 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1669 | p->kind = GeneratorExp_kind; |
| 1670 | p->v.GeneratorExp.elt = elt; |
| 1671 | p->v.GeneratorExp.generators = generators; |
| 1672 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1673 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1674 | return p; |
| 1675 | } |
| 1676 | |
| 1677 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1678 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1679 | { |
| 1680 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1681 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1682 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1683 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1684 | p->kind = Yield_kind; |
| 1685 | p->v.Yield.value = value; |
| 1686 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1687 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1688 | return p; |
| 1689 | } |
| 1690 | |
| 1691 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1692 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1693 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1694 | { |
| 1695 | expr_ty p; |
| 1696 | if (!left) { |
| 1697 | PyErr_SetString(PyExc_ValueError, |
| 1698 | "field left is required for Compare"); |
| 1699 | return NULL; |
| 1700 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1701 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1702 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1703 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1704 | p->kind = Compare_kind; |
| 1705 | p->v.Compare.left = left; |
| 1706 | p->v.Compare.ops = ops; |
| 1707 | p->v.Compare.comparators = comparators; |
| 1708 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1709 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | return p; |
| 1711 | } |
| 1712 | |
| 1713 | expr_ty |
| 1714 | 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] | 1715 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1716 | { |
| 1717 | expr_ty p; |
| 1718 | if (!func) { |
| 1719 | PyErr_SetString(PyExc_ValueError, |
| 1720 | "field func is required for Call"); |
| 1721 | return NULL; |
| 1722 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1723 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1724 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1725 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1726 | p->kind = Call_kind; |
| 1727 | p->v.Call.func = func; |
| 1728 | p->v.Call.args = args; |
| 1729 | p->v.Call.keywords = keywords; |
| 1730 | p->v.Call.starargs = starargs; |
| 1731 | p->v.Call.kwargs = kwargs; |
| 1732 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1733 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1734 | return p; |
| 1735 | } |
| 1736 | |
| 1737 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1738 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1739 | { |
| 1740 | expr_ty p; |
| 1741 | if (!n) { |
| 1742 | PyErr_SetString(PyExc_ValueError, |
| 1743 | "field n is required for Num"); |
| 1744 | return NULL; |
| 1745 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1746 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1747 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1748 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | p->kind = Num_kind; |
| 1750 | p->v.Num.n = n; |
| 1751 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1752 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1753 | return p; |
| 1754 | } |
| 1755 | |
| 1756 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1757 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1758 | { |
| 1759 | expr_ty p; |
| 1760 | if (!s) { |
| 1761 | PyErr_SetString(PyExc_ValueError, |
| 1762 | "field s is required for Str"); |
| 1763 | return NULL; |
| 1764 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1765 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1766 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1767 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1768 | p->kind = Str_kind; |
| 1769 | p->v.Str.s = s; |
| 1770 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1771 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1772 | return p; |
| 1773 | } |
| 1774 | |
| 1775 | expr_ty |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1776 | Bytes(string s, int lineno, int col_offset, PyArena *arena) |
| 1777 | { |
| 1778 | expr_ty p; |
| 1779 | if (!s) { |
| 1780 | PyErr_SetString(PyExc_ValueError, |
| 1781 | "field s is required for Bytes"); |
| 1782 | return NULL; |
| 1783 | } |
| 1784 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1785 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1786 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1787 | p->kind = Bytes_kind; |
| 1788 | p->v.Bytes.s = s; |
| 1789 | p->lineno = lineno; |
| 1790 | p->col_offset = col_offset; |
| 1791 | return p; |
| 1792 | } |
| 1793 | |
| 1794 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1795 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1796 | { |
| 1797 | expr_ty p; |
| 1798 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1799 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1800 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1801 | p->kind = Ellipsis_kind; |
| 1802 | p->lineno = lineno; |
| 1803 | p->col_offset = col_offset; |
| 1804 | return p; |
| 1805 | } |
| 1806 | |
| 1807 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1808 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1809 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1810 | { |
| 1811 | expr_ty p; |
| 1812 | if (!value) { |
| 1813 | PyErr_SetString(PyExc_ValueError, |
| 1814 | "field value is required for Attribute"); |
| 1815 | return NULL; |
| 1816 | } |
| 1817 | if (!attr) { |
| 1818 | PyErr_SetString(PyExc_ValueError, |
| 1819 | "field attr is required for Attribute"); |
| 1820 | return NULL; |
| 1821 | } |
| 1822 | if (!ctx) { |
| 1823 | PyErr_SetString(PyExc_ValueError, |
| 1824 | "field ctx is required for Attribute"); |
| 1825 | return NULL; |
| 1826 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1827 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1828 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1829 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1830 | p->kind = Attribute_kind; |
| 1831 | p->v.Attribute.value = value; |
| 1832 | p->v.Attribute.attr = attr; |
| 1833 | p->v.Attribute.ctx = ctx; |
| 1834 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1835 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1836 | return p; |
| 1837 | } |
| 1838 | |
| 1839 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1840 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1841 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | { |
| 1843 | expr_ty p; |
| 1844 | if (!value) { |
| 1845 | PyErr_SetString(PyExc_ValueError, |
| 1846 | "field value is required for Subscript"); |
| 1847 | return NULL; |
| 1848 | } |
| 1849 | if (!slice) { |
| 1850 | PyErr_SetString(PyExc_ValueError, |
| 1851 | "field slice is required for Subscript"); |
| 1852 | return NULL; |
| 1853 | } |
| 1854 | if (!ctx) { |
| 1855 | PyErr_SetString(PyExc_ValueError, |
| 1856 | "field ctx is required for Subscript"); |
| 1857 | return NULL; |
| 1858 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1859 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1860 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1861 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1862 | p->kind = Subscript_kind; |
| 1863 | p->v.Subscript.value = value; |
| 1864 | p->v.Subscript.slice = slice; |
| 1865 | p->v.Subscript.ctx = ctx; |
| 1866 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1867 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1868 | return p; |
| 1869 | } |
| 1870 | |
| 1871 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1872 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1873 | *arena) |
| 1874 | { |
| 1875 | expr_ty p; |
| 1876 | if (!value) { |
| 1877 | PyErr_SetString(PyExc_ValueError, |
| 1878 | "field value is required for Starred"); |
| 1879 | return NULL; |
| 1880 | } |
| 1881 | if (!ctx) { |
| 1882 | PyErr_SetString(PyExc_ValueError, |
| 1883 | "field ctx is required for Starred"); |
| 1884 | return NULL; |
| 1885 | } |
| 1886 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1887 | if (!p) |
| 1888 | return NULL; |
| 1889 | p->kind = Starred_kind; |
| 1890 | p->v.Starred.value = value; |
| 1891 | p->v.Starred.ctx = ctx; |
| 1892 | p->lineno = lineno; |
| 1893 | p->col_offset = col_offset; |
| 1894 | return p; |
| 1895 | } |
| 1896 | |
| 1897 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1898 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1899 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1900 | { |
| 1901 | expr_ty p; |
| 1902 | if (!id) { |
| 1903 | PyErr_SetString(PyExc_ValueError, |
| 1904 | "field id is required for Name"); |
| 1905 | return NULL; |
| 1906 | } |
| 1907 | if (!ctx) { |
| 1908 | PyErr_SetString(PyExc_ValueError, |
| 1909 | "field ctx is required for Name"); |
| 1910 | return NULL; |
| 1911 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1912 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1913 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1914 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | p->kind = Name_kind; |
| 1916 | p->v.Name.id = id; |
| 1917 | p->v.Name.ctx = ctx; |
| 1918 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1919 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1920 | return p; |
| 1921 | } |
| 1922 | |
| 1923 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1924 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1925 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1926 | { |
| 1927 | expr_ty p; |
| 1928 | if (!ctx) { |
| 1929 | PyErr_SetString(PyExc_ValueError, |
| 1930 | "field ctx is required for List"); |
| 1931 | return NULL; |
| 1932 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1933 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1934 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | p->kind = List_kind; |
| 1937 | p->v.List.elts = elts; |
| 1938 | p->v.List.ctx = ctx; |
| 1939 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1940 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1941 | return p; |
| 1942 | } |
| 1943 | |
| 1944 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1945 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1946 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1947 | { |
| 1948 | expr_ty p; |
| 1949 | if (!ctx) { |
| 1950 | PyErr_SetString(PyExc_ValueError, |
| 1951 | "field ctx is required for Tuple"); |
| 1952 | return NULL; |
| 1953 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1954 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1955 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1956 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1957 | p->kind = Tuple_kind; |
| 1958 | p->v.Tuple.elts = elts; |
| 1959 | p->v.Tuple.ctx = ctx; |
| 1960 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1961 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1962 | return p; |
| 1963 | } |
| 1964 | |
| 1965 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1966 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1967 | { |
| 1968 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1969 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1970 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1971 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | p->kind = Slice_kind; |
| 1973 | p->v.Slice.lower = lower; |
| 1974 | p->v.Slice.upper = upper; |
| 1975 | p->v.Slice.step = step; |
| 1976 | return p; |
| 1977 | } |
| 1978 | |
| 1979 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1980 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1981 | { |
| 1982 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1983 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1984 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1985 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1986 | p->kind = ExtSlice_kind; |
| 1987 | p->v.ExtSlice.dims = dims; |
| 1988 | return p; |
| 1989 | } |
| 1990 | |
| 1991 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1992 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1993 | { |
| 1994 | slice_ty p; |
| 1995 | if (!value) { |
| 1996 | PyErr_SetString(PyExc_ValueError, |
| 1997 | "field value is required for Index"); |
| 1998 | return NULL; |
| 1999 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2000 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2001 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2002 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | p->kind = Index_kind; |
| 2004 | p->v.Index.value = value; |
| 2005 | return p; |
| 2006 | } |
| 2007 | |
| 2008 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2009 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2010 | { |
| 2011 | comprehension_ty p; |
| 2012 | if (!target) { |
| 2013 | PyErr_SetString(PyExc_ValueError, |
| 2014 | "field target is required for comprehension"); |
| 2015 | return NULL; |
| 2016 | } |
| 2017 | if (!iter) { |
| 2018 | PyErr_SetString(PyExc_ValueError, |
| 2019 | "field iter is required for comprehension"); |
| 2020 | return NULL; |
| 2021 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2022 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2023 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2024 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2025 | p->target = target; |
| 2026 | p->iter = iter; |
| 2027 | p->ifs = ifs; |
| 2028 | return p; |
| 2029 | } |
| 2030 | |
| 2031 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2032 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2033 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2034 | { |
| 2035 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2036 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2037 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2038 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2039 | p->kind = ExceptHandler_kind; |
| 2040 | p->v.ExceptHandler.type = type; |
| 2041 | p->v.ExceptHandler.name = name; |
| 2042 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2043 | p->lineno = lineno; |
| 2044 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | return p; |
| 2046 | } |
| 2047 | |
| 2048 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2049 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2050 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2051 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2052 | { |
| 2053 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2054 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2055 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2056 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | p->args = args; |
| 2058 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2059 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2060 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2062 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2063 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2064 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | return p; |
| 2066 | } |
| 2067 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2068 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2069 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2070 | { |
| 2071 | arg_ty p; |
| 2072 | if (!arg) { |
| 2073 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2074 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2075 | return NULL; |
| 2076 | } |
| 2077 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2078 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2079 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2080 | p->arg = arg; |
| 2081 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2082 | return p; |
| 2083 | } |
| 2084 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2086 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2087 | { |
| 2088 | keyword_ty p; |
| 2089 | if (!arg) { |
| 2090 | PyErr_SetString(PyExc_ValueError, |
| 2091 | "field arg is required for keyword"); |
| 2092 | return NULL; |
| 2093 | } |
| 2094 | if (!value) { |
| 2095 | PyErr_SetString(PyExc_ValueError, |
| 2096 | "field value is required for keyword"); |
| 2097 | return NULL; |
| 2098 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2099 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2100 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2101 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2102 | p->arg = arg; |
| 2103 | p->value = value; |
| 2104 | return p; |
| 2105 | } |
| 2106 | |
| 2107 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2108 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | { |
| 2110 | alias_ty p; |
| 2111 | if (!name) { |
| 2112 | PyErr_SetString(PyExc_ValueError, |
| 2113 | "field name is required for alias"); |
| 2114 | return NULL; |
| 2115 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2116 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2117 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2118 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2119 | p->name = name; |
| 2120 | p->asname = asname; |
| 2121 | return p; |
| 2122 | } |
| 2123 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2124 | withitem_ty |
| 2125 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2126 | { |
| 2127 | withitem_ty p; |
| 2128 | if (!context_expr) { |
| 2129 | PyErr_SetString(PyExc_ValueError, |
| 2130 | "field context_expr is required for withitem"); |
| 2131 | return NULL; |
| 2132 | } |
| 2133 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2134 | if (!p) |
| 2135 | return NULL; |
| 2136 | p->context_expr = context_expr; |
| 2137 | p->optional_vars = optional_vars; |
| 2138 | return p; |
| 2139 | } |
| 2140 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2141 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2142 | PyObject* |
| 2143 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2144 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2145 | mod_ty o = (mod_ty)_o; |
| 2146 | PyObject *result = NULL, *value = NULL; |
| 2147 | if (!o) { |
| 2148 | Py_INCREF(Py_None); |
| 2149 | return Py_None; |
| 2150 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2151 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2152 | switch (o->kind) { |
| 2153 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2154 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2155 | if (!result) goto failed; |
| 2156 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2157 | if (!value) goto failed; |
| 2158 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2159 | goto failed; |
| 2160 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2161 | break; |
| 2162 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2163 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2164 | if (!result) goto failed; |
| 2165 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2166 | if (!value) goto failed; |
| 2167 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2168 | goto failed; |
| 2169 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2172 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2173 | if (!result) goto failed; |
| 2174 | value = ast2obj_expr(o->v.Expression.body); |
| 2175 | if (!value) goto failed; |
| 2176 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2177 | goto failed; |
| 2178 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2179 | break; |
| 2180 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2181 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2182 | if (!result) goto failed; |
| 2183 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2184 | if (!value) goto failed; |
| 2185 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2186 | goto failed; |
| 2187 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2188 | break; |
| 2189 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2190 | return result; |
| 2191 | failed: |
| 2192 | Py_XDECREF(value); |
| 2193 | Py_XDECREF(result); |
| 2194 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2197 | PyObject* |
| 2198 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2199 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2200 | stmt_ty o = (stmt_ty)_o; |
| 2201 | PyObject *result = NULL, *value = NULL; |
| 2202 | if (!o) { |
| 2203 | Py_INCREF(Py_None); |
| 2204 | return Py_None; |
| 2205 | } |
| 2206 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2207 | switch (o->kind) { |
| 2208 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2209 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2210 | if (!result) goto failed; |
| 2211 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2212 | if (!value) goto failed; |
| 2213 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2214 | goto failed; |
| 2215 | Py_DECREF(value); |
| 2216 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2217 | if (!value) goto failed; |
| 2218 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2219 | goto failed; |
| 2220 | Py_DECREF(value); |
| 2221 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2222 | if (!value) goto failed; |
| 2223 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2224 | goto failed; |
| 2225 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2226 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2227 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2228 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2229 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2230 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2231 | goto failed; |
| 2232 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2233 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2234 | if (!value) goto failed; |
| 2235 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2236 | goto failed; |
| 2237 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2238 | break; |
| 2239 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2240 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2241 | if (!result) goto failed; |
| 2242 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2243 | if (!value) goto failed; |
| 2244 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2245 | goto failed; |
| 2246 | Py_DECREF(value); |
| 2247 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2248 | if (!value) goto failed; |
| 2249 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2250 | goto failed; |
| 2251 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2252 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2253 | if (!value) goto failed; |
| 2254 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2255 | goto failed; |
| 2256 | Py_DECREF(value); |
| 2257 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2258 | if (!value) goto failed; |
| 2259 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2260 | goto failed; |
| 2261 | Py_DECREF(value); |
| 2262 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2263 | if (!value) goto failed; |
| 2264 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2265 | goto failed; |
| 2266 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2267 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2268 | if (!value) goto failed; |
| 2269 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2270 | goto failed; |
| 2271 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2272 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2273 | ast2obj_expr); |
| 2274 | if (!value) goto failed; |
| 2275 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2276 | -1) |
| 2277 | goto failed; |
| 2278 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2281 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2282 | if (!result) goto failed; |
| 2283 | value = ast2obj_expr(o->v.Return.value); |
| 2284 | if (!value) goto failed; |
| 2285 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2286 | goto failed; |
| 2287 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2288 | break; |
| 2289 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2290 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2291 | if (!result) goto failed; |
| 2292 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2293 | if (!value) goto failed; |
| 2294 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2295 | goto failed; |
| 2296 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2299 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2300 | if (!result) goto failed; |
| 2301 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2302 | if (!value) goto failed; |
| 2303 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2304 | goto failed; |
| 2305 | Py_DECREF(value); |
| 2306 | value = ast2obj_expr(o->v.Assign.value); |
| 2307 | if (!value) goto failed; |
| 2308 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2309 | goto failed; |
| 2310 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2311 | break; |
| 2312 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2313 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2314 | if (!result) goto failed; |
| 2315 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2316 | if (!value) goto failed; |
| 2317 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2318 | goto failed; |
| 2319 | Py_DECREF(value); |
| 2320 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2321 | if (!value) goto failed; |
| 2322 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2323 | goto failed; |
| 2324 | Py_DECREF(value); |
| 2325 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2326 | if (!value) goto failed; |
| 2327 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2328 | goto failed; |
| 2329 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2330 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2331 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2332 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2333 | if (!result) goto failed; |
| 2334 | value = ast2obj_expr(o->v.For.target); |
| 2335 | if (!value) goto failed; |
| 2336 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2337 | goto failed; |
| 2338 | Py_DECREF(value); |
| 2339 | value = ast2obj_expr(o->v.For.iter); |
| 2340 | if (!value) goto failed; |
| 2341 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2342 | goto failed; |
| 2343 | Py_DECREF(value); |
| 2344 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2345 | if (!value) goto failed; |
| 2346 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2347 | goto failed; |
| 2348 | Py_DECREF(value); |
| 2349 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2350 | if (!value) goto failed; |
| 2351 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2352 | goto failed; |
| 2353 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2354 | break; |
| 2355 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2356 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2357 | if (!result) goto failed; |
| 2358 | value = ast2obj_expr(o->v.While.test); |
| 2359 | if (!value) goto failed; |
| 2360 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2361 | goto failed; |
| 2362 | Py_DECREF(value); |
| 2363 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2364 | if (!value) goto failed; |
| 2365 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2366 | goto failed; |
| 2367 | Py_DECREF(value); |
| 2368 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2369 | if (!value) goto failed; |
| 2370 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2371 | goto failed; |
| 2372 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2375 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2376 | if (!result) goto failed; |
| 2377 | value = ast2obj_expr(o->v.If.test); |
| 2378 | if (!value) goto failed; |
| 2379 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2380 | goto failed; |
| 2381 | Py_DECREF(value); |
| 2382 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2383 | if (!value) goto failed; |
| 2384 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2385 | goto failed; |
| 2386 | Py_DECREF(value); |
| 2387 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2388 | if (!value) goto failed; |
| 2389 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2390 | goto failed; |
| 2391 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2392 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2393 | case With_kind: |
| 2394 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2395 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2396 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2397 | if (!value) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2398 | if (PyObject_SetAttrString(result, "items", value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2399 | goto failed; |
| 2400 | Py_DECREF(value); |
| 2401 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2402 | if (!value) goto failed; |
| 2403 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2404 | goto failed; |
| 2405 | Py_DECREF(value); |
| 2406 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2407 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2408 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2409 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2410 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2411 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2412 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2413 | goto failed; |
| 2414 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2415 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2416 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2417 | if (PyObject_SetAttrString(result, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | goto failed; |
| 2419 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2420 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2421 | case Try_kind: |
| 2422 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2423 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2424 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2425 | if (!value) goto failed; |
| 2426 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2427 | goto failed; |
| 2428 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2429 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2430 | if (!value) goto failed; |
| 2431 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2432 | goto failed; |
| 2433 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2434 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2435 | if (!value) goto failed; |
| 2436 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2437 | goto failed; |
| 2438 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2439 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2440 | if (!value) goto failed; |
| 2441 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2442 | goto failed; |
| 2443 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2446 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2447 | if (!result) goto failed; |
| 2448 | value = ast2obj_expr(o->v.Assert.test); |
| 2449 | if (!value) goto failed; |
| 2450 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2451 | goto failed; |
| 2452 | Py_DECREF(value); |
| 2453 | value = ast2obj_expr(o->v.Assert.msg); |
| 2454 | if (!value) goto failed; |
| 2455 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2456 | goto failed; |
| 2457 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2458 | break; |
| 2459 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2460 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2461 | if (!result) goto failed; |
| 2462 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2463 | if (!value) goto failed; |
| 2464 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2465 | goto failed; |
| 2466 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2467 | break; |
| 2468 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2469 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2470 | if (!result) goto failed; |
| 2471 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2472 | if (!value) goto failed; |
| 2473 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2474 | goto failed; |
| 2475 | Py_DECREF(value); |
| 2476 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2477 | if (!value) goto failed; |
| 2478 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2479 | goto failed; |
| 2480 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2481 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2482 | if (!value) goto failed; |
| 2483 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2484 | goto failed; |
| 2485 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2486 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2487 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2488 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2489 | if (!result) goto failed; |
| 2490 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2491 | if (!value) goto failed; |
| 2492 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2493 | goto failed; |
| 2494 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2495 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2496 | case Nonlocal_kind: |
| 2497 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2498 | if (!result) goto failed; |
| 2499 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2500 | if (!value) goto failed; |
| 2501 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2502 | goto failed; |
| 2503 | Py_DECREF(value); |
| 2504 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2505 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2506 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2507 | if (!result) goto failed; |
| 2508 | value = ast2obj_expr(o->v.Expr.value); |
| 2509 | if (!value) goto failed; |
| 2510 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2511 | goto failed; |
| 2512 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2513 | break; |
| 2514 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2515 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2516 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2517 | break; |
| 2518 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2519 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2520 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2523 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2524 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2525 | break; |
| 2526 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2527 | value = ast2obj_int(o->lineno); |
| 2528 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2529 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2530 | goto failed; |
| 2531 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2532 | value = ast2obj_int(o->col_offset); |
| 2533 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2534 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2535 | goto failed; |
| 2536 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2537 | return result; |
| 2538 | failed: |
| 2539 | Py_XDECREF(value); |
| 2540 | Py_XDECREF(result); |
| 2541 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2544 | PyObject* |
| 2545 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2546 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2547 | expr_ty o = (expr_ty)_o; |
| 2548 | PyObject *result = NULL, *value = NULL; |
| 2549 | if (!o) { |
| 2550 | Py_INCREF(Py_None); |
| 2551 | return Py_None; |
| 2552 | } |
| 2553 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2554 | switch (o->kind) { |
| 2555 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2556 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2557 | if (!result) goto failed; |
| 2558 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2559 | if (!value) goto failed; |
| 2560 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2561 | goto failed; |
| 2562 | Py_DECREF(value); |
| 2563 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2564 | if (!value) goto failed; |
| 2565 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2566 | goto failed; |
| 2567 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2568 | break; |
| 2569 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2570 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2571 | if (!result) goto failed; |
| 2572 | value = ast2obj_expr(o->v.BinOp.left); |
| 2573 | if (!value) goto failed; |
| 2574 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2575 | goto failed; |
| 2576 | Py_DECREF(value); |
| 2577 | value = ast2obj_operator(o->v.BinOp.op); |
| 2578 | if (!value) goto failed; |
| 2579 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2580 | goto failed; |
| 2581 | Py_DECREF(value); |
| 2582 | value = ast2obj_expr(o->v.BinOp.right); |
| 2583 | if (!value) goto failed; |
| 2584 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2585 | goto failed; |
| 2586 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2587 | break; |
| 2588 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2589 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2590 | if (!result) goto failed; |
| 2591 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2592 | if (!value) goto failed; |
| 2593 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2594 | goto failed; |
| 2595 | Py_DECREF(value); |
| 2596 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2597 | if (!value) goto failed; |
| 2598 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2599 | goto failed; |
| 2600 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2603 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2604 | if (!result) goto failed; |
| 2605 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2606 | if (!value) goto failed; |
| 2607 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2608 | goto failed; |
| 2609 | Py_DECREF(value); |
| 2610 | value = ast2obj_expr(o->v.Lambda.body); |
| 2611 | if (!value) goto failed; |
| 2612 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2613 | goto failed; |
| 2614 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2615 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2616 | case IfExp_kind: |
| 2617 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2618 | if (!result) goto failed; |
| 2619 | value = ast2obj_expr(o->v.IfExp.test); |
| 2620 | if (!value) goto failed; |
| 2621 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2622 | goto failed; |
| 2623 | Py_DECREF(value); |
| 2624 | value = ast2obj_expr(o->v.IfExp.body); |
| 2625 | if (!value) goto failed; |
| 2626 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2627 | goto failed; |
| 2628 | Py_DECREF(value); |
| 2629 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2630 | if (!value) goto failed; |
| 2631 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
| 2634 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2635 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2636 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2637 | if (!result) goto failed; |
| 2638 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2639 | if (!value) goto failed; |
| 2640 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2641 | goto failed; |
| 2642 | Py_DECREF(value); |
| 2643 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2644 | if (!value) goto failed; |
| 2645 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2646 | goto failed; |
| 2647 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2648 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2649 | case Set_kind: |
| 2650 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2651 | if (!result) goto failed; |
| 2652 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2653 | if (!value) goto failed; |
| 2654 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2655 | goto failed; |
| 2656 | Py_DECREF(value); |
| 2657 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2658 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2659 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2660 | if (!result) goto failed; |
| 2661 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2662 | if (!value) goto failed; |
| 2663 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2664 | goto failed; |
| 2665 | Py_DECREF(value); |
| 2666 | value = ast2obj_list(o->v.ListComp.generators, |
| 2667 | ast2obj_comprehension); |
| 2668 | if (!value) goto failed; |
| 2669 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2670 | goto failed; |
| 2671 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2672 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2673 | case SetComp_kind: |
| 2674 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2675 | if (!result) goto failed; |
| 2676 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2677 | if (!value) goto failed; |
| 2678 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
| 2681 | value = ast2obj_list(o->v.SetComp.generators, |
| 2682 | ast2obj_comprehension); |
| 2683 | if (!value) goto failed; |
| 2684 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2685 | goto failed; |
| 2686 | Py_DECREF(value); |
| 2687 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2688 | case DictComp_kind: |
| 2689 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2690 | if (!result) goto failed; |
| 2691 | value = ast2obj_expr(o->v.DictComp.key); |
| 2692 | if (!value) goto failed; |
| 2693 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2694 | goto failed; |
| 2695 | Py_DECREF(value); |
| 2696 | value = ast2obj_expr(o->v.DictComp.value); |
| 2697 | if (!value) goto failed; |
| 2698 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2699 | goto failed; |
| 2700 | Py_DECREF(value); |
| 2701 | value = ast2obj_list(o->v.DictComp.generators, |
| 2702 | ast2obj_comprehension); |
| 2703 | if (!value) goto failed; |
| 2704 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2705 | goto failed; |
| 2706 | Py_DECREF(value); |
| 2707 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2708 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2709 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2710 | if (!result) goto failed; |
| 2711 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2712 | if (!value) goto failed; |
| 2713 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2714 | goto failed; |
| 2715 | Py_DECREF(value); |
| 2716 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2717 | ast2obj_comprehension); |
| 2718 | if (!value) goto failed; |
| 2719 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2722 | break; |
| 2723 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2724 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2725 | if (!result) goto failed; |
| 2726 | value = ast2obj_expr(o->v.Yield.value); |
| 2727 | if (!value) goto failed; |
| 2728 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2733 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2734 | if (!result) goto failed; |
| 2735 | value = ast2obj_expr(o->v.Compare.left); |
| 2736 | if (!value) goto failed; |
| 2737 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2738 | goto failed; |
| 2739 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2740 | { |
| 2741 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2742 | value = PyList_New(n); |
| 2743 | if (!value) goto failed; |
| 2744 | for(i = 0; i < n; i++) |
| 2745 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2746 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2747 | if (!value) goto failed; |
| 2748 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2749 | goto failed; |
| 2750 | Py_DECREF(value); |
| 2751 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2752 | if (!value) goto failed; |
| 2753 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2754 | goto failed; |
| 2755 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2756 | break; |
| 2757 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2758 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2759 | if (!result) goto failed; |
| 2760 | value = ast2obj_expr(o->v.Call.func); |
| 2761 | if (!value) goto failed; |
| 2762 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2763 | goto failed; |
| 2764 | Py_DECREF(value); |
| 2765 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2766 | if (!value) goto failed; |
| 2767 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2768 | goto failed; |
| 2769 | Py_DECREF(value); |
| 2770 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2771 | if (!value) goto failed; |
| 2772 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2773 | goto failed; |
| 2774 | Py_DECREF(value); |
| 2775 | value = ast2obj_expr(o->v.Call.starargs); |
| 2776 | if (!value) goto failed; |
| 2777 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2778 | goto failed; |
| 2779 | Py_DECREF(value); |
| 2780 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2781 | if (!value) goto failed; |
| 2782 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2783 | goto failed; |
| 2784 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2785 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2786 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2787 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2788 | if (!result) goto failed; |
| 2789 | value = ast2obj_object(o->v.Num.n); |
| 2790 | if (!value) goto failed; |
| 2791 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2792 | goto failed; |
| 2793 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2796 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2797 | if (!result) goto failed; |
| 2798 | value = ast2obj_string(o->v.Str.s); |
| 2799 | if (!value) goto failed; |
| 2800 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2801 | goto failed; |
| 2802 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2803 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2804 | case Bytes_kind: |
| 2805 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2806 | if (!result) goto failed; |
| 2807 | value = ast2obj_string(o->v.Bytes.s); |
| 2808 | if (!value) goto failed; |
| 2809 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2810 | goto failed; |
| 2811 | Py_DECREF(value); |
| 2812 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2813 | case Ellipsis_kind: |
| 2814 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2815 | if (!result) goto failed; |
| 2816 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2817 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2818 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2819 | if (!result) goto failed; |
| 2820 | value = ast2obj_expr(o->v.Attribute.value); |
| 2821 | if (!value) goto failed; |
| 2822 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2823 | goto failed; |
| 2824 | Py_DECREF(value); |
| 2825 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2826 | if (!value) goto failed; |
| 2827 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2828 | goto failed; |
| 2829 | Py_DECREF(value); |
| 2830 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2831 | if (!value) goto failed; |
| 2832 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2833 | goto failed; |
| 2834 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2837 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2838 | if (!result) goto failed; |
| 2839 | value = ast2obj_expr(o->v.Subscript.value); |
| 2840 | if (!value) goto failed; |
| 2841 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2842 | goto failed; |
| 2843 | Py_DECREF(value); |
| 2844 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2845 | if (!value) goto failed; |
| 2846 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2847 | goto failed; |
| 2848 | Py_DECREF(value); |
| 2849 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2850 | if (!value) goto failed; |
| 2851 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2852 | goto failed; |
| 2853 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2854 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2855 | case Starred_kind: |
| 2856 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2857 | if (!result) goto failed; |
| 2858 | value = ast2obj_expr(o->v.Starred.value); |
| 2859 | if (!value) goto failed; |
| 2860 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2861 | goto failed; |
| 2862 | Py_DECREF(value); |
| 2863 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2864 | if (!value) goto failed; |
| 2865 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2866 | goto failed; |
| 2867 | Py_DECREF(value); |
| 2868 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2869 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2870 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2871 | if (!result) goto failed; |
| 2872 | value = ast2obj_identifier(o->v.Name.id); |
| 2873 | if (!value) goto failed; |
| 2874 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2875 | goto failed; |
| 2876 | Py_DECREF(value); |
| 2877 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2878 | if (!value) goto failed; |
| 2879 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2880 | goto failed; |
| 2881 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2882 | break; |
| 2883 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2884 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2885 | if (!result) goto failed; |
| 2886 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2887 | if (!value) goto failed; |
| 2888 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2889 | goto failed; |
| 2890 | Py_DECREF(value); |
| 2891 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2892 | if (!value) goto failed; |
| 2893 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2894 | goto failed; |
| 2895 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2896 | break; |
| 2897 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2898 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2899 | if (!result) goto failed; |
| 2900 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2901 | if (!value) goto failed; |
| 2902 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2903 | goto failed; |
| 2904 | Py_DECREF(value); |
| 2905 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2906 | if (!value) goto failed; |
| 2907 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2908 | goto failed; |
| 2909 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2912 | value = ast2obj_int(o->lineno); |
| 2913 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2914 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2915 | goto failed; |
| 2916 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2917 | value = ast2obj_int(o->col_offset); |
| 2918 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2919 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2920 | goto failed; |
| 2921 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2922 | return result; |
| 2923 | failed: |
| 2924 | Py_XDECREF(value); |
| 2925 | Py_XDECREF(result); |
| 2926 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2929 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2930 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2931 | switch(o) { |
| 2932 | case Load: |
| 2933 | Py_INCREF(Load_singleton); |
| 2934 | return Load_singleton; |
| 2935 | case Store: |
| 2936 | Py_INCREF(Store_singleton); |
| 2937 | return Store_singleton; |
| 2938 | case Del: |
| 2939 | Py_INCREF(Del_singleton); |
| 2940 | return Del_singleton; |
| 2941 | case AugLoad: |
| 2942 | Py_INCREF(AugLoad_singleton); |
| 2943 | return AugLoad_singleton; |
| 2944 | case AugStore: |
| 2945 | Py_INCREF(AugStore_singleton); |
| 2946 | return AugStore_singleton; |
| 2947 | case Param: |
| 2948 | Py_INCREF(Param_singleton); |
| 2949 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2950 | default: |
| 2951 | /* should never happen, but just in case ... */ |
| 2952 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2953 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2954 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2955 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2956 | PyObject* |
| 2957 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2958 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2959 | slice_ty o = (slice_ty)_o; |
| 2960 | PyObject *result = NULL, *value = NULL; |
| 2961 | if (!o) { |
| 2962 | Py_INCREF(Py_None); |
| 2963 | return Py_None; |
| 2964 | } |
| 2965 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2966 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2967 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2968 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2969 | if (!result) goto failed; |
| 2970 | value = ast2obj_expr(o->v.Slice.lower); |
| 2971 | if (!value) goto failed; |
| 2972 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2973 | goto failed; |
| 2974 | Py_DECREF(value); |
| 2975 | value = ast2obj_expr(o->v.Slice.upper); |
| 2976 | if (!value) goto failed; |
| 2977 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2978 | goto failed; |
| 2979 | Py_DECREF(value); |
| 2980 | value = ast2obj_expr(o->v.Slice.step); |
| 2981 | if (!value) goto failed; |
| 2982 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2985 | break; |
| 2986 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2987 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2988 | if (!result) goto failed; |
| 2989 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 2990 | if (!value) goto failed; |
| 2991 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 2992 | goto failed; |
| 2993 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2994 | break; |
| 2995 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2996 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 2997 | if (!result) goto failed; |
| 2998 | value = ast2obj_expr(o->v.Index.value); |
| 2999 | if (!value) goto failed; |
| 3000 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3001 | goto failed; |
| 3002 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3003 | break; |
| 3004 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3005 | return result; |
| 3006 | failed: |
| 3007 | Py_XDECREF(value); |
| 3008 | Py_XDECREF(result); |
| 3009 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3012 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3013 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3014 | switch(o) { |
| 3015 | case And: |
| 3016 | Py_INCREF(And_singleton); |
| 3017 | return And_singleton; |
| 3018 | case Or: |
| 3019 | Py_INCREF(Or_singleton); |
| 3020 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3021 | default: |
| 3022 | /* should never happen, but just in case ... */ |
| 3023 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3024 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3025 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3026 | } |
| 3027 | PyObject* ast2obj_operator(operator_ty o) |
| 3028 | { |
| 3029 | switch(o) { |
| 3030 | case Add: |
| 3031 | Py_INCREF(Add_singleton); |
| 3032 | return Add_singleton; |
| 3033 | case Sub: |
| 3034 | Py_INCREF(Sub_singleton); |
| 3035 | return Sub_singleton; |
| 3036 | case Mult: |
| 3037 | Py_INCREF(Mult_singleton); |
| 3038 | return Mult_singleton; |
| 3039 | case Div: |
| 3040 | Py_INCREF(Div_singleton); |
| 3041 | return Div_singleton; |
| 3042 | case Mod: |
| 3043 | Py_INCREF(Mod_singleton); |
| 3044 | return Mod_singleton; |
| 3045 | case Pow: |
| 3046 | Py_INCREF(Pow_singleton); |
| 3047 | return Pow_singleton; |
| 3048 | case LShift: |
| 3049 | Py_INCREF(LShift_singleton); |
| 3050 | return LShift_singleton; |
| 3051 | case RShift: |
| 3052 | Py_INCREF(RShift_singleton); |
| 3053 | return RShift_singleton; |
| 3054 | case BitOr: |
| 3055 | Py_INCREF(BitOr_singleton); |
| 3056 | return BitOr_singleton; |
| 3057 | case BitXor: |
| 3058 | Py_INCREF(BitXor_singleton); |
| 3059 | return BitXor_singleton; |
| 3060 | case BitAnd: |
| 3061 | Py_INCREF(BitAnd_singleton); |
| 3062 | return BitAnd_singleton; |
| 3063 | case FloorDiv: |
| 3064 | Py_INCREF(FloorDiv_singleton); |
| 3065 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3066 | default: |
| 3067 | /* should never happen, but just in case ... */ |
| 3068 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3069 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3070 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3071 | } |
| 3072 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3073 | { |
| 3074 | switch(o) { |
| 3075 | case Invert: |
| 3076 | Py_INCREF(Invert_singleton); |
| 3077 | return Invert_singleton; |
| 3078 | case Not: |
| 3079 | Py_INCREF(Not_singleton); |
| 3080 | return Not_singleton; |
| 3081 | case UAdd: |
| 3082 | Py_INCREF(UAdd_singleton); |
| 3083 | return UAdd_singleton; |
| 3084 | case USub: |
| 3085 | Py_INCREF(USub_singleton); |
| 3086 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3087 | default: |
| 3088 | /* should never happen, but just in case ... */ |
| 3089 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3090 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3091 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3092 | } |
| 3093 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3094 | { |
| 3095 | switch(o) { |
| 3096 | case Eq: |
| 3097 | Py_INCREF(Eq_singleton); |
| 3098 | return Eq_singleton; |
| 3099 | case NotEq: |
| 3100 | Py_INCREF(NotEq_singleton); |
| 3101 | return NotEq_singleton; |
| 3102 | case Lt: |
| 3103 | Py_INCREF(Lt_singleton); |
| 3104 | return Lt_singleton; |
| 3105 | case LtE: |
| 3106 | Py_INCREF(LtE_singleton); |
| 3107 | return LtE_singleton; |
| 3108 | case Gt: |
| 3109 | Py_INCREF(Gt_singleton); |
| 3110 | return Gt_singleton; |
| 3111 | case GtE: |
| 3112 | Py_INCREF(GtE_singleton); |
| 3113 | return GtE_singleton; |
| 3114 | case Is: |
| 3115 | Py_INCREF(Is_singleton); |
| 3116 | return Is_singleton; |
| 3117 | case IsNot: |
| 3118 | Py_INCREF(IsNot_singleton); |
| 3119 | return IsNot_singleton; |
| 3120 | case In: |
| 3121 | Py_INCREF(In_singleton); |
| 3122 | return In_singleton; |
| 3123 | case NotIn: |
| 3124 | Py_INCREF(NotIn_singleton); |
| 3125 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3126 | default: |
| 3127 | /* should never happen, but just in case ... */ |
| 3128 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3129 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3130 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3131 | } |
| 3132 | PyObject* |
| 3133 | ast2obj_comprehension(void* _o) |
| 3134 | { |
| 3135 | comprehension_ty o = (comprehension_ty)_o; |
| 3136 | PyObject *result = NULL, *value = NULL; |
| 3137 | if (!o) { |
| 3138 | Py_INCREF(Py_None); |
| 3139 | return Py_None; |
| 3140 | } |
| 3141 | |
| 3142 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3143 | if (!result) return NULL; |
| 3144 | value = ast2obj_expr(o->target); |
| 3145 | if (!value) goto failed; |
| 3146 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3147 | goto failed; |
| 3148 | Py_DECREF(value); |
| 3149 | value = ast2obj_expr(o->iter); |
| 3150 | if (!value) goto failed; |
| 3151 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3152 | goto failed; |
| 3153 | Py_DECREF(value); |
| 3154 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3155 | if (!value) goto failed; |
| 3156 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3157 | goto failed; |
| 3158 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3159 | return result; |
| 3160 | failed: |
| 3161 | Py_XDECREF(value); |
| 3162 | Py_XDECREF(result); |
| 3163 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3166 | PyObject* |
| 3167 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3168 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3169 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3170 | PyObject *result = NULL, *value = NULL; |
| 3171 | if (!o) { |
| 3172 | Py_INCREF(Py_None); |
| 3173 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3174 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3175 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3176 | switch (o->kind) { |
| 3177 | case ExceptHandler_kind: |
| 3178 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3179 | if (!result) goto failed; |
| 3180 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3181 | if (!value) goto failed; |
| 3182 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3183 | goto failed; |
| 3184 | Py_DECREF(value); |
| 3185 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3186 | if (!value) goto failed; |
| 3187 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3188 | goto failed; |
| 3189 | Py_DECREF(value); |
| 3190 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3191 | if (!value) goto failed; |
| 3192 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
| 3195 | break; |
| 3196 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3197 | value = ast2obj_int(o->lineno); |
| 3198 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3199 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3200 | goto failed; |
| 3201 | Py_DECREF(value); |
| 3202 | value = ast2obj_int(o->col_offset); |
| 3203 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3204 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3205 | goto failed; |
| 3206 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3207 | return result; |
| 3208 | failed: |
| 3209 | Py_XDECREF(value); |
| 3210 | Py_XDECREF(result); |
| 3211 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3214 | PyObject* |
| 3215 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3216 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3217 | arguments_ty o = (arguments_ty)_o; |
| 3218 | PyObject *result = NULL, *value = NULL; |
| 3219 | if (!o) { |
| 3220 | Py_INCREF(Py_None); |
| 3221 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3222 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3223 | |
| 3224 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3225 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3226 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | if (!value) goto failed; |
| 3228 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3229 | goto failed; |
| 3230 | Py_DECREF(value); |
| 3231 | value = ast2obj_identifier(o->vararg); |
| 3232 | if (!value) goto failed; |
| 3233 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3234 | goto failed; |
| 3235 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3236 | value = ast2obj_expr(o->varargannotation); |
| 3237 | if (!value) goto failed; |
| 3238 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3239 | goto failed; |
| 3240 | Py_DECREF(value); |
| 3241 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3242 | if (!value) goto failed; |
| 3243 | if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) |
| 3244 | goto failed; |
| 3245 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3246 | value = ast2obj_identifier(o->kwarg); |
| 3247 | if (!value) goto failed; |
| 3248 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3249 | goto failed; |
| 3250 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3251 | value = ast2obj_expr(o->kwargannotation); |
| 3252 | if (!value) goto failed; |
| 3253 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3254 | goto failed; |
| 3255 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3256 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3257 | if (!value) goto failed; |
| 3258 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3259 | goto failed; |
| 3260 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3261 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3262 | if (!value) goto failed; |
| 3263 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3264 | goto failed; |
| 3265 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3266 | return result; |
| 3267 | failed: |
| 3268 | Py_XDECREF(value); |
| 3269 | Py_XDECREF(result); |
| 3270 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3273 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3274 | ast2obj_arg(void* _o) |
| 3275 | { |
| 3276 | arg_ty o = (arg_ty)_o; |
| 3277 | PyObject *result = NULL, *value = NULL; |
| 3278 | if (!o) { |
| 3279 | Py_INCREF(Py_None); |
| 3280 | return Py_None; |
| 3281 | } |
| 3282 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3283 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3284 | if (!result) return NULL; |
| 3285 | value = ast2obj_identifier(o->arg); |
| 3286 | if (!value) goto failed; |
| 3287 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3288 | goto failed; |
| 3289 | Py_DECREF(value); |
| 3290 | value = ast2obj_expr(o->annotation); |
| 3291 | if (!value) goto failed; |
| 3292 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3293 | goto failed; |
| 3294 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3295 | return result; |
| 3296 | failed: |
| 3297 | Py_XDECREF(value); |
| 3298 | Py_XDECREF(result); |
| 3299 | return NULL; |
| 3300 | } |
| 3301 | |
| 3302 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3303 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3304 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3305 | keyword_ty o = (keyword_ty)_o; |
| 3306 | PyObject *result = NULL, *value = NULL; |
| 3307 | if (!o) { |
| 3308 | Py_INCREF(Py_None); |
| 3309 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3310 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3311 | |
| 3312 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3313 | if (!result) return NULL; |
| 3314 | value = ast2obj_identifier(o->arg); |
| 3315 | if (!value) goto failed; |
| 3316 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3317 | goto failed; |
| 3318 | Py_DECREF(value); |
| 3319 | value = ast2obj_expr(o->value); |
| 3320 | if (!value) goto failed; |
| 3321 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3322 | goto failed; |
| 3323 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3324 | return result; |
| 3325 | failed: |
| 3326 | Py_XDECREF(value); |
| 3327 | Py_XDECREF(result); |
| 3328 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3331 | PyObject* |
| 3332 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3333 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3334 | alias_ty o = (alias_ty)_o; |
| 3335 | PyObject *result = NULL, *value = NULL; |
| 3336 | if (!o) { |
| 3337 | Py_INCREF(Py_None); |
| 3338 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3339 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3340 | |
| 3341 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3342 | if (!result) return NULL; |
| 3343 | value = ast2obj_identifier(o->name); |
| 3344 | if (!value) goto failed; |
| 3345 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3346 | goto failed; |
| 3347 | Py_DECREF(value); |
| 3348 | value = ast2obj_identifier(o->asname); |
| 3349 | if (!value) goto failed; |
| 3350 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3351 | goto failed; |
| 3352 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3353 | return result; |
| 3354 | failed: |
| 3355 | Py_XDECREF(value); |
| 3356 | Py_XDECREF(result); |
| 3357 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3360 | PyObject* |
| 3361 | ast2obj_withitem(void* _o) |
| 3362 | { |
| 3363 | withitem_ty o = (withitem_ty)_o; |
| 3364 | PyObject *result = NULL, *value = NULL; |
| 3365 | if (!o) { |
| 3366 | Py_INCREF(Py_None); |
| 3367 | return Py_None; |
| 3368 | } |
| 3369 | |
| 3370 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3371 | if (!result) return NULL; |
| 3372 | value = ast2obj_expr(o->context_expr); |
| 3373 | if (!value) goto failed; |
| 3374 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 3375 | goto failed; |
| 3376 | Py_DECREF(value); |
| 3377 | value = ast2obj_expr(o->optional_vars); |
| 3378 | if (!value) goto failed; |
| 3379 | if (PyObject_SetAttrString(result, "optional_vars", value) == -1) |
| 3380 | goto failed; |
| 3381 | Py_DECREF(value); |
| 3382 | return result; |
| 3383 | failed: |
| 3384 | Py_XDECREF(value); |
| 3385 | Py_XDECREF(result); |
| 3386 | return NULL; |
| 3387 | } |
| 3388 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3389 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3390 | int |
| 3391 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3392 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3393 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3394 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3395 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3396 | |
| 3397 | if (obj == Py_None) { |
| 3398 | *out = NULL; |
| 3399 | return 0; |
| 3400 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3401 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3402 | if (isinstance == -1) { |
| 3403 | return 1; |
| 3404 | } |
| 3405 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3406 | asdl_seq* body; |
| 3407 | |
| 3408 | if (PyObject_HasAttrString(obj, "body")) { |
| 3409 | int res; |
| 3410 | Py_ssize_t len; |
| 3411 | Py_ssize_t i; |
| 3412 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3413 | if (tmp == NULL) goto failed; |
| 3414 | if (!PyList_Check(tmp)) { |
| 3415 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3416 | goto failed; |
| 3417 | } |
| 3418 | len = PyList_GET_SIZE(tmp); |
| 3419 | body = asdl_seq_new(len, arena); |
| 3420 | if (body == NULL) goto failed; |
| 3421 | for (i = 0; i < len; i++) { |
| 3422 | stmt_ty value; |
| 3423 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3424 | if (res != 0) goto failed; |
| 3425 | asdl_seq_SET(body, i, value); |
| 3426 | } |
| 3427 | Py_XDECREF(tmp); |
| 3428 | tmp = NULL; |
| 3429 | } else { |
| 3430 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3431 | return 1; |
| 3432 | } |
| 3433 | *out = Module(body, arena); |
| 3434 | if (*out == NULL) goto failed; |
| 3435 | return 0; |
| 3436 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3437 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3438 | if (isinstance == -1) { |
| 3439 | return 1; |
| 3440 | } |
| 3441 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3442 | asdl_seq* body; |
| 3443 | |
| 3444 | if (PyObject_HasAttrString(obj, "body")) { |
| 3445 | int res; |
| 3446 | Py_ssize_t len; |
| 3447 | Py_ssize_t i; |
| 3448 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3449 | if (tmp == NULL) goto failed; |
| 3450 | if (!PyList_Check(tmp)) { |
| 3451 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3452 | goto failed; |
| 3453 | } |
| 3454 | len = PyList_GET_SIZE(tmp); |
| 3455 | body = asdl_seq_new(len, arena); |
| 3456 | if (body == NULL) goto failed; |
| 3457 | for (i = 0; i < len; i++) { |
| 3458 | stmt_ty value; |
| 3459 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3460 | if (res != 0) goto failed; |
| 3461 | asdl_seq_SET(body, i, value); |
| 3462 | } |
| 3463 | Py_XDECREF(tmp); |
| 3464 | tmp = NULL; |
| 3465 | } else { |
| 3466 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3467 | return 1; |
| 3468 | } |
| 3469 | *out = Interactive(body, arena); |
| 3470 | if (*out == NULL) goto failed; |
| 3471 | return 0; |
| 3472 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3473 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3474 | if (isinstance == -1) { |
| 3475 | return 1; |
| 3476 | } |
| 3477 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3478 | expr_ty body; |
| 3479 | |
| 3480 | if (PyObject_HasAttrString(obj, "body")) { |
| 3481 | int res; |
| 3482 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3483 | if (tmp == NULL) goto failed; |
| 3484 | res = obj2ast_expr(tmp, &body, arena); |
| 3485 | if (res != 0) goto failed; |
| 3486 | Py_XDECREF(tmp); |
| 3487 | tmp = NULL; |
| 3488 | } else { |
| 3489 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3490 | return 1; |
| 3491 | } |
| 3492 | *out = Expression(body, arena); |
| 3493 | if (*out == NULL) goto failed; |
| 3494 | return 0; |
| 3495 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3496 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3497 | if (isinstance == -1) { |
| 3498 | return 1; |
| 3499 | } |
| 3500 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3501 | asdl_seq* body; |
| 3502 | |
| 3503 | if (PyObject_HasAttrString(obj, "body")) { |
| 3504 | int res; |
| 3505 | Py_ssize_t len; |
| 3506 | Py_ssize_t i; |
| 3507 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3508 | if (tmp == NULL) goto failed; |
| 3509 | if (!PyList_Check(tmp)) { |
| 3510 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3511 | goto failed; |
| 3512 | } |
| 3513 | len = PyList_GET_SIZE(tmp); |
| 3514 | body = asdl_seq_new(len, arena); |
| 3515 | if (body == NULL) goto failed; |
| 3516 | for (i = 0; i < len; i++) { |
| 3517 | stmt_ty value; |
| 3518 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3519 | if (res != 0) goto failed; |
| 3520 | asdl_seq_SET(body, i, value); |
| 3521 | } |
| 3522 | Py_XDECREF(tmp); |
| 3523 | tmp = NULL; |
| 3524 | } else { |
| 3525 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3526 | return 1; |
| 3527 | } |
| 3528 | *out = Suite(body, arena); |
| 3529 | if (*out == NULL) goto failed; |
| 3530 | return 0; |
| 3531 | } |
| 3532 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3533 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3534 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3535 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3536 | return 1; |
| 3537 | } |
| 3538 | |
| 3539 | int |
| 3540 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3541 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3542 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3543 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3544 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3545 | int lineno; |
| 3546 | int col_offset; |
| 3547 | |
| 3548 | if (obj == Py_None) { |
| 3549 | *out = NULL; |
| 3550 | return 0; |
| 3551 | } |
| 3552 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3553 | int res; |
| 3554 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3555 | if (tmp == NULL) goto failed; |
| 3556 | res = obj2ast_int(tmp, &lineno, arena); |
| 3557 | if (res != 0) goto failed; |
| 3558 | Py_XDECREF(tmp); |
| 3559 | tmp = NULL; |
| 3560 | } else { |
| 3561 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3562 | return 1; |
| 3563 | } |
| 3564 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3565 | int res; |
| 3566 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3567 | if (tmp == NULL) goto failed; |
| 3568 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3569 | if (res != 0) goto failed; |
| 3570 | Py_XDECREF(tmp); |
| 3571 | tmp = NULL; |
| 3572 | } else { |
| 3573 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3574 | return 1; |
| 3575 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3576 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3577 | if (isinstance == -1) { |
| 3578 | return 1; |
| 3579 | } |
| 3580 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3581 | identifier name; |
| 3582 | arguments_ty args; |
| 3583 | asdl_seq* body; |
| 3584 | asdl_seq* decorator_list; |
| 3585 | expr_ty returns; |
| 3586 | |
| 3587 | if (PyObject_HasAttrString(obj, "name")) { |
| 3588 | int res; |
| 3589 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3590 | if (tmp == NULL) goto failed; |
| 3591 | res = obj2ast_identifier(tmp, &name, arena); |
| 3592 | if (res != 0) goto failed; |
| 3593 | Py_XDECREF(tmp); |
| 3594 | tmp = NULL; |
| 3595 | } else { |
| 3596 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3597 | return 1; |
| 3598 | } |
| 3599 | if (PyObject_HasAttrString(obj, "args")) { |
| 3600 | int res; |
| 3601 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3602 | if (tmp == NULL) goto failed; |
| 3603 | res = obj2ast_arguments(tmp, &args, arena); |
| 3604 | if (res != 0) goto failed; |
| 3605 | Py_XDECREF(tmp); |
| 3606 | tmp = NULL; |
| 3607 | } else { |
| 3608 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3609 | return 1; |
| 3610 | } |
| 3611 | if (PyObject_HasAttrString(obj, "body")) { |
| 3612 | int res; |
| 3613 | Py_ssize_t len; |
| 3614 | Py_ssize_t i; |
| 3615 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3616 | if (tmp == NULL) goto failed; |
| 3617 | if (!PyList_Check(tmp)) { |
| 3618 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3619 | goto failed; |
| 3620 | } |
| 3621 | len = PyList_GET_SIZE(tmp); |
| 3622 | body = asdl_seq_new(len, arena); |
| 3623 | if (body == NULL) goto failed; |
| 3624 | for (i = 0; i < len; i++) { |
| 3625 | stmt_ty value; |
| 3626 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3627 | if (res != 0) goto failed; |
| 3628 | asdl_seq_SET(body, i, value); |
| 3629 | } |
| 3630 | Py_XDECREF(tmp); |
| 3631 | tmp = NULL; |
| 3632 | } else { |
| 3633 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3634 | return 1; |
| 3635 | } |
| 3636 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3637 | int res; |
| 3638 | Py_ssize_t len; |
| 3639 | Py_ssize_t i; |
| 3640 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3641 | if (tmp == NULL) goto failed; |
| 3642 | if (!PyList_Check(tmp)) { |
| 3643 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3644 | goto failed; |
| 3645 | } |
| 3646 | len = PyList_GET_SIZE(tmp); |
| 3647 | decorator_list = asdl_seq_new(len, arena); |
| 3648 | if (decorator_list == NULL) goto failed; |
| 3649 | for (i = 0; i < len; i++) { |
| 3650 | expr_ty value; |
| 3651 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3652 | if (res != 0) goto failed; |
| 3653 | asdl_seq_SET(decorator_list, i, value); |
| 3654 | } |
| 3655 | Py_XDECREF(tmp); |
| 3656 | tmp = NULL; |
| 3657 | } else { |
| 3658 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3659 | return 1; |
| 3660 | } |
| 3661 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3662 | int res; |
| 3663 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3664 | if (tmp == NULL) goto failed; |
| 3665 | res = obj2ast_expr(tmp, &returns, arena); |
| 3666 | if (res != 0) goto failed; |
| 3667 | Py_XDECREF(tmp); |
| 3668 | tmp = NULL; |
| 3669 | } else { |
| 3670 | returns = NULL; |
| 3671 | } |
| 3672 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3673 | lineno, col_offset, arena); |
| 3674 | if (*out == NULL) goto failed; |
| 3675 | return 0; |
| 3676 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3677 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3678 | if (isinstance == -1) { |
| 3679 | return 1; |
| 3680 | } |
| 3681 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3682 | identifier name; |
| 3683 | asdl_seq* bases; |
| 3684 | asdl_seq* keywords; |
| 3685 | expr_ty starargs; |
| 3686 | expr_ty kwargs; |
| 3687 | asdl_seq* body; |
| 3688 | asdl_seq* decorator_list; |
| 3689 | |
| 3690 | if (PyObject_HasAttrString(obj, "name")) { |
| 3691 | int res; |
| 3692 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3693 | if (tmp == NULL) goto failed; |
| 3694 | res = obj2ast_identifier(tmp, &name, arena); |
| 3695 | if (res != 0) goto failed; |
| 3696 | Py_XDECREF(tmp); |
| 3697 | tmp = NULL; |
| 3698 | } else { |
| 3699 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3700 | return 1; |
| 3701 | } |
| 3702 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3703 | int res; |
| 3704 | Py_ssize_t len; |
| 3705 | Py_ssize_t i; |
| 3706 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3707 | if (tmp == NULL) goto failed; |
| 3708 | if (!PyList_Check(tmp)) { |
| 3709 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3710 | goto failed; |
| 3711 | } |
| 3712 | len = PyList_GET_SIZE(tmp); |
| 3713 | bases = asdl_seq_new(len, arena); |
| 3714 | if (bases == NULL) goto failed; |
| 3715 | for (i = 0; i < len; i++) { |
| 3716 | expr_ty value; |
| 3717 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3718 | if (res != 0) goto failed; |
| 3719 | asdl_seq_SET(bases, i, value); |
| 3720 | } |
| 3721 | Py_XDECREF(tmp); |
| 3722 | tmp = NULL; |
| 3723 | } else { |
| 3724 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3725 | return 1; |
| 3726 | } |
| 3727 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3728 | int res; |
| 3729 | Py_ssize_t len; |
| 3730 | Py_ssize_t i; |
| 3731 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3732 | if (tmp == NULL) goto failed; |
| 3733 | if (!PyList_Check(tmp)) { |
| 3734 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3735 | goto failed; |
| 3736 | } |
| 3737 | len = PyList_GET_SIZE(tmp); |
| 3738 | keywords = asdl_seq_new(len, arena); |
| 3739 | if (keywords == NULL) goto failed; |
| 3740 | for (i = 0; i < len; i++) { |
| 3741 | keyword_ty value; |
| 3742 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3743 | if (res != 0) goto failed; |
| 3744 | asdl_seq_SET(keywords, i, value); |
| 3745 | } |
| 3746 | Py_XDECREF(tmp); |
| 3747 | tmp = NULL; |
| 3748 | } else { |
| 3749 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3750 | return 1; |
| 3751 | } |
| 3752 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3753 | int res; |
| 3754 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3755 | if (tmp == NULL) goto failed; |
| 3756 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3757 | if (res != 0) goto failed; |
| 3758 | Py_XDECREF(tmp); |
| 3759 | tmp = NULL; |
| 3760 | } else { |
| 3761 | starargs = NULL; |
| 3762 | } |
| 3763 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3764 | int res; |
| 3765 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3766 | if (tmp == NULL) goto failed; |
| 3767 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3768 | if (res != 0) goto failed; |
| 3769 | Py_XDECREF(tmp); |
| 3770 | tmp = NULL; |
| 3771 | } else { |
| 3772 | kwargs = NULL; |
| 3773 | } |
| 3774 | if (PyObject_HasAttrString(obj, "body")) { |
| 3775 | int res; |
| 3776 | Py_ssize_t len; |
| 3777 | Py_ssize_t i; |
| 3778 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3779 | if (tmp == NULL) goto failed; |
| 3780 | if (!PyList_Check(tmp)) { |
| 3781 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3782 | goto failed; |
| 3783 | } |
| 3784 | len = PyList_GET_SIZE(tmp); |
| 3785 | body = asdl_seq_new(len, arena); |
| 3786 | if (body == NULL) goto failed; |
| 3787 | for (i = 0; i < len; i++) { |
| 3788 | stmt_ty value; |
| 3789 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3790 | if (res != 0) goto failed; |
| 3791 | asdl_seq_SET(body, i, value); |
| 3792 | } |
| 3793 | Py_XDECREF(tmp); |
| 3794 | tmp = NULL; |
| 3795 | } else { |
| 3796 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3797 | return 1; |
| 3798 | } |
| 3799 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3800 | int res; |
| 3801 | Py_ssize_t len; |
| 3802 | Py_ssize_t i; |
| 3803 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3804 | if (tmp == NULL) goto failed; |
| 3805 | if (!PyList_Check(tmp)) { |
| 3806 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3807 | goto failed; |
| 3808 | } |
| 3809 | len = PyList_GET_SIZE(tmp); |
| 3810 | decorator_list = asdl_seq_new(len, arena); |
| 3811 | if (decorator_list == NULL) goto failed; |
| 3812 | for (i = 0; i < len; i++) { |
| 3813 | expr_ty value; |
| 3814 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3815 | if (res != 0) goto failed; |
| 3816 | asdl_seq_SET(decorator_list, i, value); |
| 3817 | } |
| 3818 | Py_XDECREF(tmp); |
| 3819 | tmp = NULL; |
| 3820 | } else { |
| 3821 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3822 | return 1; |
| 3823 | } |
| 3824 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3825 | decorator_list, lineno, col_offset, arena); |
| 3826 | if (*out == NULL) goto failed; |
| 3827 | return 0; |
| 3828 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3829 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3830 | if (isinstance == -1) { |
| 3831 | return 1; |
| 3832 | } |
| 3833 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3834 | expr_ty value; |
| 3835 | |
| 3836 | if (PyObject_HasAttrString(obj, "value")) { |
| 3837 | int res; |
| 3838 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3839 | if (tmp == NULL) goto failed; |
| 3840 | res = obj2ast_expr(tmp, &value, arena); |
| 3841 | if (res != 0) goto failed; |
| 3842 | Py_XDECREF(tmp); |
| 3843 | tmp = NULL; |
| 3844 | } else { |
| 3845 | value = NULL; |
| 3846 | } |
| 3847 | *out = Return(value, lineno, col_offset, arena); |
| 3848 | if (*out == NULL) goto failed; |
| 3849 | return 0; |
| 3850 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3851 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3852 | if (isinstance == -1) { |
| 3853 | return 1; |
| 3854 | } |
| 3855 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3856 | asdl_seq* targets; |
| 3857 | |
| 3858 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3859 | int res; |
| 3860 | Py_ssize_t len; |
| 3861 | Py_ssize_t i; |
| 3862 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3863 | if (tmp == NULL) goto failed; |
| 3864 | if (!PyList_Check(tmp)) { |
| 3865 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3866 | goto failed; |
| 3867 | } |
| 3868 | len = PyList_GET_SIZE(tmp); |
| 3869 | targets = asdl_seq_new(len, arena); |
| 3870 | if (targets == NULL) goto failed; |
| 3871 | for (i = 0; i < len; i++) { |
| 3872 | expr_ty value; |
| 3873 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3874 | if (res != 0) goto failed; |
| 3875 | asdl_seq_SET(targets, i, value); |
| 3876 | } |
| 3877 | Py_XDECREF(tmp); |
| 3878 | tmp = NULL; |
| 3879 | } else { |
| 3880 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3881 | return 1; |
| 3882 | } |
| 3883 | *out = Delete(targets, lineno, col_offset, arena); |
| 3884 | if (*out == NULL) goto failed; |
| 3885 | return 0; |
| 3886 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3887 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3888 | if (isinstance == -1) { |
| 3889 | return 1; |
| 3890 | } |
| 3891 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3892 | asdl_seq* targets; |
| 3893 | expr_ty value; |
| 3894 | |
| 3895 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3896 | int res; |
| 3897 | Py_ssize_t len; |
| 3898 | Py_ssize_t i; |
| 3899 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3900 | if (tmp == NULL) goto failed; |
| 3901 | if (!PyList_Check(tmp)) { |
| 3902 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3903 | goto failed; |
| 3904 | } |
| 3905 | len = PyList_GET_SIZE(tmp); |
| 3906 | targets = asdl_seq_new(len, arena); |
| 3907 | if (targets == NULL) goto failed; |
| 3908 | for (i = 0; i < len; i++) { |
| 3909 | expr_ty value; |
| 3910 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3911 | if (res != 0) goto failed; |
| 3912 | asdl_seq_SET(targets, i, value); |
| 3913 | } |
| 3914 | Py_XDECREF(tmp); |
| 3915 | tmp = NULL; |
| 3916 | } else { |
| 3917 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3918 | return 1; |
| 3919 | } |
| 3920 | if (PyObject_HasAttrString(obj, "value")) { |
| 3921 | int res; |
| 3922 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3923 | if (tmp == NULL) goto failed; |
| 3924 | res = obj2ast_expr(tmp, &value, arena); |
| 3925 | if (res != 0) goto failed; |
| 3926 | Py_XDECREF(tmp); |
| 3927 | tmp = NULL; |
| 3928 | } else { |
| 3929 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3930 | return 1; |
| 3931 | } |
| 3932 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3933 | if (*out == NULL) goto failed; |
| 3934 | return 0; |
| 3935 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3936 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3937 | if (isinstance == -1) { |
| 3938 | return 1; |
| 3939 | } |
| 3940 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3941 | expr_ty target; |
| 3942 | operator_ty op; |
| 3943 | expr_ty value; |
| 3944 | |
| 3945 | if (PyObject_HasAttrString(obj, "target")) { |
| 3946 | int res; |
| 3947 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3948 | if (tmp == NULL) goto failed; |
| 3949 | res = obj2ast_expr(tmp, &target, arena); |
| 3950 | if (res != 0) goto failed; |
| 3951 | Py_XDECREF(tmp); |
| 3952 | tmp = NULL; |
| 3953 | } else { |
| 3954 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3955 | return 1; |
| 3956 | } |
| 3957 | if (PyObject_HasAttrString(obj, "op")) { |
| 3958 | int res; |
| 3959 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3960 | if (tmp == NULL) goto failed; |
| 3961 | res = obj2ast_operator(tmp, &op, arena); |
| 3962 | if (res != 0) goto failed; |
| 3963 | Py_XDECREF(tmp); |
| 3964 | tmp = NULL; |
| 3965 | } else { |
| 3966 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3967 | return 1; |
| 3968 | } |
| 3969 | if (PyObject_HasAttrString(obj, "value")) { |
| 3970 | int res; |
| 3971 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3972 | if (tmp == NULL) goto failed; |
| 3973 | res = obj2ast_expr(tmp, &value, arena); |
| 3974 | if (res != 0) goto failed; |
| 3975 | Py_XDECREF(tmp); |
| 3976 | tmp = NULL; |
| 3977 | } else { |
| 3978 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3979 | return 1; |
| 3980 | } |
| 3981 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3982 | if (*out == NULL) goto failed; |
| 3983 | return 0; |
| 3984 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3985 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3986 | if (isinstance == -1) { |
| 3987 | return 1; |
| 3988 | } |
| 3989 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3990 | expr_ty target; |
| 3991 | expr_ty iter; |
| 3992 | asdl_seq* body; |
| 3993 | asdl_seq* orelse; |
| 3994 | |
| 3995 | if (PyObject_HasAttrString(obj, "target")) { |
| 3996 | int res; |
| 3997 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3998 | if (tmp == NULL) goto failed; |
| 3999 | res = obj2ast_expr(tmp, &target, arena); |
| 4000 | if (res != 0) goto failed; |
| 4001 | Py_XDECREF(tmp); |
| 4002 | tmp = NULL; |
| 4003 | } else { |
| 4004 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4005 | return 1; |
| 4006 | } |
| 4007 | if (PyObject_HasAttrString(obj, "iter")) { |
| 4008 | int res; |
| 4009 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 4010 | if (tmp == NULL) goto failed; |
| 4011 | res = obj2ast_expr(tmp, &iter, arena); |
| 4012 | if (res != 0) goto failed; |
| 4013 | Py_XDECREF(tmp); |
| 4014 | tmp = NULL; |
| 4015 | } else { |
| 4016 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4017 | return 1; |
| 4018 | } |
| 4019 | if (PyObject_HasAttrString(obj, "body")) { |
| 4020 | int res; |
| 4021 | Py_ssize_t len; |
| 4022 | Py_ssize_t i; |
| 4023 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4024 | if (tmp == NULL) goto failed; |
| 4025 | if (!PyList_Check(tmp)) { |
| 4026 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4027 | goto failed; |
| 4028 | } |
| 4029 | len = PyList_GET_SIZE(tmp); |
| 4030 | body = asdl_seq_new(len, arena); |
| 4031 | if (body == NULL) goto failed; |
| 4032 | for (i = 0; i < len; i++) { |
| 4033 | stmt_ty value; |
| 4034 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4035 | if (res != 0) goto failed; |
| 4036 | asdl_seq_SET(body, i, value); |
| 4037 | } |
| 4038 | Py_XDECREF(tmp); |
| 4039 | tmp = NULL; |
| 4040 | } else { |
| 4041 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4042 | return 1; |
| 4043 | } |
| 4044 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4045 | int res; |
| 4046 | Py_ssize_t len; |
| 4047 | Py_ssize_t i; |
| 4048 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4049 | if (tmp == NULL) goto failed; |
| 4050 | if (!PyList_Check(tmp)) { |
| 4051 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4052 | goto failed; |
| 4053 | } |
| 4054 | len = PyList_GET_SIZE(tmp); |
| 4055 | orelse = asdl_seq_new(len, arena); |
| 4056 | if (orelse == NULL) goto failed; |
| 4057 | for (i = 0; i < len; i++) { |
| 4058 | stmt_ty value; |
| 4059 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4060 | if (res != 0) goto failed; |
| 4061 | asdl_seq_SET(orelse, i, value); |
| 4062 | } |
| 4063 | Py_XDECREF(tmp); |
| 4064 | tmp = NULL; |
| 4065 | } else { |
| 4066 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4067 | return 1; |
| 4068 | } |
| 4069 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4070 | arena); |
| 4071 | if (*out == NULL) goto failed; |
| 4072 | return 0; |
| 4073 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4074 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4075 | if (isinstance == -1) { |
| 4076 | return 1; |
| 4077 | } |
| 4078 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4079 | expr_ty test; |
| 4080 | asdl_seq* body; |
| 4081 | asdl_seq* orelse; |
| 4082 | |
| 4083 | if (PyObject_HasAttrString(obj, "test")) { |
| 4084 | int res; |
| 4085 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4086 | if (tmp == NULL) goto failed; |
| 4087 | res = obj2ast_expr(tmp, &test, arena); |
| 4088 | if (res != 0) goto failed; |
| 4089 | Py_XDECREF(tmp); |
| 4090 | tmp = NULL; |
| 4091 | } else { |
| 4092 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4093 | return 1; |
| 4094 | } |
| 4095 | if (PyObject_HasAttrString(obj, "body")) { |
| 4096 | int res; |
| 4097 | Py_ssize_t len; |
| 4098 | Py_ssize_t i; |
| 4099 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4100 | if (tmp == NULL) goto failed; |
| 4101 | if (!PyList_Check(tmp)) { |
| 4102 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4103 | goto failed; |
| 4104 | } |
| 4105 | len = PyList_GET_SIZE(tmp); |
| 4106 | body = asdl_seq_new(len, arena); |
| 4107 | if (body == NULL) goto failed; |
| 4108 | for (i = 0; i < len; i++) { |
| 4109 | stmt_ty value; |
| 4110 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4111 | if (res != 0) goto failed; |
| 4112 | asdl_seq_SET(body, i, value); |
| 4113 | } |
| 4114 | Py_XDECREF(tmp); |
| 4115 | tmp = NULL; |
| 4116 | } else { |
| 4117 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4118 | return 1; |
| 4119 | } |
| 4120 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4121 | int res; |
| 4122 | Py_ssize_t len; |
| 4123 | Py_ssize_t i; |
| 4124 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4125 | if (tmp == NULL) goto failed; |
| 4126 | if (!PyList_Check(tmp)) { |
| 4127 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4128 | goto failed; |
| 4129 | } |
| 4130 | len = PyList_GET_SIZE(tmp); |
| 4131 | orelse = asdl_seq_new(len, arena); |
| 4132 | if (orelse == NULL) goto failed; |
| 4133 | for (i = 0; i < len; i++) { |
| 4134 | stmt_ty value; |
| 4135 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4136 | if (res != 0) goto failed; |
| 4137 | asdl_seq_SET(orelse, i, value); |
| 4138 | } |
| 4139 | Py_XDECREF(tmp); |
| 4140 | tmp = NULL; |
| 4141 | } else { |
| 4142 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4143 | return 1; |
| 4144 | } |
| 4145 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4146 | if (*out == NULL) goto failed; |
| 4147 | return 0; |
| 4148 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4149 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4150 | if (isinstance == -1) { |
| 4151 | return 1; |
| 4152 | } |
| 4153 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4154 | expr_ty test; |
| 4155 | asdl_seq* body; |
| 4156 | asdl_seq* orelse; |
| 4157 | |
| 4158 | if (PyObject_HasAttrString(obj, "test")) { |
| 4159 | int res; |
| 4160 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4161 | if (tmp == NULL) goto failed; |
| 4162 | res = obj2ast_expr(tmp, &test, arena); |
| 4163 | if (res != 0) goto failed; |
| 4164 | Py_XDECREF(tmp); |
| 4165 | tmp = NULL; |
| 4166 | } else { |
| 4167 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4168 | return 1; |
| 4169 | } |
| 4170 | if (PyObject_HasAttrString(obj, "body")) { |
| 4171 | int res; |
| 4172 | Py_ssize_t len; |
| 4173 | Py_ssize_t i; |
| 4174 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4175 | if (tmp == NULL) goto failed; |
| 4176 | if (!PyList_Check(tmp)) { |
| 4177 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4178 | goto failed; |
| 4179 | } |
| 4180 | len = PyList_GET_SIZE(tmp); |
| 4181 | body = asdl_seq_new(len, arena); |
| 4182 | if (body == NULL) goto failed; |
| 4183 | for (i = 0; i < len; i++) { |
| 4184 | stmt_ty value; |
| 4185 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4186 | if (res != 0) goto failed; |
| 4187 | asdl_seq_SET(body, i, value); |
| 4188 | } |
| 4189 | Py_XDECREF(tmp); |
| 4190 | tmp = NULL; |
| 4191 | } else { |
| 4192 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4193 | return 1; |
| 4194 | } |
| 4195 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4196 | int res; |
| 4197 | Py_ssize_t len; |
| 4198 | Py_ssize_t i; |
| 4199 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4200 | if (tmp == NULL) goto failed; |
| 4201 | if (!PyList_Check(tmp)) { |
| 4202 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4203 | goto failed; |
| 4204 | } |
| 4205 | len = PyList_GET_SIZE(tmp); |
| 4206 | orelse = asdl_seq_new(len, arena); |
| 4207 | if (orelse == NULL) goto failed; |
| 4208 | for (i = 0; i < len; i++) { |
| 4209 | stmt_ty value; |
| 4210 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4211 | if (res != 0) goto failed; |
| 4212 | asdl_seq_SET(orelse, i, value); |
| 4213 | } |
| 4214 | Py_XDECREF(tmp); |
| 4215 | tmp = NULL; |
| 4216 | } else { |
| 4217 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4218 | return 1; |
| 4219 | } |
| 4220 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4221 | if (*out == NULL) goto failed; |
| 4222 | return 0; |
| 4223 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4224 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4225 | if (isinstance == -1) { |
| 4226 | return 1; |
| 4227 | } |
| 4228 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4229 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4230 | asdl_seq* body; |
| 4231 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4232 | if (PyObject_HasAttrString(obj, "items")) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4233 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4234 | Py_ssize_t len; |
| 4235 | Py_ssize_t i; |
| 4236 | tmp = PyObject_GetAttrString(obj, "items"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4237 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4238 | if (!PyList_Check(tmp)) { |
| 4239 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4240 | goto failed; |
| 4241 | } |
| 4242 | len = PyList_GET_SIZE(tmp); |
| 4243 | items = asdl_seq_new(len, arena); |
| 4244 | if (items == NULL) goto failed; |
| 4245 | for (i = 0; i < len; i++) { |
| 4246 | withitem_ty value; |
| 4247 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4248 | if (res != 0) goto failed; |
| 4249 | asdl_seq_SET(items, i, value); |
| 4250 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4251 | Py_XDECREF(tmp); |
| 4252 | tmp = NULL; |
| 4253 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4254 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4255 | return 1; |
| 4256 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4257 | if (PyObject_HasAttrString(obj, "body")) { |
| 4258 | int res; |
| 4259 | Py_ssize_t len; |
| 4260 | Py_ssize_t i; |
| 4261 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4262 | if (tmp == NULL) goto failed; |
| 4263 | if (!PyList_Check(tmp)) { |
| 4264 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4265 | goto failed; |
| 4266 | } |
| 4267 | len = PyList_GET_SIZE(tmp); |
| 4268 | body = asdl_seq_new(len, arena); |
| 4269 | if (body == NULL) goto failed; |
| 4270 | for (i = 0; i < len; i++) { |
| 4271 | stmt_ty value; |
| 4272 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4273 | if (res != 0) goto failed; |
| 4274 | asdl_seq_SET(body, i, value); |
| 4275 | } |
| 4276 | Py_XDECREF(tmp); |
| 4277 | tmp = NULL; |
| 4278 | } else { |
| 4279 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4280 | return 1; |
| 4281 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4282 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4283 | if (*out == NULL) goto failed; |
| 4284 | return 0; |
| 4285 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4286 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4287 | if (isinstance == -1) { |
| 4288 | return 1; |
| 4289 | } |
| 4290 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4291 | expr_ty exc; |
| 4292 | expr_ty cause; |
| 4293 | |
| 4294 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4295 | int res; |
| 4296 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4297 | if (tmp == NULL) goto failed; |
| 4298 | res = obj2ast_expr(tmp, &exc, arena); |
| 4299 | if (res != 0) goto failed; |
| 4300 | Py_XDECREF(tmp); |
| 4301 | tmp = NULL; |
| 4302 | } else { |
| 4303 | exc = NULL; |
| 4304 | } |
| 4305 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4306 | int res; |
| 4307 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4308 | if (tmp == NULL) goto failed; |
| 4309 | res = obj2ast_expr(tmp, &cause, arena); |
| 4310 | if (res != 0) goto failed; |
| 4311 | Py_XDECREF(tmp); |
| 4312 | tmp = NULL; |
| 4313 | } else { |
| 4314 | cause = NULL; |
| 4315 | } |
| 4316 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4317 | if (*out == NULL) goto failed; |
| 4318 | return 0; |
| 4319 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4320 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4321 | if (isinstance == -1) { |
| 4322 | return 1; |
| 4323 | } |
| 4324 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4325 | asdl_seq* body; |
| 4326 | asdl_seq* handlers; |
| 4327 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4328 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4329 | |
| 4330 | if (PyObject_HasAttrString(obj, "body")) { |
| 4331 | int res; |
| 4332 | Py_ssize_t len; |
| 4333 | Py_ssize_t i; |
| 4334 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4335 | if (tmp == NULL) goto failed; |
| 4336 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4337 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4338 | goto failed; |
| 4339 | } |
| 4340 | len = PyList_GET_SIZE(tmp); |
| 4341 | body = asdl_seq_new(len, arena); |
| 4342 | if (body == NULL) goto failed; |
| 4343 | for (i = 0; i < len; i++) { |
| 4344 | stmt_ty value; |
| 4345 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4346 | if (res != 0) goto failed; |
| 4347 | asdl_seq_SET(body, i, value); |
| 4348 | } |
| 4349 | Py_XDECREF(tmp); |
| 4350 | tmp = NULL; |
| 4351 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4352 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4353 | return 1; |
| 4354 | } |
| 4355 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4356 | int res; |
| 4357 | Py_ssize_t len; |
| 4358 | Py_ssize_t i; |
| 4359 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4360 | if (tmp == NULL) goto failed; |
| 4361 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4362 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4363 | goto failed; |
| 4364 | } |
| 4365 | len = PyList_GET_SIZE(tmp); |
| 4366 | handlers = asdl_seq_new(len, arena); |
| 4367 | if (handlers == NULL) goto failed; |
| 4368 | for (i = 0; i < len; i++) { |
| 4369 | excepthandler_ty value; |
| 4370 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4371 | if (res != 0) goto failed; |
| 4372 | asdl_seq_SET(handlers, i, value); |
| 4373 | } |
| 4374 | Py_XDECREF(tmp); |
| 4375 | tmp = NULL; |
| 4376 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4377 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4378 | return 1; |
| 4379 | } |
| 4380 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4381 | int res; |
| 4382 | Py_ssize_t len; |
| 4383 | Py_ssize_t i; |
| 4384 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4385 | if (tmp == NULL) goto failed; |
| 4386 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4387 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4388 | goto failed; |
| 4389 | } |
| 4390 | len = PyList_GET_SIZE(tmp); |
| 4391 | orelse = asdl_seq_new(len, arena); |
| 4392 | if (orelse == NULL) goto failed; |
| 4393 | for (i = 0; i < len; i++) { |
| 4394 | stmt_ty value; |
| 4395 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4396 | if (res != 0) goto failed; |
| 4397 | asdl_seq_SET(orelse, i, value); |
| 4398 | } |
| 4399 | Py_XDECREF(tmp); |
| 4400 | tmp = NULL; |
| 4401 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4402 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4403 | return 1; |
| 4404 | } |
| 4405 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4406 | int res; |
| 4407 | Py_ssize_t len; |
| 4408 | Py_ssize_t i; |
| 4409 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4410 | if (tmp == NULL) goto failed; |
| 4411 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4412 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4413 | goto failed; |
| 4414 | } |
| 4415 | len = PyList_GET_SIZE(tmp); |
| 4416 | finalbody = asdl_seq_new(len, arena); |
| 4417 | if (finalbody == NULL) goto failed; |
| 4418 | for (i = 0; i < len; i++) { |
| 4419 | stmt_ty value; |
| 4420 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4421 | if (res != 0) goto failed; |
| 4422 | asdl_seq_SET(finalbody, i, value); |
| 4423 | } |
| 4424 | Py_XDECREF(tmp); |
| 4425 | tmp = NULL; |
| 4426 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4427 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4428 | return 1; |
| 4429 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4430 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4431 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4432 | if (*out == NULL) goto failed; |
| 4433 | return 0; |
| 4434 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4435 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4436 | if (isinstance == -1) { |
| 4437 | return 1; |
| 4438 | } |
| 4439 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4440 | expr_ty test; |
| 4441 | expr_ty msg; |
| 4442 | |
| 4443 | if (PyObject_HasAttrString(obj, "test")) { |
| 4444 | int res; |
| 4445 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4446 | if (tmp == NULL) goto failed; |
| 4447 | res = obj2ast_expr(tmp, &test, arena); |
| 4448 | if (res != 0) goto failed; |
| 4449 | Py_XDECREF(tmp); |
| 4450 | tmp = NULL; |
| 4451 | } else { |
| 4452 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4453 | return 1; |
| 4454 | } |
| 4455 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4456 | int res; |
| 4457 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4458 | if (tmp == NULL) goto failed; |
| 4459 | res = obj2ast_expr(tmp, &msg, arena); |
| 4460 | if (res != 0) goto failed; |
| 4461 | Py_XDECREF(tmp); |
| 4462 | tmp = NULL; |
| 4463 | } else { |
| 4464 | msg = NULL; |
| 4465 | } |
| 4466 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4467 | if (*out == NULL) goto failed; |
| 4468 | return 0; |
| 4469 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4470 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4471 | if (isinstance == -1) { |
| 4472 | return 1; |
| 4473 | } |
| 4474 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4475 | asdl_seq* names; |
| 4476 | |
| 4477 | if (PyObject_HasAttrString(obj, "names")) { |
| 4478 | int res; |
| 4479 | Py_ssize_t len; |
| 4480 | Py_ssize_t i; |
| 4481 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4482 | if (tmp == NULL) goto failed; |
| 4483 | if (!PyList_Check(tmp)) { |
| 4484 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4485 | goto failed; |
| 4486 | } |
| 4487 | len = PyList_GET_SIZE(tmp); |
| 4488 | names = asdl_seq_new(len, arena); |
| 4489 | if (names == NULL) goto failed; |
| 4490 | for (i = 0; i < len; i++) { |
| 4491 | alias_ty value; |
| 4492 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4493 | if (res != 0) goto failed; |
| 4494 | asdl_seq_SET(names, i, value); |
| 4495 | } |
| 4496 | Py_XDECREF(tmp); |
| 4497 | tmp = NULL; |
| 4498 | } else { |
| 4499 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4500 | return 1; |
| 4501 | } |
| 4502 | *out = Import(names, lineno, col_offset, arena); |
| 4503 | if (*out == NULL) goto failed; |
| 4504 | return 0; |
| 4505 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4506 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4507 | if (isinstance == -1) { |
| 4508 | return 1; |
| 4509 | } |
| 4510 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4511 | identifier module; |
| 4512 | asdl_seq* names; |
| 4513 | int level; |
| 4514 | |
| 4515 | if (PyObject_HasAttrString(obj, "module")) { |
| 4516 | int res; |
| 4517 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4518 | if (tmp == NULL) goto failed; |
| 4519 | res = obj2ast_identifier(tmp, &module, arena); |
| 4520 | if (res != 0) goto failed; |
| 4521 | Py_XDECREF(tmp); |
| 4522 | tmp = NULL; |
| 4523 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4524 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4525 | } |
| 4526 | if (PyObject_HasAttrString(obj, "names")) { |
| 4527 | int res; |
| 4528 | Py_ssize_t len; |
| 4529 | Py_ssize_t i; |
| 4530 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4531 | if (tmp == NULL) goto failed; |
| 4532 | if (!PyList_Check(tmp)) { |
| 4533 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4534 | goto failed; |
| 4535 | } |
| 4536 | len = PyList_GET_SIZE(tmp); |
| 4537 | names = asdl_seq_new(len, arena); |
| 4538 | if (names == NULL) goto failed; |
| 4539 | for (i = 0; i < len; i++) { |
| 4540 | alias_ty value; |
| 4541 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4542 | if (res != 0) goto failed; |
| 4543 | asdl_seq_SET(names, i, value); |
| 4544 | } |
| 4545 | Py_XDECREF(tmp); |
| 4546 | tmp = NULL; |
| 4547 | } else { |
| 4548 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4549 | return 1; |
| 4550 | } |
| 4551 | if (PyObject_HasAttrString(obj, "level")) { |
| 4552 | int res; |
| 4553 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4554 | if (tmp == NULL) goto failed; |
| 4555 | res = obj2ast_int(tmp, &level, arena); |
| 4556 | if (res != 0) goto failed; |
| 4557 | Py_XDECREF(tmp); |
| 4558 | tmp = NULL; |
| 4559 | } else { |
| 4560 | level = 0; |
| 4561 | } |
| 4562 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4563 | arena); |
| 4564 | if (*out == NULL) goto failed; |
| 4565 | return 0; |
| 4566 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4567 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4568 | if (isinstance == -1) { |
| 4569 | return 1; |
| 4570 | } |
| 4571 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4572 | asdl_seq* names; |
| 4573 | |
| 4574 | if (PyObject_HasAttrString(obj, "names")) { |
| 4575 | int res; |
| 4576 | Py_ssize_t len; |
| 4577 | Py_ssize_t i; |
| 4578 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4579 | if (tmp == NULL) goto failed; |
| 4580 | if (!PyList_Check(tmp)) { |
| 4581 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4582 | goto failed; |
| 4583 | } |
| 4584 | len = PyList_GET_SIZE(tmp); |
| 4585 | names = asdl_seq_new(len, arena); |
| 4586 | if (names == NULL) goto failed; |
| 4587 | for (i = 0; i < len; i++) { |
| 4588 | identifier value; |
| 4589 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4590 | if (res != 0) goto failed; |
| 4591 | asdl_seq_SET(names, i, value); |
| 4592 | } |
| 4593 | Py_XDECREF(tmp); |
| 4594 | tmp = NULL; |
| 4595 | } else { |
| 4596 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4597 | return 1; |
| 4598 | } |
| 4599 | *out = Global(names, lineno, col_offset, arena); |
| 4600 | if (*out == NULL) goto failed; |
| 4601 | return 0; |
| 4602 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4603 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4604 | if (isinstance == -1) { |
| 4605 | return 1; |
| 4606 | } |
| 4607 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4608 | asdl_seq* names; |
| 4609 | |
| 4610 | if (PyObject_HasAttrString(obj, "names")) { |
| 4611 | int res; |
| 4612 | Py_ssize_t len; |
| 4613 | Py_ssize_t i; |
| 4614 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4615 | if (tmp == NULL) goto failed; |
| 4616 | if (!PyList_Check(tmp)) { |
| 4617 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4618 | goto failed; |
| 4619 | } |
| 4620 | len = PyList_GET_SIZE(tmp); |
| 4621 | names = asdl_seq_new(len, arena); |
| 4622 | if (names == NULL) goto failed; |
| 4623 | for (i = 0; i < len; i++) { |
| 4624 | identifier value; |
| 4625 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4626 | if (res != 0) goto failed; |
| 4627 | asdl_seq_SET(names, i, value); |
| 4628 | } |
| 4629 | Py_XDECREF(tmp); |
| 4630 | tmp = NULL; |
| 4631 | } else { |
| 4632 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4633 | return 1; |
| 4634 | } |
| 4635 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4636 | if (*out == NULL) goto failed; |
| 4637 | return 0; |
| 4638 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4639 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4640 | if (isinstance == -1) { |
| 4641 | return 1; |
| 4642 | } |
| 4643 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4644 | expr_ty value; |
| 4645 | |
| 4646 | if (PyObject_HasAttrString(obj, "value")) { |
| 4647 | int res; |
| 4648 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4649 | if (tmp == NULL) goto failed; |
| 4650 | res = obj2ast_expr(tmp, &value, arena); |
| 4651 | if (res != 0) goto failed; |
| 4652 | Py_XDECREF(tmp); |
| 4653 | tmp = NULL; |
| 4654 | } else { |
| 4655 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4656 | return 1; |
| 4657 | } |
| 4658 | *out = Expr(value, lineno, col_offset, arena); |
| 4659 | if (*out == NULL) goto failed; |
| 4660 | return 0; |
| 4661 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4662 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 4663 | if (isinstance == -1) { |
| 4664 | return 1; |
| 4665 | } |
| 4666 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4667 | |
| 4668 | *out = Pass(lineno, col_offset, arena); |
| 4669 | if (*out == NULL) goto failed; |
| 4670 | return 0; |
| 4671 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4672 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 4673 | if (isinstance == -1) { |
| 4674 | return 1; |
| 4675 | } |
| 4676 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4677 | |
| 4678 | *out = Break(lineno, col_offset, arena); |
| 4679 | if (*out == NULL) goto failed; |
| 4680 | return 0; |
| 4681 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4682 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4683 | if (isinstance == -1) { |
| 4684 | return 1; |
| 4685 | } |
| 4686 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4687 | |
| 4688 | *out = Continue(lineno, col_offset, arena); |
| 4689 | if (*out == NULL) goto failed; |
| 4690 | return 0; |
| 4691 | } |
| 4692 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4693 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4694 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4695 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4696 | return 1; |
| 4697 | } |
| 4698 | |
| 4699 | int |
| 4700 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4701 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4702 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4703 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4704 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4705 | int lineno; |
| 4706 | int col_offset; |
| 4707 | |
| 4708 | if (obj == Py_None) { |
| 4709 | *out = NULL; |
| 4710 | return 0; |
| 4711 | } |
| 4712 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4713 | int res; |
| 4714 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4715 | if (tmp == NULL) goto failed; |
| 4716 | res = obj2ast_int(tmp, &lineno, arena); |
| 4717 | if (res != 0) goto failed; |
| 4718 | Py_XDECREF(tmp); |
| 4719 | tmp = NULL; |
| 4720 | } else { |
| 4721 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4722 | return 1; |
| 4723 | } |
| 4724 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4725 | int res; |
| 4726 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4727 | if (tmp == NULL) goto failed; |
| 4728 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4729 | if (res != 0) goto failed; |
| 4730 | Py_XDECREF(tmp); |
| 4731 | tmp = NULL; |
| 4732 | } else { |
| 4733 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4734 | return 1; |
| 4735 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4736 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4737 | if (isinstance == -1) { |
| 4738 | return 1; |
| 4739 | } |
| 4740 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4741 | boolop_ty op; |
| 4742 | asdl_seq* values; |
| 4743 | |
| 4744 | if (PyObject_HasAttrString(obj, "op")) { |
| 4745 | int res; |
| 4746 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4747 | if (tmp == NULL) goto failed; |
| 4748 | res = obj2ast_boolop(tmp, &op, arena); |
| 4749 | if (res != 0) goto failed; |
| 4750 | Py_XDECREF(tmp); |
| 4751 | tmp = NULL; |
| 4752 | } else { |
| 4753 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4754 | return 1; |
| 4755 | } |
| 4756 | if (PyObject_HasAttrString(obj, "values")) { |
| 4757 | int res; |
| 4758 | Py_ssize_t len; |
| 4759 | Py_ssize_t i; |
| 4760 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4761 | if (tmp == NULL) goto failed; |
| 4762 | if (!PyList_Check(tmp)) { |
| 4763 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4764 | goto failed; |
| 4765 | } |
| 4766 | len = PyList_GET_SIZE(tmp); |
| 4767 | values = asdl_seq_new(len, arena); |
| 4768 | if (values == NULL) goto failed; |
| 4769 | for (i = 0; i < len; i++) { |
| 4770 | expr_ty value; |
| 4771 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4772 | if (res != 0) goto failed; |
| 4773 | asdl_seq_SET(values, i, value); |
| 4774 | } |
| 4775 | Py_XDECREF(tmp); |
| 4776 | tmp = NULL; |
| 4777 | } else { |
| 4778 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4779 | return 1; |
| 4780 | } |
| 4781 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4782 | if (*out == NULL) goto failed; |
| 4783 | return 0; |
| 4784 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4785 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4786 | if (isinstance == -1) { |
| 4787 | return 1; |
| 4788 | } |
| 4789 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4790 | expr_ty left; |
| 4791 | operator_ty op; |
| 4792 | expr_ty right; |
| 4793 | |
| 4794 | if (PyObject_HasAttrString(obj, "left")) { |
| 4795 | int res; |
| 4796 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4797 | if (tmp == NULL) goto failed; |
| 4798 | res = obj2ast_expr(tmp, &left, arena); |
| 4799 | if (res != 0) goto failed; |
| 4800 | Py_XDECREF(tmp); |
| 4801 | tmp = NULL; |
| 4802 | } else { |
| 4803 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4804 | return 1; |
| 4805 | } |
| 4806 | if (PyObject_HasAttrString(obj, "op")) { |
| 4807 | int res; |
| 4808 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4809 | if (tmp == NULL) goto failed; |
| 4810 | res = obj2ast_operator(tmp, &op, arena); |
| 4811 | if (res != 0) goto failed; |
| 4812 | Py_XDECREF(tmp); |
| 4813 | tmp = NULL; |
| 4814 | } else { |
| 4815 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4816 | return 1; |
| 4817 | } |
| 4818 | if (PyObject_HasAttrString(obj, "right")) { |
| 4819 | int res; |
| 4820 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4821 | if (tmp == NULL) goto failed; |
| 4822 | res = obj2ast_expr(tmp, &right, arena); |
| 4823 | if (res != 0) goto failed; |
| 4824 | Py_XDECREF(tmp); |
| 4825 | tmp = NULL; |
| 4826 | } else { |
| 4827 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4828 | return 1; |
| 4829 | } |
| 4830 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4831 | if (*out == NULL) goto failed; |
| 4832 | return 0; |
| 4833 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4834 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4835 | if (isinstance == -1) { |
| 4836 | return 1; |
| 4837 | } |
| 4838 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4839 | unaryop_ty op; |
| 4840 | expr_ty operand; |
| 4841 | |
| 4842 | if (PyObject_HasAttrString(obj, "op")) { |
| 4843 | int res; |
| 4844 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4845 | if (tmp == NULL) goto failed; |
| 4846 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4847 | if (res != 0) goto failed; |
| 4848 | Py_XDECREF(tmp); |
| 4849 | tmp = NULL; |
| 4850 | } else { |
| 4851 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4852 | return 1; |
| 4853 | } |
| 4854 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4855 | int res; |
| 4856 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4857 | if (tmp == NULL) goto failed; |
| 4858 | res = obj2ast_expr(tmp, &operand, arena); |
| 4859 | if (res != 0) goto failed; |
| 4860 | Py_XDECREF(tmp); |
| 4861 | tmp = NULL; |
| 4862 | } else { |
| 4863 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4864 | return 1; |
| 4865 | } |
| 4866 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4867 | if (*out == NULL) goto failed; |
| 4868 | return 0; |
| 4869 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4870 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4871 | if (isinstance == -1) { |
| 4872 | return 1; |
| 4873 | } |
| 4874 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4875 | arguments_ty args; |
| 4876 | expr_ty body; |
| 4877 | |
| 4878 | if (PyObject_HasAttrString(obj, "args")) { |
| 4879 | int res; |
| 4880 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4881 | if (tmp == NULL) goto failed; |
| 4882 | res = obj2ast_arguments(tmp, &args, arena); |
| 4883 | if (res != 0) goto failed; |
| 4884 | Py_XDECREF(tmp); |
| 4885 | tmp = NULL; |
| 4886 | } else { |
| 4887 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4888 | return 1; |
| 4889 | } |
| 4890 | if (PyObject_HasAttrString(obj, "body")) { |
| 4891 | int res; |
| 4892 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4893 | if (tmp == NULL) goto failed; |
| 4894 | res = obj2ast_expr(tmp, &body, arena); |
| 4895 | if (res != 0) goto failed; |
| 4896 | Py_XDECREF(tmp); |
| 4897 | tmp = NULL; |
| 4898 | } else { |
| 4899 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4900 | return 1; |
| 4901 | } |
| 4902 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4903 | if (*out == NULL) goto failed; |
| 4904 | return 0; |
| 4905 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4906 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4907 | if (isinstance == -1) { |
| 4908 | return 1; |
| 4909 | } |
| 4910 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4911 | expr_ty test; |
| 4912 | expr_ty body; |
| 4913 | expr_ty orelse; |
| 4914 | |
| 4915 | if (PyObject_HasAttrString(obj, "test")) { |
| 4916 | int res; |
| 4917 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4918 | if (tmp == NULL) goto failed; |
| 4919 | res = obj2ast_expr(tmp, &test, arena); |
| 4920 | if (res != 0) goto failed; |
| 4921 | Py_XDECREF(tmp); |
| 4922 | tmp = NULL; |
| 4923 | } else { |
| 4924 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4925 | return 1; |
| 4926 | } |
| 4927 | if (PyObject_HasAttrString(obj, "body")) { |
| 4928 | int res; |
| 4929 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4930 | if (tmp == NULL) goto failed; |
| 4931 | res = obj2ast_expr(tmp, &body, arena); |
| 4932 | if (res != 0) goto failed; |
| 4933 | Py_XDECREF(tmp); |
| 4934 | tmp = NULL; |
| 4935 | } else { |
| 4936 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4937 | return 1; |
| 4938 | } |
| 4939 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4940 | int res; |
| 4941 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4942 | if (tmp == NULL) goto failed; |
| 4943 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4944 | if (res != 0) goto failed; |
| 4945 | Py_XDECREF(tmp); |
| 4946 | tmp = NULL; |
| 4947 | } else { |
| 4948 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4949 | return 1; |
| 4950 | } |
| 4951 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4952 | if (*out == NULL) goto failed; |
| 4953 | return 0; |
| 4954 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4955 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 4956 | if (isinstance == -1) { |
| 4957 | return 1; |
| 4958 | } |
| 4959 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4960 | asdl_seq* keys; |
| 4961 | asdl_seq* values; |
| 4962 | |
| 4963 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4964 | int res; |
| 4965 | Py_ssize_t len; |
| 4966 | Py_ssize_t i; |
| 4967 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4968 | if (tmp == NULL) goto failed; |
| 4969 | if (!PyList_Check(tmp)) { |
| 4970 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4971 | goto failed; |
| 4972 | } |
| 4973 | len = PyList_GET_SIZE(tmp); |
| 4974 | keys = asdl_seq_new(len, arena); |
| 4975 | if (keys == NULL) goto failed; |
| 4976 | for (i = 0; i < len; i++) { |
| 4977 | expr_ty value; |
| 4978 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4979 | if (res != 0) goto failed; |
| 4980 | asdl_seq_SET(keys, i, value); |
| 4981 | } |
| 4982 | Py_XDECREF(tmp); |
| 4983 | tmp = NULL; |
| 4984 | } else { |
| 4985 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4986 | return 1; |
| 4987 | } |
| 4988 | if (PyObject_HasAttrString(obj, "values")) { |
| 4989 | int res; |
| 4990 | Py_ssize_t len; |
| 4991 | Py_ssize_t i; |
| 4992 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4993 | if (tmp == NULL) goto failed; |
| 4994 | if (!PyList_Check(tmp)) { |
| 4995 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4996 | goto failed; |
| 4997 | } |
| 4998 | len = PyList_GET_SIZE(tmp); |
| 4999 | values = asdl_seq_new(len, arena); |
| 5000 | if (values == NULL) goto failed; |
| 5001 | for (i = 0; i < len; i++) { |
| 5002 | expr_ty value; |
| 5003 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5004 | if (res != 0) goto failed; |
| 5005 | asdl_seq_SET(values, i, value); |
| 5006 | } |
| 5007 | Py_XDECREF(tmp); |
| 5008 | tmp = NULL; |
| 5009 | } else { |
| 5010 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5011 | return 1; |
| 5012 | } |
| 5013 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5014 | if (*out == NULL) goto failed; |
| 5015 | return 0; |
| 5016 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5017 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5018 | if (isinstance == -1) { |
| 5019 | return 1; |
| 5020 | } |
| 5021 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5022 | asdl_seq* elts; |
| 5023 | |
| 5024 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5025 | int res; |
| 5026 | Py_ssize_t len; |
| 5027 | Py_ssize_t i; |
| 5028 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5029 | if (tmp == NULL) goto failed; |
| 5030 | if (!PyList_Check(tmp)) { |
| 5031 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5032 | goto failed; |
| 5033 | } |
| 5034 | len = PyList_GET_SIZE(tmp); |
| 5035 | elts = asdl_seq_new(len, arena); |
| 5036 | if (elts == NULL) goto failed; |
| 5037 | for (i = 0; i < len; i++) { |
| 5038 | expr_ty value; |
| 5039 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5040 | if (res != 0) goto failed; |
| 5041 | asdl_seq_SET(elts, i, value); |
| 5042 | } |
| 5043 | Py_XDECREF(tmp); |
| 5044 | tmp = NULL; |
| 5045 | } else { |
| 5046 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5047 | return 1; |
| 5048 | } |
| 5049 | *out = Set(elts, lineno, col_offset, arena); |
| 5050 | if (*out == NULL) goto failed; |
| 5051 | return 0; |
| 5052 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5053 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5054 | if (isinstance == -1) { |
| 5055 | return 1; |
| 5056 | } |
| 5057 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5058 | expr_ty elt; |
| 5059 | asdl_seq* generators; |
| 5060 | |
| 5061 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5062 | int res; |
| 5063 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5064 | if (tmp == NULL) goto failed; |
| 5065 | res = obj2ast_expr(tmp, &elt, arena); |
| 5066 | if (res != 0) goto failed; |
| 5067 | Py_XDECREF(tmp); |
| 5068 | tmp = NULL; |
| 5069 | } else { |
| 5070 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5071 | return 1; |
| 5072 | } |
| 5073 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5074 | int res; |
| 5075 | Py_ssize_t len; |
| 5076 | Py_ssize_t i; |
| 5077 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5078 | if (tmp == NULL) goto failed; |
| 5079 | if (!PyList_Check(tmp)) { |
| 5080 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5081 | goto failed; |
| 5082 | } |
| 5083 | len = PyList_GET_SIZE(tmp); |
| 5084 | generators = asdl_seq_new(len, arena); |
| 5085 | if (generators == NULL) goto failed; |
| 5086 | for (i = 0; i < len; i++) { |
| 5087 | comprehension_ty value; |
| 5088 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5089 | if (res != 0) goto failed; |
| 5090 | asdl_seq_SET(generators, i, value); |
| 5091 | } |
| 5092 | Py_XDECREF(tmp); |
| 5093 | tmp = NULL; |
| 5094 | } else { |
| 5095 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5096 | return 1; |
| 5097 | } |
| 5098 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5099 | if (*out == NULL) goto failed; |
| 5100 | return 0; |
| 5101 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5102 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5103 | if (isinstance == -1) { |
| 5104 | return 1; |
| 5105 | } |
| 5106 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5107 | expr_ty elt; |
| 5108 | asdl_seq* generators; |
| 5109 | |
| 5110 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5111 | int res; |
| 5112 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5113 | if (tmp == NULL) goto failed; |
| 5114 | res = obj2ast_expr(tmp, &elt, arena); |
| 5115 | if (res != 0) goto failed; |
| 5116 | Py_XDECREF(tmp); |
| 5117 | tmp = NULL; |
| 5118 | } else { |
| 5119 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5120 | return 1; |
| 5121 | } |
| 5122 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5123 | int res; |
| 5124 | Py_ssize_t len; |
| 5125 | Py_ssize_t i; |
| 5126 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5127 | if (tmp == NULL) goto failed; |
| 5128 | if (!PyList_Check(tmp)) { |
| 5129 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5130 | goto failed; |
| 5131 | } |
| 5132 | len = PyList_GET_SIZE(tmp); |
| 5133 | generators = asdl_seq_new(len, arena); |
| 5134 | if (generators == NULL) goto failed; |
| 5135 | for (i = 0; i < len; i++) { |
| 5136 | comprehension_ty value; |
| 5137 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5138 | if (res != 0) goto failed; |
| 5139 | asdl_seq_SET(generators, i, value); |
| 5140 | } |
| 5141 | Py_XDECREF(tmp); |
| 5142 | tmp = NULL; |
| 5143 | } else { |
| 5144 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5145 | return 1; |
| 5146 | } |
| 5147 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5148 | if (*out == NULL) goto failed; |
| 5149 | return 0; |
| 5150 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5151 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5152 | if (isinstance == -1) { |
| 5153 | return 1; |
| 5154 | } |
| 5155 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5156 | expr_ty key; |
| 5157 | expr_ty value; |
| 5158 | asdl_seq* generators; |
| 5159 | |
| 5160 | if (PyObject_HasAttrString(obj, "key")) { |
| 5161 | int res; |
| 5162 | tmp = PyObject_GetAttrString(obj, "key"); |
| 5163 | if (tmp == NULL) goto failed; |
| 5164 | res = obj2ast_expr(tmp, &key, arena); |
| 5165 | if (res != 0) goto failed; |
| 5166 | Py_XDECREF(tmp); |
| 5167 | tmp = NULL; |
| 5168 | } else { |
| 5169 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5170 | return 1; |
| 5171 | } |
| 5172 | if (PyObject_HasAttrString(obj, "value")) { |
| 5173 | int res; |
| 5174 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5175 | if (tmp == NULL) goto failed; |
| 5176 | res = obj2ast_expr(tmp, &value, arena); |
| 5177 | if (res != 0) goto failed; |
| 5178 | Py_XDECREF(tmp); |
| 5179 | tmp = NULL; |
| 5180 | } else { |
| 5181 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5182 | return 1; |
| 5183 | } |
| 5184 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5185 | int res; |
| 5186 | Py_ssize_t len; |
| 5187 | Py_ssize_t i; |
| 5188 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5189 | if (tmp == NULL) goto failed; |
| 5190 | if (!PyList_Check(tmp)) { |
| 5191 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5192 | goto failed; |
| 5193 | } |
| 5194 | len = PyList_GET_SIZE(tmp); |
| 5195 | generators = asdl_seq_new(len, arena); |
| 5196 | if (generators == NULL) goto failed; |
| 5197 | for (i = 0; i < len; i++) { |
| 5198 | comprehension_ty value; |
| 5199 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5200 | if (res != 0) goto failed; |
| 5201 | asdl_seq_SET(generators, i, value); |
| 5202 | } |
| 5203 | Py_XDECREF(tmp); |
| 5204 | tmp = NULL; |
| 5205 | } else { |
| 5206 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5207 | return 1; |
| 5208 | } |
| 5209 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5210 | arena); |
| 5211 | if (*out == NULL) goto failed; |
| 5212 | return 0; |
| 5213 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5214 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5215 | if (isinstance == -1) { |
| 5216 | return 1; |
| 5217 | } |
| 5218 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5219 | expr_ty elt; |
| 5220 | asdl_seq* generators; |
| 5221 | |
| 5222 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5223 | int res; |
| 5224 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5225 | if (tmp == NULL) goto failed; |
| 5226 | res = obj2ast_expr(tmp, &elt, arena); |
| 5227 | if (res != 0) goto failed; |
| 5228 | Py_XDECREF(tmp); |
| 5229 | tmp = NULL; |
| 5230 | } else { |
| 5231 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5232 | return 1; |
| 5233 | } |
| 5234 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5235 | int res; |
| 5236 | Py_ssize_t len; |
| 5237 | Py_ssize_t i; |
| 5238 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5239 | if (tmp == NULL) goto failed; |
| 5240 | if (!PyList_Check(tmp)) { |
| 5241 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5242 | goto failed; |
| 5243 | } |
| 5244 | len = PyList_GET_SIZE(tmp); |
| 5245 | generators = asdl_seq_new(len, arena); |
| 5246 | if (generators == NULL) goto failed; |
| 5247 | for (i = 0; i < len; i++) { |
| 5248 | comprehension_ty value; |
| 5249 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5250 | if (res != 0) goto failed; |
| 5251 | asdl_seq_SET(generators, i, value); |
| 5252 | } |
| 5253 | Py_XDECREF(tmp); |
| 5254 | tmp = NULL; |
| 5255 | } else { |
| 5256 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5257 | return 1; |
| 5258 | } |
| 5259 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5260 | if (*out == NULL) goto failed; |
| 5261 | return 0; |
| 5262 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5263 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5264 | if (isinstance == -1) { |
| 5265 | return 1; |
| 5266 | } |
| 5267 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5268 | expr_ty value; |
| 5269 | |
| 5270 | if (PyObject_HasAttrString(obj, "value")) { |
| 5271 | int res; |
| 5272 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5273 | if (tmp == NULL) goto failed; |
| 5274 | res = obj2ast_expr(tmp, &value, arena); |
| 5275 | if (res != 0) goto failed; |
| 5276 | Py_XDECREF(tmp); |
| 5277 | tmp = NULL; |
| 5278 | } else { |
| 5279 | value = NULL; |
| 5280 | } |
| 5281 | *out = Yield(value, lineno, col_offset, arena); |
| 5282 | if (*out == NULL) goto failed; |
| 5283 | return 0; |
| 5284 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5285 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5286 | if (isinstance == -1) { |
| 5287 | return 1; |
| 5288 | } |
| 5289 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5290 | expr_ty left; |
| 5291 | asdl_int_seq* ops; |
| 5292 | asdl_seq* comparators; |
| 5293 | |
| 5294 | if (PyObject_HasAttrString(obj, "left")) { |
| 5295 | int res; |
| 5296 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5297 | if (tmp == NULL) goto failed; |
| 5298 | res = obj2ast_expr(tmp, &left, arena); |
| 5299 | if (res != 0) goto failed; |
| 5300 | Py_XDECREF(tmp); |
| 5301 | tmp = NULL; |
| 5302 | } else { |
| 5303 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5304 | return 1; |
| 5305 | } |
| 5306 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5307 | int res; |
| 5308 | Py_ssize_t len; |
| 5309 | Py_ssize_t i; |
| 5310 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5311 | if (tmp == NULL) goto failed; |
| 5312 | if (!PyList_Check(tmp)) { |
| 5313 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5314 | goto failed; |
| 5315 | } |
| 5316 | len = PyList_GET_SIZE(tmp); |
| 5317 | ops = asdl_int_seq_new(len, arena); |
| 5318 | if (ops == NULL) goto failed; |
| 5319 | for (i = 0; i < len; i++) { |
| 5320 | cmpop_ty value; |
| 5321 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5322 | if (res != 0) goto failed; |
| 5323 | asdl_seq_SET(ops, i, value); |
| 5324 | } |
| 5325 | Py_XDECREF(tmp); |
| 5326 | tmp = NULL; |
| 5327 | } else { |
| 5328 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5329 | return 1; |
| 5330 | } |
| 5331 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5332 | int res; |
| 5333 | Py_ssize_t len; |
| 5334 | Py_ssize_t i; |
| 5335 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5336 | if (tmp == NULL) goto failed; |
| 5337 | if (!PyList_Check(tmp)) { |
| 5338 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5339 | goto failed; |
| 5340 | } |
| 5341 | len = PyList_GET_SIZE(tmp); |
| 5342 | comparators = asdl_seq_new(len, arena); |
| 5343 | if (comparators == NULL) goto failed; |
| 5344 | for (i = 0; i < len; i++) { |
| 5345 | expr_ty value; |
| 5346 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5347 | if (res != 0) goto failed; |
| 5348 | asdl_seq_SET(comparators, i, value); |
| 5349 | } |
| 5350 | Py_XDECREF(tmp); |
| 5351 | tmp = NULL; |
| 5352 | } else { |
| 5353 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5354 | return 1; |
| 5355 | } |
| 5356 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5357 | arena); |
| 5358 | if (*out == NULL) goto failed; |
| 5359 | return 0; |
| 5360 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5361 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5362 | if (isinstance == -1) { |
| 5363 | return 1; |
| 5364 | } |
| 5365 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5366 | expr_ty func; |
| 5367 | asdl_seq* args; |
| 5368 | asdl_seq* keywords; |
| 5369 | expr_ty starargs; |
| 5370 | expr_ty kwargs; |
| 5371 | |
| 5372 | if (PyObject_HasAttrString(obj, "func")) { |
| 5373 | int res; |
| 5374 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5375 | if (tmp == NULL) goto failed; |
| 5376 | res = obj2ast_expr(tmp, &func, arena); |
| 5377 | if (res != 0) goto failed; |
| 5378 | Py_XDECREF(tmp); |
| 5379 | tmp = NULL; |
| 5380 | } else { |
| 5381 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5382 | return 1; |
| 5383 | } |
| 5384 | if (PyObject_HasAttrString(obj, "args")) { |
| 5385 | int res; |
| 5386 | Py_ssize_t len; |
| 5387 | Py_ssize_t i; |
| 5388 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5389 | if (tmp == NULL) goto failed; |
| 5390 | if (!PyList_Check(tmp)) { |
| 5391 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5392 | goto failed; |
| 5393 | } |
| 5394 | len = PyList_GET_SIZE(tmp); |
| 5395 | args = asdl_seq_new(len, arena); |
| 5396 | if (args == NULL) goto failed; |
| 5397 | for (i = 0; i < len; i++) { |
| 5398 | expr_ty value; |
| 5399 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5400 | if (res != 0) goto failed; |
| 5401 | asdl_seq_SET(args, i, value); |
| 5402 | } |
| 5403 | Py_XDECREF(tmp); |
| 5404 | tmp = NULL; |
| 5405 | } else { |
| 5406 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5407 | return 1; |
| 5408 | } |
| 5409 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5410 | int res; |
| 5411 | Py_ssize_t len; |
| 5412 | Py_ssize_t i; |
| 5413 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5414 | if (tmp == NULL) goto failed; |
| 5415 | if (!PyList_Check(tmp)) { |
| 5416 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5417 | goto failed; |
| 5418 | } |
| 5419 | len = PyList_GET_SIZE(tmp); |
| 5420 | keywords = asdl_seq_new(len, arena); |
| 5421 | if (keywords == NULL) goto failed; |
| 5422 | for (i = 0; i < len; i++) { |
| 5423 | keyword_ty value; |
| 5424 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5425 | if (res != 0) goto failed; |
| 5426 | asdl_seq_SET(keywords, i, value); |
| 5427 | } |
| 5428 | Py_XDECREF(tmp); |
| 5429 | tmp = NULL; |
| 5430 | } else { |
| 5431 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5432 | return 1; |
| 5433 | } |
| 5434 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5435 | int res; |
| 5436 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5437 | if (tmp == NULL) goto failed; |
| 5438 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5439 | if (res != 0) goto failed; |
| 5440 | Py_XDECREF(tmp); |
| 5441 | tmp = NULL; |
| 5442 | } else { |
| 5443 | starargs = NULL; |
| 5444 | } |
| 5445 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5446 | int res; |
| 5447 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5448 | if (tmp == NULL) goto failed; |
| 5449 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5450 | if (res != 0) goto failed; |
| 5451 | Py_XDECREF(tmp); |
| 5452 | tmp = NULL; |
| 5453 | } else { |
| 5454 | kwargs = NULL; |
| 5455 | } |
| 5456 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5457 | col_offset, arena); |
| 5458 | if (*out == NULL) goto failed; |
| 5459 | return 0; |
| 5460 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5461 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5462 | if (isinstance == -1) { |
| 5463 | return 1; |
| 5464 | } |
| 5465 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5466 | object n; |
| 5467 | |
| 5468 | if (PyObject_HasAttrString(obj, "n")) { |
| 5469 | int res; |
| 5470 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5471 | if (tmp == NULL) goto failed; |
| 5472 | res = obj2ast_object(tmp, &n, arena); |
| 5473 | if (res != 0) goto failed; |
| 5474 | Py_XDECREF(tmp); |
| 5475 | tmp = NULL; |
| 5476 | } else { |
| 5477 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5478 | return 1; |
| 5479 | } |
| 5480 | *out = Num(n, lineno, col_offset, arena); |
| 5481 | if (*out == NULL) goto failed; |
| 5482 | return 0; |
| 5483 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5484 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5485 | if (isinstance == -1) { |
| 5486 | return 1; |
| 5487 | } |
| 5488 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5489 | string s; |
| 5490 | |
| 5491 | if (PyObject_HasAttrString(obj, "s")) { |
| 5492 | int res; |
| 5493 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5494 | if (tmp == NULL) goto failed; |
| 5495 | res = obj2ast_string(tmp, &s, arena); |
| 5496 | if (res != 0) goto failed; |
| 5497 | Py_XDECREF(tmp); |
| 5498 | tmp = NULL; |
| 5499 | } else { |
| 5500 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5501 | return 1; |
| 5502 | } |
| 5503 | *out = Str(s, lineno, col_offset, arena); |
| 5504 | if (*out == NULL) goto failed; |
| 5505 | return 0; |
| 5506 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5507 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5508 | if (isinstance == -1) { |
| 5509 | return 1; |
| 5510 | } |
| 5511 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5512 | string s; |
| 5513 | |
| 5514 | if (PyObject_HasAttrString(obj, "s")) { |
| 5515 | int res; |
| 5516 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5517 | if (tmp == NULL) goto failed; |
| 5518 | res = obj2ast_string(tmp, &s, arena); |
| 5519 | if (res != 0) goto failed; |
| 5520 | Py_XDECREF(tmp); |
| 5521 | tmp = NULL; |
| 5522 | } else { |
| 5523 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5524 | return 1; |
| 5525 | } |
| 5526 | *out = Bytes(s, lineno, col_offset, arena); |
| 5527 | if (*out == NULL) goto failed; |
| 5528 | return 0; |
| 5529 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5530 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 5531 | if (isinstance == -1) { |
| 5532 | return 1; |
| 5533 | } |
| 5534 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5535 | |
| 5536 | *out = Ellipsis(lineno, col_offset, arena); |
| 5537 | if (*out == NULL) goto failed; |
| 5538 | return 0; |
| 5539 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5540 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5541 | if (isinstance == -1) { |
| 5542 | return 1; |
| 5543 | } |
| 5544 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5545 | expr_ty value; |
| 5546 | identifier attr; |
| 5547 | expr_context_ty ctx; |
| 5548 | |
| 5549 | if (PyObject_HasAttrString(obj, "value")) { |
| 5550 | int res; |
| 5551 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5552 | if (tmp == NULL) goto failed; |
| 5553 | res = obj2ast_expr(tmp, &value, arena); |
| 5554 | if (res != 0) goto failed; |
| 5555 | Py_XDECREF(tmp); |
| 5556 | tmp = NULL; |
| 5557 | } else { |
| 5558 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5559 | return 1; |
| 5560 | } |
| 5561 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5562 | int res; |
| 5563 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5564 | if (tmp == NULL) goto failed; |
| 5565 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5566 | if (res != 0) goto failed; |
| 5567 | Py_XDECREF(tmp); |
| 5568 | tmp = NULL; |
| 5569 | } else { |
| 5570 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5571 | return 1; |
| 5572 | } |
| 5573 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5574 | int res; |
| 5575 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5576 | if (tmp == NULL) goto failed; |
| 5577 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5578 | if (res != 0) goto failed; |
| 5579 | Py_XDECREF(tmp); |
| 5580 | tmp = NULL; |
| 5581 | } else { |
| 5582 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5583 | return 1; |
| 5584 | } |
| 5585 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5586 | if (*out == NULL) goto failed; |
| 5587 | return 0; |
| 5588 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5589 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5590 | if (isinstance == -1) { |
| 5591 | return 1; |
| 5592 | } |
| 5593 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5594 | expr_ty value; |
| 5595 | slice_ty slice; |
| 5596 | expr_context_ty ctx; |
| 5597 | |
| 5598 | if (PyObject_HasAttrString(obj, "value")) { |
| 5599 | int res; |
| 5600 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5601 | if (tmp == NULL) goto failed; |
| 5602 | res = obj2ast_expr(tmp, &value, arena); |
| 5603 | if (res != 0) goto failed; |
| 5604 | Py_XDECREF(tmp); |
| 5605 | tmp = NULL; |
| 5606 | } else { |
| 5607 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5608 | return 1; |
| 5609 | } |
| 5610 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5611 | int res; |
| 5612 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5613 | if (tmp == NULL) goto failed; |
| 5614 | res = obj2ast_slice(tmp, &slice, arena); |
| 5615 | if (res != 0) goto failed; |
| 5616 | Py_XDECREF(tmp); |
| 5617 | tmp = NULL; |
| 5618 | } else { |
| 5619 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5620 | return 1; |
| 5621 | } |
| 5622 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5623 | int res; |
| 5624 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5625 | if (tmp == NULL) goto failed; |
| 5626 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5627 | if (res != 0) goto failed; |
| 5628 | Py_XDECREF(tmp); |
| 5629 | tmp = NULL; |
| 5630 | } else { |
| 5631 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5632 | return 1; |
| 5633 | } |
| 5634 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5635 | if (*out == NULL) goto failed; |
| 5636 | return 0; |
| 5637 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5638 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5639 | if (isinstance == -1) { |
| 5640 | return 1; |
| 5641 | } |
| 5642 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5643 | expr_ty value; |
| 5644 | expr_context_ty ctx; |
| 5645 | |
| 5646 | if (PyObject_HasAttrString(obj, "value")) { |
| 5647 | int res; |
| 5648 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5649 | if (tmp == NULL) goto failed; |
| 5650 | res = obj2ast_expr(tmp, &value, arena); |
| 5651 | if (res != 0) goto failed; |
| 5652 | Py_XDECREF(tmp); |
| 5653 | tmp = NULL; |
| 5654 | } else { |
| 5655 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5656 | return 1; |
| 5657 | } |
| 5658 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5659 | int res; |
| 5660 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5661 | if (tmp == NULL) goto failed; |
| 5662 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5663 | if (res != 0) goto failed; |
| 5664 | Py_XDECREF(tmp); |
| 5665 | tmp = NULL; |
| 5666 | } else { |
| 5667 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5668 | return 1; |
| 5669 | } |
| 5670 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5671 | if (*out == NULL) goto failed; |
| 5672 | return 0; |
| 5673 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5674 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5675 | if (isinstance == -1) { |
| 5676 | return 1; |
| 5677 | } |
| 5678 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5679 | identifier id; |
| 5680 | expr_context_ty ctx; |
| 5681 | |
| 5682 | if (PyObject_HasAttrString(obj, "id")) { |
| 5683 | int res; |
| 5684 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5685 | if (tmp == NULL) goto failed; |
| 5686 | res = obj2ast_identifier(tmp, &id, arena); |
| 5687 | if (res != 0) goto failed; |
| 5688 | Py_XDECREF(tmp); |
| 5689 | tmp = NULL; |
| 5690 | } else { |
| 5691 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5692 | return 1; |
| 5693 | } |
| 5694 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5695 | int res; |
| 5696 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5697 | if (tmp == NULL) goto failed; |
| 5698 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5699 | if (res != 0) goto failed; |
| 5700 | Py_XDECREF(tmp); |
| 5701 | tmp = NULL; |
| 5702 | } else { |
| 5703 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5704 | return 1; |
| 5705 | } |
| 5706 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5707 | if (*out == NULL) goto failed; |
| 5708 | return 0; |
| 5709 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5710 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5711 | if (isinstance == -1) { |
| 5712 | return 1; |
| 5713 | } |
| 5714 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5715 | asdl_seq* elts; |
| 5716 | expr_context_ty ctx; |
| 5717 | |
| 5718 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5719 | int res; |
| 5720 | Py_ssize_t len; |
| 5721 | Py_ssize_t i; |
| 5722 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5723 | if (tmp == NULL) goto failed; |
| 5724 | if (!PyList_Check(tmp)) { |
| 5725 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5726 | goto failed; |
| 5727 | } |
| 5728 | len = PyList_GET_SIZE(tmp); |
| 5729 | elts = asdl_seq_new(len, arena); |
| 5730 | if (elts == NULL) goto failed; |
| 5731 | for (i = 0; i < len; i++) { |
| 5732 | expr_ty value; |
| 5733 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5734 | if (res != 0) goto failed; |
| 5735 | asdl_seq_SET(elts, i, value); |
| 5736 | } |
| 5737 | Py_XDECREF(tmp); |
| 5738 | tmp = NULL; |
| 5739 | } else { |
| 5740 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5741 | return 1; |
| 5742 | } |
| 5743 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5744 | int res; |
| 5745 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5746 | if (tmp == NULL) goto failed; |
| 5747 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5748 | if (res != 0) goto failed; |
| 5749 | Py_XDECREF(tmp); |
| 5750 | tmp = NULL; |
| 5751 | } else { |
| 5752 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5753 | return 1; |
| 5754 | } |
| 5755 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5756 | if (*out == NULL) goto failed; |
| 5757 | return 0; |
| 5758 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5759 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5760 | if (isinstance == -1) { |
| 5761 | return 1; |
| 5762 | } |
| 5763 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5764 | asdl_seq* elts; |
| 5765 | expr_context_ty ctx; |
| 5766 | |
| 5767 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5768 | int res; |
| 5769 | Py_ssize_t len; |
| 5770 | Py_ssize_t i; |
| 5771 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5772 | if (tmp == NULL) goto failed; |
| 5773 | if (!PyList_Check(tmp)) { |
| 5774 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5775 | goto failed; |
| 5776 | } |
| 5777 | len = PyList_GET_SIZE(tmp); |
| 5778 | elts = asdl_seq_new(len, arena); |
| 5779 | if (elts == NULL) goto failed; |
| 5780 | for (i = 0; i < len; i++) { |
| 5781 | expr_ty value; |
| 5782 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5783 | if (res != 0) goto failed; |
| 5784 | asdl_seq_SET(elts, i, value); |
| 5785 | } |
| 5786 | Py_XDECREF(tmp); |
| 5787 | tmp = NULL; |
| 5788 | } else { |
| 5789 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5790 | return 1; |
| 5791 | } |
| 5792 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5793 | int res; |
| 5794 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5795 | if (tmp == NULL) goto failed; |
| 5796 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5797 | if (res != 0) goto failed; |
| 5798 | Py_XDECREF(tmp); |
| 5799 | tmp = NULL; |
| 5800 | } else { |
| 5801 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5802 | return 1; |
| 5803 | } |
| 5804 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5805 | if (*out == NULL) goto failed; |
| 5806 | return 0; |
| 5807 | } |
| 5808 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5809 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5810 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5811 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5812 | return 1; |
| 5813 | } |
| 5814 | |
| 5815 | int |
| 5816 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5817 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5818 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5819 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5820 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5821 | if (isinstance == -1) { |
| 5822 | return 1; |
| 5823 | } |
| 5824 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5825 | *out = Load; |
| 5826 | return 0; |
| 5827 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5828 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5829 | if (isinstance == -1) { |
| 5830 | return 1; |
| 5831 | } |
| 5832 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5833 | *out = Store; |
| 5834 | return 0; |
| 5835 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5836 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5837 | if (isinstance == -1) { |
| 5838 | return 1; |
| 5839 | } |
| 5840 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5841 | *out = Del; |
| 5842 | return 0; |
| 5843 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5844 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5845 | if (isinstance == -1) { |
| 5846 | return 1; |
| 5847 | } |
| 5848 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5849 | *out = AugLoad; |
| 5850 | return 0; |
| 5851 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5852 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5853 | if (isinstance == -1) { |
| 5854 | return 1; |
| 5855 | } |
| 5856 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5857 | *out = AugStore; |
| 5858 | return 0; |
| 5859 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5860 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5861 | if (isinstance == -1) { |
| 5862 | return 1; |
| 5863 | } |
| 5864 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5865 | *out = Param; |
| 5866 | return 0; |
| 5867 | } |
| 5868 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5869 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5870 | return 1; |
| 5871 | } |
| 5872 | |
| 5873 | int |
| 5874 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5875 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5876 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5877 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 5878 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5879 | |
| 5880 | if (obj == Py_None) { |
| 5881 | *out = NULL; |
| 5882 | return 0; |
| 5883 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5884 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5885 | if (isinstance == -1) { |
| 5886 | return 1; |
| 5887 | } |
| 5888 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5889 | expr_ty lower; |
| 5890 | expr_ty upper; |
| 5891 | expr_ty step; |
| 5892 | |
| 5893 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5894 | int res; |
| 5895 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5896 | if (tmp == NULL) goto failed; |
| 5897 | res = obj2ast_expr(tmp, &lower, arena); |
| 5898 | if (res != 0) goto failed; |
| 5899 | Py_XDECREF(tmp); |
| 5900 | tmp = NULL; |
| 5901 | } else { |
| 5902 | lower = NULL; |
| 5903 | } |
| 5904 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5905 | int res; |
| 5906 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5907 | if (tmp == NULL) goto failed; |
| 5908 | res = obj2ast_expr(tmp, &upper, arena); |
| 5909 | if (res != 0) goto failed; |
| 5910 | Py_XDECREF(tmp); |
| 5911 | tmp = NULL; |
| 5912 | } else { |
| 5913 | upper = NULL; |
| 5914 | } |
| 5915 | if (PyObject_HasAttrString(obj, "step")) { |
| 5916 | int res; |
| 5917 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5918 | if (tmp == NULL) goto failed; |
| 5919 | res = obj2ast_expr(tmp, &step, arena); |
| 5920 | if (res != 0) goto failed; |
| 5921 | Py_XDECREF(tmp); |
| 5922 | tmp = NULL; |
| 5923 | } else { |
| 5924 | step = NULL; |
| 5925 | } |
| 5926 | *out = Slice(lower, upper, step, arena); |
| 5927 | if (*out == NULL) goto failed; |
| 5928 | return 0; |
| 5929 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5930 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5931 | if (isinstance == -1) { |
| 5932 | return 1; |
| 5933 | } |
| 5934 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5935 | asdl_seq* dims; |
| 5936 | |
| 5937 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5938 | int res; |
| 5939 | Py_ssize_t len; |
| 5940 | Py_ssize_t i; |
| 5941 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5942 | if (tmp == NULL) goto failed; |
| 5943 | if (!PyList_Check(tmp)) { |
| 5944 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5945 | goto failed; |
| 5946 | } |
| 5947 | len = PyList_GET_SIZE(tmp); |
| 5948 | dims = asdl_seq_new(len, arena); |
| 5949 | if (dims == NULL) goto failed; |
| 5950 | for (i = 0; i < len; i++) { |
| 5951 | slice_ty value; |
| 5952 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5953 | if (res != 0) goto failed; |
| 5954 | asdl_seq_SET(dims, i, value); |
| 5955 | } |
| 5956 | Py_XDECREF(tmp); |
| 5957 | tmp = NULL; |
| 5958 | } else { |
| 5959 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5960 | return 1; |
| 5961 | } |
| 5962 | *out = ExtSlice(dims, arena); |
| 5963 | if (*out == NULL) goto failed; |
| 5964 | return 0; |
| 5965 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5966 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5967 | if (isinstance == -1) { |
| 5968 | return 1; |
| 5969 | } |
| 5970 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5971 | expr_ty value; |
| 5972 | |
| 5973 | if (PyObject_HasAttrString(obj, "value")) { |
| 5974 | int res; |
| 5975 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5976 | if (tmp == NULL) goto failed; |
| 5977 | res = obj2ast_expr(tmp, &value, arena); |
| 5978 | if (res != 0) goto failed; |
| 5979 | Py_XDECREF(tmp); |
| 5980 | tmp = NULL; |
| 5981 | } else { |
| 5982 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5983 | return 1; |
| 5984 | } |
| 5985 | *out = Index(value, arena); |
| 5986 | if (*out == NULL) goto failed; |
| 5987 | return 0; |
| 5988 | } |
| 5989 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5990 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 5991 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5992 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5993 | return 1; |
| 5994 | } |
| 5995 | |
| 5996 | int |
| 5997 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 5998 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5999 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6000 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6001 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6002 | if (isinstance == -1) { |
| 6003 | return 1; |
| 6004 | } |
| 6005 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6006 | *out = And; |
| 6007 | return 0; |
| 6008 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6009 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6010 | if (isinstance == -1) { |
| 6011 | return 1; |
| 6012 | } |
| 6013 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6014 | *out = Or; |
| 6015 | return 0; |
| 6016 | } |
| 6017 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6018 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6019 | return 1; |
| 6020 | } |
| 6021 | |
| 6022 | int |
| 6023 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6024 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6025 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6026 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6027 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6028 | if (isinstance == -1) { |
| 6029 | return 1; |
| 6030 | } |
| 6031 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6032 | *out = Add; |
| 6033 | return 0; |
| 6034 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6035 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6036 | if (isinstance == -1) { |
| 6037 | return 1; |
| 6038 | } |
| 6039 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6040 | *out = Sub; |
| 6041 | return 0; |
| 6042 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6043 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6044 | if (isinstance == -1) { |
| 6045 | return 1; |
| 6046 | } |
| 6047 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6048 | *out = Mult; |
| 6049 | return 0; |
| 6050 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6051 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6052 | if (isinstance == -1) { |
| 6053 | return 1; |
| 6054 | } |
| 6055 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6056 | *out = Div; |
| 6057 | return 0; |
| 6058 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6059 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6060 | if (isinstance == -1) { |
| 6061 | return 1; |
| 6062 | } |
| 6063 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6064 | *out = Mod; |
| 6065 | return 0; |
| 6066 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6067 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6068 | if (isinstance == -1) { |
| 6069 | return 1; |
| 6070 | } |
| 6071 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6072 | *out = Pow; |
| 6073 | return 0; |
| 6074 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6075 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6076 | if (isinstance == -1) { |
| 6077 | return 1; |
| 6078 | } |
| 6079 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6080 | *out = LShift; |
| 6081 | return 0; |
| 6082 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6083 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6084 | if (isinstance == -1) { |
| 6085 | return 1; |
| 6086 | } |
| 6087 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6088 | *out = RShift; |
| 6089 | return 0; |
| 6090 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6091 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6092 | if (isinstance == -1) { |
| 6093 | return 1; |
| 6094 | } |
| 6095 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6096 | *out = BitOr; |
| 6097 | return 0; |
| 6098 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6099 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6100 | if (isinstance == -1) { |
| 6101 | return 1; |
| 6102 | } |
| 6103 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6104 | *out = BitXor; |
| 6105 | return 0; |
| 6106 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6107 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6108 | if (isinstance == -1) { |
| 6109 | return 1; |
| 6110 | } |
| 6111 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6112 | *out = BitAnd; |
| 6113 | return 0; |
| 6114 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6115 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6116 | if (isinstance == -1) { |
| 6117 | return 1; |
| 6118 | } |
| 6119 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6120 | *out = FloorDiv; |
| 6121 | return 0; |
| 6122 | } |
| 6123 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6124 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6125 | return 1; |
| 6126 | } |
| 6127 | |
| 6128 | int |
| 6129 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6130 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6131 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6132 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6133 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6134 | if (isinstance == -1) { |
| 6135 | return 1; |
| 6136 | } |
| 6137 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6138 | *out = Invert; |
| 6139 | return 0; |
| 6140 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6141 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6142 | if (isinstance == -1) { |
| 6143 | return 1; |
| 6144 | } |
| 6145 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6146 | *out = Not; |
| 6147 | return 0; |
| 6148 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6149 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6150 | if (isinstance == -1) { |
| 6151 | return 1; |
| 6152 | } |
| 6153 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6154 | *out = UAdd; |
| 6155 | return 0; |
| 6156 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6157 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6158 | if (isinstance == -1) { |
| 6159 | return 1; |
| 6160 | } |
| 6161 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6162 | *out = USub; |
| 6163 | return 0; |
| 6164 | } |
| 6165 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6166 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6167 | return 1; |
| 6168 | } |
| 6169 | |
| 6170 | int |
| 6171 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6172 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6173 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6174 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6175 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6176 | if (isinstance == -1) { |
| 6177 | return 1; |
| 6178 | } |
| 6179 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6180 | *out = Eq; |
| 6181 | return 0; |
| 6182 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6183 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6184 | if (isinstance == -1) { |
| 6185 | return 1; |
| 6186 | } |
| 6187 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6188 | *out = NotEq; |
| 6189 | return 0; |
| 6190 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6191 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6192 | if (isinstance == -1) { |
| 6193 | return 1; |
| 6194 | } |
| 6195 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6196 | *out = Lt; |
| 6197 | return 0; |
| 6198 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6199 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6200 | if (isinstance == -1) { |
| 6201 | return 1; |
| 6202 | } |
| 6203 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6204 | *out = LtE; |
| 6205 | return 0; |
| 6206 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6207 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6208 | if (isinstance == -1) { |
| 6209 | return 1; |
| 6210 | } |
| 6211 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6212 | *out = Gt; |
| 6213 | return 0; |
| 6214 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6215 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6216 | if (isinstance == -1) { |
| 6217 | return 1; |
| 6218 | } |
| 6219 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6220 | *out = GtE; |
| 6221 | return 0; |
| 6222 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6223 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6224 | if (isinstance == -1) { |
| 6225 | return 1; |
| 6226 | } |
| 6227 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6228 | *out = Is; |
| 6229 | return 0; |
| 6230 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6231 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6232 | if (isinstance == -1) { |
| 6233 | return 1; |
| 6234 | } |
| 6235 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6236 | *out = IsNot; |
| 6237 | return 0; |
| 6238 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6239 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6240 | if (isinstance == -1) { |
| 6241 | return 1; |
| 6242 | } |
| 6243 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6244 | *out = In; |
| 6245 | return 0; |
| 6246 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6247 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6248 | if (isinstance == -1) { |
| 6249 | return 1; |
| 6250 | } |
| 6251 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6252 | *out = NotIn; |
| 6253 | return 0; |
| 6254 | } |
| 6255 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6256 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6257 | return 1; |
| 6258 | } |
| 6259 | |
| 6260 | int |
| 6261 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6262 | { |
| 6263 | PyObject* tmp = NULL; |
| 6264 | expr_ty target; |
| 6265 | expr_ty iter; |
| 6266 | asdl_seq* ifs; |
| 6267 | |
| 6268 | if (PyObject_HasAttrString(obj, "target")) { |
| 6269 | int res; |
| 6270 | tmp = PyObject_GetAttrString(obj, "target"); |
| 6271 | if (tmp == NULL) goto failed; |
| 6272 | res = obj2ast_expr(tmp, &target, arena); |
| 6273 | if (res != 0) goto failed; |
| 6274 | Py_XDECREF(tmp); |
| 6275 | tmp = NULL; |
| 6276 | } else { |
| 6277 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6278 | return 1; |
| 6279 | } |
| 6280 | if (PyObject_HasAttrString(obj, "iter")) { |
| 6281 | int res; |
| 6282 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 6283 | if (tmp == NULL) goto failed; |
| 6284 | res = obj2ast_expr(tmp, &iter, arena); |
| 6285 | if (res != 0) goto failed; |
| 6286 | Py_XDECREF(tmp); |
| 6287 | tmp = NULL; |
| 6288 | } else { |
| 6289 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6290 | return 1; |
| 6291 | } |
| 6292 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 6293 | int res; |
| 6294 | Py_ssize_t len; |
| 6295 | Py_ssize_t i; |
| 6296 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 6297 | if (tmp == NULL) goto failed; |
| 6298 | if (!PyList_Check(tmp)) { |
| 6299 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6300 | goto failed; |
| 6301 | } |
| 6302 | len = PyList_GET_SIZE(tmp); |
| 6303 | ifs = asdl_seq_new(len, arena); |
| 6304 | if (ifs == NULL) goto failed; |
| 6305 | for (i = 0; i < len; i++) { |
| 6306 | expr_ty value; |
| 6307 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6308 | if (res != 0) goto failed; |
| 6309 | asdl_seq_SET(ifs, i, value); |
| 6310 | } |
| 6311 | Py_XDECREF(tmp); |
| 6312 | tmp = NULL; |
| 6313 | } else { |
| 6314 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6315 | return 1; |
| 6316 | } |
| 6317 | *out = comprehension(target, iter, ifs, arena); |
| 6318 | return 0; |
| 6319 | failed: |
| 6320 | Py_XDECREF(tmp); |
| 6321 | return 1; |
| 6322 | } |
| 6323 | |
| 6324 | int |
| 6325 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6326 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6327 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6328 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6329 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6330 | int lineno; |
| 6331 | int col_offset; |
| 6332 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6333 | if (obj == Py_None) { |
| 6334 | *out = NULL; |
| 6335 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6336 | } |
| 6337 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6338 | int res; |
| 6339 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6340 | if (tmp == NULL) goto failed; |
| 6341 | res = obj2ast_int(tmp, &lineno, arena); |
| 6342 | if (res != 0) goto failed; |
| 6343 | Py_XDECREF(tmp); |
| 6344 | tmp = NULL; |
| 6345 | } else { |
| 6346 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6347 | return 1; |
| 6348 | } |
| 6349 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6350 | int res; |
| 6351 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6352 | if (tmp == NULL) goto failed; |
| 6353 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6354 | if (res != 0) goto failed; |
| 6355 | Py_XDECREF(tmp); |
| 6356 | tmp = NULL; |
| 6357 | } else { |
| 6358 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6359 | return 1; |
| 6360 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6361 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6362 | if (isinstance == -1) { |
| 6363 | return 1; |
| 6364 | } |
| 6365 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6366 | expr_ty type; |
| 6367 | identifier name; |
| 6368 | asdl_seq* body; |
| 6369 | |
| 6370 | if (PyObject_HasAttrString(obj, "type")) { |
| 6371 | int res; |
| 6372 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6373 | if (tmp == NULL) goto failed; |
| 6374 | res = obj2ast_expr(tmp, &type, arena); |
| 6375 | if (res != 0) goto failed; |
| 6376 | Py_XDECREF(tmp); |
| 6377 | tmp = NULL; |
| 6378 | } else { |
| 6379 | type = NULL; |
| 6380 | } |
| 6381 | if (PyObject_HasAttrString(obj, "name")) { |
| 6382 | int res; |
| 6383 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6384 | if (tmp == NULL) goto failed; |
| 6385 | res = obj2ast_identifier(tmp, &name, arena); |
| 6386 | if (res != 0) goto failed; |
| 6387 | Py_XDECREF(tmp); |
| 6388 | tmp = NULL; |
| 6389 | } else { |
| 6390 | name = NULL; |
| 6391 | } |
| 6392 | if (PyObject_HasAttrString(obj, "body")) { |
| 6393 | int res; |
| 6394 | Py_ssize_t len; |
| 6395 | Py_ssize_t i; |
| 6396 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6397 | if (tmp == NULL) goto failed; |
| 6398 | if (!PyList_Check(tmp)) { |
| 6399 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6400 | goto failed; |
| 6401 | } |
| 6402 | len = PyList_GET_SIZE(tmp); |
| 6403 | body = asdl_seq_new(len, arena); |
| 6404 | if (body == NULL) goto failed; |
| 6405 | for (i = 0; i < len; i++) { |
| 6406 | stmt_ty value; |
| 6407 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6408 | if (res != 0) goto failed; |
| 6409 | asdl_seq_SET(body, i, value); |
| 6410 | } |
| 6411 | Py_XDECREF(tmp); |
| 6412 | tmp = NULL; |
| 6413 | } else { |
| 6414 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6415 | return 1; |
| 6416 | } |
| 6417 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6418 | arena); |
| 6419 | if (*out == NULL) goto failed; |
| 6420 | return 0; |
| 6421 | } |
| 6422 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6423 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6424 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6425 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6426 | return 1; |
| 6427 | } |
| 6428 | |
| 6429 | int |
| 6430 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6431 | { |
| 6432 | PyObject* tmp = NULL; |
| 6433 | asdl_seq* args; |
| 6434 | identifier vararg; |
| 6435 | expr_ty varargannotation; |
| 6436 | asdl_seq* kwonlyargs; |
| 6437 | identifier kwarg; |
| 6438 | expr_ty kwargannotation; |
| 6439 | asdl_seq* defaults; |
| 6440 | asdl_seq* kw_defaults; |
| 6441 | |
| 6442 | if (PyObject_HasAttrString(obj, "args")) { |
| 6443 | int res; |
| 6444 | Py_ssize_t len; |
| 6445 | Py_ssize_t i; |
| 6446 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6447 | if (tmp == NULL) goto failed; |
| 6448 | if (!PyList_Check(tmp)) { |
| 6449 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6450 | goto failed; |
| 6451 | } |
| 6452 | len = PyList_GET_SIZE(tmp); |
| 6453 | args = asdl_seq_new(len, arena); |
| 6454 | if (args == NULL) goto failed; |
| 6455 | for (i = 0; i < len; i++) { |
| 6456 | arg_ty value; |
| 6457 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6458 | if (res != 0) goto failed; |
| 6459 | asdl_seq_SET(args, i, value); |
| 6460 | } |
| 6461 | Py_XDECREF(tmp); |
| 6462 | tmp = NULL; |
| 6463 | } else { |
| 6464 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6465 | return 1; |
| 6466 | } |
| 6467 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6468 | int res; |
| 6469 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6470 | if (tmp == NULL) goto failed; |
| 6471 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6472 | if (res != 0) goto failed; |
| 6473 | Py_XDECREF(tmp); |
| 6474 | tmp = NULL; |
| 6475 | } else { |
| 6476 | vararg = NULL; |
| 6477 | } |
| 6478 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6479 | int res; |
| 6480 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6481 | if (tmp == NULL) goto failed; |
| 6482 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6483 | if (res != 0) goto failed; |
| 6484 | Py_XDECREF(tmp); |
| 6485 | tmp = NULL; |
| 6486 | } else { |
| 6487 | varargannotation = NULL; |
| 6488 | } |
| 6489 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6490 | int res; |
| 6491 | Py_ssize_t len; |
| 6492 | Py_ssize_t i; |
| 6493 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6494 | if (tmp == NULL) goto failed; |
| 6495 | if (!PyList_Check(tmp)) { |
| 6496 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6497 | goto failed; |
| 6498 | } |
| 6499 | len = PyList_GET_SIZE(tmp); |
| 6500 | kwonlyargs = asdl_seq_new(len, arena); |
| 6501 | if (kwonlyargs == NULL) goto failed; |
| 6502 | for (i = 0; i < len; i++) { |
| 6503 | arg_ty value; |
| 6504 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6505 | if (res != 0) goto failed; |
| 6506 | asdl_seq_SET(kwonlyargs, i, value); |
| 6507 | } |
| 6508 | Py_XDECREF(tmp); |
| 6509 | tmp = NULL; |
| 6510 | } else { |
| 6511 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6512 | return 1; |
| 6513 | } |
| 6514 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6515 | int res; |
| 6516 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6517 | if (tmp == NULL) goto failed; |
| 6518 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6519 | if (res != 0) goto failed; |
| 6520 | Py_XDECREF(tmp); |
| 6521 | tmp = NULL; |
| 6522 | } else { |
| 6523 | kwarg = NULL; |
| 6524 | } |
| 6525 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6526 | int res; |
| 6527 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6528 | if (tmp == NULL) goto failed; |
| 6529 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6530 | if (res != 0) goto failed; |
| 6531 | Py_XDECREF(tmp); |
| 6532 | tmp = NULL; |
| 6533 | } else { |
| 6534 | kwargannotation = NULL; |
| 6535 | } |
| 6536 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6537 | int res; |
| 6538 | Py_ssize_t len; |
| 6539 | Py_ssize_t i; |
| 6540 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6541 | if (tmp == NULL) goto failed; |
| 6542 | if (!PyList_Check(tmp)) { |
| 6543 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6544 | goto failed; |
| 6545 | } |
| 6546 | len = PyList_GET_SIZE(tmp); |
| 6547 | defaults = asdl_seq_new(len, arena); |
| 6548 | if (defaults == NULL) goto failed; |
| 6549 | for (i = 0; i < len; i++) { |
| 6550 | expr_ty value; |
| 6551 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6552 | if (res != 0) goto failed; |
| 6553 | asdl_seq_SET(defaults, i, value); |
| 6554 | } |
| 6555 | Py_XDECREF(tmp); |
| 6556 | tmp = NULL; |
| 6557 | } else { |
| 6558 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6559 | return 1; |
| 6560 | } |
| 6561 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6562 | int res; |
| 6563 | Py_ssize_t len; |
| 6564 | Py_ssize_t i; |
| 6565 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6566 | if (tmp == NULL) goto failed; |
| 6567 | if (!PyList_Check(tmp)) { |
| 6568 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6569 | goto failed; |
| 6570 | } |
| 6571 | len = PyList_GET_SIZE(tmp); |
| 6572 | kw_defaults = asdl_seq_new(len, arena); |
| 6573 | if (kw_defaults == NULL) goto failed; |
| 6574 | for (i = 0; i < len; i++) { |
| 6575 | expr_ty value; |
| 6576 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6577 | if (res != 0) goto failed; |
| 6578 | asdl_seq_SET(kw_defaults, i, value); |
| 6579 | } |
| 6580 | Py_XDECREF(tmp); |
| 6581 | tmp = NULL; |
| 6582 | } else { |
| 6583 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6584 | return 1; |
| 6585 | } |
| 6586 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6587 | kwargannotation, defaults, kw_defaults, arena); |
| 6588 | return 0; |
| 6589 | failed: |
| 6590 | Py_XDECREF(tmp); |
| 6591 | return 1; |
| 6592 | } |
| 6593 | |
| 6594 | int |
| 6595 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6596 | { |
| 6597 | PyObject* tmp = NULL; |
| 6598 | identifier arg; |
| 6599 | expr_ty annotation; |
| 6600 | |
| 6601 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6602 | int res; |
| 6603 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6604 | if (tmp == NULL) goto failed; |
| 6605 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6606 | if (res != 0) goto failed; |
| 6607 | Py_XDECREF(tmp); |
| 6608 | tmp = NULL; |
| 6609 | } else { |
| 6610 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6611 | return 1; |
| 6612 | } |
| 6613 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6614 | int res; |
| 6615 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6616 | if (tmp == NULL) goto failed; |
| 6617 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6618 | if (res != 0) goto failed; |
| 6619 | Py_XDECREF(tmp); |
| 6620 | tmp = NULL; |
| 6621 | } else { |
| 6622 | annotation = NULL; |
| 6623 | } |
| 6624 | *out = arg(arg, annotation, arena); |
| 6625 | return 0; |
| 6626 | failed: |
| 6627 | Py_XDECREF(tmp); |
| 6628 | return 1; |
| 6629 | } |
| 6630 | |
| 6631 | int |
| 6632 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6633 | { |
| 6634 | PyObject* tmp = NULL; |
| 6635 | identifier arg; |
| 6636 | expr_ty value; |
| 6637 | |
| 6638 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6639 | int res; |
| 6640 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6641 | if (tmp == NULL) goto failed; |
| 6642 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6643 | if (res != 0) goto failed; |
| 6644 | Py_XDECREF(tmp); |
| 6645 | tmp = NULL; |
| 6646 | } else { |
| 6647 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6648 | return 1; |
| 6649 | } |
| 6650 | if (PyObject_HasAttrString(obj, "value")) { |
| 6651 | int res; |
| 6652 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6653 | if (tmp == NULL) goto failed; |
| 6654 | res = obj2ast_expr(tmp, &value, arena); |
| 6655 | if (res != 0) goto failed; |
| 6656 | Py_XDECREF(tmp); |
| 6657 | tmp = NULL; |
| 6658 | } else { |
| 6659 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6660 | return 1; |
| 6661 | } |
| 6662 | *out = keyword(arg, value, arena); |
| 6663 | return 0; |
| 6664 | failed: |
| 6665 | Py_XDECREF(tmp); |
| 6666 | return 1; |
| 6667 | } |
| 6668 | |
| 6669 | int |
| 6670 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6671 | { |
| 6672 | PyObject* tmp = NULL; |
| 6673 | identifier name; |
| 6674 | identifier asname; |
| 6675 | |
| 6676 | if (PyObject_HasAttrString(obj, "name")) { |
| 6677 | int res; |
| 6678 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6679 | if (tmp == NULL) goto failed; |
| 6680 | res = obj2ast_identifier(tmp, &name, arena); |
| 6681 | if (res != 0) goto failed; |
| 6682 | Py_XDECREF(tmp); |
| 6683 | tmp = NULL; |
| 6684 | } else { |
| 6685 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6686 | return 1; |
| 6687 | } |
| 6688 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6689 | int res; |
| 6690 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6691 | if (tmp == NULL) goto failed; |
| 6692 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6693 | if (res != 0) goto failed; |
| 6694 | Py_XDECREF(tmp); |
| 6695 | tmp = NULL; |
| 6696 | } else { |
| 6697 | asname = NULL; |
| 6698 | } |
| 6699 | *out = alias(name, asname, arena); |
| 6700 | return 0; |
| 6701 | failed: |
| 6702 | Py_XDECREF(tmp); |
| 6703 | return 1; |
| 6704 | } |
| 6705 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6706 | int |
| 6707 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6708 | { |
| 6709 | PyObject* tmp = NULL; |
| 6710 | expr_ty context_expr; |
| 6711 | expr_ty optional_vars; |
| 6712 | |
| 6713 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 6714 | int res; |
| 6715 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 6716 | if (tmp == NULL) goto failed; |
| 6717 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6718 | if (res != 0) goto failed; |
| 6719 | Py_XDECREF(tmp); |
| 6720 | tmp = NULL; |
| 6721 | } else { |
| 6722 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6723 | return 1; |
| 6724 | } |
| 6725 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 6726 | int res; |
| 6727 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 6728 | if (tmp == NULL) goto failed; |
| 6729 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6730 | if (res != 0) goto failed; |
| 6731 | Py_XDECREF(tmp); |
| 6732 | tmp = NULL; |
| 6733 | } else { |
| 6734 | optional_vars = NULL; |
| 6735 | } |
| 6736 | *out = withitem(context_expr, optional_vars, arena); |
| 6737 | return 0; |
| 6738 | failed: |
| 6739 | Py_XDECREF(tmp); |
| 6740 | return 1; |
| 6741 | } |
| 6742 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6743 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6744 | static struct PyModuleDef _astmodule = { |
| 6745 | PyModuleDef_HEAD_INIT, "_ast" |
| 6746 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6747 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6748 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6749 | { |
| 6750 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6751 | if (!init_types()) return NULL; |
| 6752 | m = PyModule_Create(&_astmodule); |
| 6753 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6754 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6755 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6756 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6757 | if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6758 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6759 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6760 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6761 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6762 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6763 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6764 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6765 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6766 | 0) return NULL; |
| 6767 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6768 | NULL; |
| 6769 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6770 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6771 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6772 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6773 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6774 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6775 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6776 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6777 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6778 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6779 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6780 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6781 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6782 | 0) return NULL; |
| 6783 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6784 | NULL; |
| 6785 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6786 | NULL; |
| 6787 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6788 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6789 | NULL; |
| 6790 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6791 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 6792 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 6793 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6794 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6795 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6796 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6797 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6798 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6799 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6800 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6801 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6802 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6803 | return NULL; |
| 6804 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6805 | NULL; |
| 6806 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6807 | NULL; |
| 6808 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6809 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6810 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6811 | return NULL; |
| 6812 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6813 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6814 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6815 | return NULL; |
| 6816 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6817 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6818 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6819 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6820 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6821 | return NULL; |
| 6822 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6823 | NULL; |
| 6824 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6825 | NULL; |
| 6826 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6827 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6828 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6829 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6830 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6831 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6832 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6833 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6834 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6835 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6836 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6837 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6838 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6839 | return NULL; |
| 6840 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6841 | NULL; |
| 6842 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6843 | NULL; |
| 6844 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6845 | NULL; |
| 6846 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6847 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6848 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6849 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6850 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6851 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6852 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6853 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6854 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6855 | return NULL; |
| 6856 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6857 | NULL; |
| 6858 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6859 | NULL; |
| 6860 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6861 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6862 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6863 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6864 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6865 | NULL; |
| 6866 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6867 | NULL; |
| 6868 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6869 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6870 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6871 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6872 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6873 | return NULL; |
| 6874 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6875 | NULL; |
| 6876 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6877 | NULL; |
| 6878 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6879 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6880 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6881 | return NULL; |
| 6882 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6883 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6884 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6885 | return NULL; |
| 6886 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6887 | NULL; |
| 6888 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6889 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6890 | return NULL; |
| 6891 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6892 | NULL; |
| 6893 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6894 | NULL; |
| 6895 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6896 | NULL; |
| 6897 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6898 | NULL; |
| 6899 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6900 | NULL; |
| 6901 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6902 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6903 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6904 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6905 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6906 | return NULL; |
| 6907 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6908 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6909 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6910 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6911 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6912 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6913 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6914 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6915 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6916 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6917 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6918 | return NULL; |
| 6919 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 6920 | NULL; |
| 6921 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 6922 | NULL; |
| 6923 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 6924 | NULL; |
| 6925 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 6926 | NULL; |
| 6927 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 6928 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 6929 | NULL; |
| 6930 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 6931 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 6932 | NULL; |
| 6933 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 6934 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 6935 | NULL; |
| 6936 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 6937 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 6938 | NULL; |
| 6939 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 6940 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 6941 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6942 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6943 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6944 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6945 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6946 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6947 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6948 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6949 | 0) return NULL; |
| 6950 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 6951 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6952 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6953 | return NULL; |
| 6954 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 6955 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6956 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 6957 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6958 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6959 | } |
| 6960 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6961 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6962 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6963 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6964 | init_types(); |
| 6965 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6966 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6967 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6968 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6969 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6970 | { |
| 6971 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6972 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6973 | (PyObject*)Interactive_type}; |
| 6974 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6975 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6976 | assert(0 <= mode && mode <= 2); |
| 6977 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6978 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6979 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6980 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 6981 | if (isinstance == -1) |
| 6982 | return NULL; |
| 6983 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6984 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6985 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6986 | return NULL; |
| 6987 | } |
| 6988 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6989 | return NULL; |
| 6990 | else |
| 6991 | return res; |
| 6992 | } |
| 6993 | |
| 6994 | int PyAST_Check(PyObject* obj) |
| 6995 | { |
| 6996 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 6997 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6998 | } |
| 6999 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7000 | |