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 |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 576 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 577 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 578 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 579 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 580 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 583 | /* Conversion Python -> AST */ |
| 584 | |
| 585 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 586 | { |
| 587 | if (obj == Py_None) |
| 588 | obj = NULL; |
| 589 | if (obj) |
| 590 | PyArena_AddPyObject(arena, obj); |
| 591 | Py_XINCREF(obj); |
| 592 | *out = obj; |
| 593 | return 0; |
| 594 | } |
| 595 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 596 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 597 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 598 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 599 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 600 | return 1; |
| 601 | } |
| 602 | return obj2ast_object(obj, out, arena); |
| 603 | } |
| 604 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 605 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 606 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 607 | if (!PyUnicode_CheckExact(obj)) { |
| 608 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 609 | return 1; |
| 610 | } |
| 611 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 612 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 613 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 614 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 615 | { |
| 616 | if (!PyBytes_CheckExact(obj)) { |
| 617 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 618 | return 1; |
| 619 | } |
| 620 | return obj2ast_object(obj, out, arena); |
| 621 | } |
| 622 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 623 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 624 | { |
| 625 | int i; |
| 626 | if (!PyLong_Check(obj)) { |
| 627 | PyObject *s = PyObject_Repr(obj); |
| 628 | if (s == NULL) return 1; |
| 629 | PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 630 | PyBytes_AS_STRING(s)); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 631 | Py_DECREF(s); |
| 632 | return 1; |
| 633 | } |
| 634 | |
| 635 | i = (int)PyLong_AsLong(obj); |
| 636 | if (i == -1 && PyErr_Occurred()) |
| 637 | return 1; |
| 638 | *out = i; |
| 639 | return 0; |
| 640 | } |
| 641 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 642 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 643 | { |
| 644 | PyObject *empty_tuple, *d; |
| 645 | if (PyType_Ready(&AST_type) < 0) |
| 646 | return -1; |
| 647 | d = AST_type.tp_dict; |
| 648 | empty_tuple = PyTuple_New(0); |
| 649 | if (!empty_tuple || |
| 650 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 651 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 652 | Py_XDECREF(empty_tuple); |
| 653 | return -1; |
| 654 | } |
| 655 | Py_DECREF(empty_tuple); |
| 656 | return 0; |
| 657 | } |
| 658 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 659 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | static int init_types(void) |
| 661 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 662 | static int initialized; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 663 | if (initialized) return 1; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 664 | if (add_ast_fields() < 0) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 665 | mod_type = make_type("mod", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 666 | if (!mod_type) return 0; |
| 667 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 668 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 669 | if (!Module_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 670 | Interactive_type = make_type("Interactive", mod_type, |
| 671 | Interactive_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 672 | if (!Interactive_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 673 | Expression_type = make_type("Expression", mod_type, Expression_fields, |
| 674 | 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 675 | if (!Expression_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 677 | if (!Suite_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 678 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 679 | if (!stmt_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 680 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 681 | FunctionDef_type = make_type("FunctionDef", stmt_type, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 682 | FunctionDef_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 683 | if (!FunctionDef_type) return 0; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 684 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 685 | if (!ClassDef_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 687 | if (!Return_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 688 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 689 | if (!Delete_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 690 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 691 | if (!Assign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 692 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 693 | if (!AugAssign_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 694 | For_type = make_type("For", stmt_type, For_fields, 4); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 695 | if (!For_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 696 | While_type = make_type("While", stmt_type, While_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 697 | if (!While_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 698 | If_type = make_type("If", stmt_type, If_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | if (!If_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 700 | With_type = make_type("With", stmt_type, With_fields, 2); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 701 | if (!With_type) return 0; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 702 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 703 | if (!Raise_type) return 0; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 704 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 705 | if (!Try_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 706 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!Assert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 708 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 709 | if (!Import_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 710 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 711 | 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | if (!ImportFrom_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 713 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | if (!Global_type) return 0; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 715 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 716 | if (!Nonlocal_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 717 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | if (!Expr_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 719 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | if (!Pass_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 721 | Break_type = make_type("Break", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 722 | if (!Break_type) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 723 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | if (!Continue_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 725 | expr_type = make_type("expr", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 726 | if (!expr_type) return 0; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 727 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 728 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 729 | if (!BoolOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 730 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 731 | if (!BinOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 732 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 733 | if (!UnaryOp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 734 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 735 | if (!Lambda_type) return 0; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 736 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 737 | if (!IfExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 738 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 739 | if (!Dict_type) return 0; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 740 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 741 | if (!Set_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 742 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 743 | if (!ListComp_type) return 0; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 744 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 745 | if (!SetComp_type) return 0; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 746 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 747 | if (!DictComp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 748 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 749 | GeneratorExp_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 750 | if (!GeneratorExp_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 751 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 752 | if (!Yield_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 753 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 754 | if (!Compare_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 755 | Call_type = make_type("Call", expr_type, Call_fields, 5); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 756 | if (!Call_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 757 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 758 | if (!Num_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 759 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 760 | if (!Str_type) return 0; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 761 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 762 | if (!Bytes_type) return 0; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 763 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 764 | if (!Ellipsis_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 766 | if (!Attribute_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 767 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 768 | if (!Subscript_type) return 0; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 769 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 770 | if (!Starred_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 771 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 772 | if (!Name_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 773 | List_type = make_type("List", expr_type, List_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 774 | if (!List_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 776 | if (!Tuple_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 777 | 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] | 778 | if (!expr_context_type) return 0; |
| 779 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 780 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 781 | if (!Load_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 782 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 783 | if (!Load_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 784 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | if (!Store_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 787 | if (!Store_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 788 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 789 | if (!Del_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 790 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 791 | if (!Del_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 792 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 793 | if (!AugLoad_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 795 | if (!AugLoad_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 796 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 797 | if (!AugStore_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 798 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | if (!AugStore_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 800 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 801 | if (!Param_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 803 | if (!Param_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 804 | slice_type = make_type("slice", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 805 | if (!slice_type) return 0; |
| 806 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 807 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 808 | if (!Slice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 810 | if (!ExtSlice_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 811 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 812 | if (!Index_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 813 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 814 | if (!boolop_type) return 0; |
| 815 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 816 | And_type = make_type("And", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | if (!And_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 818 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 819 | if (!And_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 820 | Or_type = make_type("Or", boolop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 821 | if (!Or_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 822 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 823 | if (!Or_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 824 | operator_type = make_type("operator", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 825 | if (!operator_type) return 0; |
| 826 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 827 | Add_type = make_type("Add", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 828 | if (!Add_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 829 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 830 | if (!Add_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 831 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 832 | if (!Sub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 833 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 834 | if (!Sub_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 835 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 836 | if (!Mult_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 838 | if (!Mult_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 839 | Div_type = make_type("Div", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 840 | if (!Div_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 841 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 842 | if (!Div_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 843 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 844 | if (!Mod_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 845 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 846 | if (!Mod_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 847 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 848 | if (!Pow_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 849 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 850 | if (!Pow_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 851 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 852 | if (!LShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 853 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 854 | if (!LShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 855 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 856 | if (!RShift_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 857 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 858 | if (!RShift_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 859 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 860 | if (!BitOr_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 861 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 862 | if (!BitOr_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 863 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 864 | if (!BitXor_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 866 | if (!BitXor_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 867 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 868 | if (!BitAnd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 870 | if (!BitAnd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 871 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 872 | if (!FloorDiv_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 873 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 874 | if (!FloorDiv_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 875 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 876 | if (!unaryop_type) return 0; |
| 877 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 878 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 879 | if (!Invert_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 880 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 881 | if (!Invert_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 882 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 883 | if (!Not_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 884 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 885 | if (!Not_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 886 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 887 | if (!UAdd_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 888 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 889 | if (!UAdd_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 890 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 891 | if (!USub_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 892 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 893 | if (!USub_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 894 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 895 | if (!cmpop_type) return 0; |
| 896 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 897 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 898 | if (!Eq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 899 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 900 | if (!Eq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 901 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | if (!NotEq_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 904 | if (!NotEq_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 905 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 906 | if (!Lt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 908 | if (!Lt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 909 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 910 | if (!LtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 911 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 912 | if (!LtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 913 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 914 | if (!Gt_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 915 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | if (!Gt_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 917 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 918 | if (!GtE_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 919 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 920 | if (!GtE_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 921 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 922 | if (!Is_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 924 | if (!Is_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 925 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 926 | if (!IsNot_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 927 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 928 | if (!IsNot_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 929 | In_type = make_type("In", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 930 | if (!In_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 931 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 932 | if (!In_singleton) return 0; |
Martin v. Löwis | 8d0701d | 2006-02-26 23:40:20 +0000 | [diff] [blame] | 933 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 934 | if (!NotIn_type) return 0; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 935 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 936 | if (!NotIn_singleton) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 937 | comprehension_type = make_type("comprehension", &AST_type, |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 938 | comprehension_fields, 3); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 939 | if (!comprehension_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 940 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 941 | if (!excepthandler_type) return 0; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 942 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 943 | return 0; |
| 944 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 945 | ExceptHandler_fields, 3); |
| 946 | if (!ExceptHandler_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 947 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 948 | if (!arguments_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 949 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 950 | if (!arg_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 951 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 952 | if (!keyword_type) return 0; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 953 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 954 | if (!alias_type) return 0; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 955 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 956 | if (!withitem_type) return 0; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 957 | initialized = 1; |
| 958 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 959 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 960 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 961 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 962 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 963 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 964 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 965 | arena); |
| 966 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 967 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 968 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 969 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 970 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 971 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 972 | arena); |
| 973 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 974 | arena); |
| 975 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 976 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 977 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 978 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 979 | 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] | 980 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 981 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 982 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 983 | { |
| 984 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 985 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 986 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 987 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 988 | p->kind = Module_kind; |
| 989 | p->v.Module.body = body; |
| 990 | return p; |
| 991 | } |
| 992 | |
| 993 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 994 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 995 | { |
| 996 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 997 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 998 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 999 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1000 | p->kind = Interactive_kind; |
| 1001 | p->v.Interactive.body = body; |
| 1002 | return p; |
| 1003 | } |
| 1004 | |
| 1005 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1006 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1007 | { |
| 1008 | mod_ty p; |
| 1009 | if (!body) { |
| 1010 | PyErr_SetString(PyExc_ValueError, |
| 1011 | "field body is required for Expression"); |
| 1012 | return NULL; |
| 1013 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1014 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1015 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1016 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1017 | p->kind = Expression_kind; |
| 1018 | p->v.Expression.body = body; |
| 1019 | return p; |
| 1020 | } |
| 1021 | |
| 1022 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1023 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1024 | { |
| 1025 | mod_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1026 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1027 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1028 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1029 | p->kind = Suite_kind; |
| 1030 | p->v.Suite.body = body; |
| 1031 | return p; |
| 1032 | } |
| 1033 | |
| 1034 | stmt_ty |
| 1035 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1036 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1037 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1038 | { |
| 1039 | stmt_ty p; |
| 1040 | if (!name) { |
| 1041 | PyErr_SetString(PyExc_ValueError, |
| 1042 | "field name is required for FunctionDef"); |
| 1043 | return NULL; |
| 1044 | } |
| 1045 | if (!args) { |
| 1046 | PyErr_SetString(PyExc_ValueError, |
| 1047 | "field args is required for FunctionDef"); |
| 1048 | return NULL; |
| 1049 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1050 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1051 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1052 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1053 | p->kind = FunctionDef_kind; |
| 1054 | p->v.FunctionDef.name = name; |
| 1055 | p->v.FunctionDef.args = args; |
| 1056 | p->v.FunctionDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1057 | p->v.FunctionDef.decorator_list = decorator_list; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1058 | p->v.FunctionDef.returns = returns; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1059 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1060 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1061 | return p; |
| 1062 | } |
| 1063 | |
| 1064 | stmt_ty |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1065 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1066 | starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list, |
| 1067 | int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1068 | { |
| 1069 | stmt_ty p; |
| 1070 | if (!name) { |
| 1071 | PyErr_SetString(PyExc_ValueError, |
| 1072 | "field name is required for ClassDef"); |
| 1073 | return NULL; |
| 1074 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1075 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1076 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1077 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1078 | p->kind = ClassDef_kind; |
| 1079 | p->v.ClassDef.name = name; |
| 1080 | p->v.ClassDef.bases = bases; |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 1081 | p->v.ClassDef.keywords = keywords; |
| 1082 | p->v.ClassDef.starargs = starargs; |
| 1083 | p->v.ClassDef.kwargs = kwargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1084 | p->v.ClassDef.body = body; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1085 | p->v.ClassDef.decorator_list = decorator_list; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1086 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1087 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1088 | return p; |
| 1089 | } |
| 1090 | |
| 1091 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1092 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1093 | { |
| 1094 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1095 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1096 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1097 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1098 | p->kind = Return_kind; |
| 1099 | p->v.Return.value = value; |
| 1100 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1101 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1102 | return p; |
| 1103 | } |
| 1104 | |
| 1105 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1106 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1107 | { |
| 1108 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1109 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1110 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1111 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1112 | p->kind = Delete_kind; |
| 1113 | p->v.Delete.targets = targets; |
| 1114 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1115 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1116 | return p; |
| 1117 | } |
| 1118 | |
| 1119 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1120 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1121 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1122 | { |
| 1123 | stmt_ty p; |
| 1124 | if (!value) { |
| 1125 | PyErr_SetString(PyExc_ValueError, |
| 1126 | "field value is required for Assign"); |
| 1127 | return NULL; |
| 1128 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1129 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1130 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1131 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1132 | p->kind = Assign_kind; |
| 1133 | p->v.Assign.targets = targets; |
| 1134 | p->v.Assign.value = value; |
| 1135 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1136 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1137 | return p; |
| 1138 | } |
| 1139 | |
| 1140 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1141 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1142 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1143 | { |
| 1144 | stmt_ty p; |
| 1145 | if (!target) { |
| 1146 | PyErr_SetString(PyExc_ValueError, |
| 1147 | "field target is required for AugAssign"); |
| 1148 | return NULL; |
| 1149 | } |
| 1150 | if (!op) { |
| 1151 | PyErr_SetString(PyExc_ValueError, |
| 1152 | "field op is required for AugAssign"); |
| 1153 | return NULL; |
| 1154 | } |
| 1155 | if (!value) { |
| 1156 | PyErr_SetString(PyExc_ValueError, |
| 1157 | "field value is required for AugAssign"); |
| 1158 | return NULL; |
| 1159 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1160 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1161 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1162 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1163 | p->kind = AugAssign_kind; |
| 1164 | p->v.AugAssign.target = target; |
| 1165 | p->v.AugAssign.op = op; |
| 1166 | p->v.AugAssign.value = value; |
| 1167 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1168 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1169 | return p; |
| 1170 | } |
| 1171 | |
| 1172 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1173 | 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] | 1174 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1175 | { |
| 1176 | stmt_ty p; |
| 1177 | if (!target) { |
| 1178 | PyErr_SetString(PyExc_ValueError, |
| 1179 | "field target is required for For"); |
| 1180 | return NULL; |
| 1181 | } |
| 1182 | if (!iter) { |
| 1183 | PyErr_SetString(PyExc_ValueError, |
| 1184 | "field iter is required for For"); |
| 1185 | return NULL; |
| 1186 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1187 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1188 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1189 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1190 | p->kind = For_kind; |
| 1191 | p->v.For.target = target; |
| 1192 | p->v.For.iter = iter; |
| 1193 | p->v.For.body = body; |
| 1194 | p->v.For.orelse = orelse; |
| 1195 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1196 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | return p; |
| 1198 | } |
| 1199 | |
| 1200 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1201 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1202 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1203 | { |
| 1204 | stmt_ty p; |
| 1205 | if (!test) { |
| 1206 | PyErr_SetString(PyExc_ValueError, |
| 1207 | "field test is required for While"); |
| 1208 | return NULL; |
| 1209 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1210 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1211 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1213 | p->kind = While_kind; |
| 1214 | p->v.While.test = test; |
| 1215 | p->v.While.body = body; |
| 1216 | p->v.While.orelse = orelse; |
| 1217 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1218 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1219 | return p; |
| 1220 | } |
| 1221 | |
| 1222 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1223 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1224 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1225 | { |
| 1226 | stmt_ty p; |
| 1227 | if (!test) { |
| 1228 | PyErr_SetString(PyExc_ValueError, |
| 1229 | "field test is required for If"); |
| 1230 | return NULL; |
| 1231 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1232 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1233 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1234 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | p->kind = If_kind; |
| 1236 | p->v.If.test = test; |
| 1237 | p->v.If.body = body; |
| 1238 | p->v.If.orelse = orelse; |
| 1239 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1240 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1241 | return p; |
| 1242 | } |
| 1243 | |
| 1244 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1245 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1246 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1247 | { |
| 1248 | stmt_ty p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1249 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1250 | if (!p) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1251 | return NULL; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1252 | p->kind = With_kind; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1253 | p->v.With.items = items; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1254 | p->v.With.body = body; |
| 1255 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1256 | p->col_offset = col_offset; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1257 | return p; |
| 1258 | } |
| 1259 | |
| 1260 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1261 | 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] | 1262 | { |
| 1263 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1264 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1265 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1266 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | p->kind = Raise_kind; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1268 | p->v.Raise.exc = exc; |
| 1269 | p->v.Raise.cause = cause; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1270 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1271 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1272 | return p; |
| 1273 | } |
| 1274 | |
| 1275 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1276 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1277 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1278 | { |
| 1279 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1280 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1281 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1282 | return NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1283 | p->kind = Try_kind; |
| 1284 | p->v.Try.body = body; |
| 1285 | p->v.Try.handlers = handlers; |
| 1286 | p->v.Try.orelse = orelse; |
| 1287 | p->v.Try.finalbody = finalbody; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1288 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1289 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1290 | return p; |
| 1291 | } |
| 1292 | |
| 1293 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1294 | 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] | 1295 | { |
| 1296 | stmt_ty p; |
| 1297 | if (!test) { |
| 1298 | PyErr_SetString(PyExc_ValueError, |
| 1299 | "field test is required for Assert"); |
| 1300 | return NULL; |
| 1301 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1302 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1303 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1304 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1305 | p->kind = Assert_kind; |
| 1306 | p->v.Assert.test = test; |
| 1307 | p->v.Assert.msg = msg; |
| 1308 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1309 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1310 | return p; |
| 1311 | } |
| 1312 | |
| 1313 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1314 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1315 | { |
| 1316 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1317 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1318 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1319 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | p->kind = Import_kind; |
| 1321 | p->v.Import.names = names; |
| 1322 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1323 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1324 | return p; |
| 1325 | } |
| 1326 | |
| 1327 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1328 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1329 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1330 | { |
| 1331 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1332 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1333 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1334 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1335 | p->kind = ImportFrom_kind; |
| 1336 | p->v.ImportFrom.module = module; |
| 1337 | p->v.ImportFrom.names = names; |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 1338 | p->v.ImportFrom.level = level; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1339 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1340 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1341 | return p; |
| 1342 | } |
| 1343 | |
| 1344 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1345 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1346 | { |
| 1347 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1348 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1349 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1350 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1351 | p->kind = Global_kind; |
| 1352 | p->v.Global.names = names; |
| 1353 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1354 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1355 | return p; |
| 1356 | } |
| 1357 | |
| 1358 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1359 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1360 | { |
| 1361 | stmt_ty p; |
| 1362 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1363 | if (!p) |
| 1364 | return NULL; |
| 1365 | p->kind = Nonlocal_kind; |
| 1366 | p->v.Nonlocal.names = names; |
| 1367 | p->lineno = lineno; |
| 1368 | p->col_offset = col_offset; |
| 1369 | return p; |
| 1370 | } |
| 1371 | |
| 1372 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1373 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1374 | { |
| 1375 | stmt_ty p; |
| 1376 | if (!value) { |
| 1377 | PyErr_SetString(PyExc_ValueError, |
| 1378 | "field value is required for Expr"); |
| 1379 | return NULL; |
| 1380 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1381 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1382 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1384 | p->kind = Expr_kind; |
| 1385 | p->v.Expr.value = value; |
| 1386 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1387 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1388 | return p; |
| 1389 | } |
| 1390 | |
| 1391 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1392 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1393 | { |
| 1394 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1395 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1396 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1397 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1398 | p->kind = Pass_kind; |
| 1399 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1400 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1401 | return p; |
| 1402 | } |
| 1403 | |
| 1404 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1405 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1406 | { |
| 1407 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1408 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1409 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1410 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1411 | p->kind = Break_kind; |
| 1412 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1413 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | return p; |
| 1415 | } |
| 1416 | |
| 1417 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1418 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | { |
| 1420 | stmt_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1421 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1422 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1423 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1424 | p->kind = Continue_kind; |
| 1425 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1426 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1427 | return p; |
| 1428 | } |
| 1429 | |
| 1430 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1431 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1432 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1433 | { |
| 1434 | expr_ty p; |
| 1435 | if (!op) { |
| 1436 | PyErr_SetString(PyExc_ValueError, |
| 1437 | "field op is required for BoolOp"); |
| 1438 | return NULL; |
| 1439 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1440 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1441 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1442 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1443 | p->kind = BoolOp_kind; |
| 1444 | p->v.BoolOp.op = op; |
| 1445 | p->v.BoolOp.values = values; |
| 1446 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1447 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1448 | return p; |
| 1449 | } |
| 1450 | |
| 1451 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1452 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1453 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1454 | { |
| 1455 | expr_ty p; |
| 1456 | if (!left) { |
| 1457 | PyErr_SetString(PyExc_ValueError, |
| 1458 | "field left is required for BinOp"); |
| 1459 | return NULL; |
| 1460 | } |
| 1461 | if (!op) { |
| 1462 | PyErr_SetString(PyExc_ValueError, |
| 1463 | "field op is required for BinOp"); |
| 1464 | return NULL; |
| 1465 | } |
| 1466 | if (!right) { |
| 1467 | PyErr_SetString(PyExc_ValueError, |
| 1468 | "field right is required for BinOp"); |
| 1469 | return NULL; |
| 1470 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1471 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1472 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1473 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1474 | p->kind = BinOp_kind; |
| 1475 | p->v.BinOp.left = left; |
| 1476 | p->v.BinOp.op = op; |
| 1477 | p->v.BinOp.right = right; |
| 1478 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1479 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1480 | return p; |
| 1481 | } |
| 1482 | |
| 1483 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1484 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1485 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1486 | { |
| 1487 | expr_ty p; |
| 1488 | if (!op) { |
| 1489 | PyErr_SetString(PyExc_ValueError, |
| 1490 | "field op is required for UnaryOp"); |
| 1491 | return NULL; |
| 1492 | } |
| 1493 | if (!operand) { |
| 1494 | PyErr_SetString(PyExc_ValueError, |
| 1495 | "field operand is required for UnaryOp"); |
| 1496 | return NULL; |
| 1497 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1498 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1499 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1500 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1501 | p->kind = UnaryOp_kind; |
| 1502 | p->v.UnaryOp.op = op; |
| 1503 | p->v.UnaryOp.operand = operand; |
| 1504 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1505 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1506 | return p; |
| 1507 | } |
| 1508 | |
| 1509 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1510 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1511 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1512 | { |
| 1513 | expr_ty p; |
| 1514 | if (!args) { |
| 1515 | PyErr_SetString(PyExc_ValueError, |
| 1516 | "field args is required for Lambda"); |
| 1517 | return NULL; |
| 1518 | } |
| 1519 | if (!body) { |
| 1520 | PyErr_SetString(PyExc_ValueError, |
| 1521 | "field body is required for Lambda"); |
| 1522 | return NULL; |
| 1523 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1524 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1525 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1526 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1527 | p->kind = Lambda_kind; |
| 1528 | p->v.Lambda.args = args; |
| 1529 | p->v.Lambda.body = body; |
| 1530 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1531 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1532 | return p; |
| 1533 | } |
| 1534 | |
| 1535 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1536 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1537 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1538 | { |
| 1539 | expr_ty p; |
| 1540 | if (!test) { |
| 1541 | PyErr_SetString(PyExc_ValueError, |
| 1542 | "field test is required for IfExp"); |
| 1543 | return NULL; |
| 1544 | } |
| 1545 | if (!body) { |
| 1546 | PyErr_SetString(PyExc_ValueError, |
| 1547 | "field body is required for IfExp"); |
| 1548 | return NULL; |
| 1549 | } |
| 1550 | if (!orelse) { |
| 1551 | PyErr_SetString(PyExc_ValueError, |
| 1552 | "field orelse is required for IfExp"); |
| 1553 | return NULL; |
| 1554 | } |
| 1555 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1556 | if (!p) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1557 | return NULL; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1558 | p->kind = IfExp_kind; |
| 1559 | p->v.IfExp.test = test; |
| 1560 | p->v.IfExp.body = body; |
| 1561 | p->v.IfExp.orelse = orelse; |
| 1562 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1563 | p->col_offset = col_offset; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1564 | return p; |
| 1565 | } |
| 1566 | |
| 1567 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1568 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1569 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | { |
| 1571 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1572 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1573 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1574 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1575 | p->kind = Dict_kind; |
| 1576 | p->v.Dict.keys = keys; |
| 1577 | p->v.Dict.values = values; |
| 1578 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1579 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1580 | return p; |
| 1581 | } |
| 1582 | |
| 1583 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1584 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1585 | { |
| 1586 | expr_ty p; |
| 1587 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1588 | if (!p) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1589 | return NULL; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1590 | p->kind = Set_kind; |
| 1591 | p->v.Set.elts = elts; |
| 1592 | p->lineno = lineno; |
| 1593 | p->col_offset = col_offset; |
| 1594 | return p; |
| 1595 | } |
| 1596 | |
| 1597 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1598 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1599 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1600 | { |
| 1601 | expr_ty p; |
| 1602 | if (!elt) { |
| 1603 | PyErr_SetString(PyExc_ValueError, |
| 1604 | "field elt is required for ListComp"); |
| 1605 | return NULL; |
| 1606 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1607 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1608 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1609 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1610 | p->kind = ListComp_kind; |
| 1611 | p->v.ListComp.elt = elt; |
| 1612 | p->v.ListComp.generators = generators; |
| 1613 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1614 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1615 | return p; |
| 1616 | } |
| 1617 | |
| 1618 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1619 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1620 | *arena) |
| 1621 | { |
| 1622 | expr_ty p; |
| 1623 | if (!elt) { |
| 1624 | PyErr_SetString(PyExc_ValueError, |
| 1625 | "field elt is required for SetComp"); |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1629 | if (!p) |
| 1630 | return NULL; |
| 1631 | p->kind = SetComp_kind; |
| 1632 | p->v.SetComp.elt = elt; |
| 1633 | p->v.SetComp.generators = generators; |
| 1634 | p->lineno = lineno; |
| 1635 | p->col_offset = col_offset; |
| 1636 | return p; |
| 1637 | } |
| 1638 | |
| 1639 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1640 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1641 | col_offset, PyArena *arena) |
| 1642 | { |
| 1643 | expr_ty p; |
| 1644 | if (!key) { |
| 1645 | PyErr_SetString(PyExc_ValueError, |
| 1646 | "field key is required for DictComp"); |
| 1647 | return NULL; |
| 1648 | } |
| 1649 | if (!value) { |
| 1650 | PyErr_SetString(PyExc_ValueError, |
| 1651 | "field value is required for DictComp"); |
| 1652 | return NULL; |
| 1653 | } |
| 1654 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1655 | if (!p) |
| 1656 | return NULL; |
| 1657 | p->kind = DictComp_kind; |
| 1658 | p->v.DictComp.key = key; |
| 1659 | p->v.DictComp.value = value; |
| 1660 | p->v.DictComp.generators = generators; |
| 1661 | p->lineno = lineno; |
| 1662 | p->col_offset = col_offset; |
| 1663 | return p; |
| 1664 | } |
| 1665 | |
| 1666 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1667 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1668 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1669 | { |
| 1670 | expr_ty p; |
| 1671 | if (!elt) { |
| 1672 | PyErr_SetString(PyExc_ValueError, |
| 1673 | "field elt is required for GeneratorExp"); |
| 1674 | return NULL; |
| 1675 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1676 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1677 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1678 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1679 | p->kind = GeneratorExp_kind; |
| 1680 | p->v.GeneratorExp.elt = elt; |
| 1681 | p->v.GeneratorExp.generators = generators; |
| 1682 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1683 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1684 | return p; |
| 1685 | } |
| 1686 | |
| 1687 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1688 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1689 | { |
| 1690 | expr_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1691 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1692 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1693 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1694 | p->kind = Yield_kind; |
| 1695 | p->v.Yield.value = value; |
| 1696 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1697 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1698 | return p; |
| 1699 | } |
| 1700 | |
| 1701 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1702 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 1703 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1704 | { |
| 1705 | expr_ty p; |
| 1706 | if (!left) { |
| 1707 | PyErr_SetString(PyExc_ValueError, |
| 1708 | "field left is required for Compare"); |
| 1709 | return NULL; |
| 1710 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1711 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1712 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1713 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1714 | p->kind = Compare_kind; |
| 1715 | p->v.Compare.left = left; |
| 1716 | p->v.Compare.ops = ops; |
| 1717 | p->v.Compare.comparators = comparators; |
| 1718 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1719 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1720 | return p; |
| 1721 | } |
| 1722 | |
| 1723 | expr_ty |
| 1724 | 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] | 1725 | expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1726 | { |
| 1727 | expr_ty p; |
| 1728 | if (!func) { |
| 1729 | PyErr_SetString(PyExc_ValueError, |
| 1730 | "field func is required for Call"); |
| 1731 | return NULL; |
| 1732 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1733 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1734 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1735 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1736 | p->kind = Call_kind; |
| 1737 | p->v.Call.func = func; |
| 1738 | p->v.Call.args = args; |
| 1739 | p->v.Call.keywords = keywords; |
| 1740 | p->v.Call.starargs = starargs; |
| 1741 | p->v.Call.kwargs = kwargs; |
| 1742 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1743 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1744 | return p; |
| 1745 | } |
| 1746 | |
| 1747 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1748 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | { |
| 1750 | expr_ty p; |
| 1751 | if (!n) { |
| 1752 | PyErr_SetString(PyExc_ValueError, |
| 1753 | "field n is required for Num"); |
| 1754 | return NULL; |
| 1755 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1756 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1757 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1758 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1759 | p->kind = Num_kind; |
| 1760 | p->v.Num.n = n; |
| 1761 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1762 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | return p; |
| 1764 | } |
| 1765 | |
| 1766 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1767 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1768 | { |
| 1769 | expr_ty p; |
| 1770 | if (!s) { |
| 1771 | PyErr_SetString(PyExc_ValueError, |
| 1772 | "field s is required for Str"); |
| 1773 | return NULL; |
| 1774 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1775 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1776 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1777 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1778 | p->kind = Str_kind; |
| 1779 | p->v.Str.s = s; |
| 1780 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1781 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1782 | return p; |
| 1783 | } |
| 1784 | |
| 1785 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1786 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1787 | { |
| 1788 | expr_ty p; |
| 1789 | if (!s) { |
| 1790 | PyErr_SetString(PyExc_ValueError, |
| 1791 | "field s is required for Bytes"); |
| 1792 | return NULL; |
| 1793 | } |
| 1794 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1795 | if (!p) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1796 | return NULL; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 1797 | p->kind = Bytes_kind; |
| 1798 | p->v.Bytes.s = s; |
| 1799 | p->lineno = lineno; |
| 1800 | p->col_offset = col_offset; |
| 1801 | return p; |
| 1802 | } |
| 1803 | |
| 1804 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1805 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 1806 | { |
| 1807 | expr_ty p; |
| 1808 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1809 | if (!p) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1810 | return NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 1811 | p->kind = Ellipsis_kind; |
| 1812 | p->lineno = lineno; |
| 1813 | p->col_offset = col_offset; |
| 1814 | return p; |
| 1815 | } |
| 1816 | |
| 1817 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1818 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 1819 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1820 | { |
| 1821 | expr_ty p; |
| 1822 | if (!value) { |
| 1823 | PyErr_SetString(PyExc_ValueError, |
| 1824 | "field value is required for Attribute"); |
| 1825 | return NULL; |
| 1826 | } |
| 1827 | if (!attr) { |
| 1828 | PyErr_SetString(PyExc_ValueError, |
| 1829 | "field attr is required for Attribute"); |
| 1830 | return NULL; |
| 1831 | } |
| 1832 | if (!ctx) { |
| 1833 | PyErr_SetString(PyExc_ValueError, |
| 1834 | "field ctx is required for Attribute"); |
| 1835 | return NULL; |
| 1836 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1837 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1838 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1839 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1840 | p->kind = Attribute_kind; |
| 1841 | p->v.Attribute.value = value; |
| 1842 | p->v.Attribute.attr = attr; |
| 1843 | p->v.Attribute.ctx = ctx; |
| 1844 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1845 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1846 | return p; |
| 1847 | } |
| 1848 | |
| 1849 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1850 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 1851 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1852 | { |
| 1853 | expr_ty p; |
| 1854 | if (!value) { |
| 1855 | PyErr_SetString(PyExc_ValueError, |
| 1856 | "field value is required for Subscript"); |
| 1857 | return NULL; |
| 1858 | } |
| 1859 | if (!slice) { |
| 1860 | PyErr_SetString(PyExc_ValueError, |
| 1861 | "field slice is required for Subscript"); |
| 1862 | return NULL; |
| 1863 | } |
| 1864 | if (!ctx) { |
| 1865 | PyErr_SetString(PyExc_ValueError, |
| 1866 | "field ctx is required for Subscript"); |
| 1867 | return NULL; |
| 1868 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1869 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1870 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1871 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1872 | p->kind = Subscript_kind; |
| 1873 | p->v.Subscript.value = value; |
| 1874 | p->v.Subscript.slice = slice; |
| 1875 | p->v.Subscript.ctx = ctx; |
| 1876 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1877 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1878 | return p; |
| 1879 | } |
| 1880 | |
| 1881 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1882 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1883 | *arena) |
| 1884 | { |
| 1885 | expr_ty p; |
| 1886 | if (!value) { |
| 1887 | PyErr_SetString(PyExc_ValueError, |
| 1888 | "field value is required for Starred"); |
| 1889 | return NULL; |
| 1890 | } |
| 1891 | if (!ctx) { |
| 1892 | PyErr_SetString(PyExc_ValueError, |
| 1893 | "field ctx is required for Starred"); |
| 1894 | return NULL; |
| 1895 | } |
| 1896 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1897 | if (!p) |
| 1898 | return NULL; |
| 1899 | p->kind = Starred_kind; |
| 1900 | p->v.Starred.value = value; |
| 1901 | p->v.Starred.ctx = ctx; |
| 1902 | p->lineno = lineno; |
| 1903 | p->col_offset = col_offset; |
| 1904 | return p; |
| 1905 | } |
| 1906 | |
| 1907 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1908 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1909 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1910 | { |
| 1911 | expr_ty p; |
| 1912 | if (!id) { |
| 1913 | PyErr_SetString(PyExc_ValueError, |
| 1914 | "field id is required for Name"); |
| 1915 | return NULL; |
| 1916 | } |
| 1917 | if (!ctx) { |
| 1918 | PyErr_SetString(PyExc_ValueError, |
| 1919 | "field ctx is required for Name"); |
| 1920 | return NULL; |
| 1921 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1922 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1923 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1924 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1925 | p->kind = Name_kind; |
| 1926 | p->v.Name.id = id; |
| 1927 | p->v.Name.ctx = ctx; |
| 1928 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1929 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1930 | return p; |
| 1931 | } |
| 1932 | |
| 1933 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1934 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1935 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1936 | { |
| 1937 | expr_ty p; |
| 1938 | if (!ctx) { |
| 1939 | PyErr_SetString(PyExc_ValueError, |
| 1940 | "field ctx is required for List"); |
| 1941 | return NULL; |
| 1942 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1943 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1944 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1945 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1946 | p->kind = List_kind; |
| 1947 | p->v.List.elts = elts; |
| 1948 | p->v.List.ctx = ctx; |
| 1949 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1950 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1951 | return p; |
| 1952 | } |
| 1953 | |
| 1954 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1955 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 1956 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1957 | { |
| 1958 | expr_ty p; |
| 1959 | if (!ctx) { |
| 1960 | PyErr_SetString(PyExc_ValueError, |
| 1961 | "field ctx is required for Tuple"); |
| 1962 | return NULL; |
| 1963 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1964 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1965 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1967 | p->kind = Tuple_kind; |
| 1968 | p->v.Tuple.elts = elts; |
| 1969 | p->v.Tuple.ctx = ctx; |
| 1970 | p->lineno = lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1971 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | return p; |
| 1973 | } |
| 1974 | |
| 1975 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1976 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1977 | { |
| 1978 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1979 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1980 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1981 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1982 | p->kind = Slice_kind; |
| 1983 | p->v.Slice.lower = lower; |
| 1984 | p->v.Slice.upper = upper; |
| 1985 | p->v.Slice.step = step; |
| 1986 | return p; |
| 1987 | } |
| 1988 | |
| 1989 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1990 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1991 | { |
| 1992 | slice_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1993 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1994 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1995 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1996 | p->kind = ExtSlice_kind; |
| 1997 | p->v.ExtSlice.dims = dims; |
| 1998 | return p; |
| 1999 | } |
| 2000 | |
| 2001 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2002 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | { |
| 2004 | slice_ty p; |
| 2005 | if (!value) { |
| 2006 | PyErr_SetString(PyExc_ValueError, |
| 2007 | "field value is required for Index"); |
| 2008 | return NULL; |
| 2009 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2010 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2011 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2012 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2013 | p->kind = Index_kind; |
| 2014 | p->v.Index.value = value; |
| 2015 | return p; |
| 2016 | } |
| 2017 | |
| 2018 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2019 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2020 | { |
| 2021 | comprehension_ty p; |
| 2022 | if (!target) { |
| 2023 | PyErr_SetString(PyExc_ValueError, |
| 2024 | "field target is required for comprehension"); |
| 2025 | return NULL; |
| 2026 | } |
| 2027 | if (!iter) { |
| 2028 | PyErr_SetString(PyExc_ValueError, |
| 2029 | "field iter is required for comprehension"); |
| 2030 | return NULL; |
| 2031 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2032 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2033 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2034 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2035 | p->target = target; |
| 2036 | p->iter = iter; |
| 2037 | p->ifs = ifs; |
| 2038 | return p; |
| 2039 | } |
| 2040 | |
| 2041 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2042 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2043 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2044 | { |
| 2045 | excepthandler_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2046 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2047 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2048 | return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2049 | p->kind = ExceptHandler_kind; |
| 2050 | p->v.ExceptHandler.type = type; |
| 2051 | p->v.ExceptHandler.name = name; |
| 2052 | p->v.ExceptHandler.body = body; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2053 | p->lineno = lineno; |
| 2054 | p->col_offset = col_offset; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2055 | return p; |
| 2056 | } |
| 2057 | |
| 2058 | arguments_ty |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2059 | arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, |
| 2060 | asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, |
| 2061 | asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2062 | { |
| 2063 | arguments_ty p; |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2064 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2065 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2066 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2067 | p->args = args; |
| 2068 | p->vararg = vararg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2069 | p->varargannotation = varargannotation; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2070 | p->kwonlyargs = kwonlyargs; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2071 | p->kwarg = kwarg; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2072 | p->kwargannotation = kwargannotation; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2073 | p->defaults = defaults; |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 2074 | p->kw_defaults = kw_defaults; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2075 | return p; |
| 2076 | } |
| 2077 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2078 | arg_ty |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2079 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2080 | { |
| 2081 | arg_ty p; |
| 2082 | if (!arg) { |
| 2083 | PyErr_SetString(PyExc_ValueError, |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2084 | "field arg is required for arg"); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2085 | return NULL; |
| 2086 | } |
| 2087 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2088 | if (!p) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2089 | return NULL; |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2090 | p->arg = arg; |
| 2091 | p->annotation = annotation; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2092 | return p; |
| 2093 | } |
| 2094 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2095 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2096 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2097 | { |
| 2098 | keyword_ty p; |
| 2099 | if (!arg) { |
| 2100 | PyErr_SetString(PyExc_ValueError, |
| 2101 | "field arg is required for keyword"); |
| 2102 | return NULL; |
| 2103 | } |
| 2104 | if (!value) { |
| 2105 | PyErr_SetString(PyExc_ValueError, |
| 2106 | "field value is required for keyword"); |
| 2107 | return NULL; |
| 2108 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2109 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2110 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2111 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2112 | p->arg = arg; |
| 2113 | p->value = value; |
| 2114 | return p; |
| 2115 | } |
| 2116 | |
| 2117 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2118 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2119 | { |
| 2120 | alias_ty p; |
| 2121 | if (!name) { |
| 2122 | PyErr_SetString(PyExc_ValueError, |
| 2123 | "field name is required for alias"); |
| 2124 | return NULL; |
| 2125 | } |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2126 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 2127 | if (!p) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2128 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2129 | p->name = name; |
| 2130 | p->asname = asname; |
| 2131 | return p; |
| 2132 | } |
| 2133 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2134 | withitem_ty |
| 2135 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2136 | { |
| 2137 | withitem_ty p; |
| 2138 | if (!context_expr) { |
| 2139 | PyErr_SetString(PyExc_ValueError, |
| 2140 | "field context_expr is required for withitem"); |
| 2141 | return NULL; |
| 2142 | } |
| 2143 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2144 | if (!p) |
| 2145 | return NULL; |
| 2146 | p->context_expr = context_expr; |
| 2147 | p->optional_vars = optional_vars; |
| 2148 | return p; |
| 2149 | } |
| 2150 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2151 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2152 | PyObject* |
| 2153 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2154 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2155 | mod_ty o = (mod_ty)_o; |
| 2156 | PyObject *result = NULL, *value = NULL; |
| 2157 | if (!o) { |
| 2158 | Py_INCREF(Py_None); |
| 2159 | return Py_None; |
| 2160 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2161 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | switch (o->kind) { |
| 2163 | case Module_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2164 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2165 | if (!result) goto failed; |
| 2166 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2167 | if (!value) goto failed; |
| 2168 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2169 | goto failed; |
| 2170 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2171 | break; |
| 2172 | case Interactive_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2173 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2174 | if (!result) goto failed; |
| 2175 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2176 | if (!value) goto failed; |
| 2177 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2178 | goto failed; |
| 2179 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2180 | break; |
| 2181 | case Expression_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2182 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2183 | if (!result) goto failed; |
| 2184 | value = ast2obj_expr(o->v.Expression.body); |
| 2185 | if (!value) goto failed; |
| 2186 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2187 | goto failed; |
| 2188 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | case Suite_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2191 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2192 | if (!result) goto failed; |
| 2193 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2194 | if (!value) goto failed; |
| 2195 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2196 | goto failed; |
| 2197 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2200 | return result; |
| 2201 | failed: |
| 2202 | Py_XDECREF(value); |
| 2203 | Py_XDECREF(result); |
| 2204 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2207 | PyObject* |
| 2208 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2209 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2210 | stmt_ty o = (stmt_ty)_o; |
| 2211 | PyObject *result = NULL, *value = NULL; |
| 2212 | if (!o) { |
| 2213 | Py_INCREF(Py_None); |
| 2214 | return Py_None; |
| 2215 | } |
| 2216 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2217 | switch (o->kind) { |
| 2218 | case FunctionDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2219 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2220 | if (!result) goto failed; |
| 2221 | value = ast2obj_identifier(o->v.FunctionDef.name); |
| 2222 | if (!value) goto failed; |
| 2223 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2224 | goto failed; |
| 2225 | Py_DECREF(value); |
| 2226 | value = ast2obj_arguments(o->v.FunctionDef.args); |
| 2227 | if (!value) goto failed; |
| 2228 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2229 | goto failed; |
| 2230 | Py_DECREF(value); |
| 2231 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2232 | if (!value) goto failed; |
| 2233 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2234 | goto failed; |
| 2235 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2236 | value = ast2obj_list(o->v.FunctionDef.decorator_list, |
| 2237 | ast2obj_expr); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2238 | if (!value) goto failed; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2239 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2240 | -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2241 | goto failed; |
| 2242 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2243 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2244 | if (!value) goto failed; |
| 2245 | if (PyObject_SetAttrString(result, "returns", value) == -1) |
| 2246 | goto failed; |
| 2247 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | case ClassDef_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2250 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2251 | if (!result) goto failed; |
| 2252 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2253 | if (!value) goto failed; |
| 2254 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 2255 | goto failed; |
| 2256 | Py_DECREF(value); |
| 2257 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2258 | if (!value) goto failed; |
| 2259 | if (PyObject_SetAttrString(result, "bases", value) == -1) |
| 2260 | goto failed; |
| 2261 | Py_DECREF(value); |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 2262 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2263 | if (!value) goto failed; |
| 2264 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2265 | goto failed; |
| 2266 | Py_DECREF(value); |
| 2267 | value = ast2obj_expr(o->v.ClassDef.starargs); |
| 2268 | if (!value) goto failed; |
| 2269 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2270 | goto failed; |
| 2271 | Py_DECREF(value); |
| 2272 | value = ast2obj_expr(o->v.ClassDef.kwargs); |
| 2273 | if (!value) goto failed; |
| 2274 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2275 | goto failed; |
| 2276 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2277 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2278 | if (!value) goto failed; |
| 2279 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2280 | goto failed; |
| 2281 | Py_DECREF(value); |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 2282 | value = ast2obj_list(o->v.ClassDef.decorator_list, |
| 2283 | ast2obj_expr); |
| 2284 | if (!value) goto failed; |
| 2285 | if (PyObject_SetAttrString(result, "decorator_list", value) == |
| 2286 | -1) |
| 2287 | goto failed; |
| 2288 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2289 | break; |
| 2290 | case Return_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2291 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2292 | if (!result) goto failed; |
| 2293 | value = ast2obj_expr(o->v.Return.value); |
| 2294 | if (!value) goto failed; |
| 2295 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2296 | goto failed; |
| 2297 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2298 | break; |
| 2299 | case Delete_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2300 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2301 | if (!result) goto failed; |
| 2302 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2303 | if (!value) goto failed; |
| 2304 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2305 | goto failed; |
| 2306 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | case Assign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2309 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2310 | if (!result) goto failed; |
| 2311 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2312 | if (!value) goto failed; |
| 2313 | if (PyObject_SetAttrString(result, "targets", value) == -1) |
| 2314 | goto failed; |
| 2315 | Py_DECREF(value); |
| 2316 | value = ast2obj_expr(o->v.Assign.value); |
| 2317 | if (!value) goto failed; |
| 2318 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2319 | goto failed; |
| 2320 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2321 | break; |
| 2322 | case AugAssign_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2323 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2324 | if (!result) goto failed; |
| 2325 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2326 | if (!value) goto failed; |
| 2327 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2328 | goto failed; |
| 2329 | Py_DECREF(value); |
| 2330 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2331 | if (!value) goto failed; |
| 2332 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2333 | goto failed; |
| 2334 | Py_DECREF(value); |
| 2335 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2336 | if (!value) goto failed; |
| 2337 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2338 | goto failed; |
| 2339 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2340 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2341 | case For_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2342 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2343 | if (!result) goto failed; |
| 2344 | value = ast2obj_expr(o->v.For.target); |
| 2345 | if (!value) goto failed; |
| 2346 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 2347 | goto failed; |
| 2348 | Py_DECREF(value); |
| 2349 | value = ast2obj_expr(o->v.For.iter); |
| 2350 | if (!value) goto failed; |
| 2351 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 2352 | goto failed; |
| 2353 | Py_DECREF(value); |
| 2354 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2355 | if (!value) goto failed; |
| 2356 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2357 | goto failed; |
| 2358 | Py_DECREF(value); |
| 2359 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2360 | if (!value) goto failed; |
| 2361 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2362 | goto failed; |
| 2363 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | case While_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2366 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2367 | if (!result) goto failed; |
| 2368 | value = ast2obj_expr(o->v.While.test); |
| 2369 | if (!value) goto failed; |
| 2370 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2371 | goto failed; |
| 2372 | Py_DECREF(value); |
| 2373 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2374 | if (!value) goto failed; |
| 2375 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2376 | goto failed; |
| 2377 | Py_DECREF(value); |
| 2378 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2379 | if (!value) goto failed; |
| 2380 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2381 | goto failed; |
| 2382 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | break; |
| 2384 | case If_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2385 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2386 | if (!result) goto failed; |
| 2387 | value = ast2obj_expr(o->v.If.test); |
| 2388 | if (!value) goto failed; |
| 2389 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2390 | goto failed; |
| 2391 | Py_DECREF(value); |
| 2392 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2393 | if (!value) goto failed; |
| 2394 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2395 | goto failed; |
| 2396 | Py_DECREF(value); |
| 2397 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2398 | if (!value) goto failed; |
| 2399 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2400 | goto failed; |
| 2401 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2402 | break; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2403 | case With_kind: |
| 2404 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2405 | if (!result) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2406 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2407 | if (!value) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2408 | if (PyObject_SetAttrString(result, "items", value) == -1) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2409 | goto failed; |
| 2410 | Py_DECREF(value); |
| 2411 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2412 | if (!value) goto failed; |
| 2413 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2414 | goto failed; |
| 2415 | Py_DECREF(value); |
| 2416 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2417 | case Raise_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2418 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2419 | if (!result) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2420 | value = ast2obj_expr(o->v.Raise.exc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2421 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2422 | if (PyObject_SetAttrString(result, "exc", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2423 | goto failed; |
| 2424 | Py_DECREF(value); |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2425 | value = ast2obj_expr(o->v.Raise.cause); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2426 | if (!value) goto failed; |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 2427 | if (PyObject_SetAttrString(result, "cause", value) == -1) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2428 | goto failed; |
| 2429 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2430 | break; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2431 | case Try_kind: |
| 2432 | result = PyType_GenericNew(Try_type, NULL, NULL); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2433 | if (!result) goto failed; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2434 | value = ast2obj_list(o->v.Try.body, 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, "body", 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.handlers, ast2obj_excepthandler); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2440 | if (!value) goto failed; |
| 2441 | if (PyObject_SetAttrString(result, "handlers", value) == -1) |
| 2442 | goto failed; |
| 2443 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2444 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2445 | if (!value) goto failed; |
| 2446 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2447 | goto failed; |
| 2448 | Py_DECREF(value); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2449 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2450 | if (!value) goto failed; |
| 2451 | if (PyObject_SetAttrString(result, "finalbody", value) == -1) |
| 2452 | goto failed; |
| 2453 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2454 | break; |
| 2455 | case Assert_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2456 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2457 | if (!result) goto failed; |
| 2458 | value = ast2obj_expr(o->v.Assert.test); |
| 2459 | if (!value) goto failed; |
| 2460 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2461 | goto failed; |
| 2462 | Py_DECREF(value); |
| 2463 | value = ast2obj_expr(o->v.Assert.msg); |
| 2464 | if (!value) goto failed; |
| 2465 | if (PyObject_SetAttrString(result, "msg", value) == -1) |
| 2466 | goto failed; |
| 2467 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2468 | break; |
| 2469 | case Import_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2470 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2471 | if (!result) goto failed; |
| 2472 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2473 | if (!value) goto failed; |
| 2474 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2475 | goto failed; |
| 2476 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2477 | break; |
| 2478 | case ImportFrom_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2479 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2480 | if (!result) goto failed; |
| 2481 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2482 | if (!value) goto failed; |
| 2483 | if (PyObject_SetAttrString(result, "module", value) == -1) |
| 2484 | goto failed; |
| 2485 | Py_DECREF(value); |
| 2486 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2487 | if (!value) goto failed; |
| 2488 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2489 | goto failed; |
| 2490 | Py_DECREF(value); |
Thomas Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 2491 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2492 | if (!value) goto failed; |
| 2493 | if (PyObject_SetAttrString(result, "level", value) == -1) |
| 2494 | goto failed; |
| 2495 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2496 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2497 | case Global_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2498 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2499 | if (!result) goto failed; |
| 2500 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2501 | if (!value) goto failed; |
| 2502 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2503 | goto failed; |
| 2504 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2505 | break; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2506 | case Nonlocal_kind: |
| 2507 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2508 | if (!result) goto failed; |
| 2509 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2510 | if (!value) goto failed; |
| 2511 | if (PyObject_SetAttrString(result, "names", value) == -1) |
| 2512 | goto failed; |
| 2513 | Py_DECREF(value); |
| 2514 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2515 | case Expr_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2516 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2517 | if (!result) goto failed; |
| 2518 | value = ast2obj_expr(o->v.Expr.value); |
| 2519 | if (!value) goto failed; |
| 2520 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2521 | goto failed; |
| 2522 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2523 | break; |
| 2524 | case Pass_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2525 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2526 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2527 | break; |
| 2528 | case Break_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2529 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2530 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2531 | break; |
| 2532 | case Continue_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2533 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2534 | if (!result) goto failed; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2537 | value = ast2obj_int(o->lineno); |
| 2538 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2539 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2540 | goto failed; |
| 2541 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2542 | value = ast2obj_int(o->col_offset); |
| 2543 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2544 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2545 | goto failed; |
| 2546 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2547 | return result; |
| 2548 | failed: |
| 2549 | Py_XDECREF(value); |
| 2550 | Py_XDECREF(result); |
| 2551 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2554 | PyObject* |
| 2555 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2557 | expr_ty o = (expr_ty)_o; |
| 2558 | PyObject *result = NULL, *value = NULL; |
| 2559 | if (!o) { |
| 2560 | Py_INCREF(Py_None); |
| 2561 | return Py_None; |
| 2562 | } |
| 2563 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2564 | switch (o->kind) { |
| 2565 | case BoolOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2566 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2567 | if (!result) goto failed; |
| 2568 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2569 | if (!value) goto failed; |
| 2570 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2571 | goto failed; |
| 2572 | Py_DECREF(value); |
| 2573 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2574 | if (!value) goto failed; |
| 2575 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2576 | goto failed; |
| 2577 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2578 | break; |
| 2579 | case BinOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2580 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2581 | if (!result) goto failed; |
| 2582 | value = ast2obj_expr(o->v.BinOp.left); |
| 2583 | if (!value) goto failed; |
| 2584 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2585 | goto failed; |
| 2586 | Py_DECREF(value); |
| 2587 | value = ast2obj_operator(o->v.BinOp.op); |
| 2588 | if (!value) goto failed; |
| 2589 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2590 | goto failed; |
| 2591 | Py_DECREF(value); |
| 2592 | value = ast2obj_expr(o->v.BinOp.right); |
| 2593 | if (!value) goto failed; |
| 2594 | if (PyObject_SetAttrString(result, "right", value) == -1) |
| 2595 | goto failed; |
| 2596 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | case UnaryOp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2599 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2600 | if (!result) goto failed; |
| 2601 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 2602 | if (!value) goto failed; |
| 2603 | if (PyObject_SetAttrString(result, "op", value) == -1) |
| 2604 | goto failed; |
| 2605 | Py_DECREF(value); |
| 2606 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 2607 | if (!value) goto failed; |
| 2608 | if (PyObject_SetAttrString(result, "operand", value) == -1) |
| 2609 | goto failed; |
| 2610 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | case Lambda_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2613 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 2614 | if (!result) goto failed; |
| 2615 | value = ast2obj_arguments(o->v.Lambda.args); |
| 2616 | if (!value) goto failed; |
| 2617 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2618 | goto failed; |
| 2619 | Py_DECREF(value); |
| 2620 | value = ast2obj_expr(o->v.Lambda.body); |
| 2621 | if (!value) goto failed; |
| 2622 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2623 | goto failed; |
| 2624 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2625 | break; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2626 | case IfExp_kind: |
| 2627 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 2628 | if (!result) goto failed; |
| 2629 | value = ast2obj_expr(o->v.IfExp.test); |
| 2630 | if (!value) goto failed; |
| 2631 | if (PyObject_SetAttrString(result, "test", value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
| 2634 | value = ast2obj_expr(o->v.IfExp.body); |
| 2635 | if (!value) goto failed; |
| 2636 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 2637 | goto failed; |
| 2638 | Py_DECREF(value); |
| 2639 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 2640 | if (!value) goto failed; |
| 2641 | if (PyObject_SetAttrString(result, "orelse", value) == -1) |
| 2642 | goto failed; |
| 2643 | Py_DECREF(value); |
| 2644 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2645 | case Dict_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2646 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 2647 | if (!result) goto failed; |
| 2648 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 2649 | if (!value) goto failed; |
| 2650 | if (PyObject_SetAttrString(result, "keys", value) == -1) |
| 2651 | goto failed; |
| 2652 | Py_DECREF(value); |
| 2653 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2654 | if (!value) goto failed; |
| 2655 | if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2656 | goto failed; |
| 2657 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2658 | break; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2659 | case Set_kind: |
| 2660 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 2661 | if (!result) goto failed; |
| 2662 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 2663 | if (!value) goto failed; |
| 2664 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2665 | goto failed; |
| 2666 | Py_DECREF(value); |
| 2667 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2668 | case ListComp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2669 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 2670 | if (!result) goto failed; |
| 2671 | value = ast2obj_expr(o->v.ListComp.elt); |
| 2672 | if (!value) goto failed; |
| 2673 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2674 | goto failed; |
| 2675 | Py_DECREF(value); |
| 2676 | value = ast2obj_list(o->v.ListComp.generators, |
| 2677 | ast2obj_comprehension); |
| 2678 | if (!value) goto failed; |
| 2679 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2680 | goto failed; |
| 2681 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2682 | break; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2683 | case SetComp_kind: |
| 2684 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 2685 | if (!result) goto failed; |
| 2686 | value = ast2obj_expr(o->v.SetComp.elt); |
| 2687 | if (!value) goto failed; |
| 2688 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2689 | goto failed; |
| 2690 | Py_DECREF(value); |
| 2691 | value = ast2obj_list(o->v.SetComp.generators, |
| 2692 | ast2obj_comprehension); |
| 2693 | if (!value) goto failed; |
| 2694 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2695 | goto failed; |
| 2696 | Py_DECREF(value); |
| 2697 | break; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2698 | case DictComp_kind: |
| 2699 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 2700 | if (!result) goto failed; |
| 2701 | value = ast2obj_expr(o->v.DictComp.key); |
| 2702 | if (!value) goto failed; |
| 2703 | if (PyObject_SetAttrString(result, "key", value) == -1) |
| 2704 | goto failed; |
| 2705 | Py_DECREF(value); |
| 2706 | value = ast2obj_expr(o->v.DictComp.value); |
| 2707 | if (!value) goto failed; |
| 2708 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2709 | goto failed; |
| 2710 | Py_DECREF(value); |
| 2711 | value = ast2obj_list(o->v.DictComp.generators, |
| 2712 | ast2obj_comprehension); |
| 2713 | if (!value) goto failed; |
| 2714 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2715 | goto failed; |
| 2716 | Py_DECREF(value); |
| 2717 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2718 | case GeneratorExp_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2719 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 2720 | if (!result) goto failed; |
| 2721 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 2722 | if (!value) goto failed; |
| 2723 | if (PyObject_SetAttrString(result, "elt", value) == -1) |
| 2724 | goto failed; |
| 2725 | Py_DECREF(value); |
| 2726 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 2727 | ast2obj_comprehension); |
| 2728 | if (!value) goto failed; |
| 2729 | if (PyObject_SetAttrString(result, "generators", value) == -1) |
| 2730 | goto failed; |
| 2731 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2732 | break; |
| 2733 | case Yield_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2734 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2735 | if (!result) goto failed; |
| 2736 | value = ast2obj_expr(o->v.Yield.value); |
| 2737 | if (!value) goto failed; |
| 2738 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2739 | goto failed; |
| 2740 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | case Compare_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2743 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 2744 | if (!result) goto failed; |
| 2745 | value = ast2obj_expr(o->v.Compare.left); |
| 2746 | if (!value) goto failed; |
| 2747 | if (PyObject_SetAttrString(result, "left", value) == -1) |
| 2748 | goto failed; |
| 2749 | Py_DECREF(value); |
Martin v. Löwis | ce1d5d2 | 2006-02-26 20:51:25 +0000 | [diff] [blame] | 2750 | { |
| 2751 | int i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 2752 | value = PyList_New(n); |
| 2753 | if (!value) goto failed; |
| 2754 | for(i = 0; i < n; i++) |
| 2755 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
| 2756 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2757 | if (!value) goto failed; |
| 2758 | if (PyObject_SetAttrString(result, "ops", value) == -1) |
| 2759 | goto failed; |
| 2760 | Py_DECREF(value); |
| 2761 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
| 2762 | if (!value) goto failed; |
| 2763 | if (PyObject_SetAttrString(result, "comparators", value) == -1) |
| 2764 | goto failed; |
| 2765 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2766 | break; |
| 2767 | case Call_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2768 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 2769 | if (!result) goto failed; |
| 2770 | value = ast2obj_expr(o->v.Call.func); |
| 2771 | if (!value) goto failed; |
| 2772 | if (PyObject_SetAttrString(result, "func", value) == -1) |
| 2773 | goto failed; |
| 2774 | Py_DECREF(value); |
| 2775 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 2776 | if (!value) goto failed; |
| 2777 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 2778 | goto failed; |
| 2779 | Py_DECREF(value); |
| 2780 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 2781 | if (!value) goto failed; |
| 2782 | if (PyObject_SetAttrString(result, "keywords", value) == -1) |
| 2783 | goto failed; |
| 2784 | Py_DECREF(value); |
| 2785 | value = ast2obj_expr(o->v.Call.starargs); |
| 2786 | if (!value) goto failed; |
| 2787 | if (PyObject_SetAttrString(result, "starargs", value) == -1) |
| 2788 | goto failed; |
| 2789 | Py_DECREF(value); |
| 2790 | value = ast2obj_expr(o->v.Call.kwargs); |
| 2791 | if (!value) goto failed; |
| 2792 | if (PyObject_SetAttrString(result, "kwargs", value) == -1) |
| 2793 | goto failed; |
| 2794 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2795 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2796 | case Num_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2797 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 2798 | if (!result) goto failed; |
| 2799 | value = ast2obj_object(o->v.Num.n); |
| 2800 | if (!value) goto failed; |
| 2801 | if (PyObject_SetAttrString(result, "n", value) == -1) |
| 2802 | goto failed; |
| 2803 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | case Str_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2806 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 2807 | if (!result) goto failed; |
| 2808 | value = ast2obj_string(o->v.Str.s); |
| 2809 | if (!value) goto failed; |
| 2810 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2811 | goto failed; |
| 2812 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2813 | break; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2814 | case Bytes_kind: |
| 2815 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 2816 | if (!result) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2817 | value = ast2obj_bytes(o->v.Bytes.s); |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2818 | if (!value) goto failed; |
| 2819 | if (PyObject_SetAttrString(result, "s", value) == -1) |
| 2820 | goto failed; |
| 2821 | Py_DECREF(value); |
| 2822 | break; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2823 | case Ellipsis_kind: |
| 2824 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 2825 | if (!result) goto failed; |
| 2826 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2827 | case Attribute_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2828 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 2829 | if (!result) goto failed; |
| 2830 | value = ast2obj_expr(o->v.Attribute.value); |
| 2831 | if (!value) goto failed; |
| 2832 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2833 | goto failed; |
| 2834 | Py_DECREF(value); |
| 2835 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 2836 | if (!value) goto failed; |
| 2837 | if (PyObject_SetAttrString(result, "attr", value) == -1) |
| 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
| 2840 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 2841 | if (!value) goto failed; |
| 2842 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2843 | goto failed; |
| 2844 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | case Subscript_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2847 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 2848 | if (!result) goto failed; |
| 2849 | value = ast2obj_expr(o->v.Subscript.value); |
| 2850 | if (!value) goto failed; |
| 2851 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2852 | goto failed; |
| 2853 | Py_DECREF(value); |
| 2854 | value = ast2obj_slice(o->v.Subscript.slice); |
| 2855 | if (!value) goto failed; |
| 2856 | if (PyObject_SetAttrString(result, "slice", value) == -1) |
| 2857 | goto failed; |
| 2858 | Py_DECREF(value); |
| 2859 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 2860 | if (!value) goto failed; |
| 2861 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2864 | break; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2865 | case Starred_kind: |
| 2866 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 2867 | if (!result) goto failed; |
| 2868 | value = ast2obj_expr(o->v.Starred.value); |
| 2869 | if (!value) goto failed; |
| 2870 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 2871 | goto failed; |
| 2872 | Py_DECREF(value); |
| 2873 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 2874 | if (!value) goto failed; |
| 2875 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2876 | goto failed; |
| 2877 | Py_DECREF(value); |
| 2878 | break; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2879 | case Name_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2880 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 2881 | if (!result) goto failed; |
| 2882 | value = ast2obj_identifier(o->v.Name.id); |
| 2883 | if (!value) goto failed; |
| 2884 | if (PyObject_SetAttrString(result, "id", value) == -1) |
| 2885 | goto failed; |
| 2886 | Py_DECREF(value); |
| 2887 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 2888 | if (!value) goto failed; |
| 2889 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2890 | goto failed; |
| 2891 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2892 | break; |
| 2893 | case List_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2894 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 2895 | if (!result) goto failed; |
| 2896 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 2897 | if (!value) goto failed; |
| 2898 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2899 | goto failed; |
| 2900 | Py_DECREF(value); |
| 2901 | value = ast2obj_expr_context(o->v.List.ctx); |
| 2902 | if (!value) goto failed; |
| 2903 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2904 | goto failed; |
| 2905 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2906 | break; |
| 2907 | case Tuple_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2908 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 2909 | if (!result) goto failed; |
| 2910 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 2911 | if (!value) goto failed; |
| 2912 | if (PyObject_SetAttrString(result, "elts", value) == -1) |
| 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
| 2915 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 2916 | if (!value) goto failed; |
| 2917 | if (PyObject_SetAttrString(result, "ctx", value) == -1) |
| 2918 | goto failed; |
| 2919 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2922 | value = ast2obj_int(o->lineno); |
| 2923 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2924 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
| 2925 | goto failed; |
| 2926 | Py_DECREF(value); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2927 | value = ast2obj_int(o->col_offset); |
| 2928 | if (!value) goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2929 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
| 2930 | goto failed; |
| 2931 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2932 | return result; |
| 2933 | failed: |
| 2934 | Py_XDECREF(value); |
| 2935 | Py_XDECREF(result); |
| 2936 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2939 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2940 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2941 | switch(o) { |
| 2942 | case Load: |
| 2943 | Py_INCREF(Load_singleton); |
| 2944 | return Load_singleton; |
| 2945 | case Store: |
| 2946 | Py_INCREF(Store_singleton); |
| 2947 | return Store_singleton; |
| 2948 | case Del: |
| 2949 | Py_INCREF(Del_singleton); |
| 2950 | return Del_singleton; |
| 2951 | case AugLoad: |
| 2952 | Py_INCREF(AugLoad_singleton); |
| 2953 | return AugLoad_singleton; |
| 2954 | case AugStore: |
| 2955 | Py_INCREF(AugStore_singleton); |
| 2956 | return AugStore_singleton; |
| 2957 | case Param: |
| 2958 | Py_INCREF(Param_singleton); |
| 2959 | return Param_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2960 | default: |
| 2961 | /* should never happen, but just in case ... */ |
| 2962 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 2963 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2964 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2965 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2966 | PyObject* |
| 2967 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2968 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2969 | slice_ty o = (slice_ty)_o; |
| 2970 | PyObject *result = NULL, *value = NULL; |
| 2971 | if (!o) { |
| 2972 | Py_INCREF(Py_None); |
| 2973 | return Py_None; |
| 2974 | } |
| 2975 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2976 | switch (o->kind) { |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2977 | case Slice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2978 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 2979 | if (!result) goto failed; |
| 2980 | value = ast2obj_expr(o->v.Slice.lower); |
| 2981 | if (!value) goto failed; |
| 2982 | if (PyObject_SetAttrString(result, "lower", value) == -1) |
| 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
| 2985 | value = ast2obj_expr(o->v.Slice.upper); |
| 2986 | if (!value) goto failed; |
| 2987 | if (PyObject_SetAttrString(result, "upper", value) == -1) |
| 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
| 2990 | value = ast2obj_expr(o->v.Slice.step); |
| 2991 | if (!value) goto failed; |
| 2992 | if (PyObject_SetAttrString(result, "step", value) == -1) |
| 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2995 | break; |
| 2996 | case ExtSlice_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2997 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
| 2999 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3000 | if (!value) goto failed; |
| 3001 | if (PyObject_SetAttrString(result, "dims", value) == -1) |
| 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3004 | break; |
| 3005 | case Index_kind: |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3006 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3007 | if (!result) goto failed; |
| 3008 | value = ast2obj_expr(o->v.Index.value); |
| 3009 | if (!value) goto failed; |
| 3010 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3011 | goto failed; |
| 3012 | Py_DECREF(value); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3015 | return result; |
| 3016 | failed: |
| 3017 | Py_XDECREF(value); |
| 3018 | Py_XDECREF(result); |
| 3019 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3022 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3023 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3024 | switch(o) { |
| 3025 | case And: |
| 3026 | Py_INCREF(And_singleton); |
| 3027 | return And_singleton; |
| 3028 | case Or: |
| 3029 | Py_INCREF(Or_singleton); |
| 3030 | return Or_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3031 | default: |
| 3032 | /* should never happen, but just in case ... */ |
| 3033 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3034 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3035 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3036 | } |
| 3037 | PyObject* ast2obj_operator(operator_ty o) |
| 3038 | { |
| 3039 | switch(o) { |
| 3040 | case Add: |
| 3041 | Py_INCREF(Add_singleton); |
| 3042 | return Add_singleton; |
| 3043 | case Sub: |
| 3044 | Py_INCREF(Sub_singleton); |
| 3045 | return Sub_singleton; |
| 3046 | case Mult: |
| 3047 | Py_INCREF(Mult_singleton); |
| 3048 | return Mult_singleton; |
| 3049 | case Div: |
| 3050 | Py_INCREF(Div_singleton); |
| 3051 | return Div_singleton; |
| 3052 | case Mod: |
| 3053 | Py_INCREF(Mod_singleton); |
| 3054 | return Mod_singleton; |
| 3055 | case Pow: |
| 3056 | Py_INCREF(Pow_singleton); |
| 3057 | return Pow_singleton; |
| 3058 | case LShift: |
| 3059 | Py_INCREF(LShift_singleton); |
| 3060 | return LShift_singleton; |
| 3061 | case RShift: |
| 3062 | Py_INCREF(RShift_singleton); |
| 3063 | return RShift_singleton; |
| 3064 | case BitOr: |
| 3065 | Py_INCREF(BitOr_singleton); |
| 3066 | return BitOr_singleton; |
| 3067 | case BitXor: |
| 3068 | Py_INCREF(BitXor_singleton); |
| 3069 | return BitXor_singleton; |
| 3070 | case BitAnd: |
| 3071 | Py_INCREF(BitAnd_singleton); |
| 3072 | return BitAnd_singleton; |
| 3073 | case FloorDiv: |
| 3074 | Py_INCREF(FloorDiv_singleton); |
| 3075 | return FloorDiv_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3076 | default: |
| 3077 | /* should never happen, but just in case ... */ |
| 3078 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3079 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3080 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3081 | } |
| 3082 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3083 | { |
| 3084 | switch(o) { |
| 3085 | case Invert: |
| 3086 | Py_INCREF(Invert_singleton); |
| 3087 | return Invert_singleton; |
| 3088 | case Not: |
| 3089 | Py_INCREF(Not_singleton); |
| 3090 | return Not_singleton; |
| 3091 | case UAdd: |
| 3092 | Py_INCREF(UAdd_singleton); |
| 3093 | return UAdd_singleton; |
| 3094 | case USub: |
| 3095 | Py_INCREF(USub_singleton); |
| 3096 | return USub_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3097 | default: |
| 3098 | /* should never happen, but just in case ... */ |
| 3099 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3100 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3101 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3102 | } |
| 3103 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3104 | { |
| 3105 | switch(o) { |
| 3106 | case Eq: |
| 3107 | Py_INCREF(Eq_singleton); |
| 3108 | return Eq_singleton; |
| 3109 | case NotEq: |
| 3110 | Py_INCREF(NotEq_singleton); |
| 3111 | return NotEq_singleton; |
| 3112 | case Lt: |
| 3113 | Py_INCREF(Lt_singleton); |
| 3114 | return Lt_singleton; |
| 3115 | case LtE: |
| 3116 | Py_INCREF(LtE_singleton); |
| 3117 | return LtE_singleton; |
| 3118 | case Gt: |
| 3119 | Py_INCREF(Gt_singleton); |
| 3120 | return Gt_singleton; |
| 3121 | case GtE: |
| 3122 | Py_INCREF(GtE_singleton); |
| 3123 | return GtE_singleton; |
| 3124 | case Is: |
| 3125 | Py_INCREF(Is_singleton); |
| 3126 | return Is_singleton; |
| 3127 | case IsNot: |
| 3128 | Py_INCREF(IsNot_singleton); |
| 3129 | return IsNot_singleton; |
| 3130 | case In: |
| 3131 | Py_INCREF(In_singleton); |
| 3132 | return In_singleton; |
| 3133 | case NotIn: |
| 3134 | Py_INCREF(NotIn_singleton); |
| 3135 | return NotIn_singleton; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3136 | default: |
| 3137 | /* should never happen, but just in case ... */ |
| 3138 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3139 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3140 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3141 | } |
| 3142 | PyObject* |
| 3143 | ast2obj_comprehension(void* _o) |
| 3144 | { |
| 3145 | comprehension_ty o = (comprehension_ty)_o; |
| 3146 | PyObject *result = NULL, *value = NULL; |
| 3147 | if (!o) { |
| 3148 | Py_INCREF(Py_None); |
| 3149 | return Py_None; |
| 3150 | } |
| 3151 | |
| 3152 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3153 | if (!result) return NULL; |
| 3154 | value = ast2obj_expr(o->target); |
| 3155 | if (!value) goto failed; |
| 3156 | if (PyObject_SetAttrString(result, "target", value) == -1) |
| 3157 | goto failed; |
| 3158 | Py_DECREF(value); |
| 3159 | value = ast2obj_expr(o->iter); |
| 3160 | if (!value) goto failed; |
| 3161 | if (PyObject_SetAttrString(result, "iter", value) == -1) |
| 3162 | goto failed; |
| 3163 | Py_DECREF(value); |
| 3164 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3165 | if (!value) goto failed; |
| 3166 | if (PyObject_SetAttrString(result, "ifs", value) == -1) |
| 3167 | goto failed; |
| 3168 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3169 | return result; |
| 3170 | failed: |
| 3171 | Py_XDECREF(value); |
| 3172 | Py_XDECREF(result); |
| 3173 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3176 | PyObject* |
| 3177 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3178 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3179 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3180 | PyObject *result = NULL, *value = NULL; |
| 3181 | if (!o) { |
| 3182 | Py_INCREF(Py_None); |
| 3183 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3184 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3185 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3186 | switch (o->kind) { |
| 3187 | case ExceptHandler_kind: |
| 3188 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3189 | if (!result) goto failed; |
| 3190 | value = ast2obj_expr(o->v.ExceptHandler.type); |
| 3191 | if (!value) goto failed; |
| 3192 | if (PyObject_SetAttrString(result, "type", value) == -1) |
| 3193 | goto failed; |
| 3194 | Py_DECREF(value); |
| 3195 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
| 3196 | if (!value) goto failed; |
| 3197 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3198 | goto failed; |
| 3199 | Py_DECREF(value); |
| 3200 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3201 | if (!value) goto failed; |
| 3202 | if (PyObject_SetAttrString(result, "body", value) == -1) |
| 3203 | goto failed; |
| 3204 | Py_DECREF(value); |
| 3205 | break; |
| 3206 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3207 | value = ast2obj_int(o->lineno); |
| 3208 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3209 | if (PyObject_SetAttrString(result, "lineno", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3210 | goto failed; |
| 3211 | Py_DECREF(value); |
| 3212 | value = ast2obj_int(o->col_offset); |
| 3213 | if (!value) goto failed; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3214 | if (PyObject_SetAttrString(result, "col_offset", value) < 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3215 | goto failed; |
| 3216 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3217 | return result; |
| 3218 | failed: |
| 3219 | Py_XDECREF(value); |
| 3220 | Py_XDECREF(result); |
| 3221 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3224 | PyObject* |
| 3225 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3226 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3227 | arguments_ty o = (arguments_ty)_o; |
| 3228 | PyObject *result = NULL, *value = NULL; |
| 3229 | if (!o) { |
| 3230 | Py_INCREF(Py_None); |
| 3231 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3232 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3233 | |
| 3234 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3235 | if (!result) return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3236 | value = ast2obj_list(o->args, ast2obj_arg); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3237 | if (!value) goto failed; |
| 3238 | if (PyObject_SetAttrString(result, "args", value) == -1) |
| 3239 | goto failed; |
| 3240 | Py_DECREF(value); |
| 3241 | value = ast2obj_identifier(o->vararg); |
| 3242 | if (!value) goto failed; |
| 3243 | if (PyObject_SetAttrString(result, "vararg", value) == -1) |
| 3244 | goto failed; |
| 3245 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3246 | value = ast2obj_expr(o->varargannotation); |
| 3247 | if (!value) goto failed; |
| 3248 | if (PyObject_SetAttrString(result, "varargannotation", value) == -1) |
| 3249 | goto failed; |
| 3250 | Py_DECREF(value); |
| 3251 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3252 | if (!value) goto failed; |
| 3253 | if (PyObject_SetAttrString(result, "kwonlyargs", 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_identifier(o->kwarg); |
| 3257 | if (!value) goto failed; |
| 3258 | if (PyObject_SetAttrString(result, "kwarg", value) == -1) |
| 3259 | goto failed; |
| 3260 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3261 | value = ast2obj_expr(o->kwargannotation); |
| 3262 | if (!value) goto failed; |
| 3263 | if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) |
| 3264 | goto failed; |
| 3265 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3266 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3267 | if (!value) goto failed; |
| 3268 | if (PyObject_SetAttrString(result, "defaults", value) == -1) |
| 3269 | goto failed; |
| 3270 | Py_DECREF(value); |
Guido van Rossum | 4f72a78 | 2006-10-27 23:31:49 +0000 | [diff] [blame] | 3271 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
| 3272 | if (!value) goto failed; |
| 3273 | if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) |
| 3274 | goto failed; |
| 3275 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3276 | return result; |
| 3277 | failed: |
| 3278 | Py_XDECREF(value); |
| 3279 | Py_XDECREF(result); |
| 3280 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3283 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3284 | ast2obj_arg(void* _o) |
| 3285 | { |
| 3286 | arg_ty o = (arg_ty)_o; |
| 3287 | PyObject *result = NULL, *value = NULL; |
| 3288 | if (!o) { |
| 3289 | Py_INCREF(Py_None); |
| 3290 | return Py_None; |
| 3291 | } |
| 3292 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 3293 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3294 | if (!result) return NULL; |
| 3295 | value = ast2obj_identifier(o->arg); |
| 3296 | if (!value) goto failed; |
| 3297 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3298 | goto failed; |
| 3299 | Py_DECREF(value); |
| 3300 | value = ast2obj_expr(o->annotation); |
| 3301 | if (!value) goto failed; |
| 3302 | if (PyObject_SetAttrString(result, "annotation", value) == -1) |
| 3303 | goto failed; |
| 3304 | Py_DECREF(value); |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3305 | return result; |
| 3306 | failed: |
| 3307 | Py_XDECREF(value); |
| 3308 | Py_XDECREF(result); |
| 3309 | return NULL; |
| 3310 | } |
| 3311 | |
| 3312 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3313 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3314 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3315 | keyword_ty o = (keyword_ty)_o; |
| 3316 | PyObject *result = NULL, *value = NULL; |
| 3317 | if (!o) { |
| 3318 | Py_INCREF(Py_None); |
| 3319 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3320 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3321 | |
| 3322 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3323 | if (!result) return NULL; |
| 3324 | value = ast2obj_identifier(o->arg); |
| 3325 | if (!value) goto failed; |
| 3326 | if (PyObject_SetAttrString(result, "arg", value) == -1) |
| 3327 | goto failed; |
| 3328 | Py_DECREF(value); |
| 3329 | value = ast2obj_expr(o->value); |
| 3330 | if (!value) goto failed; |
| 3331 | if (PyObject_SetAttrString(result, "value", value) == -1) |
| 3332 | goto failed; |
| 3333 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3334 | return result; |
| 3335 | failed: |
| 3336 | Py_XDECREF(value); |
| 3337 | Py_XDECREF(result); |
| 3338 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3339 | } |
| 3340 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3341 | PyObject* |
| 3342 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3343 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3344 | alias_ty o = (alias_ty)_o; |
| 3345 | PyObject *result = NULL, *value = NULL; |
| 3346 | if (!o) { |
| 3347 | Py_INCREF(Py_None); |
| 3348 | return Py_None; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3349 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3350 | |
| 3351 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3352 | if (!result) return NULL; |
| 3353 | value = ast2obj_identifier(o->name); |
| 3354 | if (!value) goto failed; |
| 3355 | if (PyObject_SetAttrString(result, "name", value) == -1) |
| 3356 | goto failed; |
| 3357 | Py_DECREF(value); |
| 3358 | value = ast2obj_identifier(o->asname); |
| 3359 | if (!value) goto failed; |
| 3360 | if (PyObject_SetAttrString(result, "asname", value) == -1) |
| 3361 | goto failed; |
| 3362 | Py_DECREF(value); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3363 | return result; |
| 3364 | failed: |
| 3365 | Py_XDECREF(value); |
| 3366 | Py_XDECREF(result); |
| 3367 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3370 | PyObject* |
| 3371 | ast2obj_withitem(void* _o) |
| 3372 | { |
| 3373 | withitem_ty o = (withitem_ty)_o; |
| 3374 | PyObject *result = NULL, *value = NULL; |
| 3375 | if (!o) { |
| 3376 | Py_INCREF(Py_None); |
| 3377 | return Py_None; |
| 3378 | } |
| 3379 | |
| 3380 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3381 | if (!result) return NULL; |
| 3382 | value = ast2obj_expr(o->context_expr); |
| 3383 | if (!value) goto failed; |
| 3384 | if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
| 3385 | goto failed; |
| 3386 | Py_DECREF(value); |
| 3387 | value = ast2obj_expr(o->optional_vars); |
| 3388 | if (!value) goto failed; |
| 3389 | if (PyObject_SetAttrString(result, "optional_vars", value) == -1) |
| 3390 | goto failed; |
| 3391 | Py_DECREF(value); |
| 3392 | return result; |
| 3393 | failed: |
| 3394 | Py_XDECREF(value); |
| 3395 | Py_XDECREF(result); |
| 3396 | return NULL; |
| 3397 | } |
| 3398 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3399 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3400 | int |
| 3401 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3402 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3403 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3404 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3405 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3406 | |
| 3407 | if (obj == Py_None) { |
| 3408 | *out = NULL; |
| 3409 | return 0; |
| 3410 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3411 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3412 | if (isinstance == -1) { |
| 3413 | return 1; |
| 3414 | } |
| 3415 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3416 | asdl_seq* body; |
| 3417 | |
| 3418 | if (PyObject_HasAttrString(obj, "body")) { |
| 3419 | int res; |
| 3420 | Py_ssize_t len; |
| 3421 | Py_ssize_t i; |
| 3422 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3423 | if (tmp == NULL) goto failed; |
| 3424 | if (!PyList_Check(tmp)) { |
| 3425 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3426 | goto failed; |
| 3427 | } |
| 3428 | len = PyList_GET_SIZE(tmp); |
| 3429 | body = asdl_seq_new(len, arena); |
| 3430 | if (body == NULL) goto failed; |
| 3431 | for (i = 0; i < len; i++) { |
| 3432 | stmt_ty value; |
| 3433 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3434 | if (res != 0) goto failed; |
| 3435 | asdl_seq_SET(body, i, value); |
| 3436 | } |
| 3437 | Py_XDECREF(tmp); |
| 3438 | tmp = NULL; |
| 3439 | } else { |
| 3440 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3441 | return 1; |
| 3442 | } |
| 3443 | *out = Module(body, arena); |
| 3444 | if (*out == NULL) goto failed; |
| 3445 | return 0; |
| 3446 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3447 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3448 | if (isinstance == -1) { |
| 3449 | return 1; |
| 3450 | } |
| 3451 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3452 | asdl_seq* body; |
| 3453 | |
| 3454 | if (PyObject_HasAttrString(obj, "body")) { |
| 3455 | int res; |
| 3456 | Py_ssize_t len; |
| 3457 | Py_ssize_t i; |
| 3458 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3459 | if (tmp == NULL) goto failed; |
| 3460 | if (!PyList_Check(tmp)) { |
| 3461 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3462 | goto failed; |
| 3463 | } |
| 3464 | len = PyList_GET_SIZE(tmp); |
| 3465 | body = asdl_seq_new(len, arena); |
| 3466 | if (body == NULL) goto failed; |
| 3467 | for (i = 0; i < len; i++) { |
| 3468 | stmt_ty value; |
| 3469 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3470 | if (res != 0) goto failed; |
| 3471 | asdl_seq_SET(body, i, value); |
| 3472 | } |
| 3473 | Py_XDECREF(tmp); |
| 3474 | tmp = NULL; |
| 3475 | } else { |
| 3476 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3477 | return 1; |
| 3478 | } |
| 3479 | *out = Interactive(body, arena); |
| 3480 | if (*out == NULL) goto failed; |
| 3481 | return 0; |
| 3482 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3483 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3484 | if (isinstance == -1) { |
| 3485 | return 1; |
| 3486 | } |
| 3487 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3488 | expr_ty body; |
| 3489 | |
| 3490 | if (PyObject_HasAttrString(obj, "body")) { |
| 3491 | int res; |
| 3492 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3493 | if (tmp == NULL) goto failed; |
| 3494 | res = obj2ast_expr(tmp, &body, arena); |
| 3495 | if (res != 0) goto failed; |
| 3496 | Py_XDECREF(tmp); |
| 3497 | tmp = NULL; |
| 3498 | } else { |
| 3499 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3500 | return 1; |
| 3501 | } |
| 3502 | *out = Expression(body, arena); |
| 3503 | if (*out == NULL) goto failed; |
| 3504 | return 0; |
| 3505 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3506 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3507 | if (isinstance == -1) { |
| 3508 | return 1; |
| 3509 | } |
| 3510 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3511 | asdl_seq* body; |
| 3512 | |
| 3513 | if (PyObject_HasAttrString(obj, "body")) { |
| 3514 | int res; |
| 3515 | Py_ssize_t len; |
| 3516 | Py_ssize_t i; |
| 3517 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3518 | if (tmp == NULL) goto failed; |
| 3519 | if (!PyList_Check(tmp)) { |
| 3520 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3521 | goto failed; |
| 3522 | } |
| 3523 | len = PyList_GET_SIZE(tmp); |
| 3524 | body = asdl_seq_new(len, arena); |
| 3525 | if (body == NULL) goto failed; |
| 3526 | for (i = 0; i < len; i++) { |
| 3527 | stmt_ty value; |
| 3528 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3529 | if (res != 0) goto failed; |
| 3530 | asdl_seq_SET(body, i, value); |
| 3531 | } |
| 3532 | Py_XDECREF(tmp); |
| 3533 | tmp = NULL; |
| 3534 | } else { |
| 3535 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3536 | return 1; |
| 3537 | } |
| 3538 | *out = Suite(body, arena); |
| 3539 | if (*out == NULL) goto failed; |
| 3540 | return 0; |
| 3541 | } |
| 3542 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 3543 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3544 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 3545 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3546 | return 1; |
| 3547 | } |
| 3548 | |
| 3549 | int |
| 3550 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3551 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3552 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3553 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 3554 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3555 | int lineno; |
| 3556 | int col_offset; |
| 3557 | |
| 3558 | if (obj == Py_None) { |
| 3559 | *out = NULL; |
| 3560 | return 0; |
| 3561 | } |
| 3562 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 3563 | int res; |
| 3564 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 3565 | if (tmp == NULL) goto failed; |
| 3566 | res = obj2ast_int(tmp, &lineno, arena); |
| 3567 | if (res != 0) goto failed; |
| 3568 | Py_XDECREF(tmp); |
| 3569 | tmp = NULL; |
| 3570 | } else { |
| 3571 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 3572 | return 1; |
| 3573 | } |
| 3574 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 3575 | int res; |
| 3576 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 3577 | if (tmp == NULL) goto failed; |
| 3578 | res = obj2ast_int(tmp, &col_offset, arena); |
| 3579 | if (res != 0) goto failed; |
| 3580 | Py_XDECREF(tmp); |
| 3581 | tmp = NULL; |
| 3582 | } else { |
| 3583 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 3584 | return 1; |
| 3585 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3586 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 3587 | if (isinstance == -1) { |
| 3588 | return 1; |
| 3589 | } |
| 3590 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3591 | identifier name; |
| 3592 | arguments_ty args; |
| 3593 | asdl_seq* body; |
| 3594 | asdl_seq* decorator_list; |
| 3595 | expr_ty returns; |
| 3596 | |
| 3597 | if (PyObject_HasAttrString(obj, "name")) { |
| 3598 | int res; |
| 3599 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3600 | if (tmp == NULL) goto failed; |
| 3601 | res = obj2ast_identifier(tmp, &name, arena); |
| 3602 | if (res != 0) goto failed; |
| 3603 | Py_XDECREF(tmp); |
| 3604 | tmp = NULL; |
| 3605 | } else { |
| 3606 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 3607 | return 1; |
| 3608 | } |
| 3609 | if (PyObject_HasAttrString(obj, "args")) { |
| 3610 | int res; |
| 3611 | tmp = PyObject_GetAttrString(obj, "args"); |
| 3612 | if (tmp == NULL) goto failed; |
| 3613 | res = obj2ast_arguments(tmp, &args, arena); |
| 3614 | if (res != 0) goto failed; |
| 3615 | Py_XDECREF(tmp); |
| 3616 | tmp = NULL; |
| 3617 | } else { |
| 3618 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 3619 | return 1; |
| 3620 | } |
| 3621 | if (PyObject_HasAttrString(obj, "body")) { |
| 3622 | int res; |
| 3623 | Py_ssize_t len; |
| 3624 | Py_ssize_t i; |
| 3625 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3626 | if (tmp == NULL) goto failed; |
| 3627 | if (!PyList_Check(tmp)) { |
| 3628 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3629 | goto failed; |
| 3630 | } |
| 3631 | len = PyList_GET_SIZE(tmp); |
| 3632 | body = asdl_seq_new(len, arena); |
| 3633 | if (body == NULL) goto failed; |
| 3634 | for (i = 0; i < len; i++) { |
| 3635 | stmt_ty value; |
| 3636 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3637 | if (res != 0) goto failed; |
| 3638 | asdl_seq_SET(body, i, value); |
| 3639 | } |
| 3640 | Py_XDECREF(tmp); |
| 3641 | tmp = NULL; |
| 3642 | } else { |
| 3643 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 3644 | return 1; |
| 3645 | } |
| 3646 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3647 | int res; |
| 3648 | Py_ssize_t len; |
| 3649 | Py_ssize_t i; |
| 3650 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3651 | if (tmp == NULL) goto failed; |
| 3652 | if (!PyList_Check(tmp)) { |
| 3653 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3654 | goto failed; |
| 3655 | } |
| 3656 | len = PyList_GET_SIZE(tmp); |
| 3657 | decorator_list = asdl_seq_new(len, arena); |
| 3658 | if (decorator_list == NULL) goto failed; |
| 3659 | for (i = 0; i < len; i++) { |
| 3660 | expr_ty value; |
| 3661 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3662 | if (res != 0) goto failed; |
| 3663 | asdl_seq_SET(decorator_list, i, value); |
| 3664 | } |
| 3665 | Py_XDECREF(tmp); |
| 3666 | tmp = NULL; |
| 3667 | } else { |
| 3668 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 3669 | return 1; |
| 3670 | } |
| 3671 | if (PyObject_HasAttrString(obj, "returns")) { |
| 3672 | int res; |
| 3673 | tmp = PyObject_GetAttrString(obj, "returns"); |
| 3674 | if (tmp == NULL) goto failed; |
| 3675 | res = obj2ast_expr(tmp, &returns, arena); |
| 3676 | if (res != 0) goto failed; |
| 3677 | Py_XDECREF(tmp); |
| 3678 | tmp = NULL; |
| 3679 | } else { |
| 3680 | returns = NULL; |
| 3681 | } |
| 3682 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 3683 | lineno, col_offset, arena); |
| 3684 | if (*out == NULL) goto failed; |
| 3685 | return 0; |
| 3686 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3687 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 3688 | if (isinstance == -1) { |
| 3689 | return 1; |
| 3690 | } |
| 3691 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3692 | identifier name; |
| 3693 | asdl_seq* bases; |
| 3694 | asdl_seq* keywords; |
| 3695 | expr_ty starargs; |
| 3696 | expr_ty kwargs; |
| 3697 | asdl_seq* body; |
| 3698 | asdl_seq* decorator_list; |
| 3699 | |
| 3700 | if (PyObject_HasAttrString(obj, "name")) { |
| 3701 | int res; |
| 3702 | tmp = PyObject_GetAttrString(obj, "name"); |
| 3703 | if (tmp == NULL) goto failed; |
| 3704 | res = obj2ast_identifier(tmp, &name, arena); |
| 3705 | if (res != 0) goto failed; |
| 3706 | Py_XDECREF(tmp); |
| 3707 | tmp = NULL; |
| 3708 | } else { |
| 3709 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 3710 | return 1; |
| 3711 | } |
| 3712 | if (PyObject_HasAttrString(obj, "bases")) { |
| 3713 | int res; |
| 3714 | Py_ssize_t len; |
| 3715 | Py_ssize_t i; |
| 3716 | tmp = PyObject_GetAttrString(obj, "bases"); |
| 3717 | if (tmp == NULL) goto failed; |
| 3718 | if (!PyList_Check(tmp)) { |
| 3719 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3720 | goto failed; |
| 3721 | } |
| 3722 | len = PyList_GET_SIZE(tmp); |
| 3723 | bases = asdl_seq_new(len, arena); |
| 3724 | if (bases == NULL) goto failed; |
| 3725 | for (i = 0; i < len; i++) { |
| 3726 | expr_ty value; |
| 3727 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3728 | if (res != 0) goto failed; |
| 3729 | asdl_seq_SET(bases, i, value); |
| 3730 | } |
| 3731 | Py_XDECREF(tmp); |
| 3732 | tmp = NULL; |
| 3733 | } else { |
| 3734 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 3735 | return 1; |
| 3736 | } |
| 3737 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 3738 | int res; |
| 3739 | Py_ssize_t len; |
| 3740 | Py_ssize_t i; |
| 3741 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 3742 | if (tmp == NULL) goto failed; |
| 3743 | if (!PyList_Check(tmp)) { |
| 3744 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3745 | goto failed; |
| 3746 | } |
| 3747 | len = PyList_GET_SIZE(tmp); |
| 3748 | keywords = asdl_seq_new(len, arena); |
| 3749 | if (keywords == NULL) goto failed; |
| 3750 | for (i = 0; i < len; i++) { |
| 3751 | keyword_ty value; |
| 3752 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3753 | if (res != 0) goto failed; |
| 3754 | asdl_seq_SET(keywords, i, value); |
| 3755 | } |
| 3756 | Py_XDECREF(tmp); |
| 3757 | tmp = NULL; |
| 3758 | } else { |
| 3759 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 3760 | return 1; |
| 3761 | } |
| 3762 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 3763 | int res; |
| 3764 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 3765 | if (tmp == NULL) goto failed; |
| 3766 | res = obj2ast_expr(tmp, &starargs, arena); |
| 3767 | if (res != 0) goto failed; |
| 3768 | Py_XDECREF(tmp); |
| 3769 | tmp = NULL; |
| 3770 | } else { |
| 3771 | starargs = NULL; |
| 3772 | } |
| 3773 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 3774 | int res; |
| 3775 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 3776 | if (tmp == NULL) goto failed; |
| 3777 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 3778 | if (res != 0) goto failed; |
| 3779 | Py_XDECREF(tmp); |
| 3780 | tmp = NULL; |
| 3781 | } else { |
| 3782 | kwargs = NULL; |
| 3783 | } |
| 3784 | if (PyObject_HasAttrString(obj, "body")) { |
| 3785 | int res; |
| 3786 | Py_ssize_t len; |
| 3787 | Py_ssize_t i; |
| 3788 | tmp = PyObject_GetAttrString(obj, "body"); |
| 3789 | if (tmp == NULL) goto failed; |
| 3790 | if (!PyList_Check(tmp)) { |
| 3791 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3792 | goto failed; |
| 3793 | } |
| 3794 | len = PyList_GET_SIZE(tmp); |
| 3795 | body = asdl_seq_new(len, arena); |
| 3796 | if (body == NULL) goto failed; |
| 3797 | for (i = 0; i < len; i++) { |
| 3798 | stmt_ty value; |
| 3799 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3800 | if (res != 0) goto failed; |
| 3801 | asdl_seq_SET(body, i, value); |
| 3802 | } |
| 3803 | Py_XDECREF(tmp); |
| 3804 | tmp = NULL; |
| 3805 | } else { |
| 3806 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 3807 | return 1; |
| 3808 | } |
| 3809 | if (PyObject_HasAttrString(obj, "decorator_list")) { |
| 3810 | int res; |
| 3811 | Py_ssize_t len; |
| 3812 | Py_ssize_t i; |
| 3813 | tmp = PyObject_GetAttrString(obj, "decorator_list"); |
| 3814 | if (tmp == NULL) goto failed; |
| 3815 | if (!PyList_Check(tmp)) { |
| 3816 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3817 | goto failed; |
| 3818 | } |
| 3819 | len = PyList_GET_SIZE(tmp); |
| 3820 | decorator_list = asdl_seq_new(len, arena); |
| 3821 | if (decorator_list == NULL) goto failed; |
| 3822 | for (i = 0; i < len; i++) { |
| 3823 | expr_ty value; |
| 3824 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3825 | if (res != 0) goto failed; |
| 3826 | asdl_seq_SET(decorator_list, i, value); |
| 3827 | } |
| 3828 | Py_XDECREF(tmp); |
| 3829 | tmp = NULL; |
| 3830 | } else { |
| 3831 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 3832 | return 1; |
| 3833 | } |
| 3834 | *out = ClassDef(name, bases, keywords, starargs, kwargs, body, |
| 3835 | decorator_list, lineno, col_offset, arena); |
| 3836 | if (*out == NULL) goto failed; |
| 3837 | return 0; |
| 3838 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3839 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 3840 | if (isinstance == -1) { |
| 3841 | return 1; |
| 3842 | } |
| 3843 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3844 | expr_ty value; |
| 3845 | |
| 3846 | if (PyObject_HasAttrString(obj, "value")) { |
| 3847 | int res; |
| 3848 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3849 | if (tmp == NULL) goto failed; |
| 3850 | res = obj2ast_expr(tmp, &value, arena); |
| 3851 | if (res != 0) goto failed; |
| 3852 | Py_XDECREF(tmp); |
| 3853 | tmp = NULL; |
| 3854 | } else { |
| 3855 | value = NULL; |
| 3856 | } |
| 3857 | *out = Return(value, lineno, col_offset, arena); |
| 3858 | if (*out == NULL) goto failed; |
| 3859 | return 0; |
| 3860 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3861 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 3862 | if (isinstance == -1) { |
| 3863 | return 1; |
| 3864 | } |
| 3865 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3866 | asdl_seq* targets; |
| 3867 | |
| 3868 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3869 | int res; |
| 3870 | Py_ssize_t len; |
| 3871 | Py_ssize_t i; |
| 3872 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3873 | if (tmp == NULL) goto failed; |
| 3874 | if (!PyList_Check(tmp)) { |
| 3875 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3876 | goto failed; |
| 3877 | } |
| 3878 | len = PyList_GET_SIZE(tmp); |
| 3879 | targets = asdl_seq_new(len, arena); |
| 3880 | if (targets == NULL) goto failed; |
| 3881 | for (i = 0; i < len; i++) { |
| 3882 | expr_ty value; |
| 3883 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3884 | if (res != 0) goto failed; |
| 3885 | asdl_seq_SET(targets, i, value); |
| 3886 | } |
| 3887 | Py_XDECREF(tmp); |
| 3888 | tmp = NULL; |
| 3889 | } else { |
| 3890 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 3891 | return 1; |
| 3892 | } |
| 3893 | *out = Delete(targets, lineno, col_offset, arena); |
| 3894 | if (*out == NULL) goto failed; |
| 3895 | return 0; |
| 3896 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3897 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 3898 | if (isinstance == -1) { |
| 3899 | return 1; |
| 3900 | } |
| 3901 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3902 | asdl_seq* targets; |
| 3903 | expr_ty value; |
| 3904 | |
| 3905 | if (PyObject_HasAttrString(obj, "targets")) { |
| 3906 | int res; |
| 3907 | Py_ssize_t len; |
| 3908 | Py_ssize_t i; |
| 3909 | tmp = PyObject_GetAttrString(obj, "targets"); |
| 3910 | if (tmp == NULL) goto failed; |
| 3911 | if (!PyList_Check(tmp)) { |
| 3912 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3913 | goto failed; |
| 3914 | } |
| 3915 | len = PyList_GET_SIZE(tmp); |
| 3916 | targets = asdl_seq_new(len, arena); |
| 3917 | if (targets == NULL) goto failed; |
| 3918 | for (i = 0; i < len; i++) { |
| 3919 | expr_ty value; |
| 3920 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3921 | if (res != 0) goto failed; |
| 3922 | asdl_seq_SET(targets, i, value); |
| 3923 | } |
| 3924 | Py_XDECREF(tmp); |
| 3925 | tmp = NULL; |
| 3926 | } else { |
| 3927 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 3928 | return 1; |
| 3929 | } |
| 3930 | if (PyObject_HasAttrString(obj, "value")) { |
| 3931 | int res; |
| 3932 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3933 | if (tmp == NULL) goto failed; |
| 3934 | res = obj2ast_expr(tmp, &value, arena); |
| 3935 | if (res != 0) goto failed; |
| 3936 | Py_XDECREF(tmp); |
| 3937 | tmp = NULL; |
| 3938 | } else { |
| 3939 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 3940 | return 1; |
| 3941 | } |
| 3942 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 3943 | if (*out == NULL) goto failed; |
| 3944 | return 0; |
| 3945 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3946 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 3947 | if (isinstance == -1) { |
| 3948 | return 1; |
| 3949 | } |
| 3950 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3951 | expr_ty target; |
| 3952 | operator_ty op; |
| 3953 | expr_ty value; |
| 3954 | |
| 3955 | if (PyObject_HasAttrString(obj, "target")) { |
| 3956 | int res; |
| 3957 | tmp = PyObject_GetAttrString(obj, "target"); |
| 3958 | if (tmp == NULL) goto failed; |
| 3959 | res = obj2ast_expr(tmp, &target, arena); |
| 3960 | if (res != 0) goto failed; |
| 3961 | Py_XDECREF(tmp); |
| 3962 | tmp = NULL; |
| 3963 | } else { |
| 3964 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 3965 | return 1; |
| 3966 | } |
| 3967 | if (PyObject_HasAttrString(obj, "op")) { |
| 3968 | int res; |
| 3969 | tmp = PyObject_GetAttrString(obj, "op"); |
| 3970 | if (tmp == NULL) goto failed; |
| 3971 | res = obj2ast_operator(tmp, &op, arena); |
| 3972 | if (res != 0) goto failed; |
| 3973 | Py_XDECREF(tmp); |
| 3974 | tmp = NULL; |
| 3975 | } else { |
| 3976 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 3977 | return 1; |
| 3978 | } |
| 3979 | if (PyObject_HasAttrString(obj, "value")) { |
| 3980 | int res; |
| 3981 | tmp = PyObject_GetAttrString(obj, "value"); |
| 3982 | if (tmp == NULL) goto failed; |
| 3983 | res = obj2ast_expr(tmp, &value, arena); |
| 3984 | if (res != 0) goto failed; |
| 3985 | Py_XDECREF(tmp); |
| 3986 | tmp = NULL; |
| 3987 | } else { |
| 3988 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 3989 | return 1; |
| 3990 | } |
| 3991 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 3992 | if (*out == NULL) goto failed; |
| 3993 | return 0; |
| 3994 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 3995 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 3996 | if (isinstance == -1) { |
| 3997 | return 1; |
| 3998 | } |
| 3999 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4000 | expr_ty target; |
| 4001 | expr_ty iter; |
| 4002 | asdl_seq* body; |
| 4003 | asdl_seq* orelse; |
| 4004 | |
| 4005 | if (PyObject_HasAttrString(obj, "target")) { |
| 4006 | int res; |
| 4007 | tmp = PyObject_GetAttrString(obj, "target"); |
| 4008 | if (tmp == NULL) goto failed; |
| 4009 | res = obj2ast_expr(tmp, &target, arena); |
| 4010 | if (res != 0) goto failed; |
| 4011 | Py_XDECREF(tmp); |
| 4012 | tmp = NULL; |
| 4013 | } else { |
| 4014 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4015 | return 1; |
| 4016 | } |
| 4017 | if (PyObject_HasAttrString(obj, "iter")) { |
| 4018 | int res; |
| 4019 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 4020 | if (tmp == NULL) goto failed; |
| 4021 | res = obj2ast_expr(tmp, &iter, arena); |
| 4022 | if (res != 0) goto failed; |
| 4023 | Py_XDECREF(tmp); |
| 4024 | tmp = NULL; |
| 4025 | } else { |
| 4026 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4027 | return 1; |
| 4028 | } |
| 4029 | if (PyObject_HasAttrString(obj, "body")) { |
| 4030 | int res; |
| 4031 | Py_ssize_t len; |
| 4032 | Py_ssize_t i; |
| 4033 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4034 | if (tmp == NULL) goto failed; |
| 4035 | if (!PyList_Check(tmp)) { |
| 4036 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4037 | goto failed; |
| 4038 | } |
| 4039 | len = PyList_GET_SIZE(tmp); |
| 4040 | body = asdl_seq_new(len, arena); |
| 4041 | if (body == NULL) goto failed; |
| 4042 | for (i = 0; i < len; i++) { |
| 4043 | stmt_ty value; |
| 4044 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4045 | if (res != 0) goto failed; |
| 4046 | asdl_seq_SET(body, i, value); |
| 4047 | } |
| 4048 | Py_XDECREF(tmp); |
| 4049 | tmp = NULL; |
| 4050 | } else { |
| 4051 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4052 | return 1; |
| 4053 | } |
| 4054 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4055 | int res; |
| 4056 | Py_ssize_t len; |
| 4057 | Py_ssize_t i; |
| 4058 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4059 | if (tmp == NULL) goto failed; |
| 4060 | if (!PyList_Check(tmp)) { |
| 4061 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4062 | goto failed; |
| 4063 | } |
| 4064 | len = PyList_GET_SIZE(tmp); |
| 4065 | orelse = asdl_seq_new(len, arena); |
| 4066 | if (orelse == NULL) goto failed; |
| 4067 | for (i = 0; i < len; i++) { |
| 4068 | stmt_ty value; |
| 4069 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4070 | if (res != 0) goto failed; |
| 4071 | asdl_seq_SET(orelse, i, value); |
| 4072 | } |
| 4073 | Py_XDECREF(tmp); |
| 4074 | tmp = NULL; |
| 4075 | } else { |
| 4076 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4077 | return 1; |
| 4078 | } |
| 4079 | *out = For(target, iter, body, orelse, lineno, col_offset, |
| 4080 | arena); |
| 4081 | if (*out == NULL) goto failed; |
| 4082 | return 0; |
| 4083 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4084 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4085 | if (isinstance == -1) { |
| 4086 | return 1; |
| 4087 | } |
| 4088 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4089 | expr_ty test; |
| 4090 | asdl_seq* body; |
| 4091 | asdl_seq* orelse; |
| 4092 | |
| 4093 | if (PyObject_HasAttrString(obj, "test")) { |
| 4094 | int res; |
| 4095 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4096 | if (tmp == NULL) goto failed; |
| 4097 | res = obj2ast_expr(tmp, &test, arena); |
| 4098 | if (res != 0) goto failed; |
| 4099 | Py_XDECREF(tmp); |
| 4100 | tmp = NULL; |
| 4101 | } else { |
| 4102 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4103 | return 1; |
| 4104 | } |
| 4105 | if (PyObject_HasAttrString(obj, "body")) { |
| 4106 | int res; |
| 4107 | Py_ssize_t len; |
| 4108 | Py_ssize_t i; |
| 4109 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4110 | if (tmp == NULL) goto failed; |
| 4111 | if (!PyList_Check(tmp)) { |
| 4112 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4113 | goto failed; |
| 4114 | } |
| 4115 | len = PyList_GET_SIZE(tmp); |
| 4116 | body = asdl_seq_new(len, arena); |
| 4117 | if (body == NULL) goto failed; |
| 4118 | for (i = 0; i < len; i++) { |
| 4119 | stmt_ty value; |
| 4120 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4121 | if (res != 0) goto failed; |
| 4122 | asdl_seq_SET(body, i, value); |
| 4123 | } |
| 4124 | Py_XDECREF(tmp); |
| 4125 | tmp = NULL; |
| 4126 | } else { |
| 4127 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4128 | return 1; |
| 4129 | } |
| 4130 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4131 | int res; |
| 4132 | Py_ssize_t len; |
| 4133 | Py_ssize_t i; |
| 4134 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4135 | if (tmp == NULL) goto failed; |
| 4136 | if (!PyList_Check(tmp)) { |
| 4137 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4138 | goto failed; |
| 4139 | } |
| 4140 | len = PyList_GET_SIZE(tmp); |
| 4141 | orelse = asdl_seq_new(len, arena); |
| 4142 | if (orelse == NULL) goto failed; |
| 4143 | for (i = 0; i < len; i++) { |
| 4144 | stmt_ty value; |
| 4145 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4146 | if (res != 0) goto failed; |
| 4147 | asdl_seq_SET(orelse, i, value); |
| 4148 | } |
| 4149 | Py_XDECREF(tmp); |
| 4150 | tmp = NULL; |
| 4151 | } else { |
| 4152 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4153 | return 1; |
| 4154 | } |
| 4155 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4156 | if (*out == NULL) goto failed; |
| 4157 | return 0; |
| 4158 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4159 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4160 | if (isinstance == -1) { |
| 4161 | return 1; |
| 4162 | } |
| 4163 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4164 | expr_ty test; |
| 4165 | asdl_seq* body; |
| 4166 | asdl_seq* orelse; |
| 4167 | |
| 4168 | if (PyObject_HasAttrString(obj, "test")) { |
| 4169 | int res; |
| 4170 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4171 | if (tmp == NULL) goto failed; |
| 4172 | res = obj2ast_expr(tmp, &test, arena); |
| 4173 | if (res != 0) goto failed; |
| 4174 | Py_XDECREF(tmp); |
| 4175 | tmp = NULL; |
| 4176 | } else { |
| 4177 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4178 | return 1; |
| 4179 | } |
| 4180 | if (PyObject_HasAttrString(obj, "body")) { |
| 4181 | int res; |
| 4182 | Py_ssize_t len; |
| 4183 | Py_ssize_t i; |
| 4184 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4185 | if (tmp == NULL) goto failed; |
| 4186 | if (!PyList_Check(tmp)) { |
| 4187 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4188 | goto failed; |
| 4189 | } |
| 4190 | len = PyList_GET_SIZE(tmp); |
| 4191 | body = asdl_seq_new(len, arena); |
| 4192 | if (body == NULL) goto failed; |
| 4193 | for (i = 0; i < len; i++) { |
| 4194 | stmt_ty value; |
| 4195 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4196 | if (res != 0) goto failed; |
| 4197 | asdl_seq_SET(body, i, value); |
| 4198 | } |
| 4199 | Py_XDECREF(tmp); |
| 4200 | tmp = NULL; |
| 4201 | } else { |
| 4202 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4203 | return 1; |
| 4204 | } |
| 4205 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4206 | int res; |
| 4207 | Py_ssize_t len; |
| 4208 | Py_ssize_t i; |
| 4209 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4210 | if (tmp == NULL) goto failed; |
| 4211 | if (!PyList_Check(tmp)) { |
| 4212 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4213 | goto failed; |
| 4214 | } |
| 4215 | len = PyList_GET_SIZE(tmp); |
| 4216 | orelse = asdl_seq_new(len, arena); |
| 4217 | if (orelse == NULL) goto failed; |
| 4218 | for (i = 0; i < len; i++) { |
| 4219 | stmt_ty value; |
| 4220 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4221 | if (res != 0) goto failed; |
| 4222 | asdl_seq_SET(orelse, i, value); |
| 4223 | } |
| 4224 | Py_XDECREF(tmp); |
| 4225 | tmp = NULL; |
| 4226 | } else { |
| 4227 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4228 | return 1; |
| 4229 | } |
| 4230 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4231 | if (*out == NULL) goto failed; |
| 4232 | return 0; |
| 4233 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4234 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4235 | if (isinstance == -1) { |
| 4236 | return 1; |
| 4237 | } |
| 4238 | if (isinstance) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4239 | asdl_seq* items; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4240 | asdl_seq* body; |
| 4241 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4242 | if (PyObject_HasAttrString(obj, "items")) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4243 | int res; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4244 | Py_ssize_t len; |
| 4245 | Py_ssize_t i; |
| 4246 | tmp = PyObject_GetAttrString(obj, "items"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4247 | if (tmp == NULL) goto failed; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4248 | if (!PyList_Check(tmp)) { |
| 4249 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4250 | goto failed; |
| 4251 | } |
| 4252 | len = PyList_GET_SIZE(tmp); |
| 4253 | items = asdl_seq_new(len, arena); |
| 4254 | if (items == NULL) goto failed; |
| 4255 | for (i = 0; i < len; i++) { |
| 4256 | withitem_ty value; |
| 4257 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4258 | if (res != 0) goto failed; |
| 4259 | asdl_seq_SET(items, i, value); |
| 4260 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4261 | Py_XDECREF(tmp); |
| 4262 | tmp = NULL; |
| 4263 | } else { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4264 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4265 | return 1; |
| 4266 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4267 | if (PyObject_HasAttrString(obj, "body")) { |
| 4268 | int res; |
| 4269 | Py_ssize_t len; |
| 4270 | Py_ssize_t i; |
| 4271 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4272 | if (tmp == NULL) goto failed; |
| 4273 | if (!PyList_Check(tmp)) { |
| 4274 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4275 | goto failed; |
| 4276 | } |
| 4277 | len = PyList_GET_SIZE(tmp); |
| 4278 | body = asdl_seq_new(len, arena); |
| 4279 | if (body == NULL) goto failed; |
| 4280 | for (i = 0; i < len; i++) { |
| 4281 | stmt_ty value; |
| 4282 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4283 | if (res != 0) goto failed; |
| 4284 | asdl_seq_SET(body, i, value); |
| 4285 | } |
| 4286 | Py_XDECREF(tmp); |
| 4287 | tmp = NULL; |
| 4288 | } else { |
| 4289 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4290 | return 1; |
| 4291 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4292 | *out = With(items, body, lineno, col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4293 | if (*out == NULL) goto failed; |
| 4294 | return 0; |
| 4295 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4296 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4297 | if (isinstance == -1) { |
| 4298 | return 1; |
| 4299 | } |
| 4300 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4301 | expr_ty exc; |
| 4302 | expr_ty cause; |
| 4303 | |
| 4304 | if (PyObject_HasAttrString(obj, "exc")) { |
| 4305 | int res; |
| 4306 | tmp = PyObject_GetAttrString(obj, "exc"); |
| 4307 | if (tmp == NULL) goto failed; |
| 4308 | res = obj2ast_expr(tmp, &exc, arena); |
| 4309 | if (res != 0) goto failed; |
| 4310 | Py_XDECREF(tmp); |
| 4311 | tmp = NULL; |
| 4312 | } else { |
| 4313 | exc = NULL; |
| 4314 | } |
| 4315 | if (PyObject_HasAttrString(obj, "cause")) { |
| 4316 | int res; |
| 4317 | tmp = PyObject_GetAttrString(obj, "cause"); |
| 4318 | if (tmp == NULL) goto failed; |
| 4319 | res = obj2ast_expr(tmp, &cause, arena); |
| 4320 | if (res != 0) goto failed; |
| 4321 | Py_XDECREF(tmp); |
| 4322 | tmp = NULL; |
| 4323 | } else { |
| 4324 | cause = NULL; |
| 4325 | } |
| 4326 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4327 | if (*out == NULL) goto failed; |
| 4328 | return 0; |
| 4329 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4330 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4331 | if (isinstance == -1) { |
| 4332 | return 1; |
| 4333 | } |
| 4334 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4335 | asdl_seq* body; |
| 4336 | asdl_seq* handlers; |
| 4337 | asdl_seq* orelse; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4338 | asdl_seq* finalbody; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4339 | |
| 4340 | if (PyObject_HasAttrString(obj, "body")) { |
| 4341 | int res; |
| 4342 | Py_ssize_t len; |
| 4343 | Py_ssize_t i; |
| 4344 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4345 | if (tmp == NULL) goto failed; |
| 4346 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4347 | 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] | 4348 | goto failed; |
| 4349 | } |
| 4350 | len = PyList_GET_SIZE(tmp); |
| 4351 | body = asdl_seq_new(len, arena); |
| 4352 | if (body == NULL) goto failed; |
| 4353 | for (i = 0; i < len; i++) { |
| 4354 | stmt_ty value; |
| 4355 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4356 | if (res != 0) goto failed; |
| 4357 | asdl_seq_SET(body, i, value); |
| 4358 | } |
| 4359 | Py_XDECREF(tmp); |
| 4360 | tmp = NULL; |
| 4361 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4362 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4363 | return 1; |
| 4364 | } |
| 4365 | if (PyObject_HasAttrString(obj, "handlers")) { |
| 4366 | int res; |
| 4367 | Py_ssize_t len; |
| 4368 | Py_ssize_t i; |
| 4369 | tmp = PyObject_GetAttrString(obj, "handlers"); |
| 4370 | if (tmp == NULL) goto failed; |
| 4371 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4372 | 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] | 4373 | goto failed; |
| 4374 | } |
| 4375 | len = PyList_GET_SIZE(tmp); |
| 4376 | handlers = asdl_seq_new(len, arena); |
| 4377 | if (handlers == NULL) goto failed; |
| 4378 | for (i = 0; i < len; i++) { |
| 4379 | excepthandler_ty value; |
| 4380 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4381 | if (res != 0) goto failed; |
| 4382 | asdl_seq_SET(handlers, i, value); |
| 4383 | } |
| 4384 | Py_XDECREF(tmp); |
| 4385 | tmp = NULL; |
| 4386 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4387 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4388 | return 1; |
| 4389 | } |
| 4390 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4391 | int res; |
| 4392 | Py_ssize_t len; |
| 4393 | Py_ssize_t i; |
| 4394 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4395 | if (tmp == NULL) goto failed; |
| 4396 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4397 | 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] | 4398 | goto failed; |
| 4399 | } |
| 4400 | len = PyList_GET_SIZE(tmp); |
| 4401 | orelse = asdl_seq_new(len, arena); |
| 4402 | if (orelse == NULL) goto failed; |
| 4403 | for (i = 0; i < len; i++) { |
| 4404 | stmt_ty value; |
| 4405 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4406 | if (res != 0) goto failed; |
| 4407 | asdl_seq_SET(orelse, i, value); |
| 4408 | } |
| 4409 | Py_XDECREF(tmp); |
| 4410 | tmp = NULL; |
| 4411 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4412 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4413 | return 1; |
| 4414 | } |
| 4415 | if (PyObject_HasAttrString(obj, "finalbody")) { |
| 4416 | int res; |
| 4417 | Py_ssize_t len; |
| 4418 | Py_ssize_t i; |
| 4419 | tmp = PyObject_GetAttrString(obj, "finalbody"); |
| 4420 | if (tmp == NULL) goto failed; |
| 4421 | if (!PyList_Check(tmp)) { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4422 | 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] | 4423 | goto failed; |
| 4424 | } |
| 4425 | len = PyList_GET_SIZE(tmp); |
| 4426 | finalbody = asdl_seq_new(len, arena); |
| 4427 | if (finalbody == NULL) goto failed; |
| 4428 | for (i = 0; i < len; i++) { |
| 4429 | stmt_ty value; |
| 4430 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4431 | if (res != 0) goto failed; |
| 4432 | asdl_seq_SET(finalbody, i, value); |
| 4433 | } |
| 4434 | Py_XDECREF(tmp); |
| 4435 | tmp = NULL; |
| 4436 | } else { |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4437 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4438 | return 1; |
| 4439 | } |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 4440 | *out = Try(body, handlers, orelse, finalbody, lineno, |
| 4441 | col_offset, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4442 | if (*out == NULL) goto failed; |
| 4443 | return 0; |
| 4444 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4445 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 4446 | if (isinstance == -1) { |
| 4447 | return 1; |
| 4448 | } |
| 4449 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4450 | expr_ty test; |
| 4451 | expr_ty msg; |
| 4452 | |
| 4453 | if (PyObject_HasAttrString(obj, "test")) { |
| 4454 | int res; |
| 4455 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4456 | if (tmp == NULL) goto failed; |
| 4457 | res = obj2ast_expr(tmp, &test, arena); |
| 4458 | if (res != 0) goto failed; |
| 4459 | Py_XDECREF(tmp); |
| 4460 | tmp = NULL; |
| 4461 | } else { |
| 4462 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 4463 | return 1; |
| 4464 | } |
| 4465 | if (PyObject_HasAttrString(obj, "msg")) { |
| 4466 | int res; |
| 4467 | tmp = PyObject_GetAttrString(obj, "msg"); |
| 4468 | if (tmp == NULL) goto failed; |
| 4469 | res = obj2ast_expr(tmp, &msg, arena); |
| 4470 | if (res != 0) goto failed; |
| 4471 | Py_XDECREF(tmp); |
| 4472 | tmp = NULL; |
| 4473 | } else { |
| 4474 | msg = NULL; |
| 4475 | } |
| 4476 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 4477 | if (*out == NULL) goto failed; |
| 4478 | return 0; |
| 4479 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4480 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 4481 | if (isinstance == -1) { |
| 4482 | return 1; |
| 4483 | } |
| 4484 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4485 | asdl_seq* names; |
| 4486 | |
| 4487 | if (PyObject_HasAttrString(obj, "names")) { |
| 4488 | int res; |
| 4489 | Py_ssize_t len; |
| 4490 | Py_ssize_t i; |
| 4491 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4492 | if (tmp == NULL) goto failed; |
| 4493 | if (!PyList_Check(tmp)) { |
| 4494 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4495 | goto failed; |
| 4496 | } |
| 4497 | len = PyList_GET_SIZE(tmp); |
| 4498 | names = asdl_seq_new(len, arena); |
| 4499 | if (names == NULL) goto failed; |
| 4500 | for (i = 0; i < len; i++) { |
| 4501 | alias_ty value; |
| 4502 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4503 | if (res != 0) goto failed; |
| 4504 | asdl_seq_SET(names, i, value); |
| 4505 | } |
| 4506 | Py_XDECREF(tmp); |
| 4507 | tmp = NULL; |
| 4508 | } else { |
| 4509 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 4510 | return 1; |
| 4511 | } |
| 4512 | *out = Import(names, lineno, col_offset, arena); |
| 4513 | if (*out == NULL) goto failed; |
| 4514 | return 0; |
| 4515 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4516 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 4517 | if (isinstance == -1) { |
| 4518 | return 1; |
| 4519 | } |
| 4520 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4521 | identifier module; |
| 4522 | asdl_seq* names; |
| 4523 | int level; |
| 4524 | |
| 4525 | if (PyObject_HasAttrString(obj, "module")) { |
| 4526 | int res; |
| 4527 | tmp = PyObject_GetAttrString(obj, "module"); |
| 4528 | if (tmp == NULL) goto failed; |
| 4529 | res = obj2ast_identifier(tmp, &module, arena); |
| 4530 | if (res != 0) goto failed; |
| 4531 | Py_XDECREF(tmp); |
| 4532 | tmp = NULL; |
| 4533 | } else { |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 4534 | module = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4535 | } |
| 4536 | if (PyObject_HasAttrString(obj, "names")) { |
| 4537 | int res; |
| 4538 | Py_ssize_t len; |
| 4539 | Py_ssize_t i; |
| 4540 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4541 | if (tmp == NULL) goto failed; |
| 4542 | if (!PyList_Check(tmp)) { |
| 4543 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4544 | goto failed; |
| 4545 | } |
| 4546 | len = PyList_GET_SIZE(tmp); |
| 4547 | names = asdl_seq_new(len, arena); |
| 4548 | if (names == NULL) goto failed; |
| 4549 | for (i = 0; i < len; i++) { |
| 4550 | alias_ty value; |
| 4551 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4552 | if (res != 0) goto failed; |
| 4553 | asdl_seq_SET(names, i, value); |
| 4554 | } |
| 4555 | Py_XDECREF(tmp); |
| 4556 | tmp = NULL; |
| 4557 | } else { |
| 4558 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 4559 | return 1; |
| 4560 | } |
| 4561 | if (PyObject_HasAttrString(obj, "level")) { |
| 4562 | int res; |
| 4563 | tmp = PyObject_GetAttrString(obj, "level"); |
| 4564 | if (tmp == NULL) goto failed; |
| 4565 | res = obj2ast_int(tmp, &level, arena); |
| 4566 | if (res != 0) goto failed; |
| 4567 | Py_XDECREF(tmp); |
| 4568 | tmp = NULL; |
| 4569 | } else { |
| 4570 | level = 0; |
| 4571 | } |
| 4572 | *out = ImportFrom(module, names, level, lineno, col_offset, |
| 4573 | arena); |
| 4574 | if (*out == NULL) goto failed; |
| 4575 | return 0; |
| 4576 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4577 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 4578 | if (isinstance == -1) { |
| 4579 | return 1; |
| 4580 | } |
| 4581 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4582 | asdl_seq* names; |
| 4583 | |
| 4584 | if (PyObject_HasAttrString(obj, "names")) { |
| 4585 | int res; |
| 4586 | Py_ssize_t len; |
| 4587 | Py_ssize_t i; |
| 4588 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4589 | if (tmp == NULL) goto failed; |
| 4590 | if (!PyList_Check(tmp)) { |
| 4591 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4592 | goto failed; |
| 4593 | } |
| 4594 | len = PyList_GET_SIZE(tmp); |
| 4595 | names = asdl_seq_new(len, arena); |
| 4596 | if (names == NULL) goto failed; |
| 4597 | for (i = 0; i < len; i++) { |
| 4598 | identifier value; |
| 4599 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4600 | if (res != 0) goto failed; |
| 4601 | asdl_seq_SET(names, i, value); |
| 4602 | } |
| 4603 | Py_XDECREF(tmp); |
| 4604 | tmp = NULL; |
| 4605 | } else { |
| 4606 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 4607 | return 1; |
| 4608 | } |
| 4609 | *out = Global(names, lineno, col_offset, arena); |
| 4610 | if (*out == NULL) goto failed; |
| 4611 | return 0; |
| 4612 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4613 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 4614 | if (isinstance == -1) { |
| 4615 | return 1; |
| 4616 | } |
| 4617 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4618 | asdl_seq* names; |
| 4619 | |
| 4620 | if (PyObject_HasAttrString(obj, "names")) { |
| 4621 | int res; |
| 4622 | Py_ssize_t len; |
| 4623 | Py_ssize_t i; |
| 4624 | tmp = PyObject_GetAttrString(obj, "names"); |
| 4625 | if (tmp == NULL) goto failed; |
| 4626 | if (!PyList_Check(tmp)) { |
| 4627 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4628 | goto failed; |
| 4629 | } |
| 4630 | len = PyList_GET_SIZE(tmp); |
| 4631 | names = asdl_seq_new(len, arena); |
| 4632 | if (names == NULL) goto failed; |
| 4633 | for (i = 0; i < len; i++) { |
| 4634 | identifier value; |
| 4635 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4636 | if (res != 0) goto failed; |
| 4637 | asdl_seq_SET(names, i, value); |
| 4638 | } |
| 4639 | Py_XDECREF(tmp); |
| 4640 | tmp = NULL; |
| 4641 | } else { |
| 4642 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 4643 | return 1; |
| 4644 | } |
| 4645 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 4646 | if (*out == NULL) goto failed; |
| 4647 | return 0; |
| 4648 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4649 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 4650 | if (isinstance == -1) { |
| 4651 | return 1; |
| 4652 | } |
| 4653 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4654 | expr_ty value; |
| 4655 | |
| 4656 | if (PyObject_HasAttrString(obj, "value")) { |
| 4657 | int res; |
| 4658 | tmp = PyObject_GetAttrString(obj, "value"); |
| 4659 | if (tmp == NULL) goto failed; |
| 4660 | res = obj2ast_expr(tmp, &value, arena); |
| 4661 | if (res != 0) goto failed; |
| 4662 | Py_XDECREF(tmp); |
| 4663 | tmp = NULL; |
| 4664 | } else { |
| 4665 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 4666 | return 1; |
| 4667 | } |
| 4668 | *out = Expr(value, 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*)Pass_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 = Pass(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*)Break_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 = Break(lineno, col_offset, arena); |
| 4689 | if (*out == NULL) goto failed; |
| 4690 | return 0; |
| 4691 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4692 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 4693 | if (isinstance == -1) { |
| 4694 | return 1; |
| 4695 | } |
| 4696 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4697 | |
| 4698 | *out = Continue(lineno, col_offset, arena); |
| 4699 | if (*out == NULL) goto failed; |
| 4700 | return 0; |
| 4701 | } |
| 4702 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 4703 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 4704 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 4705 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4706 | return 1; |
| 4707 | } |
| 4708 | |
| 4709 | int |
| 4710 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 4711 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4712 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4713 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 4714 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4715 | int lineno; |
| 4716 | int col_offset; |
| 4717 | |
| 4718 | if (obj == Py_None) { |
| 4719 | *out = NULL; |
| 4720 | return 0; |
| 4721 | } |
| 4722 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 4723 | int res; |
| 4724 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 4725 | if (tmp == NULL) goto failed; |
| 4726 | res = obj2ast_int(tmp, &lineno, arena); |
| 4727 | if (res != 0) goto failed; |
| 4728 | Py_XDECREF(tmp); |
| 4729 | tmp = NULL; |
| 4730 | } else { |
| 4731 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 4732 | return 1; |
| 4733 | } |
| 4734 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 4735 | int res; |
| 4736 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 4737 | if (tmp == NULL) goto failed; |
| 4738 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4739 | if (res != 0) goto failed; |
| 4740 | Py_XDECREF(tmp); |
| 4741 | tmp = NULL; |
| 4742 | } else { |
| 4743 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 4744 | return 1; |
| 4745 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4746 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 4747 | if (isinstance == -1) { |
| 4748 | return 1; |
| 4749 | } |
| 4750 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4751 | boolop_ty op; |
| 4752 | asdl_seq* values; |
| 4753 | |
| 4754 | if (PyObject_HasAttrString(obj, "op")) { |
| 4755 | int res; |
| 4756 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4757 | if (tmp == NULL) goto failed; |
| 4758 | res = obj2ast_boolop(tmp, &op, arena); |
| 4759 | if (res != 0) goto failed; |
| 4760 | Py_XDECREF(tmp); |
| 4761 | tmp = NULL; |
| 4762 | } else { |
| 4763 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 4764 | return 1; |
| 4765 | } |
| 4766 | if (PyObject_HasAttrString(obj, "values")) { |
| 4767 | int res; |
| 4768 | Py_ssize_t len; |
| 4769 | Py_ssize_t i; |
| 4770 | tmp = PyObject_GetAttrString(obj, "values"); |
| 4771 | if (tmp == NULL) goto failed; |
| 4772 | if (!PyList_Check(tmp)) { |
| 4773 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4774 | goto failed; |
| 4775 | } |
| 4776 | len = PyList_GET_SIZE(tmp); |
| 4777 | values = asdl_seq_new(len, arena); |
| 4778 | if (values == NULL) goto failed; |
| 4779 | for (i = 0; i < len; i++) { |
| 4780 | expr_ty value; |
| 4781 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4782 | if (res != 0) goto failed; |
| 4783 | asdl_seq_SET(values, i, value); |
| 4784 | } |
| 4785 | Py_XDECREF(tmp); |
| 4786 | tmp = NULL; |
| 4787 | } else { |
| 4788 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 4789 | return 1; |
| 4790 | } |
| 4791 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 4792 | if (*out == NULL) goto failed; |
| 4793 | return 0; |
| 4794 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4795 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 4796 | if (isinstance == -1) { |
| 4797 | return 1; |
| 4798 | } |
| 4799 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4800 | expr_ty left; |
| 4801 | operator_ty op; |
| 4802 | expr_ty right; |
| 4803 | |
| 4804 | if (PyObject_HasAttrString(obj, "left")) { |
| 4805 | int res; |
| 4806 | tmp = PyObject_GetAttrString(obj, "left"); |
| 4807 | if (tmp == NULL) goto failed; |
| 4808 | res = obj2ast_expr(tmp, &left, arena); |
| 4809 | if (res != 0) goto failed; |
| 4810 | Py_XDECREF(tmp); |
| 4811 | tmp = NULL; |
| 4812 | } else { |
| 4813 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 4814 | return 1; |
| 4815 | } |
| 4816 | if (PyObject_HasAttrString(obj, "op")) { |
| 4817 | int res; |
| 4818 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4819 | if (tmp == NULL) goto failed; |
| 4820 | res = obj2ast_operator(tmp, &op, arena); |
| 4821 | if (res != 0) goto failed; |
| 4822 | Py_XDECREF(tmp); |
| 4823 | tmp = NULL; |
| 4824 | } else { |
| 4825 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 4826 | return 1; |
| 4827 | } |
| 4828 | if (PyObject_HasAttrString(obj, "right")) { |
| 4829 | int res; |
| 4830 | tmp = PyObject_GetAttrString(obj, "right"); |
| 4831 | if (tmp == NULL) goto failed; |
| 4832 | res = obj2ast_expr(tmp, &right, arena); |
| 4833 | if (res != 0) goto failed; |
| 4834 | Py_XDECREF(tmp); |
| 4835 | tmp = NULL; |
| 4836 | } else { |
| 4837 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 4838 | return 1; |
| 4839 | } |
| 4840 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 4841 | if (*out == NULL) goto failed; |
| 4842 | return 0; |
| 4843 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4844 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 4845 | if (isinstance == -1) { |
| 4846 | return 1; |
| 4847 | } |
| 4848 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4849 | unaryop_ty op; |
| 4850 | expr_ty operand; |
| 4851 | |
| 4852 | if (PyObject_HasAttrString(obj, "op")) { |
| 4853 | int res; |
| 4854 | tmp = PyObject_GetAttrString(obj, "op"); |
| 4855 | if (tmp == NULL) goto failed; |
| 4856 | res = obj2ast_unaryop(tmp, &op, arena); |
| 4857 | if (res != 0) goto failed; |
| 4858 | Py_XDECREF(tmp); |
| 4859 | tmp = NULL; |
| 4860 | } else { |
| 4861 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 4862 | return 1; |
| 4863 | } |
| 4864 | if (PyObject_HasAttrString(obj, "operand")) { |
| 4865 | int res; |
| 4866 | tmp = PyObject_GetAttrString(obj, "operand"); |
| 4867 | if (tmp == NULL) goto failed; |
| 4868 | res = obj2ast_expr(tmp, &operand, arena); |
| 4869 | if (res != 0) goto failed; |
| 4870 | Py_XDECREF(tmp); |
| 4871 | tmp = NULL; |
| 4872 | } else { |
| 4873 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 4874 | return 1; |
| 4875 | } |
| 4876 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 4877 | if (*out == NULL) goto failed; |
| 4878 | return 0; |
| 4879 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4880 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 4881 | if (isinstance == -1) { |
| 4882 | return 1; |
| 4883 | } |
| 4884 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4885 | arguments_ty args; |
| 4886 | expr_ty body; |
| 4887 | |
| 4888 | if (PyObject_HasAttrString(obj, "args")) { |
| 4889 | int res; |
| 4890 | tmp = PyObject_GetAttrString(obj, "args"); |
| 4891 | if (tmp == NULL) goto failed; |
| 4892 | res = obj2ast_arguments(tmp, &args, arena); |
| 4893 | if (res != 0) goto failed; |
| 4894 | Py_XDECREF(tmp); |
| 4895 | tmp = NULL; |
| 4896 | } else { |
| 4897 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 4898 | return 1; |
| 4899 | } |
| 4900 | if (PyObject_HasAttrString(obj, "body")) { |
| 4901 | int res; |
| 4902 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4903 | if (tmp == NULL) goto failed; |
| 4904 | res = obj2ast_expr(tmp, &body, arena); |
| 4905 | if (res != 0) goto failed; |
| 4906 | Py_XDECREF(tmp); |
| 4907 | tmp = NULL; |
| 4908 | } else { |
| 4909 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 4910 | return 1; |
| 4911 | } |
| 4912 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 4913 | if (*out == NULL) goto failed; |
| 4914 | return 0; |
| 4915 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4916 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 4917 | if (isinstance == -1) { |
| 4918 | return 1; |
| 4919 | } |
| 4920 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4921 | expr_ty test; |
| 4922 | expr_ty body; |
| 4923 | expr_ty orelse; |
| 4924 | |
| 4925 | if (PyObject_HasAttrString(obj, "test")) { |
| 4926 | int res; |
| 4927 | tmp = PyObject_GetAttrString(obj, "test"); |
| 4928 | if (tmp == NULL) goto failed; |
| 4929 | res = obj2ast_expr(tmp, &test, arena); |
| 4930 | if (res != 0) goto failed; |
| 4931 | Py_XDECREF(tmp); |
| 4932 | tmp = NULL; |
| 4933 | } else { |
| 4934 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 4935 | return 1; |
| 4936 | } |
| 4937 | if (PyObject_HasAttrString(obj, "body")) { |
| 4938 | int res; |
| 4939 | tmp = PyObject_GetAttrString(obj, "body"); |
| 4940 | if (tmp == NULL) goto failed; |
| 4941 | res = obj2ast_expr(tmp, &body, arena); |
| 4942 | if (res != 0) goto failed; |
| 4943 | Py_XDECREF(tmp); |
| 4944 | tmp = NULL; |
| 4945 | } else { |
| 4946 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 4947 | return 1; |
| 4948 | } |
| 4949 | if (PyObject_HasAttrString(obj, "orelse")) { |
| 4950 | int res; |
| 4951 | tmp = PyObject_GetAttrString(obj, "orelse"); |
| 4952 | if (tmp == NULL) goto failed; |
| 4953 | res = obj2ast_expr(tmp, &orelse, arena); |
| 4954 | if (res != 0) goto failed; |
| 4955 | Py_XDECREF(tmp); |
| 4956 | tmp = NULL; |
| 4957 | } else { |
| 4958 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 4959 | return 1; |
| 4960 | } |
| 4961 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 4962 | if (*out == NULL) goto failed; |
| 4963 | return 0; |
| 4964 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 4965 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 4966 | if (isinstance == -1) { |
| 4967 | return 1; |
| 4968 | } |
| 4969 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4970 | asdl_seq* keys; |
| 4971 | asdl_seq* values; |
| 4972 | |
| 4973 | if (PyObject_HasAttrString(obj, "keys")) { |
| 4974 | int res; |
| 4975 | Py_ssize_t len; |
| 4976 | Py_ssize_t i; |
| 4977 | tmp = PyObject_GetAttrString(obj, "keys"); |
| 4978 | if (tmp == NULL) goto failed; |
| 4979 | if (!PyList_Check(tmp)) { |
| 4980 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4981 | goto failed; |
| 4982 | } |
| 4983 | len = PyList_GET_SIZE(tmp); |
| 4984 | keys = asdl_seq_new(len, arena); |
| 4985 | if (keys == NULL) goto failed; |
| 4986 | for (i = 0; i < len; i++) { |
| 4987 | expr_ty value; |
| 4988 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4989 | if (res != 0) goto failed; |
| 4990 | asdl_seq_SET(keys, i, value); |
| 4991 | } |
| 4992 | Py_XDECREF(tmp); |
| 4993 | tmp = NULL; |
| 4994 | } else { |
| 4995 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 4996 | return 1; |
| 4997 | } |
| 4998 | if (PyObject_HasAttrString(obj, "values")) { |
| 4999 | int res; |
| 5000 | Py_ssize_t len; |
| 5001 | Py_ssize_t i; |
| 5002 | tmp = PyObject_GetAttrString(obj, "values"); |
| 5003 | if (tmp == NULL) goto failed; |
| 5004 | if (!PyList_Check(tmp)) { |
| 5005 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5006 | goto failed; |
| 5007 | } |
| 5008 | len = PyList_GET_SIZE(tmp); |
| 5009 | values = asdl_seq_new(len, arena); |
| 5010 | if (values == NULL) goto failed; |
| 5011 | for (i = 0; i < len; i++) { |
| 5012 | expr_ty value; |
| 5013 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5014 | if (res != 0) goto failed; |
| 5015 | asdl_seq_SET(values, i, value); |
| 5016 | } |
| 5017 | Py_XDECREF(tmp); |
| 5018 | tmp = NULL; |
| 5019 | } else { |
| 5020 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5021 | return 1; |
| 5022 | } |
| 5023 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5024 | if (*out == NULL) goto failed; |
| 5025 | return 0; |
| 5026 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5027 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5028 | if (isinstance == -1) { |
| 5029 | return 1; |
| 5030 | } |
| 5031 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5032 | asdl_seq* elts; |
| 5033 | |
| 5034 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5035 | int res; |
| 5036 | Py_ssize_t len; |
| 5037 | Py_ssize_t i; |
| 5038 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5039 | if (tmp == NULL) goto failed; |
| 5040 | if (!PyList_Check(tmp)) { |
| 5041 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5042 | goto failed; |
| 5043 | } |
| 5044 | len = PyList_GET_SIZE(tmp); |
| 5045 | elts = asdl_seq_new(len, arena); |
| 5046 | if (elts == NULL) goto failed; |
| 5047 | for (i = 0; i < len; i++) { |
| 5048 | expr_ty value; |
| 5049 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5050 | if (res != 0) goto failed; |
| 5051 | asdl_seq_SET(elts, i, value); |
| 5052 | } |
| 5053 | Py_XDECREF(tmp); |
| 5054 | tmp = NULL; |
| 5055 | } else { |
| 5056 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5057 | return 1; |
| 5058 | } |
| 5059 | *out = Set(elts, lineno, col_offset, arena); |
| 5060 | if (*out == NULL) goto failed; |
| 5061 | return 0; |
| 5062 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5063 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5064 | if (isinstance == -1) { |
| 5065 | return 1; |
| 5066 | } |
| 5067 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5068 | expr_ty elt; |
| 5069 | asdl_seq* generators; |
| 5070 | |
| 5071 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5072 | int res; |
| 5073 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5074 | if (tmp == NULL) goto failed; |
| 5075 | res = obj2ast_expr(tmp, &elt, arena); |
| 5076 | if (res != 0) goto failed; |
| 5077 | Py_XDECREF(tmp); |
| 5078 | tmp = NULL; |
| 5079 | } else { |
| 5080 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5081 | return 1; |
| 5082 | } |
| 5083 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5084 | int res; |
| 5085 | Py_ssize_t len; |
| 5086 | Py_ssize_t i; |
| 5087 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5088 | if (tmp == NULL) goto failed; |
| 5089 | if (!PyList_Check(tmp)) { |
| 5090 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5091 | goto failed; |
| 5092 | } |
| 5093 | len = PyList_GET_SIZE(tmp); |
| 5094 | generators = asdl_seq_new(len, arena); |
| 5095 | if (generators == NULL) goto failed; |
| 5096 | for (i = 0; i < len; i++) { |
| 5097 | comprehension_ty value; |
| 5098 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5099 | if (res != 0) goto failed; |
| 5100 | asdl_seq_SET(generators, i, value); |
| 5101 | } |
| 5102 | Py_XDECREF(tmp); |
| 5103 | tmp = NULL; |
| 5104 | } else { |
| 5105 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5106 | return 1; |
| 5107 | } |
| 5108 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5109 | if (*out == NULL) goto failed; |
| 5110 | return 0; |
| 5111 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5112 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5113 | if (isinstance == -1) { |
| 5114 | return 1; |
| 5115 | } |
| 5116 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5117 | expr_ty elt; |
| 5118 | asdl_seq* generators; |
| 5119 | |
| 5120 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5121 | int res; |
| 5122 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5123 | if (tmp == NULL) goto failed; |
| 5124 | res = obj2ast_expr(tmp, &elt, arena); |
| 5125 | if (res != 0) goto failed; |
| 5126 | Py_XDECREF(tmp); |
| 5127 | tmp = NULL; |
| 5128 | } else { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5130 | return 1; |
| 5131 | } |
| 5132 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5133 | int res; |
| 5134 | Py_ssize_t len; |
| 5135 | Py_ssize_t i; |
| 5136 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5137 | if (tmp == NULL) goto failed; |
| 5138 | if (!PyList_Check(tmp)) { |
| 5139 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5140 | goto failed; |
| 5141 | } |
| 5142 | len = PyList_GET_SIZE(tmp); |
| 5143 | generators = asdl_seq_new(len, arena); |
| 5144 | if (generators == NULL) goto failed; |
| 5145 | for (i = 0; i < len; i++) { |
| 5146 | comprehension_ty value; |
| 5147 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5148 | if (res != 0) goto failed; |
| 5149 | asdl_seq_SET(generators, i, value); |
| 5150 | } |
| 5151 | Py_XDECREF(tmp); |
| 5152 | tmp = NULL; |
| 5153 | } else { |
| 5154 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5155 | return 1; |
| 5156 | } |
| 5157 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5158 | if (*out == NULL) goto failed; |
| 5159 | return 0; |
| 5160 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5161 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5162 | if (isinstance == -1) { |
| 5163 | return 1; |
| 5164 | } |
| 5165 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5166 | expr_ty key; |
| 5167 | expr_ty value; |
| 5168 | asdl_seq* generators; |
| 5169 | |
| 5170 | if (PyObject_HasAttrString(obj, "key")) { |
| 5171 | int res; |
| 5172 | tmp = PyObject_GetAttrString(obj, "key"); |
| 5173 | if (tmp == NULL) goto failed; |
| 5174 | res = obj2ast_expr(tmp, &key, arena); |
| 5175 | if (res != 0) goto failed; |
| 5176 | Py_XDECREF(tmp); |
| 5177 | tmp = NULL; |
| 5178 | } else { |
| 5179 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5180 | return 1; |
| 5181 | } |
| 5182 | if (PyObject_HasAttrString(obj, "value")) { |
| 5183 | int res; |
| 5184 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5185 | if (tmp == NULL) goto failed; |
| 5186 | res = obj2ast_expr(tmp, &value, arena); |
| 5187 | if (res != 0) goto failed; |
| 5188 | Py_XDECREF(tmp); |
| 5189 | tmp = NULL; |
| 5190 | } else { |
| 5191 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5192 | return 1; |
| 5193 | } |
| 5194 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5195 | int res; |
| 5196 | Py_ssize_t len; |
| 5197 | Py_ssize_t i; |
| 5198 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5199 | if (tmp == NULL) goto failed; |
| 5200 | if (!PyList_Check(tmp)) { |
| 5201 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5202 | goto failed; |
| 5203 | } |
| 5204 | len = PyList_GET_SIZE(tmp); |
| 5205 | generators = asdl_seq_new(len, arena); |
| 5206 | if (generators == NULL) goto failed; |
| 5207 | for (i = 0; i < len; i++) { |
| 5208 | comprehension_ty value; |
| 5209 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5210 | if (res != 0) goto failed; |
| 5211 | asdl_seq_SET(generators, i, value); |
| 5212 | } |
| 5213 | Py_XDECREF(tmp); |
| 5214 | tmp = NULL; |
| 5215 | } else { |
| 5216 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5217 | return 1; |
| 5218 | } |
| 5219 | *out = DictComp(key, value, generators, lineno, col_offset, |
| 5220 | arena); |
| 5221 | if (*out == NULL) goto failed; |
| 5222 | return 0; |
| 5223 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5224 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5225 | if (isinstance == -1) { |
| 5226 | return 1; |
| 5227 | } |
| 5228 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5229 | expr_ty elt; |
| 5230 | asdl_seq* generators; |
| 5231 | |
| 5232 | if (PyObject_HasAttrString(obj, "elt")) { |
| 5233 | int res; |
| 5234 | tmp = PyObject_GetAttrString(obj, "elt"); |
| 5235 | if (tmp == NULL) goto failed; |
| 5236 | res = obj2ast_expr(tmp, &elt, arena); |
| 5237 | if (res != 0) goto failed; |
| 5238 | Py_XDECREF(tmp); |
| 5239 | tmp = NULL; |
| 5240 | } else { |
| 5241 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5242 | return 1; |
| 5243 | } |
| 5244 | if (PyObject_HasAttrString(obj, "generators")) { |
| 5245 | int res; |
| 5246 | Py_ssize_t len; |
| 5247 | Py_ssize_t i; |
| 5248 | tmp = PyObject_GetAttrString(obj, "generators"); |
| 5249 | if (tmp == NULL) goto failed; |
| 5250 | if (!PyList_Check(tmp)) { |
| 5251 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5252 | goto failed; |
| 5253 | } |
| 5254 | len = PyList_GET_SIZE(tmp); |
| 5255 | generators = asdl_seq_new(len, arena); |
| 5256 | if (generators == NULL) goto failed; |
| 5257 | for (i = 0; i < len; i++) { |
| 5258 | comprehension_ty value; |
| 5259 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5260 | if (res != 0) goto failed; |
| 5261 | asdl_seq_SET(generators, i, value); |
| 5262 | } |
| 5263 | Py_XDECREF(tmp); |
| 5264 | tmp = NULL; |
| 5265 | } else { |
| 5266 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5267 | return 1; |
| 5268 | } |
| 5269 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5270 | if (*out == NULL) goto failed; |
| 5271 | return 0; |
| 5272 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5273 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5274 | if (isinstance == -1) { |
| 5275 | return 1; |
| 5276 | } |
| 5277 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5278 | expr_ty value; |
| 5279 | |
| 5280 | if (PyObject_HasAttrString(obj, "value")) { |
| 5281 | int res; |
| 5282 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5283 | if (tmp == NULL) goto failed; |
| 5284 | res = obj2ast_expr(tmp, &value, arena); |
| 5285 | if (res != 0) goto failed; |
| 5286 | Py_XDECREF(tmp); |
| 5287 | tmp = NULL; |
| 5288 | } else { |
| 5289 | value = NULL; |
| 5290 | } |
| 5291 | *out = Yield(value, lineno, col_offset, arena); |
| 5292 | if (*out == NULL) goto failed; |
| 5293 | return 0; |
| 5294 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5295 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5296 | if (isinstance == -1) { |
| 5297 | return 1; |
| 5298 | } |
| 5299 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5300 | expr_ty left; |
| 5301 | asdl_int_seq* ops; |
| 5302 | asdl_seq* comparators; |
| 5303 | |
| 5304 | if (PyObject_HasAttrString(obj, "left")) { |
| 5305 | int res; |
| 5306 | tmp = PyObject_GetAttrString(obj, "left"); |
| 5307 | if (tmp == NULL) goto failed; |
| 5308 | res = obj2ast_expr(tmp, &left, arena); |
| 5309 | if (res != 0) goto failed; |
| 5310 | Py_XDECREF(tmp); |
| 5311 | tmp = NULL; |
| 5312 | } else { |
| 5313 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5314 | return 1; |
| 5315 | } |
| 5316 | if (PyObject_HasAttrString(obj, "ops")) { |
| 5317 | int res; |
| 5318 | Py_ssize_t len; |
| 5319 | Py_ssize_t i; |
| 5320 | tmp = PyObject_GetAttrString(obj, "ops"); |
| 5321 | if (tmp == NULL) goto failed; |
| 5322 | if (!PyList_Check(tmp)) { |
| 5323 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5324 | goto failed; |
| 5325 | } |
| 5326 | len = PyList_GET_SIZE(tmp); |
| 5327 | ops = asdl_int_seq_new(len, arena); |
| 5328 | if (ops == NULL) goto failed; |
| 5329 | for (i = 0; i < len; i++) { |
| 5330 | cmpop_ty value; |
| 5331 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5332 | if (res != 0) goto failed; |
| 5333 | asdl_seq_SET(ops, i, value); |
| 5334 | } |
| 5335 | Py_XDECREF(tmp); |
| 5336 | tmp = NULL; |
| 5337 | } else { |
| 5338 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5339 | return 1; |
| 5340 | } |
| 5341 | if (PyObject_HasAttrString(obj, "comparators")) { |
| 5342 | int res; |
| 5343 | Py_ssize_t len; |
| 5344 | Py_ssize_t i; |
| 5345 | tmp = PyObject_GetAttrString(obj, "comparators"); |
| 5346 | if (tmp == NULL) goto failed; |
| 5347 | if (!PyList_Check(tmp)) { |
| 5348 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5349 | goto failed; |
| 5350 | } |
| 5351 | len = PyList_GET_SIZE(tmp); |
| 5352 | comparators = asdl_seq_new(len, arena); |
| 5353 | if (comparators == NULL) goto failed; |
| 5354 | for (i = 0; i < len; i++) { |
| 5355 | expr_ty value; |
| 5356 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5357 | if (res != 0) goto failed; |
| 5358 | asdl_seq_SET(comparators, i, value); |
| 5359 | } |
| 5360 | Py_XDECREF(tmp); |
| 5361 | tmp = NULL; |
| 5362 | } else { |
| 5363 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5364 | return 1; |
| 5365 | } |
| 5366 | *out = Compare(left, ops, comparators, lineno, col_offset, |
| 5367 | arena); |
| 5368 | if (*out == NULL) goto failed; |
| 5369 | return 0; |
| 5370 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5371 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5372 | if (isinstance == -1) { |
| 5373 | return 1; |
| 5374 | } |
| 5375 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5376 | expr_ty func; |
| 5377 | asdl_seq* args; |
| 5378 | asdl_seq* keywords; |
| 5379 | expr_ty starargs; |
| 5380 | expr_ty kwargs; |
| 5381 | |
| 5382 | if (PyObject_HasAttrString(obj, "func")) { |
| 5383 | int res; |
| 5384 | tmp = PyObject_GetAttrString(obj, "func"); |
| 5385 | if (tmp == NULL) goto failed; |
| 5386 | res = obj2ast_expr(tmp, &func, arena); |
| 5387 | if (res != 0) goto failed; |
| 5388 | Py_XDECREF(tmp); |
| 5389 | tmp = NULL; |
| 5390 | } else { |
| 5391 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 5392 | return 1; |
| 5393 | } |
| 5394 | if (PyObject_HasAttrString(obj, "args")) { |
| 5395 | int res; |
| 5396 | Py_ssize_t len; |
| 5397 | Py_ssize_t i; |
| 5398 | tmp = PyObject_GetAttrString(obj, "args"); |
| 5399 | if (tmp == NULL) goto failed; |
| 5400 | if (!PyList_Check(tmp)) { |
| 5401 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5402 | goto failed; |
| 5403 | } |
| 5404 | len = PyList_GET_SIZE(tmp); |
| 5405 | args = asdl_seq_new(len, arena); |
| 5406 | if (args == NULL) goto failed; |
| 5407 | for (i = 0; i < len; i++) { |
| 5408 | expr_ty value; |
| 5409 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5410 | if (res != 0) goto failed; |
| 5411 | asdl_seq_SET(args, i, value); |
| 5412 | } |
| 5413 | Py_XDECREF(tmp); |
| 5414 | tmp = NULL; |
| 5415 | } else { |
| 5416 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 5417 | return 1; |
| 5418 | } |
| 5419 | if (PyObject_HasAttrString(obj, "keywords")) { |
| 5420 | int res; |
| 5421 | Py_ssize_t len; |
| 5422 | Py_ssize_t i; |
| 5423 | tmp = PyObject_GetAttrString(obj, "keywords"); |
| 5424 | if (tmp == NULL) goto failed; |
| 5425 | if (!PyList_Check(tmp)) { |
| 5426 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5427 | goto failed; |
| 5428 | } |
| 5429 | len = PyList_GET_SIZE(tmp); |
| 5430 | keywords = asdl_seq_new(len, arena); |
| 5431 | if (keywords == NULL) goto failed; |
| 5432 | for (i = 0; i < len; i++) { |
| 5433 | keyword_ty value; |
| 5434 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5435 | if (res != 0) goto failed; |
| 5436 | asdl_seq_SET(keywords, i, value); |
| 5437 | } |
| 5438 | Py_XDECREF(tmp); |
| 5439 | tmp = NULL; |
| 5440 | } else { |
| 5441 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 5442 | return 1; |
| 5443 | } |
| 5444 | if (PyObject_HasAttrString(obj, "starargs")) { |
| 5445 | int res; |
| 5446 | tmp = PyObject_GetAttrString(obj, "starargs"); |
| 5447 | if (tmp == NULL) goto failed; |
| 5448 | res = obj2ast_expr(tmp, &starargs, arena); |
| 5449 | if (res != 0) goto failed; |
| 5450 | Py_XDECREF(tmp); |
| 5451 | tmp = NULL; |
| 5452 | } else { |
| 5453 | starargs = NULL; |
| 5454 | } |
| 5455 | if (PyObject_HasAttrString(obj, "kwargs")) { |
| 5456 | int res; |
| 5457 | tmp = PyObject_GetAttrString(obj, "kwargs"); |
| 5458 | if (tmp == NULL) goto failed; |
| 5459 | res = obj2ast_expr(tmp, &kwargs, arena); |
| 5460 | if (res != 0) goto failed; |
| 5461 | Py_XDECREF(tmp); |
| 5462 | tmp = NULL; |
| 5463 | } else { |
| 5464 | kwargs = NULL; |
| 5465 | } |
| 5466 | *out = Call(func, args, keywords, starargs, kwargs, lineno, |
| 5467 | col_offset, arena); |
| 5468 | if (*out == NULL) goto failed; |
| 5469 | return 0; |
| 5470 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5471 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 5472 | if (isinstance == -1) { |
| 5473 | return 1; |
| 5474 | } |
| 5475 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5476 | object n; |
| 5477 | |
| 5478 | if (PyObject_HasAttrString(obj, "n")) { |
| 5479 | int res; |
| 5480 | tmp = PyObject_GetAttrString(obj, "n"); |
| 5481 | if (tmp == NULL) goto failed; |
| 5482 | res = obj2ast_object(tmp, &n, arena); |
| 5483 | if (res != 0) goto failed; |
| 5484 | Py_XDECREF(tmp); |
| 5485 | tmp = NULL; |
| 5486 | } else { |
| 5487 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 5488 | return 1; |
| 5489 | } |
| 5490 | *out = Num(n, lineno, col_offset, arena); |
| 5491 | if (*out == NULL) goto failed; |
| 5492 | return 0; |
| 5493 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5494 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 5495 | if (isinstance == -1) { |
| 5496 | return 1; |
| 5497 | } |
| 5498 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5499 | string s; |
| 5500 | |
| 5501 | if (PyObject_HasAttrString(obj, "s")) { |
| 5502 | int res; |
| 5503 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5504 | if (tmp == NULL) goto failed; |
| 5505 | res = obj2ast_string(tmp, &s, arena); |
| 5506 | if (res != 0) goto failed; |
| 5507 | Py_XDECREF(tmp); |
| 5508 | tmp = NULL; |
| 5509 | } else { |
| 5510 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 5511 | return 1; |
| 5512 | } |
| 5513 | *out = Str(s, lineno, col_offset, arena); |
| 5514 | if (*out == NULL) goto failed; |
| 5515 | return 0; |
| 5516 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5517 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 5518 | if (isinstance == -1) { |
| 5519 | return 1; |
| 5520 | } |
| 5521 | if (isinstance) { |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5522 | bytes s; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5523 | |
| 5524 | if (PyObject_HasAttrString(obj, "s")) { |
| 5525 | int res; |
| 5526 | tmp = PyObject_GetAttrString(obj, "s"); |
| 5527 | if (tmp == NULL) goto failed; |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 5528 | res = obj2ast_bytes(tmp, &s, arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5529 | if (res != 0) goto failed; |
| 5530 | Py_XDECREF(tmp); |
| 5531 | tmp = NULL; |
| 5532 | } else { |
| 5533 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 5534 | return 1; |
| 5535 | } |
| 5536 | *out = Bytes(s, 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*)Ellipsis_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 | |
| 5546 | *out = Ellipsis(lineno, col_offset, arena); |
| 5547 | if (*out == NULL) goto failed; |
| 5548 | return 0; |
| 5549 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5550 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 5551 | if (isinstance == -1) { |
| 5552 | return 1; |
| 5553 | } |
| 5554 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5555 | expr_ty value; |
| 5556 | identifier attr; |
| 5557 | expr_context_ty ctx; |
| 5558 | |
| 5559 | if (PyObject_HasAttrString(obj, "value")) { |
| 5560 | int res; |
| 5561 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5562 | if (tmp == NULL) goto failed; |
| 5563 | res = obj2ast_expr(tmp, &value, arena); |
| 5564 | if (res != 0) goto failed; |
| 5565 | Py_XDECREF(tmp); |
| 5566 | tmp = NULL; |
| 5567 | } else { |
| 5568 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 5569 | return 1; |
| 5570 | } |
| 5571 | if (PyObject_HasAttrString(obj, "attr")) { |
| 5572 | int res; |
| 5573 | tmp = PyObject_GetAttrString(obj, "attr"); |
| 5574 | if (tmp == NULL) goto failed; |
| 5575 | res = obj2ast_identifier(tmp, &attr, arena); |
| 5576 | if (res != 0) goto failed; |
| 5577 | Py_XDECREF(tmp); |
| 5578 | tmp = NULL; |
| 5579 | } else { |
| 5580 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 5581 | return 1; |
| 5582 | } |
| 5583 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5584 | int res; |
| 5585 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5586 | if (tmp == NULL) goto failed; |
| 5587 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5588 | if (res != 0) goto failed; |
| 5589 | Py_XDECREF(tmp); |
| 5590 | tmp = NULL; |
| 5591 | } else { |
| 5592 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 5593 | return 1; |
| 5594 | } |
| 5595 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 5596 | if (*out == NULL) goto failed; |
| 5597 | return 0; |
| 5598 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5599 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 5600 | if (isinstance == -1) { |
| 5601 | return 1; |
| 5602 | } |
| 5603 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5604 | expr_ty value; |
| 5605 | slice_ty slice; |
| 5606 | expr_context_ty ctx; |
| 5607 | |
| 5608 | if (PyObject_HasAttrString(obj, "value")) { |
| 5609 | int res; |
| 5610 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5611 | if (tmp == NULL) goto failed; |
| 5612 | res = obj2ast_expr(tmp, &value, arena); |
| 5613 | if (res != 0) goto failed; |
| 5614 | Py_XDECREF(tmp); |
| 5615 | tmp = NULL; |
| 5616 | } else { |
| 5617 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 5618 | return 1; |
| 5619 | } |
| 5620 | if (PyObject_HasAttrString(obj, "slice")) { |
| 5621 | int res; |
| 5622 | tmp = PyObject_GetAttrString(obj, "slice"); |
| 5623 | if (tmp == NULL) goto failed; |
| 5624 | res = obj2ast_slice(tmp, &slice, arena); |
| 5625 | if (res != 0) goto failed; |
| 5626 | Py_XDECREF(tmp); |
| 5627 | tmp = NULL; |
| 5628 | } else { |
| 5629 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 5630 | return 1; |
| 5631 | } |
| 5632 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5633 | int res; |
| 5634 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5635 | if (tmp == NULL) goto failed; |
| 5636 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5637 | if (res != 0) goto failed; |
| 5638 | Py_XDECREF(tmp); |
| 5639 | tmp = NULL; |
| 5640 | } else { |
| 5641 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 5642 | return 1; |
| 5643 | } |
| 5644 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 5645 | if (*out == NULL) goto failed; |
| 5646 | return 0; |
| 5647 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5648 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 5649 | if (isinstance == -1) { |
| 5650 | return 1; |
| 5651 | } |
| 5652 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5653 | expr_ty value; |
| 5654 | expr_context_ty ctx; |
| 5655 | |
| 5656 | if (PyObject_HasAttrString(obj, "value")) { |
| 5657 | int res; |
| 5658 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5659 | if (tmp == NULL) goto failed; |
| 5660 | res = obj2ast_expr(tmp, &value, arena); |
| 5661 | if (res != 0) goto failed; |
| 5662 | Py_XDECREF(tmp); |
| 5663 | tmp = NULL; |
| 5664 | } else { |
| 5665 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 5666 | return 1; |
| 5667 | } |
| 5668 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5669 | int res; |
| 5670 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5671 | if (tmp == NULL) goto failed; |
| 5672 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5673 | if (res != 0) goto failed; |
| 5674 | Py_XDECREF(tmp); |
| 5675 | tmp = NULL; |
| 5676 | } else { |
| 5677 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 5678 | return 1; |
| 5679 | } |
| 5680 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 5681 | if (*out == NULL) goto failed; |
| 5682 | return 0; |
| 5683 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5684 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 5685 | if (isinstance == -1) { |
| 5686 | return 1; |
| 5687 | } |
| 5688 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5689 | identifier id; |
| 5690 | expr_context_ty ctx; |
| 5691 | |
| 5692 | if (PyObject_HasAttrString(obj, "id")) { |
| 5693 | int res; |
| 5694 | tmp = PyObject_GetAttrString(obj, "id"); |
| 5695 | if (tmp == NULL) goto failed; |
| 5696 | res = obj2ast_identifier(tmp, &id, arena); |
| 5697 | if (res != 0) goto failed; |
| 5698 | Py_XDECREF(tmp); |
| 5699 | tmp = NULL; |
| 5700 | } else { |
| 5701 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 5702 | return 1; |
| 5703 | } |
| 5704 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5705 | int res; |
| 5706 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5707 | if (tmp == NULL) goto failed; |
| 5708 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5709 | if (res != 0) goto failed; |
| 5710 | Py_XDECREF(tmp); |
| 5711 | tmp = NULL; |
| 5712 | } else { |
| 5713 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 5714 | return 1; |
| 5715 | } |
| 5716 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 5717 | if (*out == NULL) goto failed; |
| 5718 | return 0; |
| 5719 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5720 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 5721 | if (isinstance == -1) { |
| 5722 | return 1; |
| 5723 | } |
| 5724 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5725 | asdl_seq* elts; |
| 5726 | expr_context_ty ctx; |
| 5727 | |
| 5728 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5729 | int res; |
| 5730 | Py_ssize_t len; |
| 5731 | Py_ssize_t i; |
| 5732 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5733 | if (tmp == NULL) goto failed; |
| 5734 | if (!PyList_Check(tmp)) { |
| 5735 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5736 | goto failed; |
| 5737 | } |
| 5738 | len = PyList_GET_SIZE(tmp); |
| 5739 | elts = asdl_seq_new(len, arena); |
| 5740 | if (elts == NULL) goto failed; |
| 5741 | for (i = 0; i < len; i++) { |
| 5742 | expr_ty value; |
| 5743 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5744 | if (res != 0) goto failed; |
| 5745 | asdl_seq_SET(elts, i, value); |
| 5746 | } |
| 5747 | Py_XDECREF(tmp); |
| 5748 | tmp = NULL; |
| 5749 | } else { |
| 5750 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 5751 | return 1; |
| 5752 | } |
| 5753 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5754 | int res; |
| 5755 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5756 | if (tmp == NULL) goto failed; |
| 5757 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5758 | if (res != 0) goto failed; |
| 5759 | Py_XDECREF(tmp); |
| 5760 | tmp = NULL; |
| 5761 | } else { |
| 5762 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 5763 | return 1; |
| 5764 | } |
| 5765 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 5766 | if (*out == NULL) goto failed; |
| 5767 | return 0; |
| 5768 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5769 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 5770 | if (isinstance == -1) { |
| 5771 | return 1; |
| 5772 | } |
| 5773 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5774 | asdl_seq* elts; |
| 5775 | expr_context_ty ctx; |
| 5776 | |
| 5777 | if (PyObject_HasAttrString(obj, "elts")) { |
| 5778 | int res; |
| 5779 | Py_ssize_t len; |
| 5780 | Py_ssize_t i; |
| 5781 | tmp = PyObject_GetAttrString(obj, "elts"); |
| 5782 | if (tmp == NULL) goto failed; |
| 5783 | if (!PyList_Check(tmp)) { |
| 5784 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5785 | goto failed; |
| 5786 | } |
| 5787 | len = PyList_GET_SIZE(tmp); |
| 5788 | elts = asdl_seq_new(len, arena); |
| 5789 | if (elts == NULL) goto failed; |
| 5790 | for (i = 0; i < len; i++) { |
| 5791 | expr_ty value; |
| 5792 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5793 | if (res != 0) goto failed; |
| 5794 | asdl_seq_SET(elts, i, value); |
| 5795 | } |
| 5796 | Py_XDECREF(tmp); |
| 5797 | tmp = NULL; |
| 5798 | } else { |
| 5799 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 5800 | return 1; |
| 5801 | } |
| 5802 | if (PyObject_HasAttrString(obj, "ctx")) { |
| 5803 | int res; |
| 5804 | tmp = PyObject_GetAttrString(obj, "ctx"); |
| 5805 | if (tmp == NULL) goto failed; |
| 5806 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 5807 | if (res != 0) goto failed; |
| 5808 | Py_XDECREF(tmp); |
| 5809 | tmp = NULL; |
| 5810 | } else { |
| 5811 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 5812 | return 1; |
| 5813 | } |
| 5814 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 5815 | if (*out == NULL) goto failed; |
| 5816 | return 0; |
| 5817 | } |
| 5818 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5819 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 5820 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 5821 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5822 | return 1; |
| 5823 | } |
| 5824 | |
| 5825 | int |
| 5826 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 5827 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5828 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5829 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5830 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 5831 | if (isinstance == -1) { |
| 5832 | return 1; |
| 5833 | } |
| 5834 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5835 | *out = Load; |
| 5836 | return 0; |
| 5837 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5838 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 5839 | if (isinstance == -1) { |
| 5840 | return 1; |
| 5841 | } |
| 5842 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5843 | *out = Store; |
| 5844 | return 0; |
| 5845 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5846 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 5847 | if (isinstance == -1) { |
| 5848 | return 1; |
| 5849 | } |
| 5850 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5851 | *out = Del; |
| 5852 | return 0; |
| 5853 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5854 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 5855 | if (isinstance == -1) { |
| 5856 | return 1; |
| 5857 | } |
| 5858 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5859 | *out = AugLoad; |
| 5860 | return 0; |
| 5861 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5862 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 5863 | if (isinstance == -1) { |
| 5864 | return 1; |
| 5865 | } |
| 5866 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5867 | *out = AugStore; |
| 5868 | return 0; |
| 5869 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5870 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 5871 | if (isinstance == -1) { |
| 5872 | return 1; |
| 5873 | } |
| 5874 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5875 | *out = Param; |
| 5876 | return 0; |
| 5877 | } |
| 5878 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 5879 | 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] | 5880 | return 1; |
| 5881 | } |
| 5882 | |
| 5883 | int |
| 5884 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 5885 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5886 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5887 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 5888 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5889 | |
| 5890 | if (obj == Py_None) { |
| 5891 | *out = NULL; |
| 5892 | return 0; |
| 5893 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5894 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 5895 | if (isinstance == -1) { |
| 5896 | return 1; |
| 5897 | } |
| 5898 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5899 | expr_ty lower; |
| 5900 | expr_ty upper; |
| 5901 | expr_ty step; |
| 5902 | |
| 5903 | if (PyObject_HasAttrString(obj, "lower")) { |
| 5904 | int res; |
| 5905 | tmp = PyObject_GetAttrString(obj, "lower"); |
| 5906 | if (tmp == NULL) goto failed; |
| 5907 | res = obj2ast_expr(tmp, &lower, arena); |
| 5908 | if (res != 0) goto failed; |
| 5909 | Py_XDECREF(tmp); |
| 5910 | tmp = NULL; |
| 5911 | } else { |
| 5912 | lower = NULL; |
| 5913 | } |
| 5914 | if (PyObject_HasAttrString(obj, "upper")) { |
| 5915 | int res; |
| 5916 | tmp = PyObject_GetAttrString(obj, "upper"); |
| 5917 | if (tmp == NULL) goto failed; |
| 5918 | res = obj2ast_expr(tmp, &upper, arena); |
| 5919 | if (res != 0) goto failed; |
| 5920 | Py_XDECREF(tmp); |
| 5921 | tmp = NULL; |
| 5922 | } else { |
| 5923 | upper = NULL; |
| 5924 | } |
| 5925 | if (PyObject_HasAttrString(obj, "step")) { |
| 5926 | int res; |
| 5927 | tmp = PyObject_GetAttrString(obj, "step"); |
| 5928 | if (tmp == NULL) goto failed; |
| 5929 | res = obj2ast_expr(tmp, &step, arena); |
| 5930 | if (res != 0) goto failed; |
| 5931 | Py_XDECREF(tmp); |
| 5932 | tmp = NULL; |
| 5933 | } else { |
| 5934 | step = NULL; |
| 5935 | } |
| 5936 | *out = Slice(lower, upper, step, arena); |
| 5937 | if (*out == NULL) goto failed; |
| 5938 | return 0; |
| 5939 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5940 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 5941 | if (isinstance == -1) { |
| 5942 | return 1; |
| 5943 | } |
| 5944 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5945 | asdl_seq* dims; |
| 5946 | |
| 5947 | if (PyObject_HasAttrString(obj, "dims")) { |
| 5948 | int res; |
| 5949 | Py_ssize_t len; |
| 5950 | Py_ssize_t i; |
| 5951 | tmp = PyObject_GetAttrString(obj, "dims"); |
| 5952 | if (tmp == NULL) goto failed; |
| 5953 | if (!PyList_Check(tmp)) { |
| 5954 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5955 | goto failed; |
| 5956 | } |
| 5957 | len = PyList_GET_SIZE(tmp); |
| 5958 | dims = asdl_seq_new(len, arena); |
| 5959 | if (dims == NULL) goto failed; |
| 5960 | for (i = 0; i < len; i++) { |
| 5961 | slice_ty value; |
| 5962 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5963 | if (res != 0) goto failed; |
| 5964 | asdl_seq_SET(dims, i, value); |
| 5965 | } |
| 5966 | Py_XDECREF(tmp); |
| 5967 | tmp = NULL; |
| 5968 | } else { |
| 5969 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 5970 | return 1; |
| 5971 | } |
| 5972 | *out = ExtSlice(dims, arena); |
| 5973 | if (*out == NULL) goto failed; |
| 5974 | return 0; |
| 5975 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 5976 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 5977 | if (isinstance == -1) { |
| 5978 | return 1; |
| 5979 | } |
| 5980 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5981 | expr_ty value; |
| 5982 | |
| 5983 | if (PyObject_HasAttrString(obj, "value")) { |
| 5984 | int res; |
| 5985 | tmp = PyObject_GetAttrString(obj, "value"); |
| 5986 | if (tmp == NULL) goto failed; |
| 5987 | res = obj2ast_expr(tmp, &value, arena); |
| 5988 | if (res != 0) goto failed; |
| 5989 | Py_XDECREF(tmp); |
| 5990 | tmp = NULL; |
| 5991 | } else { |
| 5992 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 5993 | return 1; |
| 5994 | } |
| 5995 | *out = Index(value, arena); |
| 5996 | if (*out == NULL) goto failed; |
| 5997 | return 0; |
| 5998 | } |
| 5999 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6000 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6001 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6002 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6003 | return 1; |
| 6004 | } |
| 6005 | |
| 6006 | int |
| 6007 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6008 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6009 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6010 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6011 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6012 | if (isinstance == -1) { |
| 6013 | return 1; |
| 6014 | } |
| 6015 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6016 | *out = And; |
| 6017 | return 0; |
| 6018 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6019 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6020 | if (isinstance == -1) { |
| 6021 | return 1; |
| 6022 | } |
| 6023 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6024 | *out = Or; |
| 6025 | return 0; |
| 6026 | } |
| 6027 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6028 | 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] | 6029 | return 1; |
| 6030 | } |
| 6031 | |
| 6032 | int |
| 6033 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6034 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6035 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6036 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6037 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6038 | if (isinstance == -1) { |
| 6039 | return 1; |
| 6040 | } |
| 6041 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6042 | *out = Add; |
| 6043 | return 0; |
| 6044 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6045 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6046 | if (isinstance == -1) { |
| 6047 | return 1; |
| 6048 | } |
| 6049 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6050 | *out = Sub; |
| 6051 | return 0; |
| 6052 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6053 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6054 | if (isinstance == -1) { |
| 6055 | return 1; |
| 6056 | } |
| 6057 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6058 | *out = Mult; |
| 6059 | return 0; |
| 6060 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6061 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6062 | if (isinstance == -1) { |
| 6063 | return 1; |
| 6064 | } |
| 6065 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6066 | *out = Div; |
| 6067 | return 0; |
| 6068 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6069 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6070 | if (isinstance == -1) { |
| 6071 | return 1; |
| 6072 | } |
| 6073 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6074 | *out = Mod; |
| 6075 | return 0; |
| 6076 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6077 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6078 | if (isinstance == -1) { |
| 6079 | return 1; |
| 6080 | } |
| 6081 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6082 | *out = Pow; |
| 6083 | return 0; |
| 6084 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6085 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6086 | if (isinstance == -1) { |
| 6087 | return 1; |
| 6088 | } |
| 6089 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6090 | *out = LShift; |
| 6091 | return 0; |
| 6092 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6093 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6094 | if (isinstance == -1) { |
| 6095 | return 1; |
| 6096 | } |
| 6097 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6098 | *out = RShift; |
| 6099 | return 0; |
| 6100 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6101 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6102 | if (isinstance == -1) { |
| 6103 | return 1; |
| 6104 | } |
| 6105 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6106 | *out = BitOr; |
| 6107 | return 0; |
| 6108 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6109 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6110 | if (isinstance == -1) { |
| 6111 | return 1; |
| 6112 | } |
| 6113 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6114 | *out = BitXor; |
| 6115 | return 0; |
| 6116 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6117 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6118 | if (isinstance == -1) { |
| 6119 | return 1; |
| 6120 | } |
| 6121 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6122 | *out = BitAnd; |
| 6123 | return 0; |
| 6124 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6125 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6126 | if (isinstance == -1) { |
| 6127 | return 1; |
| 6128 | } |
| 6129 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6130 | *out = FloorDiv; |
| 6131 | return 0; |
| 6132 | } |
| 6133 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6134 | 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] | 6135 | return 1; |
| 6136 | } |
| 6137 | |
| 6138 | int |
| 6139 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6140 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6141 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6142 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6143 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6144 | if (isinstance == -1) { |
| 6145 | return 1; |
| 6146 | } |
| 6147 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6148 | *out = Invert; |
| 6149 | return 0; |
| 6150 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6151 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6152 | if (isinstance == -1) { |
| 6153 | return 1; |
| 6154 | } |
| 6155 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6156 | *out = Not; |
| 6157 | return 0; |
| 6158 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6159 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6160 | if (isinstance == -1) { |
| 6161 | return 1; |
| 6162 | } |
| 6163 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6164 | *out = UAdd; |
| 6165 | return 0; |
| 6166 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6167 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6168 | if (isinstance == -1) { |
| 6169 | return 1; |
| 6170 | } |
| 6171 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6172 | *out = USub; |
| 6173 | return 0; |
| 6174 | } |
| 6175 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6176 | 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] | 6177 | return 1; |
| 6178 | } |
| 6179 | |
| 6180 | int |
| 6181 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6182 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6183 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6184 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6185 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6186 | if (isinstance == -1) { |
| 6187 | return 1; |
| 6188 | } |
| 6189 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6190 | *out = Eq; |
| 6191 | return 0; |
| 6192 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6193 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6194 | if (isinstance == -1) { |
| 6195 | return 1; |
| 6196 | } |
| 6197 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6198 | *out = NotEq; |
| 6199 | return 0; |
| 6200 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6201 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6202 | if (isinstance == -1) { |
| 6203 | return 1; |
| 6204 | } |
| 6205 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6206 | *out = Lt; |
| 6207 | return 0; |
| 6208 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6209 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6210 | if (isinstance == -1) { |
| 6211 | return 1; |
| 6212 | } |
| 6213 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6214 | *out = LtE; |
| 6215 | return 0; |
| 6216 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6217 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6218 | if (isinstance == -1) { |
| 6219 | return 1; |
| 6220 | } |
| 6221 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6222 | *out = Gt; |
| 6223 | return 0; |
| 6224 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6225 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6226 | if (isinstance == -1) { |
| 6227 | return 1; |
| 6228 | } |
| 6229 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6230 | *out = GtE; |
| 6231 | return 0; |
| 6232 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6233 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6234 | if (isinstance == -1) { |
| 6235 | return 1; |
| 6236 | } |
| 6237 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6238 | *out = Is; |
| 6239 | return 0; |
| 6240 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6241 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6242 | if (isinstance == -1) { |
| 6243 | return 1; |
| 6244 | } |
| 6245 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6246 | *out = IsNot; |
| 6247 | return 0; |
| 6248 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6249 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6250 | if (isinstance == -1) { |
| 6251 | return 1; |
| 6252 | } |
| 6253 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6254 | *out = In; |
| 6255 | return 0; |
| 6256 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6257 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6258 | if (isinstance == -1) { |
| 6259 | return 1; |
| 6260 | } |
| 6261 | if (isinstance) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6262 | *out = NotIn; |
| 6263 | return 0; |
| 6264 | } |
| 6265 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6266 | 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] | 6267 | return 1; |
| 6268 | } |
| 6269 | |
| 6270 | int |
| 6271 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6272 | { |
| 6273 | PyObject* tmp = NULL; |
| 6274 | expr_ty target; |
| 6275 | expr_ty iter; |
| 6276 | asdl_seq* ifs; |
| 6277 | |
| 6278 | if (PyObject_HasAttrString(obj, "target")) { |
| 6279 | int res; |
| 6280 | tmp = PyObject_GetAttrString(obj, "target"); |
| 6281 | if (tmp == NULL) goto failed; |
| 6282 | res = obj2ast_expr(tmp, &target, arena); |
| 6283 | if (res != 0) goto failed; |
| 6284 | Py_XDECREF(tmp); |
| 6285 | tmp = NULL; |
| 6286 | } else { |
| 6287 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 6288 | return 1; |
| 6289 | } |
| 6290 | if (PyObject_HasAttrString(obj, "iter")) { |
| 6291 | int res; |
| 6292 | tmp = PyObject_GetAttrString(obj, "iter"); |
| 6293 | if (tmp == NULL) goto failed; |
| 6294 | res = obj2ast_expr(tmp, &iter, arena); |
| 6295 | if (res != 0) goto failed; |
| 6296 | Py_XDECREF(tmp); |
| 6297 | tmp = NULL; |
| 6298 | } else { |
| 6299 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6300 | return 1; |
| 6301 | } |
| 6302 | if (PyObject_HasAttrString(obj, "ifs")) { |
| 6303 | int res; |
| 6304 | Py_ssize_t len; |
| 6305 | Py_ssize_t i; |
| 6306 | tmp = PyObject_GetAttrString(obj, "ifs"); |
| 6307 | if (tmp == NULL) goto failed; |
| 6308 | if (!PyList_Check(tmp)) { |
| 6309 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6310 | goto failed; |
| 6311 | } |
| 6312 | len = PyList_GET_SIZE(tmp); |
| 6313 | ifs = asdl_seq_new(len, arena); |
| 6314 | if (ifs == NULL) goto failed; |
| 6315 | for (i = 0; i < len; i++) { |
| 6316 | expr_ty value; |
| 6317 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6318 | if (res != 0) goto failed; |
| 6319 | asdl_seq_SET(ifs, i, value); |
| 6320 | } |
| 6321 | Py_XDECREF(tmp); |
| 6322 | tmp = NULL; |
| 6323 | } else { |
| 6324 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 6325 | return 1; |
| 6326 | } |
| 6327 | *out = comprehension(target, iter, ifs, arena); |
| 6328 | return 0; |
| 6329 | failed: |
| 6330 | Py_XDECREF(tmp); |
| 6331 | return 1; |
| 6332 | } |
| 6333 | |
| 6334 | int |
| 6335 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 6336 | { |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6337 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6338 | |
Benjamin Peterson | d8f6597 | 2010-11-20 04:31:07 +0000 | [diff] [blame] | 6339 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6340 | int lineno; |
| 6341 | int col_offset; |
| 6342 | |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6343 | if (obj == Py_None) { |
| 6344 | *out = NULL; |
| 6345 | return 0; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6346 | } |
| 6347 | if (PyObject_HasAttrString(obj, "lineno")) { |
| 6348 | int res; |
| 6349 | tmp = PyObject_GetAttrString(obj, "lineno"); |
| 6350 | if (tmp == NULL) goto failed; |
| 6351 | res = obj2ast_int(tmp, &lineno, arena); |
| 6352 | if (res != 0) goto failed; |
| 6353 | Py_XDECREF(tmp); |
| 6354 | tmp = NULL; |
| 6355 | } else { |
| 6356 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 6357 | return 1; |
| 6358 | } |
| 6359 | if (PyObject_HasAttrString(obj, "col_offset")) { |
| 6360 | int res; |
| 6361 | tmp = PyObject_GetAttrString(obj, "col_offset"); |
| 6362 | if (tmp == NULL) goto failed; |
| 6363 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6364 | if (res != 0) goto failed; |
| 6365 | Py_XDECREF(tmp); |
| 6366 | tmp = NULL; |
| 6367 | } else { |
| 6368 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 6369 | return 1; |
| 6370 | } |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6371 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 6372 | if (isinstance == -1) { |
| 6373 | return 1; |
| 6374 | } |
| 6375 | if (isinstance) { |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6376 | expr_ty type; |
| 6377 | identifier name; |
| 6378 | asdl_seq* body; |
| 6379 | |
| 6380 | if (PyObject_HasAttrString(obj, "type")) { |
| 6381 | int res; |
| 6382 | tmp = PyObject_GetAttrString(obj, "type"); |
| 6383 | if (tmp == NULL) goto failed; |
| 6384 | res = obj2ast_expr(tmp, &type, arena); |
| 6385 | if (res != 0) goto failed; |
| 6386 | Py_XDECREF(tmp); |
| 6387 | tmp = NULL; |
| 6388 | } else { |
| 6389 | type = NULL; |
| 6390 | } |
| 6391 | if (PyObject_HasAttrString(obj, "name")) { |
| 6392 | int res; |
| 6393 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6394 | if (tmp == NULL) goto failed; |
| 6395 | res = obj2ast_identifier(tmp, &name, arena); |
| 6396 | if (res != 0) goto failed; |
| 6397 | Py_XDECREF(tmp); |
| 6398 | tmp = NULL; |
| 6399 | } else { |
| 6400 | name = NULL; |
| 6401 | } |
| 6402 | if (PyObject_HasAttrString(obj, "body")) { |
| 6403 | int res; |
| 6404 | Py_ssize_t len; |
| 6405 | Py_ssize_t i; |
| 6406 | tmp = PyObject_GetAttrString(obj, "body"); |
| 6407 | if (tmp == NULL) goto failed; |
| 6408 | if (!PyList_Check(tmp)) { |
| 6409 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6410 | goto failed; |
| 6411 | } |
| 6412 | len = PyList_GET_SIZE(tmp); |
| 6413 | body = asdl_seq_new(len, arena); |
| 6414 | if (body == NULL) goto failed; |
| 6415 | for (i = 0; i < len; i++) { |
| 6416 | stmt_ty value; |
| 6417 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6418 | if (res != 0) goto failed; |
| 6419 | asdl_seq_SET(body, i, value); |
| 6420 | } |
| 6421 | Py_XDECREF(tmp); |
| 6422 | tmp = NULL; |
| 6423 | } else { |
| 6424 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 6425 | return 1; |
| 6426 | } |
| 6427 | *out = ExceptHandler(type, name, body, lineno, col_offset, |
| 6428 | arena); |
| 6429 | if (*out == NULL) goto failed; |
| 6430 | return 0; |
| 6431 | } |
| 6432 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 6433 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 6434 | failed: |
Benjamin Peterson | 0a4dae5 | 2010-11-21 15:12:34 +0000 | [diff] [blame] | 6435 | Py_XDECREF(tmp); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6436 | return 1; |
| 6437 | } |
| 6438 | |
| 6439 | int |
| 6440 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 6441 | { |
| 6442 | PyObject* tmp = NULL; |
| 6443 | asdl_seq* args; |
| 6444 | identifier vararg; |
| 6445 | expr_ty varargannotation; |
| 6446 | asdl_seq* kwonlyargs; |
| 6447 | identifier kwarg; |
| 6448 | expr_ty kwargannotation; |
| 6449 | asdl_seq* defaults; |
| 6450 | asdl_seq* kw_defaults; |
| 6451 | |
| 6452 | if (PyObject_HasAttrString(obj, "args")) { |
| 6453 | int res; |
| 6454 | Py_ssize_t len; |
| 6455 | Py_ssize_t i; |
| 6456 | tmp = PyObject_GetAttrString(obj, "args"); |
| 6457 | if (tmp == NULL) goto failed; |
| 6458 | if (!PyList_Check(tmp)) { |
| 6459 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6460 | goto failed; |
| 6461 | } |
| 6462 | len = PyList_GET_SIZE(tmp); |
| 6463 | args = asdl_seq_new(len, arena); |
| 6464 | if (args == NULL) goto failed; |
| 6465 | for (i = 0; i < len; i++) { |
| 6466 | arg_ty value; |
| 6467 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6468 | if (res != 0) goto failed; |
| 6469 | asdl_seq_SET(args, i, value); |
| 6470 | } |
| 6471 | Py_XDECREF(tmp); |
| 6472 | tmp = NULL; |
| 6473 | } else { |
| 6474 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 6475 | return 1; |
| 6476 | } |
| 6477 | if (PyObject_HasAttrString(obj, "vararg")) { |
| 6478 | int res; |
| 6479 | tmp = PyObject_GetAttrString(obj, "vararg"); |
| 6480 | if (tmp == NULL) goto failed; |
| 6481 | res = obj2ast_identifier(tmp, &vararg, arena); |
| 6482 | if (res != 0) goto failed; |
| 6483 | Py_XDECREF(tmp); |
| 6484 | tmp = NULL; |
| 6485 | } else { |
| 6486 | vararg = NULL; |
| 6487 | } |
| 6488 | if (PyObject_HasAttrString(obj, "varargannotation")) { |
| 6489 | int res; |
| 6490 | tmp = PyObject_GetAttrString(obj, "varargannotation"); |
| 6491 | if (tmp == NULL) goto failed; |
| 6492 | res = obj2ast_expr(tmp, &varargannotation, arena); |
| 6493 | if (res != 0) goto failed; |
| 6494 | Py_XDECREF(tmp); |
| 6495 | tmp = NULL; |
| 6496 | } else { |
| 6497 | varargannotation = NULL; |
| 6498 | } |
| 6499 | if (PyObject_HasAttrString(obj, "kwonlyargs")) { |
| 6500 | int res; |
| 6501 | Py_ssize_t len; |
| 6502 | Py_ssize_t i; |
| 6503 | tmp = PyObject_GetAttrString(obj, "kwonlyargs"); |
| 6504 | if (tmp == NULL) goto failed; |
| 6505 | if (!PyList_Check(tmp)) { |
| 6506 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6507 | goto failed; |
| 6508 | } |
| 6509 | len = PyList_GET_SIZE(tmp); |
| 6510 | kwonlyargs = asdl_seq_new(len, arena); |
| 6511 | if (kwonlyargs == NULL) goto failed; |
| 6512 | for (i = 0; i < len; i++) { |
| 6513 | arg_ty value; |
| 6514 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6515 | if (res != 0) goto failed; |
| 6516 | asdl_seq_SET(kwonlyargs, i, value); |
| 6517 | } |
| 6518 | Py_XDECREF(tmp); |
| 6519 | tmp = NULL; |
| 6520 | } else { |
| 6521 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 6522 | return 1; |
| 6523 | } |
| 6524 | if (PyObject_HasAttrString(obj, "kwarg")) { |
| 6525 | int res; |
| 6526 | tmp = PyObject_GetAttrString(obj, "kwarg"); |
| 6527 | if (tmp == NULL) goto failed; |
| 6528 | res = obj2ast_identifier(tmp, &kwarg, arena); |
| 6529 | if (res != 0) goto failed; |
| 6530 | Py_XDECREF(tmp); |
| 6531 | tmp = NULL; |
| 6532 | } else { |
| 6533 | kwarg = NULL; |
| 6534 | } |
| 6535 | if (PyObject_HasAttrString(obj, "kwargannotation")) { |
| 6536 | int res; |
| 6537 | tmp = PyObject_GetAttrString(obj, "kwargannotation"); |
| 6538 | if (tmp == NULL) goto failed; |
| 6539 | res = obj2ast_expr(tmp, &kwargannotation, arena); |
| 6540 | if (res != 0) goto failed; |
| 6541 | Py_XDECREF(tmp); |
| 6542 | tmp = NULL; |
| 6543 | } else { |
| 6544 | kwargannotation = NULL; |
| 6545 | } |
| 6546 | if (PyObject_HasAttrString(obj, "defaults")) { |
| 6547 | int res; |
| 6548 | Py_ssize_t len; |
| 6549 | Py_ssize_t i; |
| 6550 | tmp = PyObject_GetAttrString(obj, "defaults"); |
| 6551 | if (tmp == NULL) goto failed; |
| 6552 | if (!PyList_Check(tmp)) { |
| 6553 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6554 | goto failed; |
| 6555 | } |
| 6556 | len = PyList_GET_SIZE(tmp); |
| 6557 | defaults = asdl_seq_new(len, arena); |
| 6558 | if (defaults == NULL) goto failed; |
| 6559 | for (i = 0; i < len; i++) { |
| 6560 | expr_ty value; |
| 6561 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6562 | if (res != 0) goto failed; |
| 6563 | asdl_seq_SET(defaults, i, value); |
| 6564 | } |
| 6565 | Py_XDECREF(tmp); |
| 6566 | tmp = NULL; |
| 6567 | } else { |
| 6568 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 6569 | return 1; |
| 6570 | } |
| 6571 | if (PyObject_HasAttrString(obj, "kw_defaults")) { |
| 6572 | int res; |
| 6573 | Py_ssize_t len; |
| 6574 | Py_ssize_t i; |
| 6575 | tmp = PyObject_GetAttrString(obj, "kw_defaults"); |
| 6576 | if (tmp == NULL) goto failed; |
| 6577 | if (!PyList_Check(tmp)) { |
| 6578 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6579 | goto failed; |
| 6580 | } |
| 6581 | len = PyList_GET_SIZE(tmp); |
| 6582 | kw_defaults = asdl_seq_new(len, arena); |
| 6583 | if (kw_defaults == NULL) goto failed; |
| 6584 | for (i = 0; i < len; i++) { |
| 6585 | expr_ty value; |
| 6586 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6587 | if (res != 0) goto failed; |
| 6588 | asdl_seq_SET(kw_defaults, i, value); |
| 6589 | } |
| 6590 | Py_XDECREF(tmp); |
| 6591 | tmp = NULL; |
| 6592 | } else { |
| 6593 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 6594 | return 1; |
| 6595 | } |
| 6596 | *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg, |
| 6597 | kwargannotation, defaults, kw_defaults, arena); |
| 6598 | return 0; |
| 6599 | failed: |
| 6600 | Py_XDECREF(tmp); |
| 6601 | return 1; |
| 6602 | } |
| 6603 | |
| 6604 | int |
| 6605 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 6606 | { |
| 6607 | PyObject* tmp = NULL; |
| 6608 | identifier arg; |
| 6609 | expr_ty annotation; |
| 6610 | |
| 6611 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6612 | int res; |
| 6613 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6614 | if (tmp == NULL) goto failed; |
| 6615 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6616 | if (res != 0) goto failed; |
| 6617 | Py_XDECREF(tmp); |
| 6618 | tmp = NULL; |
| 6619 | } else { |
| 6620 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 6621 | return 1; |
| 6622 | } |
| 6623 | if (PyObject_HasAttrString(obj, "annotation")) { |
| 6624 | int res; |
| 6625 | tmp = PyObject_GetAttrString(obj, "annotation"); |
| 6626 | if (tmp == NULL) goto failed; |
| 6627 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6628 | if (res != 0) goto failed; |
| 6629 | Py_XDECREF(tmp); |
| 6630 | tmp = NULL; |
| 6631 | } else { |
| 6632 | annotation = NULL; |
| 6633 | } |
| 6634 | *out = arg(arg, annotation, arena); |
| 6635 | return 0; |
| 6636 | failed: |
| 6637 | Py_XDECREF(tmp); |
| 6638 | return 1; |
| 6639 | } |
| 6640 | |
| 6641 | int |
| 6642 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 6643 | { |
| 6644 | PyObject* tmp = NULL; |
| 6645 | identifier arg; |
| 6646 | expr_ty value; |
| 6647 | |
| 6648 | if (PyObject_HasAttrString(obj, "arg")) { |
| 6649 | int res; |
| 6650 | tmp = PyObject_GetAttrString(obj, "arg"); |
| 6651 | if (tmp == NULL) goto failed; |
| 6652 | res = obj2ast_identifier(tmp, &arg, arena); |
| 6653 | if (res != 0) goto failed; |
| 6654 | Py_XDECREF(tmp); |
| 6655 | tmp = NULL; |
| 6656 | } else { |
| 6657 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); |
| 6658 | return 1; |
| 6659 | } |
| 6660 | if (PyObject_HasAttrString(obj, "value")) { |
| 6661 | int res; |
| 6662 | tmp = PyObject_GetAttrString(obj, "value"); |
| 6663 | if (tmp == NULL) goto failed; |
| 6664 | res = obj2ast_expr(tmp, &value, arena); |
| 6665 | if (res != 0) goto failed; |
| 6666 | Py_XDECREF(tmp); |
| 6667 | tmp = NULL; |
| 6668 | } else { |
| 6669 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 6670 | return 1; |
| 6671 | } |
| 6672 | *out = keyword(arg, value, arena); |
| 6673 | return 0; |
| 6674 | failed: |
| 6675 | Py_XDECREF(tmp); |
| 6676 | return 1; |
| 6677 | } |
| 6678 | |
| 6679 | int |
| 6680 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 6681 | { |
| 6682 | PyObject* tmp = NULL; |
| 6683 | identifier name; |
| 6684 | identifier asname; |
| 6685 | |
| 6686 | if (PyObject_HasAttrString(obj, "name")) { |
| 6687 | int res; |
| 6688 | tmp = PyObject_GetAttrString(obj, "name"); |
| 6689 | if (tmp == NULL) goto failed; |
| 6690 | res = obj2ast_identifier(tmp, &name, arena); |
| 6691 | if (res != 0) goto failed; |
| 6692 | Py_XDECREF(tmp); |
| 6693 | tmp = NULL; |
| 6694 | } else { |
| 6695 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 6696 | return 1; |
| 6697 | } |
| 6698 | if (PyObject_HasAttrString(obj, "asname")) { |
| 6699 | int res; |
| 6700 | tmp = PyObject_GetAttrString(obj, "asname"); |
| 6701 | if (tmp == NULL) goto failed; |
| 6702 | res = obj2ast_identifier(tmp, &asname, arena); |
| 6703 | if (res != 0) goto failed; |
| 6704 | Py_XDECREF(tmp); |
| 6705 | tmp = NULL; |
| 6706 | } else { |
| 6707 | asname = NULL; |
| 6708 | } |
| 6709 | *out = alias(name, asname, arena); |
| 6710 | return 0; |
| 6711 | failed: |
| 6712 | Py_XDECREF(tmp); |
| 6713 | return 1; |
| 6714 | } |
| 6715 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6716 | int |
| 6717 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 6718 | { |
| 6719 | PyObject* tmp = NULL; |
| 6720 | expr_ty context_expr; |
| 6721 | expr_ty optional_vars; |
| 6722 | |
| 6723 | if (PyObject_HasAttrString(obj, "context_expr")) { |
| 6724 | int res; |
| 6725 | tmp = PyObject_GetAttrString(obj, "context_expr"); |
| 6726 | if (tmp == NULL) goto failed; |
| 6727 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 6728 | if (res != 0) goto failed; |
| 6729 | Py_XDECREF(tmp); |
| 6730 | tmp = NULL; |
| 6731 | } else { |
| 6732 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 6733 | return 1; |
| 6734 | } |
| 6735 | if (PyObject_HasAttrString(obj, "optional_vars")) { |
| 6736 | int res; |
| 6737 | tmp = PyObject_GetAttrString(obj, "optional_vars"); |
| 6738 | if (tmp == NULL) goto failed; |
| 6739 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 6740 | if (res != 0) goto failed; |
| 6741 | Py_XDECREF(tmp); |
| 6742 | tmp = NULL; |
| 6743 | } else { |
| 6744 | optional_vars = NULL; |
| 6745 | } |
| 6746 | *out = withitem(context_expr, optional_vars, arena); |
| 6747 | return 0; |
| 6748 | failed: |
| 6749 | Py_XDECREF(tmp); |
| 6750 | return 1; |
| 6751 | } |
| 6752 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6753 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6754 | static struct PyModuleDef _astmodule = { |
| 6755 | PyModuleDef_HEAD_INIT, "_ast" |
| 6756 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6757 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6758 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6759 | { |
| 6760 | PyObject *m, *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6761 | if (!init_types()) return NULL; |
| 6762 | m = PyModule_Create(&_astmodule); |
| 6763 | if (!m) return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6764 | d = PyModule_GetDict(m); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6765 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6766 | NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6767 | 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] | 6768 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6769 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6770 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6771 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6772 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6773 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6774 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6775 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6776 | 0) return NULL; |
| 6777 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 6778 | NULL; |
| 6779 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return |
| 6780 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6781 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6782 | < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6783 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6784 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6785 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6786 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6787 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6788 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6789 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6790 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6791 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6792 | 0) return NULL; |
| 6793 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return |
| 6794 | NULL; |
| 6795 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 6796 | NULL; |
| 6797 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 6798 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return |
| 6799 | NULL; |
| 6800 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 6801 | NULL; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 6802 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return |
| 6803 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6804 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6805 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6806 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6807 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6808 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6809 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6810 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6811 | return NULL; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 6812 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6813 | return NULL; |
| 6814 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return |
| 6815 | NULL; |
| 6816 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return |
| 6817 | NULL; |
| 6818 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 6819 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6820 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6821 | return NULL; |
| 6822 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return |
| 6823 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6824 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6825 | return NULL; |
| 6826 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 6827 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6828 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6829 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6830 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6831 | return NULL; |
| 6832 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 6833 | NULL; |
| 6834 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return |
| 6835 | NULL; |
| 6836 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return |
| 6837 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6838 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6839 | return NULL; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 6840 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6841 | return NULL; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 6842 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6843 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6844 | if (PyDict_SetItemString(d, "GeneratorExp", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6845 | (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6846 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6847 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6848 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6849 | return NULL; |
| 6850 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6851 | NULL; |
| 6852 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
| 6853 | NULL; |
| 6854 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return |
| 6855 | NULL; |
| 6856 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 6857 | NULL; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 6858 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6859 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6860 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6861 | 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6862 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6863 | 0) return NULL; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 6864 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6865 | return NULL; |
| 6866 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return |
| 6867 | NULL; |
| 6868 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return |
| 6869 | NULL; |
| 6870 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 6871 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6872 | if (PyDict_SetItemString(d, "expr_context", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6873 | (PyObject*)expr_context_type) < 0) return NULL; |
| 6874 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return |
| 6875 | NULL; |
| 6876 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 6877 | NULL; |
| 6878 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return |
| 6879 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6880 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6881 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6882 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6883 | return NULL; |
| 6884 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 6885 | NULL; |
| 6886 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 6887 | NULL; |
| 6888 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 6889 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6890 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6891 | return NULL; |
| 6892 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 6893 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6894 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6895 | return NULL; |
| 6896 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return |
| 6897 | NULL; |
| 6898 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6899 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6900 | return NULL; |
| 6901 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return |
| 6902 | NULL; |
| 6903 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return |
| 6904 | NULL; |
| 6905 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return |
| 6906 | NULL; |
| 6907 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return |
| 6908 | NULL; |
| 6909 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return |
| 6910 | NULL; |
| 6911 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return |
| 6912 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6913 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_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, "RShift", (PyObject*)RShift_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6916 | return NULL; |
| 6917 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 6918 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6919 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6920 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6921 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6922 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6923 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6924 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6925 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6926 | return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6927 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6928 | return NULL; |
| 6929 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return |
| 6930 | NULL; |
| 6931 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return |
| 6932 | NULL; |
| 6933 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return |
| 6934 | NULL; |
| 6935 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 6936 | NULL; |
| 6937 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 6938 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 6939 | NULL; |
| 6940 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 6941 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return |
| 6942 | NULL; |
| 6943 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 6944 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return |
| 6945 | NULL; |
| 6946 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 6947 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 6948 | NULL; |
| 6949 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 6950 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 6951 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6952 | if (PyDict_SetItemString(d, "comprehension", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6953 | (PyObject*)comprehension_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6954 | if (PyDict_SetItemString(d, "excepthandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6955 | (PyObject*)excepthandler_type) < 0) return NULL; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 6956 | if (PyDict_SetItemString(d, "ExceptHandler", |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6957 | (PyObject*)ExceptHandler_type) < 0) return NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6958 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6959 | 0) return NULL; |
| 6960 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return |
| 6961 | NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6962 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6963 | return NULL; |
| 6964 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 6965 | NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 6966 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 6967 | return NULL; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 6968 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 6969 | } |
| 6970 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6971 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6972 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6973 | { |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 6974 | init_types(); |
| 6975 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6976 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 6977 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6978 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 6979 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6980 | { |
| 6981 | mod_ty res; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6982 | PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, |
| 6983 | (PyObject*)Interactive_type}; |
| 6984 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6985 | int isinstance; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6986 | assert(0 <= mode && mode <= 2); |
| 6987 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6988 | init_types(); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6989 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 6990 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 6991 | if (isinstance == -1) |
| 6992 | return NULL; |
| 6993 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 6994 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 6995 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6996 | return NULL; |
| 6997 | } |
| 6998 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 6999 | return NULL; |
| 7000 | else |
| 7001 | return res; |
| 7002 | } |
| 7003 | |
| 7004 | int PyAST_Check(PyObject* obj) |
| 7005 | { |
| 7006 | init_types(); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7007 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7008 | } |
| 7009 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7010 | |